examples | ||
.gitignore | ||
benthos-vm.lua | ||
benthos.lua | ||
README.md |
Benthos
Under the waves, and at the bottom.
Benthos is a small experiment for a Nova front and runtime. Benthos is a space-seperate symbol syntax for Nova. The first symbol is used to divide rules, then symbols are read in pairs until no symbols are left. Special syntax is provided to construct /zuples
.
Currently, the compiler is hard coded with a single program, but it should work generally.
Benthos VM
Benthos VM is a small experiment at interpreting Nova's binary form. Each rule is encoded into a sequence of numerical identifiers. 0
is reserved for seperating the two parts of a Nova rule. Each instruction in the bytecode is one of two forms:
[label] [symbol]
[label] 1 [symbol]
A 1
is used to indicate a variable that needs to be binded, read, or written.
Thus a rules such as:
= # greet # creatures # ; #creatures and =
# greet # creatures # ;
#say hello #say and /#say
#say hello #say and /#say
#say hello #say and /#say
= # greet # creatures # ; #creatures $thing =
# greet # creatures # ;
#say hello #say $thing /#say
= # greet # creatures # ; =
Becomes:
0 2 3 2 4 2 5 6 10 0
2 5 2 4 2 3
7 9 7 10 7 8
7 9 7 10 7 8
7 9 7 10 7 8
0 2 3 2 4 2 5 6 1 1 0
2 5 2 4 2 3
7 9 7 1 1 7 8
0 2 3 2 4 2 5 0
Which is then directly interpreted as code.
Benthos ROM format
Benthos stores programs as a list of symbols (seperated by line breaks) and a binary encoding of the rule and state. The binary encoding uses the following system:
- Convert a symbol into binary
- Encode each rule delimiter as
00
- Encode each bit using
01
for0
and10
for1
- Each symbol is terminated by
11
- The ROM file is padded with
11
to the next byte aligment
For example the above rule set will get turned into the following:
00 1001 11 1010 11 1001 11 100101 11 1001 11 100110 11 101001 11 10011001 11 00
1001 11 100110 11 1001 11 100101 11 1001 11 1010 11
101010 11 10010110 11 101010 11 10011001 11 101010 11 10010101 11
101010 11 10010110 11 101010 11 10011001 11 101010 11 10010101 11
101010 11 10010110 11 101010 11 10011001 11 101010 11 10010101 11
00 1001 11 1010 11 1001 11 100101 11 1001 11 100110 11 101001 11 101110 11 00
101010 11 10010110 11 101010 11 101110 11 101010 11
10010101 11 1001 11 100110 11 1001 11 100101 11 1001 11 1010 11
00 1001 11 1010 11 1001 11 100101 11 1001 11 100110 11 00
1111