Honing my craft

Recurse Center Day 9

August 20, 2020

The Rust virtual machine works on binary and unary operations for double math, with grouping and precedence, from stdin OR reading from a file.

Virtual Machine in action

I’m really excited with this. The steps are:

  1. Read into a String, which is a heap-allocated type in Rust.
  2. The entry point hands the string over to the virtual machine which allocates a “chunk” and gives the chunk to the compiler.
  3. The compiler loads that into a scanner and starts to parse token by token
  4. When the compiler calls advance, the scanner grabs a token, hands the token back to the compiler and the compiler parses it - if it’s a number, it creates a constant, if it’s a parenthesis, it assumes grouping, etc.
  5. The compiler writes these opcodes to the chunk
  6. When the compiler is done grabbing tokens and turning into opcodes, it finishes and returns a compiler InterpretResult
  7. When the VM sees the compiler is done, the chunk is full of instructions
  8. The VM then walks the instructions and works with an internal stack and instruction pointer which is the index of the next instruction to run

Overall we are successful. Next step in the book is to add more types of values (bools, for example).

I also got Nand2Tetris week 2 done, which is really neat. Making an ALU from basic chips like Mux was great. I only got stumped when I forgot that a chip can have multiple outputs. Excited to try and get all the hardware stuff done during RC.

Dmitry Soshnikov’s class on finite automata is also going well - I need to try and finish it this week, so I might make that my goal for tomorrow. Additionally, I need to finish the parsing chapter from Engineering a Compiler. Whew, lots of stuff to do and such little time!.


Nikhil Thomas

I work and live in Brooklyn, NY building software.