Skip to content

Commit

Permalink
Updated README for release (1.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
L3viathan committed Apr 15, 2017
1 parent 3ab0ab6 commit f99bc07
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 28 deletions.
78 changes: 60 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Aceto
This is Aceto v1.0.
This is Aceto v1.1.

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 @@ -53,37 +53,79 @@ prints the number `6` that is on the stack.
Unless otherwise specified, commands that perform an action with an element from
the stack end up removing it.

### General
- ` ` (a space): Do nothing. Any undefined character will also nop.
- `0`, `1`, `2`, ..., `9`: Push that number on the active stack.
- `s`: Swap the top two elements on the stack.
- `d`: Pop a value and push it twice (duplicate).
- `(`, `)`: Change the active stack to the left or right stack relative to the
currently active stack.
- `{`, `}`: Pop a value and push it on the stack to the left or right (but don't
change which stack is active).
- `X`: Exit the interpreter abruptly.
- `x`: Pop a value and ignore it.

### Movement, Conditions, and Catching
- `<`, `>`, `v`, `^`: Special commands that make the interpreter ignore the
shape of the Hilbert curve for this turn and instead move in the direction
indicated by the character.
- `W`, `E`, `S`, `N`: Like `<>v^`, but turn clockwise after execution.
- `u`: Reverse the direction the IP is moving.
- `?`: Move in a random direction.
- `|`, `_`: Special commands that make the interpreter ignore the shape of the
Hilbert curve for this turn and instead move to the point on the grid mirrored
vertically/horizontally, but only if the popped value is truthy.
- `#`: Like `|`/`_`, but mirrors both vertically and horizontally.
- `@`: Set the current cell to the catch cell. When a (normal) error occurs, jump here.
- `&`: Manually raise an error.
- `$`: Pop a value and assert that it is truthy. Otherwise, raise an error.
- `O`: Jump to the origin (0,0 or the bottom right cell, if the direction is
reversed)

### Arithmetics and Comparisons
- `+`, `-`, `*`, `%`: Perform that operation (`%` means modulo) with the top two
elements of the stack. For operations where the order matters, the operation
will take the top element on the stack as the second argument; i.e. `5`, `3`,
`-` will leave a 2 on the stack, not a -2.
- `/`, `:`: Perform division. `/` is integer division, `:` float division.
- `=`: Take two elements a and b from the stack and put the result of `a==b` on
the stack (a boolean value).
- `p`: Print the element on the stack.
- `r`: Read a string from the user and put it on the stack.
- `s`: Swap the top two elements on the stack.
- `i`: Pop a value, cast it to an integer (if possible, otherwise to 0), and put
the result on the stack.
- `f`: Like `i`, but with float.
- `I`: Pop a value, increment it, and push it.
- `D`: Pop a value, decrement it, and push it.
- `!`: Push the negation of a popped value.
- `~`: Invert the popped element and push it.

### Literals
- `0`, `1`, `2`, ..., `9`: Push that number on the active stack.
- `"`: Starts a string literal. This works pretty much like in other languages.
String literals are terminated with another `"`, but escaping (with a
backslash) works too. That means that `"\"Hello\\World\n" will result in
`"Hello\World\n`, where the `\n` is a newline character (`\t` is also
supported). The resulting string will be pushed on the active stack.
- `'`: Starts a character literal. The next character will be pushed on the
stack as a string. Escaping (for `\n`, `\t`, and `\\`) also works, but not for
`\'`, because `''` will already accomplish the desired effect (push a single
quote character).

### Casting
- `i`: Pop a value, cast it to an integer (if possible, otherwise to 0), and put
the result on the stack.
- `f`: Like `i`, but with float.
- `c`: Pop a value, convert it to the character of the unicode value and push
it. If the value doesn't correspond to a unicode codepoint, push `U+FFFD`
instead.
- `o`: The opposite of `c`; Pop a character and convert it to the number of its
unicode codepoint and push the result. When anything fails, push a 0 instead.
- `d`: Pop a value and push it twice (duplicate).
- `(`, `)`: Change the active stack to the left or right stack relative to the
currently active stack.
- `{`, `}`: Pop a value and push it on the stack to the left or right (but don't
change which stack is active).
- `!`: Push the negation of a popped value.
- `X`: Exit the interpreter abruptly.
- `|`, `_`: Special commands that make the interpreter ignore the shape of the
Hilbert curve for this turn and instead move to the point on the grid mirrored
vertically/horizontally, but only if the popped value is truthy.

### I/O
- `p`: Print the element on the stack.
- `r`: Read a string from the user and put it on the stack.
- `n`: Print a newline.
- `,`: Get a single character (without requiring a newline).

### Special
- `\`: Escapes the next character: It will be ignored.
- `P`, `e`, `R`: Push π, 𝑒, or a random float between 0 and 1.
- `.`: Repeat the previous command.
- `T`: Set the global timestamp to now. It is initialized to the time of script
start.
- `t`: Push the difference between now and the global timestamp.
15 changes: 5 additions & 10 deletions aceto.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def load_code(self, filename):
self.dir = 1
self.buf = ''
self.mode = 'command'
self.previous_cmd = ' '

def run(self):
while True:
Expand Down Expand Up @@ -115,6 +116,7 @@ def step(self):
if self.mode == 'command':
method = self.commands.get(cmd, Aceto._nop)
method(self, cmd)
self.previous_cmd = cmd
elif self.mode in ('string', 'string-escape'):
if cmd == '"' and self.mode == 'string':
self.push(self.buf)
Expand Down Expand Up @@ -406,16 +408,9 @@ def _getch(self, cmd) -> ',':
self.push(getch())
self.move()

def _putch(self, cmd) -> '.':
x = self.pop()
if type(x) == int:
try:
x = chr(x)
except:
x = '\ufffd'
first = x[:1]
print(first, end='')
self.move()
def _repeat(self, cmd) -> '.':
method = self.commands.get(self.previous_cmd, Aceto._nop)
method(self, self.previous_cmd)

def _catch_mark(self, cmd) -> '@':
self.catch_mark = self.x, self.y
Expand Down

0 comments on commit f99bc07

Please sign in to comment.