mossprescott / pynand

Nand2Tetris in Python.
Other
12 stars 3 forks source link

New simulator: codegen #17

Closed mossprescott closed 4 years ago

mossprescott commented 4 years ago

This is an entirely new, simpler, faster, less flexible simulation. Both simulators expose the same API so it's easy to try either one, run the same tests, etc.

Almost 100x faster, this simulation can run Pong.asm (barely) fast enough to actually play. It assumes that all the relatively generic components are defined in the expected way (i.e. the tests pass), and substitutes simple native Python for each of them. And it generates straight-line Python code for the entire evaluation, which now boils down to instructions decode and the ALU function.

This can still be used to simulate any CPU design that mostly uses the same components, including MemorySystem.

Would still like to get another 2-5x speed out of this for true playability, but this is good enough to demo.