Crates.io | calx_vm |
lib.rs | calx_vm |
version | 0.2.0 |
source | src |
created_at | 2021-09-17 19:56:46.816154 |
updated_at | 2024-01-22 17:12:29.844552 |
description | Stack-based VM, with dynamic data, for experiment |
homepage | https://github.com/calcit-lang/calx-vm |
repository | https://github.com/calcit-lang/calx-vm.rs |
max_upload_size | |
id | 453000 |
size | 92,093 |
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.
cargo install calx-vm
calx hello.cirru
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:
$ calx demos/if.cirru -s
[calx] start preprocessing
loaded fn: CalxFunc main (-> )
00 Const(I64(1))
01 Call("demo")
02 Const(I64(0))
03 Call("demo")
loaded fn: CalxFunc demo (I64 -> )
local_names: 0_$a .
00 LocalGet(0)
01 JmpIf(5)
02 Const(I64(20))
03 Echo
04 Jmp(8)
05 Const(I64(11))
06 Echo
07 Jmp(8)
08 Const(I64(3))
09 Echo
[calx] start running
11
3
20
3
[calx] took 67.250µs: Nil
--emit-binary filename
for encode functions into a binary file.
--eval-binary
for reading a binary input file to run.
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"
Find docs on https://docs.rs/calx_vm/ .
Highly inspired by:
Before Calx running the instructions, Calx performs preprocessing to them. There are several tasks:
block
and loop
are expanded since there are block-end
instructionsbr
and br-if
also expanded to jmp
and jmp-if
instructions, internallyThe codebase would be updated as I'm learning more about WASM.
MIT