Live data from Hacker News

Implementing a Virtual Machine in C

blog.felixangell.com

51–54 of 54 posts

Re: Implementing a Virtual Machine in C

#51
post #50

This project is nice for educational purposes, but I wouldn't call it a VM, but instead a "bytecode interpreter". I think nowadays it is kind of a minimum requirement to have the intermediate code JIT-compiled (or at least compiled). I'm also missing a garbage collector, although that is not necessarily part of a VM (but often is). See NaCl for a counterexample. By the way, a project that I'd like to see is an effici…

Why is JIT a minimum requirement?

Re: Implementing a Virtual Machine in C

#52
post #50

This project is nice for educational purposes, but I wouldn't call it a VM, but instead a "bytecode interpreter". I think nowadays it is kind of a minimum requirement to have the intermediate code JIT-compiled (or at least compiled). I'm also missing a garbage collector, although that is not necessarily part of a VM (but often is). See NaCl for a counterexample. By the way, a project that I'd like to see is an effici…

It's interesting that VM for some doesn't mean the same as virtual machine. A bytecode interpreter _is_ a vm with the bytecodes representing opcodes of the machine. What this isn't is a 'modern VM' complete with JIT and GC.

Re: Implementing a Virtual Machine in C

#53

I find these kinds of very basic intro articles frustrating. They till the same ground over and over: a tiny instruction set implemented with a switch statement. None of the more difficult issues are addressed: exception handling, linking to libraries or other programs written for the same VM, portability of programs across architectures, accessing the OS for services like file I/O, time, etc.-- All the things that m…

Since I also wrote a toy VM where the toolchain supports linking of different code files (albeit the runtime doesn't implement CALL / RET) I decided to make a blog post about this specific topic.

https://netspring.wordpress.com/2015/05/10/toy-virtual-machi...

Re: Implementing a Virtual Machine in C

#54
I am starting to sound like a broken record, but here it goes. If you want a more complete tutorial on writing stack based virtual machines, check "The Elements of Computing Systems" and its accompanying course, http://www.nand2tetris.org/.

The book teaches you to build:

1) A CPU from basic electronics elements

2) An assembler to generate machine code

3) A bytecode VM that can be simulated and an assembler generator from the bytecode

4) A basic programming language that generates bytecode

5) An operating system using that language.

I'm midway through building the Assembler and VM myself :-).

Post reply on HN