src/holds the compiler implementation (lex.c,parse.c,codegen.c, etc.).demo/contains small C programs that exercise supported features and serve as manual regressions.test/lives beside a customMakefilethat buildsbuild/test_runner; tests compilesrc/*.calongside dedicated helper files.selfhost/stores headers for the bootstrap compiler, temporary build artifacts, and the demo-check harness.- Generated outputs (
build/,selfhost/bootstrap/,selfhost/build/,selfhost/demo_check/) are ignored by.gitignoreand should not be committed.
make– stage-1 build using systemclang; producesbuild/llvm7.make selfhost– usesbuild/llvm7to preprocesssrc/*.c, emit IR, and buildbuild/llvm7_selfhost.make selfhost_verify– quick comparison of IR output between Stage 1 and Stage 2 for a single file.make selfhost_test– preprocessesdemo/*.c, compiles via the self-hosted compiler, links, and verifies exit codes for known demos.make bootstrap_compare– runs the full bootstrap pipeline (tc1 vs tc2 IR) for all source files and diffs outputs.make bootstrap_check– comprehensive integrity check; runs unit tests followed bybootstrap_compare.make test– runstest/Makefile, building thetest_runnerthat executes all lexer/parse/codegen unit tests.
- Follow conventional C style: 4-space indentation, braces on the same line, descriptive variable names (
node,ctx,builder). - Use uppercase for
#includeidentifiers (#include "parse.h"), keep functions insnake_case, types inCamelCasewhen referring to structs (Type,Node). - Keep compiler helpers modular (lex, parse, codegen) and avoid mixing UI/output logic with parsing.
- No automated formatter; rely on manual alignment and clarity. Watch for consistent
ctx->usage when threading state.
- Tests live under
test/and use the micro-unit helper suite (mu_assert). Each test returnsNULLon success. - Name new tests
test_<scope>_<behavior>for clarity (e.g.,test_generate_switch_case_after_return_case). - Run
make testwhenever modifying parsing/codegen; target line coverage is functional rather than numeric. - Add regression data to
test/commonhelpers when new fixtures or execution contexts are required.
- Commit messages should be concise, prefixed if needed (“fix:”/“feat:” etc.), and mention the key change (e.g.,
fix: sync tc2 string linkage). - Pull requests should describe the bootstrap impact, any new demo/test targets touched, and reference relevant issues or bootstrap logs.
- Include command outputs when reporting regressions (e.g.,
make bootstrap_comparediffs,make testresults).
- Manual preprocessing is required for
#include/#define: expand withclang -Ebefore passing tobuild/llvm7. Documented inREADME.md. - Keep
selfhost/include/*.haligned with LLVM C APIs and host headers; missing prototypes can crash tc2 generation.