Skip to content

Commit

Permalink
New commands:
Browse files Browse the repository at this point in the history
- `Y` shuffles the current stack.
- `y` pushes the sign of a popped element (1, 0, or -1)
- `g` sorts the top two elements (ascending)
- `G` sorts the top two elements (descending)
- `a` does bitwise NOT on the top element.

This fills up all printable ascii.
  • Loading branch information
L3viathan committed May 10, 2017
1 parent 51010b4 commit 022440b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Aceto

This is Aceto v1.5.0
This is Aceto v1.6.0

Aceto is a simple stack language that is based on a 2D Hilbert curve grid. The
name is a reference to Aceto Balsamico (balsamic vinegar), and to
Expand Down Expand Up @@ -93,6 +93,8 @@ depends on the previous command.
insert it at the bottom of the stack.
- ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `Q`: Remove an item
from the bottom of the stack and push it.
- ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `Y`: Shuffle the
current stack.
- ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `X`: Exit the
interpreter abruptly.
- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) `x`: Pop a value and
Expand Down Expand Up @@ -158,6 +160,9 @@ depends on the previous command.
negation of a popped value.
- ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `~`: Invert the
popped element and push it. Will also negate booleans and reverse strings.
- ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `y`: Push the sign of
a popped element (1 for positive numbers, -1 for negative numbers, 0
otherwise).
- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) `A`: Take two
elements a and b from the stack and put the result of `a&b` (bitwise AND) on
the stack.
Expand All @@ -167,6 +172,8 @@ depends on the previous command.
- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) `H`: Take two
elements a and b from the stack and put the result of `a^b` (bitwise XOR) on
the stack.
- ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `a`: Push the result
of bitwise NOT of the popped element on the stack.
- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) `J`: Join the top two
elements as a string.

Expand Down Expand Up @@ -237,3 +244,7 @@ depends on the previous command.
push an increasing range on the stack: A popped `5` will push `1`, `2`, `3`,
`4`, `5`. Also works with negative numbers, in which case it will count down
from `-1`.
- ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `g`: Sort the top two
elements of the stack (ascending)
- ![#1589F0](https://placehold.it/15/1589F0/000000?text=+) `G`: Sort the top two
elements of the stack (descending)
39 changes: 35 additions & 4 deletions aceto.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from math import ceil, log2
from numbers import Number
from collections import defaultdict
from random import choice, random
from random import choice, random, shuffle
from math import e, pi
from docopt import docopt
from hilbert_curve import hilbert
Expand Down Expand Up @@ -487,6 +487,14 @@ def _invert(self, cmd) -> '~':
raise CodeException(f"Don't know how to invert {x!r}")
self.move()

def _bitwise_negate(self, cmd) -> 'a':
x = self.pop()
try:
self.push(~x)
except:
raise CodeException(f"Don't know how to invert {x!r}")
self.move()

def _restart(self, cmd) -> 'O':
if self.dir==1:
self.x, self.y = 0, 0
Expand Down Expand Up @@ -590,19 +598,19 @@ def _less_or_equal(self, cmd) -> 'w':
self.push(y<=x)
self.move()

def _and(self, cmd) -> 'A':
def _bitwise_and(self, cmd) -> 'A':
x = self.pop()
y = self.pop()
self.push(y&x)
self.move()

def _or(self, cmd) -> 'V':
def _bitwise_or(self, cmd) -> 'V':
x = self.pop()
y = self.pop()
self.push(y|x)
self.move()

def _xor(self, cmd) -> 'H':
def _bitwise_xor(self, cmd) -> 'H':
x = self.pop()
y = self.pop()
self.push(y^x)
Expand All @@ -626,6 +634,29 @@ def _range_up(self, cmd) -> 'Z':
self.push(element)
self.move()

def _order_up(self, cmd) -> 'G':
x = [self.pop(), self.pop()]
x.sort()
self.push(x.pop())
self.push(x.pop())
self.move()

def _order_down(self, cmd) -> 'g':
x = [self.pop(), self.pop()]
x.sort(reverse=True)
self.push(x.pop())
self.push(x.pop())
self.move()

def _shuffle(self, cmd) -> 'Y':
shuffle(self.stacks[self.sid])
self.move()

def _sign(self, cmd) -> 'y':
x = self.pop()
self.push(1 if x>0 else -1 if x<0 else 0)
self.move()


def getch():
fd = sys.stdin.fileno()
Expand Down

0 comments on commit 022440b

Please sign in to comment.