VM for statically typed language

I'm writing a little language to be embedded in my app (GitHub - audulus/lyte: A programming language for Audulus nodes) and for iOS I'll need to use an interpreter because Apple doesn't allow JIT.

Wondering how I can make a reasonably fast VM interpreter in rust. Typically a statically typed language would be compiled to bytecode, without type information (like Java). But this would seem to involve a lot of unsafe when interpreted, no?

I'm aware of Miri as something to look at, but it doesn't seem to be performance-oriented (is that right?).


No, not really. What part of interpretation makes you think it needs to be unsafe?

The design of wasm3 is probably interesting if you're looking for a performance-oriented design: wasm3/Interpreter.md at main · wasm3/wasm3 · GitHub

1 Like

Ok, reading here (transmute in std::mem - Rust) I guess I can reinterpret certain types without being unsafe. So all my loads into VM registers can be done with from_ne_bytes. Perhaps I'm good to go :slight_smile:

Taking some inspiration from wasm3. How does this look? lyte/vm.rs at main · audulus/lyte · GitHub

Ok I just realized that rust doesn't do tail calls in debug, so there goes that design! Back to a simple match loop.