As part of getting better at Zig, I've been working on building a Compiler for about a month or so now. My understanding of Zig has just sky rocketed in the last month or so. It's easy when you know nothing. To the point that I can just start doing the thing I need to do. Might be a combination of working on the compiler and my decision to code without any code completion. Whatever it is, it feels fucking awesome to get better at something, something I was totally new to just a few months ago. Crazy how a little bit of consistent effort can do for you. I already know what I want to do next, Ray tracing! Why? Why not? It's something I've never done and I have always wondered how game developers do it. I'm not really interested in building Games but this part of it has had me intrigued for a long while now. Finding this series has been exactly what I have been looking for.
The truth is I'm not just getting better at Zig but at programming in general. I'm able to see patterns and just start building what I need. When I started on the compiler, I was quite dependent on the books guidance. I think this is more thanks to the author of the Compiler book for structuring the book as he has. I'd highly recommend it. It's an awesome book. After the first couple of chapters you can just get going with very little guidance. Throughout the process I've made the virtual machine behave as I would want it to and diverted from the book whenever. It's crazy how much you can just learn now. Pick up a book and just go, you are free to build anything. It's my favorite thing about programming, you don't need anyones permission to build anything you want, literally.
Back to virtual machines, it's really just a regular program with bounded resources. Want to use a GB of memory? Just change a variable. Want half a CPU? Sure. The machine that I'm building is quite simplistic, but none the less, it is one. The CPU is the programming language that you write your VM with. I'm not sure how to specify how much CPU it is allowed to use, but I've seen somewhere in the standard library you can do this too. The beauty of it all? It'll run everywhere the underlying language runs in. Which for Zig is mostly everywhere I think. It is a fun experience, if you are a programmer and have always wanted to build one, I'd say go for it. If I can, anyone can.
Also, never thought I'd one day say that I built a virtual machine. What a wild time.