4 ms·
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
by ternaryoperator 11y ago
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 make a toy not a toy.
Every CS student in the world has written a toy VM just like this one.
- maguirre 11y agoI feel the same way. I went to read the post expecting a lot more than what I found and came away feeling both more knowledgeable than I thought I was and more ignorant for not knowing that I could get away with calling what a saw a "Virtual Machine"
- tptacek 11y agoIt's an instruction set, with an instruction dispatcher, a stack, and a register file. Why would it surprise you that someone would call it a VM? Are you maybe getting your signals crossed between the kind of VM this article is talking about (in the p-code sense of a VM) and virtualization systems?
- maguirre 11y agoI was not surprised that it was called a VM. I was surprised that I didn't know that!
- bitwize 11y ago"Virtual machine" here means "abstract machine" as in JVM or CLR, not "multiplexed hardware".
- tptacek 11y agoThe details you're talking about are pretty much just details; for instance, a foreign function interface for C functions (and thus system calls) is a pretty straightforward exercise that involves just a bit about the C ABI for your platform. It's much easier to teach someone who knows how to build a basic register machine how to set up the stack for a call to a C function than it is to teach someone who doesn't know how a register machine works how to build one. Also: there are reasons you might want to build a simple VM that has no access to system services and no notion of an exception. BPF is a good example of such a virtual machine. If there's something frustrating about this article to me, it's that it lacks a motivating example. Why would you want to build this VM? What are you compiling down to it from?
- dandrews 11y agoThat's a little ungenerous of you. The toy VM has presented an aha! moment to all of us at one time - or more than once, when you learn about Turing equivalence and the rabbit hole that leads from that. Skip the articles beneath your skill level and move along.
- ternaryoperator 11y agoAgreed, it was a bit ungenerous, esp. b/c I didn't realize til someone mentioned it below that the author was a teenager. My objection, though, is not what's above/below me, it's that given the title, I was expecting a deeper article only to find one that has appeared numerous times. It was frustration I was expressing more than condescension. But you're quite right in using the term "ungenerous." I appreciate the gentle reproof.
- tylermac1 11y agoConsidering the author is 16, I think it's a great write up/exercise.
- becausecomputer 11y agoThank you for raising this. My faith in humanity has been restored.
- rounak 11y agoYou're being unnecessarily harsh. If you got frustrated means it wasn't targeted towards you. Would appreciate if you did an advanced version of this writeup :)
- titanix2 11y agoSince 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-machine-modular-compilation/ https://netspring.wordpress.com/2015/05/10/toy-virtual-machi...