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.
I’m really excited with this. The steps are:
- Read into a String, which is a heap-allocated type in Rust.
- The entry point hands the string over to the virtual machine which allocates a “chunk” and gives the chunk to the compiler.
- The compiler loads that into a scanner and starts to parse token by token
- 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. - The compiler writes these opcodes to the chunk
- When the compiler is done grabbing tokens and turning into opcodes, it finishes and returns a compiler
InterpretResult
- When the VM sees the compiler is done, the chunk is full of instructions
- 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!.
I work and live in Brooklyn, NY building software.