2 ms·
Hey folks just saw this, author here. Happy to answer questions!
by eatonphil 5y ago
Hey folks just saw this, author here. Happy to answer questions!
- FullyFunctional 5y agoAlways happy to read compilers, Rust, or VMs. One quick and cheap trick that can help your VM, especially when you have a lot of arithmetics: explicitly represent the top of stack. Eg. Instruction::Add => { let left = data.pop().unwrap(); top = left + top; pc += 1; } Instruction::Subtract => { let left = data.pop().unwrap(); top = left - top; pc += 1; } Instruction::LessThan => { let left = data.pop().unwrap(); top = if left < top { 1 } else { 0 }); pc += 1; }
- eatonphil 5y agoYep you're right. I think I made a note if it in the post at one or two points that I'm inefficiently doing these stack pushing/popping.
- KineticLensman 5y agoNo questions (yet) but I found this a really good post. I'm a Rust newbie and I've coincidentally just started working through 'Crafting Interpreters' using Rust as my implementation language. Some of your code has helped clarify things in my mind. My actual long-term goal is to build a VM in Rust and then use this to re-do the Make A Lisp project [0]. I completed this a couple of years ago using C# but felt vaguely uneasy that I was using C# to do the heavy lifting associated with garbage collection, etc. [0] https://github.com/kanaka/mal https://github.com/kanaka/mal