AILANG Development Guide
Development Workflow
Building and Testing
make build # Build the interpreter to bin/
make install # Install ailang to system (makes it available everywhere)
make test # Run all tests
make run FILE=... # Run an AILANG file
make repl # Start interactive REPL
Code Quality & Coverage
make test-coverage-badge # Quick coverage check (shows current %)
make test-coverage # Run tests with coverage, generates HTML report
make lint # Run golangci-lint
make fmt # Format all Go code
make fmt-check # Check if code is formatted
make vet # Run go vet
Example Management
make verify-examples # Verify all example files work/fail
make update-readme # Update README with example status
make flag-broken # Add warning headers to broken examples
Development Helpers
make deps # Install all dependencies
make clean # Remove build artifacts and coverage files
make ci # Run full CI verification locally
make help # Show all available make targets
Auto-rebuild on File Changes
make watch-install # Automatically rebuilds and installs on file changes
make quick-install # Fast reinstall after changes
Project Structure
ailang/
├── cmd/ailang/ # CLI entry point with REPL
├── internal/
│ ├── repl/ # Interactive REPL
│ ├── ast/ # Abstract syntax tree definitions
│ ├── lexer/ # Tokenizer with full Unicode support
│ ├── parser/ # Recursive descent parser
│ ├── eval/ # Tree-walking interpreter
│ ├── core/ # Core AST with ANF
│ ├── elaborate/ # Surface to Core elaboration
│ ├── typedast/ # Typed AST
│ ├── types/ # Type system with HM inference
│ ├── link/ # Dictionary linker
│ ├── schema/ # Schema registry for AI features
│ ├── errors/ # Error code taxonomy and JSON encoder
│ ├── test/ # Test reporter
│ ├── manifest/ # Example manifest system
│ ├── module/ # Module loader and path resolver
│ ├── effects/ # Effect system (TODO)
│ ├── channels/ # CSP implementation (TODO)
│ ├── session/ # Session types (TODO)
│ └── typeclass/ # Type classes (TODO)
├── testutil/ # Testing utilities
├── examples/ # Example AILANG programs
├── docs/ # Documentation
├── design_docs/ # Design documents
└── scripts/ # CI/CD scripts
Adding a New Language Feature
- Update token definitions in
internal/lexer/token.go
- Modify lexer in
internal/lexer/lexer.go
to recognize tokens - Add AST nodes in
internal/ast/ast.go
- Update parser in
internal/parser/parser.go
- Add type rules in
internal/types/
- Implement evaluation in
internal/eval/
- Write tests in corresponding
*_test.go
files - Add examples in
examples/
- Update documentation
Adding a Binary Operator
- Add token in
token.go
- Add to lexer switch statement
- Define precedence in parser
- Add to
parseInfixExpression
- Add type rule
- Implement evaluation
- Write tests
Adding a Built-in Function
- Define type signature
- Add to prelude or appropriate module
- Implement in Go
- Add tests
- Document in examples
Testing Guidelines
Running Tests
# Run all tests
make test
# Run tests with coverage
make test-coverage
# Run specific package tests
go test ./internal/lexer # Tokenization
go test ./internal/parser # Parsing
go test ./internal/eval # Evaluation
go test ./internal/types # Type inference & defaulting
go test ./internal/elaborate # Dictionary elaboration
go test ./cmd/test_integration # End-to-end type class tests
# Run with verbose output
go test -v ./...
Test Coverage Highlights
- ✅ Complete type class resolution pipeline
- ✅ Spec-aligned defaulting (neutral vs primary classes)
- ✅ Dictionary-passing transformation
- ✅ ANF verification and idempotency
- ✅ Law-compliant Float instances
- ✅ Superclass provision (Ord provides Eq)
Writing Tests
- Each module should have a corresponding
*_test.go
file - Test both success and error cases
- Use table-driven tests for multiple inputs
- Include integration tests for complete programs
Code Style Guidelines
Go Code
- Follow standard Go conventions
- Use descriptive names
- Add comments for complex logic
- Keep functions under 50 lines
AILANG Code
- Use 2-space indentation
- Prefer pure functions
- Make effects explicit
- Include tests with functions
- Use type annotations when helpful
Error Handling
In Go Implementation
- Return explicit errors, don't panic
- Include position information in parse errors
- Provide helpful error messages with suggestions
In AILANG
- Use Result type for fallible operations
- Propagate errors with
?
operator - Provide structured error context
Debug Commands
# Parse and print AST (when implemented)
ailang parse file.ail
# Type check without running
ailang check file.ail
# Show execution trace
ailang run --trace file.ail
# Export training data
ailang export-training
Performance Considerations
- Parser uses Pratt parsing for efficient operator precedence
- Type inference should cache resolved types
- String interning for identifiers
- Lazy evaluation for better performance (future)
Documentation Requirements
Required Documentation Updates
Every change must update:
-
README.md
- Implementation status when adding features
- Current capabilities when functionality changes
- Examples when fixed or added
- Line counts and completion status
-
CHANGELOG.md
- Follow semantic versioning
- Group by: Added, Changed, Fixed, Deprecated, Removed
- Include code locations
- Note breaking changes
- Add migration notes if needed
-
Design Documentation
- Create design doc in
design_docs/planned/
before starting - Move to
design_docs/implemented/
after completing - Include implementation report with metrics
- Create design doc in
-
Example Files
- Create
examples/feature_name.ail
for each new feature - Include comprehensive examples
- Add comments explaining behavior
- Test that examples actually work
- Create
Testing Policy
ALWAYS remove out-of-date tests. No backward compatibility.
- When architecture changes, delete old tests completely
- Don't maintain legacy test suites
- Write new tests for new implementations
- Keep test suite clean and current
Quick Debugging Checklist
- Check lexer is producing correct tokens
- Verify parser is building proper AST
- Ensure all keywords are in the keywords map
- Confirm precedence levels are correct
- Check that all AST nodes implement correct interfaces
- Verify type substitution is working correctly