Thanks for helping with an open-source HAL/S compiler. This page covers the
development setup, the repository layout, and how to run the four test
layers. Install first as described in the README
(use pip install -e ".[dev]" for pytest, coverage, xdist and the linters).
Issues and pull requests are welcome on GitHub.
- Participation is covered by the Code of Conduct.
- Report security problems privately as described in SECURITY.md, not in a public issue.
- Contributions are accepted under the project license, GPL-3.0-or-later.
New source files start with the same two-line header as the existing
ones (
SPDX-License-Identifierand a copyright line). - Sign off every commit (
git commit -s). TheSigned-off-by:line certifies the Developer Certificate of Origin: that you wrote the change or otherwise have the right to submit it under the project license. - Pull requests must pass the
cicheck (pytest on Python 3.9 and 3.12). Changes under.github/or to the scripts intests/regression/get extra scrutiny because they execute code.
resnik/
├── src/resnik/ # Main package (clean imports!)
│ ├── lexer/ # Lexical analyzer
│ │ ├── lexer.py # Modern lexer implementation
│ │ └── tokens.py # Token definitions
│ ├── parser/ # Syntactic analyzer
│ │ ├── parser.py # Modern parser implementation
│ │ ├── ast_nodes.py # AST node classes
│ │ └── symbol_table.py # Symbol table
│ ├── backend/ # Rust code generator (host + no_std targets)
│ │ ├── codegen.py # HAL/S → Rust lowering, target profiles, Cargo scaffold
│ │ ├── rust_emitter.py # Rust source emission helpers
│ │ └── type_mapper.py # HAL/S → Rust type mapping
│ ├── cli.py # Beautiful CLI with Click + Rich
│ ├── driver.py # Reusable compile pipeline (used by the CLI and the IDE)
│ ├── templib.py # Template-library (.tpl) generation for --gen-tpl
│ ├── types.py # Type definitions
│ └── exceptions.py # Custom exceptions
│
├── ide/ # Desktop IDE (Tk) — see ide/README.md
│ ├── resnik_ide/ # resnik-ide package: editor, log pane, driver bridge
│ └── tests/ # IDE tests (Tk tests skip without a display)
├── start_ide.sh # Launch the IDE (uses resnik-venv if present)
│
├── tests/ # Test suite
│ ├── test_lexer/ # Lexer unit tests
│ ├── test_parser/ # Parser unit tests
│ ├── test_backend/ # Codegen / type-mapper unit tests
│ ├── test_driver/ # Compile-driver + CLI wrapper tests
│ ├── fixtures/ # HAL/S snippets used by unit tests
│ └── regression/ # End-to-end compile of example .hal programs
│
├── docs/ # Specifications, guides, HAL/S examples
├── examples/ # Symlink to docs/HAL-S-Source-Code-Examples
└── pyproject.toml # Single source of truth!
Resnik has four test layers:
| Layer | Command | What it covers | Needs rustc? |
|---|---|---|---|
| Unit tests | python -m pytest |
Lexer, parser, and Python-side Rust codegen | No |
| Regression | ./tests/regression/run_regression.sh |
Compile example .hal files to binaries and run them |
Yes |
| Embedded build | ./tests/regression/run_embedded_build.sh |
cargo build a curated example list for esp32-c3 (+ one cortex-m case) — proves generated no_std firmware compiles; no hardware. Skips cleanly if cargo/targets are missing; first run needs the network for crates.io |
Yes (+ rustup targets) |
| Executive semantics | ./tests/regression/run_exec_semantics.sh |
Compiles the emitted hal_exec cyclic executive against an injected fake clock and asserts priority order, declaration-order ties, one-shot slots, self-TERMINATE, no-drift periods and overrun reporting. Skips cleanly if rustc is missing |
Yes |
Run the unit tests on every change. Run the regression suite before a release
or when you touch code generation, the CLI, or an example under
docs/HAL-S-Source-Code-Examples/.
The unit suite is pytest. It imports resnik and checks
tokens, ASTs, and the text of generated Rust. It never shells out to
rustc, so it is the fast, no-toolchain check for a new clone.
Once per clone (same venv as Installation):
python3 -m venv resnik-venv
. resnik-venv/bin/activate
pip install -e ".[dev]" # pytest, coverage, xdist, linters
# pip install -e ".[test]" # pytest + coverage onlyPython 3.9 or newer is required; see Installation.
Use python -m pytest so the tests run from the venv even if another
pytest is on PATH.
From the repository root:
# Entire suite (lexer + parser + backend)
python -m pytest
# Verbose (print each test name)
python -m pytest -v
# One compiler stage
python -m pytest tests/test_lexer
python -m pytest tests/test_parser
python -m pytest tests/test_backend
# One file
python -m pytest tests/test_lexer/test_tokenization.py
# One test (node id from pytest -v)
python -m pytest tests/test_parser/test_parsing.py::TestDoUntil
# Tests whose names match a substring
python -m pytest -k tokenizepyproject.toml sets testpaths = ["tests"], so a bare python -m pytest
from the repo root is enough. A successful run prints a short summary and
exits 0. Failures print the assertion and a traceback; fix those before
opening a pull request.
The dev extra also installs pytest-xdist for parallel runs:
python -m pytest -n auto| Path | Stage |
|---|---|
tests/test_lexer/ |
Tokenization and lexer edge cases |
tests/test_parser/ |
Grammar, macros, REPLACE, symbol table, AST |
tests/test_backend/ |
HAL/S → Rust lowering and type mapping |
tests/fixtures/ |
Shared .hal snippets |
tests/regression/ |
Not collected by pytest (shell script; see below) |
# Terminal report, including uncovered lines
pytest --cov=resnik --cov-report=term-missing
# HTML report (opens as htmlcov/index.html)
pytest --cov=resnik --cov-report=html./tests/regression/run_regression.sh is the end-to-end HAL/S suite. It
compiles each registered example under docs/HAL-S-Source-Code-Examples/
with --emit-exe, runs the resulting binary (with a 120 s timeout per
run), and also exercises the template
library (--gen-tpl / --templib) and EXTERNAL C-object (--link-obj)
pipelines. Unlike the pytest unit tests, this does need rustc.
Cases are registered by hand — a new example directory is not picked up
until you add a run_regression_case line for it in the script (and, if
it builds on no_std, an ESP32_CASES entry in
run_embedded_build.sh).
Prerequisites. See Installation for rustc / cc and the
script’s sanitized PATH. You also need a git checkout (git rev-parse finds
the repo root) and the venv from Installation so
resnik-venv/bin/resnik exists.
Run
./tests/regression/run_regression.shYou can start it from anywhere inside the repo; it does not depend on the
venv being activated. Each case prints [✓ PASS] or [✗ FAIL]. A final
summary lists the pass/fail counts and exits 0 only if every case passed.
Generated .rs files, binaries, and temporary template/link directories are
removed when the script exits.
The regression script is Bash and expects a git checkout. It resets PATH to
a short system list (/usr/bin, /usr/local/bin, …), so a rustup-only
rustc under ~/.cargo/bin is not visible. After rustup, put rustc
on that list (a symlink is enough):
sudo ln -sf "$HOME/.cargo/bin/rustc" /usr/local/bin/rustc