fn_vm
A lightweight register based VM that can be used to run functions. This will be the underlying VM used by the rigz_vm, I don't want to iron down the VM yet so this is a very simple base VM.
All problems in computer science can be solved by another level of indirection...
Except for the problem of too many layers of indirection.
Inspired by iridium
How it works
This is based on the idea that if my VM and AST are using the same underlying type for values, but not just a byte array, I'll be able to build a simpler runtime to bridge the gap between the two. Additionally, I didn't want to implement the same instructions I see in most other VMs when all I needed for now is to call a couple of rust functions.
fn_vm can store any value that implements the VMValue trait, there is an implementation for all primitive types.
So all you get are a few types, a builder, and the VM.
pub type VMFunction<T> = fn ;
pub type HCFFunction<T> = fn ;
This VM offers 4 instructions:
- NOP: No operation, move the pc to the next instruction
- LOAD: Load value into register, LOAD R1 10
- HCF: Halt and catch fire, stop the VM (an optional hcf_trigger can be passed in if this command is received)
- FN: Call a function, FN <out_register>
With IVD as a default command for any invalid command.
FN
This is by far the most complicated instruction since it's really a pass through to you.
Here's an example of calling it with the builder:
NOTE: into() is used to convert to a Length, from small_len to support up to usize args.