This file provides guidance for AI agents working on the Cora project.
Cora is a Lisp-1 programming language inspired by Scheme, Shen, and FemtoLisp. Key features:
- Minimal special forms: quote, lambda, if, do
- Proper tail call optimization
- Partial function application
- Pattern matching via
matchform - Macro system
- Generational and incremental garbage collection
cora/
├── src/ # Core runtime implementation
│ ├── runtime.c/h # Function dispatch, core operations
│ ├── types.c/h # Type system and tagged values
│ ├── gc.c/h # Garbage collection
│ ├── reader.c/h # S-expression parser
│ ├── eval.c/h # Evaluator
│ └── ...
├── lib/ # Standard library modules
│ ├── toc.c # Core library
│ └── ... # String, I/O, OS, Net, Hash, Rand, JSON, Markdown modules
├── test/ # Test files
├── doc/ # Documentation
└── main.c # Entry point
# Build the project
make
# Clean build artifacts
make clean
# Run tests
make test
# Format C code (uses indent)
make fmt
# Bootstrap test
make bootstrap
# Install locally
make install-local
# Build with AddressSanitizer
ENABLE_ASAN=1 make
# Build with ThreadSanitizer
ENABLE_TSAN=1 make- C code formatting:
make fmt(uses indent with specific options) - Follow existing code patterns in src/ directory
- No unnecessary comments (unless explicitly requested)
- Runtime System (
src/runtime.c): Function dispatch, memory management, core functionality - Type System (
src/types.c): Tagged value representation - Garbage Collection (
src/gc.c): Generational and incremental GC - Reader (
src/reader.c): Parses S-expressions - Evaluator (
src/runtime.c): Executes Cora code - Compiler: Transforms Cora to C code (part of runtime)
- Test files in
test/directory - Run
make testto execute tests - Bootstrap test:
make bootstrap
When making changes:
- Read relevant source files first
- Follow existing patterns and conventions
- Test your changes with
make test - Format code with
make fmtif needed
- Add new language features: Update runtime, types, and evaluator
- Add standard library functions: Edit
lib/toc.cor create new module files - Fix memory issues: Check
src/gc.cand use sanitizers - Improve compilation: Review compiler pipeline in runtime
- This is a Lisp-1 dialect (functions and variables share namespace)
- The project uses a generational, incremental garbage collector
- Modules are implemented as shared objects loaded at runtime
- The compiler generates C code that is compiled to shared objects