If you want to understand how Nim compiler works, start by looking under the hood of the Nim0 compiler, a Nim-compatible toy language with a compiler and an emulator for a RISC CPU. This project is much smaller than the Nim compiler, everything being packed in 5 Nim files. But most important is that all this is explained in Niklaus Wirth's [Compiler Construction](https://www.projectoberon.org/) book that you'll find in the `misc` directory with cross-references in source code.
Nim0 is a very limited subset of Nim ( _every Nim0 source is valid Nim syntax with very limited changes_ ). Many features are missing, like functions or the `result` instruction. But it still can be used to write quite complex programs like a Sudoku solver (look at the examples directory). * Repository: <https://gitlab.com/pmetras/nim0> * Documentation: <https://pmetras.gitlab.io/nim0/> Under Linux, you can easily try it and run your first program in 5 commands: nimble develop nim0 # Install nim0 cd nim0 nim build # Build nim0 compiler ./nim0 comp examples/Factorial # Compile the Factorial example ./nim0 run examples/Factorial # Run Factorial until overflow... Run How can you use Nim0? * To learn how a compiler works. Try adding new features or optimising code generation. And then jump hacking Nim compiler... * To learn how an emulator works and learn a RISC assembler. Change the RISC target for a real CPU... * As a support for a computer science course. So small that your students will grab it whole and easier to read than C. Let them discover Nim... * Whatever you want. I needed a small language to try some ideas. Try yours...
