Comment by OskarS
1 year ago
Yeah, that's the way virtual machines have been written forever, some version of
for instruction in instructions {
switch (instruction) {
case OPCODE_X: //....
case OPCODE_Y: //....
case OPCODE_Z: //....
}
}
This is how VMs have been written since the dawn of time (or using computed gotos, another non-standard addition to C). It has problems though, like the fact that the `switch` branch is extremely unpredictable, and that you get a massive function which is hard to optimize. This [[musttail]] trick is a huge improvement. But yeah, if you got to support compilers that don't have [[musttail]], you in essence have to have two implementations, the [[musttail]] one and the loop/switch one.
No comments yet
Contribute on Hacker News ↗