Whitespace language VM written in Zig.
| program | Remove programs. | |
| src | Add logs and annotations. | |
| .gitignore | Initial commit | |
| build.zig | Finish CLI interpret and execute. | |
| build.zig.zon | Fix problems. | |
| LICENSE | Initial commit | |
| README.md | Add logs and annotations. | |
whitespace-vm (Zig)
A Whitespace VM written in Zig, exploring:
- pointer-free data structures (PWP style)
- inline big integer arithmetic
- memory-predictable execution
This is an experimental project focused on low-level design.
Status
- ✅ Core VM
- ✅ CLI
How to run
git clone https://codeberg.org/violeshnv/whitespace-vm-zig.git
cd whitespace-vm-zig
# print 1 to 10
zig build run -Doptimize=ReleaseSafe -- run program/count.ws
count.ws is from Whitespace language's official website.
Example:
m@linux:~/whitespace-vm-zig$ zig build run -Doptimize=ReleaseSafe -- interpret program/count.ws count
m@linux:~/whitespace-vm-zig$ zig build run -Doptimize=ReleaseSafe -- execute count
1
2
3
4
5
6
7
8
9
10
m@linux:~/whitespace-vm-zig$ zig build run -Doptimize=ReleaseSafe -- debug count
::> ?
error(arg): failed to parse '?': error.UnmatchedUnion
type 'help' to get help
::> help
Commands for debug:
step [<int>] Run n steps, default n is 1, if n is 0, run until the program
finishes or waiting for input.
restart Restart the program. Input will be cleared.
input "<string>" Input something to the program, the qoutes are required.
Must input at once, e.g., you cannot input "1" and then input "2" to
make the program receive "12", you have to input "12" at once.
Next input will overwrite the previous input.
To input ", just place it in the string and make sure it
is not the first or last quote.
To input ,円 use \\; to input newline, use \n.
show <stack|heap|flow> show the content of stack, heap or flow.
::> step 1
::> show stack
----- stack top -----
0: 0x0000000000000001
---- stack bottom ---
::> show heap
----- empty heap ------
::> show flow
0 | push | 0x0000000000000001
1 | mark | 0x0000000000000143
2 | dup
3 | out_int
4 | push | 0x000000000000000a
5 | out_char
6 | push | 0x0000000000000001
7 | add
8 | dup
9 | push | 0x000000000000000b
10 | sub
11 | jump_z | 0x000000000000000e // 14
12 | jump | 0x0000000000000002 // 2
13 | mark | 0x0000000000000145
14 | discard
15 | end
16 | mark | 0x0000000001616464
17 | add
18 | back
19 | mark | 0x0000017772697465
20 | dup
21 | retrieve
22 | dup
23 | jump_z | 0x000000000000001d // 29
24 | out_char
25 | push | 0x0000000000000001
26 | add
27 | jump | 0x0000000000000014 // 20
28 | mark | 0x0000000000000177726974655f656e64
29 | discard
30 | discard
31 | back
32 | mark | 0x0000000172656164
33 | dup
34 | dup
35 | in_char
36 | retrieve
37 | dup
38 | push | 0x000000000000000a
39 | sub
40 | jump_z | 0x000000000000002e // 46
41 | discard
42 | push | 0x0000000000000001
43 | add
44 | jump | 0x0000000000000021 // 33
45 | mark | 0x0000000000000001726561645f656e64
46 | discard
47 | push | 0x0000000000000001
48 | add
49 | push | 0x0000000000000000
50 | store
51 | back
52 | mark | 0x016e65776c696e65
53 | push | 0x000000000000000a
54 | push | 0x000000000000000d
55 | out_char
56 | out_char
57 | back
pc=1
::>