Nand2Tetris final project
- Parses HDL files with
IN,OUT, andPARTSsections - Simulates both built-in and composed chips recursively
- Supports testing via CSV-style test vectors
- Command-line interface using Typer
- Strict linting, formatting, and typing
- Includes unit tests and test coverage reporting
-
Install Dependencies
pip install -r requirements.txt
-
Run the CLI
python3 -m n2t.runner test -
Run Unit Tests
pytest
-
Check Linting, Types, and Format
black n2t tests isort n2t tests flake8 n2t tests mypy n2t tests
-
Run Coverage
pytest --cov=n2t
This project includes a Makefile to simplify development tasks. Here are the available commands:
make lint # Run black, isort, flake8, and mypy
make test # Run all unit tests
make coverage # Show test coverage report
make clean # Remove cache and temporary filesInstead of typing multiple commands, use make to run them in one go.
Note: You must have make installed (typically preinstalled on Unix/macOS).
n2t/
├── core/ # HDL parser, chip model, simulator
├── util/ # CSV test file parser
├── runner/ # Typer CLI entry point
tests/ # Unit tests and test vectors
chips/ # HDL chip definitions
a,b; out
0,0; 0
0,1; 0
1,0; 0
1,1; 1
These are hardcoded and not parsed from HDL:
- And
- Or
- Not
- Nand
You can test your own custom HDL chips by following these steps:
-
Place your
.hdlfile into thechips/directory.
For example:chips/MyChip.hdl -
Create a matching test vector file and place it in
tests/e2e/with the same base name.
For example:tests/e2e/MyChip.csvExample CSV test format:
a,b; out 0,0; 0 1,1; 1 -
Run the CLI to test all available chips:
python3 -m n2t.runner test
The runner will automatically detect and test any HDL files for which a matching .csv file exists in tests/e2e/.