I was tricked into writing a VM while doing Advent of Code last year and it really deepened my understanding of programming (e.g., on how to implement simple coroutines). Advent of Code is supposed to be 25 daily programming puzzles leading up to christmas. I went in thinking they were going to be algo/datastructure tasks but half of them were actually about implementing and using a VM for a made up assembly language…
Funny that VM related days are all prime numbers :). EDIT: No they're not, I wasn't fully awake, sorry.
Write Your Own Virtual Machine
11–20 of 44 posts
Re: Write Your Own Virtual Machine
#12Earlier quoted context omitted.
Funny that VM related days are all prime numbers :). EDIT: No they're not, I wasn't fully awake, sorry.
Not all of them, but a lot seem to be.
Re: Write Your Own Virtual Machine
#13Earlier quoted context omitted.
Funny that VM related days are all prime numbers :). EDIT: No they're not, I wasn't fully awake, sorry.
Not all of them, but a lot seem to be.
The mathematician thinks, "3 is prime, 5 is prime, 7 is prime, 9 is not prime -- nope, not all odd numbers are prime."
The physicist thinks, " 3 is prime, 5 is prime, 7 is prime, 9 is not prime -- that could be experimental error -- 11 is prime, 13 is prime, yes, they're all prime."
The engineer thinks, " 3 is prime, 5 is prime, 7 is prime, 9 is prime, 11 is prime, ..."
https://users.cs.northwestern.edu/~riesbeck/mathphyseng.html
Re: Write Your Own Virtual Machine
#14[1]https://research.vmware.com/publications/hardware-and-softwa...
Re: Write Your Own Virtual Machine
#15You can only run the already compiled binary files for it.
If you want to write something new you will need to do it in binary. If you want to write in assembly you will need to write an assembler, or find one online.
Re: Write Your Own Virtual Machine
#16I once wrote my own virtual machine in college, complete with compiler and assembler, and I cannot recommend doing this enough. Especially the virtual machine part is not nearly as difficult as you would imagine, and to this day (15 years later) I still rely on the things i learned here. The knowledge you gain from implementing a virtual machine translates reasonably well to inner workings of a CPU, and you’ll have a…
> It will be completely obvious to you why “i++” is slower than “++i” ...but it's not! All you have to do is perform the most basic of optimizations: check, before generating code for an expression, if that expression is used. If not, then don't bother generating an intermediate for the result. Source: making a c compiler, just implemented this optimization today. (In an 'industrial-grade compiler', you probably want…
Re: Write Your Own Virtual Machine
#17Re: Write Your Own Virtual Machine
#18I once wrote my own virtual machine in college, complete with compiler and assembler, and I cannot recommend doing this enough. Especially the virtual machine part is not nearly as difficult as you would imagine, and to this day (15 years later) I still rely on the things i learned here. The knowledge you gain from implementing a virtual machine translates reasonably well to inner workings of a CPU, and you’ll have a…
> It will be completely obvious to you why “i++” is slower than “++i” ...but it's not! All you have to do is perform the most basic of optimizations: check, before generating code for an expression, if that expression is used. If not, then don't bother generating an intermediate for the result. Source: making a c compiler, just implemented this optimization today. (In an 'industrial-grade compiler', you probably want…
For VMs, what is relevant is whether you implement an "inc (reg)" or not, that is if you choose to take the RISC path (small set of mostly orthogonal instructions) or the CISC path (lots of microcode, things like "repnz scasb" in x86 assembly or elaborate addressing schemes).
This actually somewhat a false dichotomy, as you can have a RISC-style instruction set plus a few "high level" instructions for things you expect to do a lot - like, for instance, array operators à la APL/J.
Re: Write Your Own Virtual Machine
#19I once wrote my own virtual machine in college, complete with compiler and assembler, and I cannot recommend doing this enough. Especially the virtual machine part is not nearly as difficult as you would imagine, and to this day (15 years later) I still rely on the things i learned here. The knowledge you gain from implementing a virtual machine translates reasonably well to inner workings of a CPU, and you’ll have a…
Re: Write Your Own Virtual Machine
#20I rarely run into solutions that fundamentally expand my perspective these days but this one did.