3 ms·
Well, the thing about this approach, I think, is that your code itself essentially becomes something like an image of your syntax tree (a la recursive descent p
by joe_the_user 7y ago
Well, the thing about this approach, I think, is that your code itself essentially becomes something like an image of your syntax tree (a la recursive descent parsing). That's fine if you want a sort of "toy" interpreter or interpreter that doesn't care about speed much.
But you're also using bytecode, which involves more caring about speed, so you've got a bit of a mismatch - as your code tries to match the multiple layers you're skipping, your code will get more complicated or your VM gets more arbitrary, so of the situation you have here.
- munificent 7y ago> or interpreter that doesn't care about speed much. This is the same approach taken by Lua and many of the original Pascal compilers, which had to run on very slow hardware, so there's pretty good precedent that you can get adequate performance. > But you're also using bytecode, which involves more caring about speed, so you've got a bit of a mismatch I wouldn't describe it as a mismatch as much as it is a trade-off. Because the compiler only has a peephole view into the source when it needs to generate code, many optimizations are off the table. However, because we have full control over the instruction set, we can sometimes tweak the bytecode format in order to more naturally align with the compiler. In return for not needing an intermediate representation or AST, we get a much simpler compiler, especially in C where you have to worry about memory management.
- joe_the_user 7y agoIt is reasonable to say this is a tradeoff. However, one of the costs is having the VM structure depend on the language structure, which kind of a software engineering no-no. But yes, tradeoffs always happen.
- munificent 7y ago> which kind of a software engineering no-no. Optimization along any axis (code size, simplicity, compile-time performance, runtime performance, memory size, etc.) always involves some level of violating software engineering norms. One way to think of software engineering is that it's the practice of optimizing long-term developer velocity. Any practice that optimizes other factors generally does so at the expense of that. That's OK. Meta-software engineering is about knowing when long-term maintainability is the right factor to optimize for. :)
- kazinator 7y agoThat is really only a political no-no. The issue is that if your VM takes off in popularity, some people get upset that it's a poor fit for their favorite language. Technically, it's perfectly fine for a VM to be designed so that the semantic gap is small between it and the intended language family.