How to Start Learning about Virtual Machines and Language Design?

April 20, 2025 6 answers
Asked by left.handed.scissors
Hey everyone! I'm diving into the world of virtual machines, specifically stack-based and register-based types. My goal is to build one from the ground up because I'm really interested in how languages like Java function. I'm not aiming for anything groundbreaking, but I'm keen to understand the mechanics behind language designโ€”like why certain languages are structured in specific ways and which ones are optimized for portability, much like Java. So, I'm looking to learn about various virtual machine types, especially the stack-based and register-based approaches. Any advice on where to start?

Answers

vm7~resume
I found some great resources online for building VMs, like courses and tutorials. Here are a few: - https://www.udemy.com/course/virtual-machine/ - https://www.jmeiners.com/lc3-vm/ - https://craftinginterpreters.com/a-virtual-machine.html - https://dmitrysoshnikov.teachable.com/p/virtual-machine - https://www.andreinc.net/2021/12/01/writing-a-simple-vm-in-less-than-125-lines-of-c - https://dev.to/bosley/building-a-virtual-machine-3ocj - https://blog.subnetzero.io/post/building-language-vm-part-00/
Reply to this answer
5 snowshoes drying
Definitely look into WebAssembly (WASM) if you want to broaden your understanding of virtual machines.

left.handed.scissors: Iโ€™ll check that out! Thanks for the suggestion!

Reply to this answer
irq_5edge
If you're into designing programming languages, I recommend starting with a simple Lisp. It could be your foundation for everything else. Check out the book 'Structure and Interpretation of Computer Programs' for a deeper dive.

left.handed.scissors: Thanks for the recommendation! Iโ€™ll definitely give it a read.

Reply to this answer
quasar_815
Iโ€™d suggest doing a bit of research first to formulate more specific questions. Just asking 'how do I start?' can be too broad. If you're still stuck, talking to an AI like ChatGPT could help!

~+NearlyThere: I appreciate it! I did some digging, but I think a conversation would be more helpful for me. Thanks, though!

Reply to this answer
distant thunder fan
Instead of focusing on VM implementation right away, you might want to start by writing a parser for your language, which can create an Abstract Syntax Tree (AST) and execute it directly. This can be a faster way to get going than diving into a VM.

left.handed.scissors: Haha, Iโ€™m interested in all aspects! But I think Iโ€™ll follow your advice. Iโ€™ve done some parsing work, but Iโ€™m unsure whether to prioritize the VM or the parser. Thanks for the insight!

Reply to this answer
!limit0
I've tinkered with a few languages and found stack-based languages are usually easier to implement than register-based ones. Register-based VMs can be faster and easier to convert to native code later if you want to add JIT/AOT. If you're interested in speed, consider using direct threaded code, which is like stack-based but generates machine code instruction directlyโ€”no need for a separate VM. A good start would be learning how to write a lexer, a parser for an AST, and then an emitter for generating bytecode. Itโ€™s totally possible to skip the AST for simpler languages, too!

left.handed.scissors: Thank you so much for the detailed info! I began crafting my lexer but got puzzled about whether I should focus on the VM or the language itself first. The tidbit about the Java compiler is super helpful!

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions