Project Structure
Overview of the Turf compiler codebase layout and directory structure.
The Turf compiler is written in C++ and uses LLVM as its backend. Below is an overview of the key directories and files in the turf-lang repository.
Root Directory
include/: Header files for the compiler.src/: Source files for the compiler implementation.tests/: Extensive test suite containing.trfiles and test scripts.scripts/: Utility scripts for building and testing.turf: The compiled compiler binary (after building).README.md: General overview and quick start guide.
Header Files (include/)
Lexer.h: Defines theLexerclass for tokenizing source code.Parser.h: Defines theParserclass for building the Abstract Syntax Tree (AST).AST.h: Contains definitions for AST nodes (expressions, statements, declarations).Codegen.h: Handles LLVM IR generation from the AST.Types.h: Defines the Turf type system and type-checking logic.SymbolTable.h: Manages variable scopes and symbol lookups.CFG.h: Construction of the Control Flow Graph for analysis.Lint.h: Implementation of the “Smart Compiler” diagnostic features.Errors.h: Centralized error reporting and fix suggestions.
Source Files (src/)
main.cpp: Entry point for the compiler, handles CLI arguments.Lexer.cpp: Implementation of the tokenizer.Parser.cpp: Implementation of the recursive-descent parser.Codegen.cpp: LLVM IR generation implementation.SymbolTable.cpp: Scope management implementation.Types.cpp: Type system implementation.Algorithms.cpp: Helper algorithms (e.g., Damerau-Levenshtein for suggestions).
Scripts (scripts/)
update_compiler.sh: Builds theturfcompiler from source.compile_and_run.sh: Helper to compile a.trfile and run it immediately.test_runner.sh: Internal script used by the test suite.
Tests (tests/)
The tests/ directory is organized by feature:
types/: Tests for basic types, casting, andtypeof().functions/: Tests for function definitions and calls.loops/: Tests forwhile,break, andcontinue.misc/: Arithmetic, logical, and relational operator tests.run_tests.sh: Main script to execute the full test suite.