blob: 2392094bc4011a9dc360c739365a329d4d139989 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# slang
…a experimental Forth-like stack language implemented in D.
## Example
1 i $
§ incr dup @ 1 + swp $ ;
§ print @ . pop ;
§ withinBounds @ 10 < ;
§ loop i withinBounds if i print i incr loop then else ;
loop
The above _slang_ code to be entered in the repl prints the numbers from 1 to 9. The repl may be compiled and executed using `dub run` in the project directory. Check the `example` directory for further further demonstrations.
## Words
Currently implemented primitives:
| Word | Description |
| --- | --- |
| `§` | Custom word definition |
| `$`, `@` | Single token variable binding, resolution |
| `if`, `then`, `else` | Conditional primitives |
| `+`, `*`, `/`, `%` | Common artithmetics |
| `.` | Non destructive printing of top-of-stack |
| `pop` | Remove uppermost stack element |
| `dup` | Duplicate top-of-stack |
| `swp` | Swap the first two stack elements |
| `over` | Place a copy of the second stack element on top-of-stack |
| `rot` | Rotate the top three stack elements |
| `true` | Write true boolean value to top-of-stack |
| `false` | Write false boolean value to top-of-stack |
| `not` | Negate boolean value |
| `and` | Boolean and |
| `or` | Boolean or |
| `<` | Compare size of two integers |
| `=` | Compare equality of two stack values |
| `#` | Debug word printing the whole stack to _stdout_ |
|