-1
$\begingroup$

There is plenty of machine/assembly languages such as LC-3, DLX, etc. designed for educational purposes. I am looking for an educational VM, by VM I mean stack virtual machine that has instructions higher-level than assembly language, something similar to JVM, but much simpler, in order to make the implementation of a compiler for this VM a doable task for a single person in restricted time, but yet practical to be a compilation target for high-level OOP language. I failed to google one, are there any?

$\endgroup$
3
  • $\begingroup$ "yet powerful to be a target for high-level OOP language" - any Turing-complete language meets this criterion, so I'm not sure this really restricts solutions in the way you want. Did you mean to narrow it down further, e.g., by requiring that this translation can be implemented easily by a single person or something? $\endgroup$ – D.W. Jan 6 '20 at 22:55
  • $\begingroup$ "narrow it down further, e.g., by requiring that this translation can be implemented easily by a single person" - yes, that is exactly what I meant. $\endgroup$ – Vladislav Jan 6 '20 at 23:21
  • $\begingroup$ Please edit the question to reflect that. People shouldn't have to read the comments to understand what the question is asking. $\endgroup$ – D.W. Jan 6 '20 at 23:32
2
$\begingroup$

The WebAssembly has a formal specification, a reference interpreter implemented in OCaml, and a bunch of advanced tools. And it's the Real Thing.

If you're looking for something educational and do not care about usability, you can have a look at my Programming Langauges Zoo. Two languages have VMs and compilers:

  1. The functional language MiniML has a virtual machine and a compiler.
  2. The imperative language comm has a simple stack VM and a compiler. If you run it with the --code command-line option it will show you the compiled code.
$\endgroup$
2
  • $\begingroup$ Thanks! I've found your zoo before. I wonder is there something in between? Not huge real VM like JVM or WebAssembly and not extremely simple as VM for "comm" language? Something that at least has out-of-box support of methods, memory segmentation (static, stack, heap, etc.), float data type, etc.? $\endgroup$ – Vladislav Jan 7 '20 at 13:55
  • 1
    $\begingroup$ It might be hard to find what you're looking for because you're looking for something that has a low reward ("it's not a real VM") for relatively high effort ("it's got all sorts of features"). Good luck! $\endgroup$ – Andrej Bauer Jan 7 '20 at 16:00
0
$\begingroup$

Maybe the best would be to write a own little VM. Its not that complicated and if its for education you can use every programming language you want.

In this book the Author describes how to write a VM and a Compiler. (The Compiler targets the bytecode language of the VM. You could just skipp the Compiler Parts and only follow the VM tutorial.

https://www.craftinginterpreters.com/a-bytecode-virtual-machine.html

$\endgroup$
1
  • $\begingroup$ Thx for reply. I've seen this blog before, it's pretty similar to what I'm going to do, but as far as I understand the author still hasn't fully described the instruction set of his VM and invents new commands while implementing compiler. I would like to focus on compilation first and not to be distracted by designing VM. $\endgroup$ – Vladislav Jan 7 '20 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.