3 ms·
Always 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 repres
by FullyFunctional 5y ago
Always 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.