Calx VM
Calcit runner can be slow being a dynamic language. Calx VM trying to provide some helper tools for faster computation of very simple but repeated tasks. Ideally Calcit should use WASM for CPU heavy computations.
Usages
it starts with a main function:
fn main ()
const 1
call demo
const 0
call demo
fn demo (($a i64) ->)
local.get $a
if (->)
do
const 11
echo
do
const 20
echo
const 3
echo
-s to show instructions:
)
))
)
))
)
)
)
)
))
)
))
)
))
--emit-binary filename for encode functions into a binary file.
--eval-binary for reading a binary input file to run.
Syntax Sugar
Code of:
fn main ()
i.add
const 1
i.mul
const 2
const 3
echo
dup
assert "|expected 7"
i.eq
const 7
is desugared to:
fn main ()
const 2
const 3
i.mul
const 1
i.add
dup
echo
const 7
i.eq
assert "|expected 7"
Instructions
Find docs on https://docs.rs/calx_vm/ .
Highly inspired by:
- WASM https://github.com/WebAssembly/design/blob/main/Semantics.md
- Lox https://github.com/Darksecond/lox/blob/master/lox-vm/src/bettervm/vm.rs
Preprocess
Before Calx running the instructions, Calx performs preprocessing to them. There are several tasks:
blockandloopare expanded since there areblock-endinstructionsbrandbr-ifalso expanded tojmpandjmp-ifinstructions, internally- stack size is checked to ensure it's consistent among branches, and tidied up at function end
- local variables are renamed to indexes
The codebase would be updated as I'm learning more about WASM.
License
MIT