This post is part of the Stack Based Virtual Machines series. In the previous part we have added many instructions to our virtual machine, such as jumps and local variables. It’s now time to discuss how we can use these instructions to implement an “if” statement, or a “while” loop. The complete unit tests implementing the code samples below can be on github. Implementing an IF Let start by implementing an if statement in our bytecode.| andreabergia.com
This post is part of the Stack Based Virtual Machines series. In the previous part we have started writing some code for our stack based virtual machine. In this part, we’re going to extend the catalog of instructions that our CPU can support. The code for this article can be found on github. Arithmetics Our VM can already handle additions, so teaching it to add subtractions, multiplications and (integer) division won’t be very hard.| andreabergia.com