4 ms·
Implementing a VM is a unique experience. You take some bytecode that's initially a meaningless blob, sketch out an execution environment, and start implementin
by nathell 6y ago
Implementing a VM is a unique experience. You take some bytecode that's initially a meaningless blob, sketch out an execution environment, and start implementing opcodes, one by one, and the blob actually starts doing real things.
Back at uni, I've done this with the ZMachine [1], in (non-idiomatic, newbie) Haskell [2], using Zork 1 as the blob. Sixteen years after, I remember the elation when my interpreter first printed out the familiar message:
You are standing in an open field west of a white house, with a boarded front door.
[1]: https://en.wikipedia.org/wiki/Z-machine https://en.wikipedia.org/wiki/Z-machine
[2]: https://github.com/nathell/haze https://github.com/nathell/haze
- AndrewDavis 6y agoIt truly is unique. I wrote a chip8[1] interpreter shortly after finishing my first year of university and was still a very novice programmer. My implementation was poor even by novice standards, i knew there was a lot of spaghetti but I didn't mind. Implementing each opcode was like beating a level in a video game - and it worked, not perfectly and with some unsolved bugs. Tetris worked flawlessly though. [1]https://en.wikipedia.org/wiki/Chip-8 https://en.wikipedia.org/wiki/Chip-8
- cardiffspaceman 6y agoI did this with the Z80 machine code variant that runs in the GameBoy. I defined my goal as, run the boot rom until it jumps to the game. The boot rom makes sound and moves a logo on the screen. Not the first person to do this and not the last. But interesting projects you can do after you get one going is, study on why Android doesn't run JVM bytecode, or come up with a better byte code for Java/Scala.