How alinalihassan/lesma works
Project Type and Purpose
• Lesma is a compiler for a statically-typed, object-oriented programming language.
• Key features: CLI entry, a modular “liblesma” library (frontend, AST, symbol analysis, backend), standard library files, and extensive tests.
• It also hosts documentation built with Docusaurus.
File Structure
• Top-level “src/cli” (main.cpp) contains the command-line interface.
• “src/liblesma” breaks down into:
• Frontend (Lexer, Parser)
• AST (AST nodes, Visitor)
• Symbol (SymbolTable, Type, Value)
• Driver (coordinates stages)
• Backend (Codegen using LLVM)
• Common (error handling, utilities)
• “src/stdlib” holds the built-in library that the compiler bundles.
• “tests” directory runs .les source files through the compiler for success/failure.
• “docs” directory is a separate site generator, not part of the compiler runtime.
Core Components & Data Flow
a. Components:
• CLI Frontend (src/cli/main.cpp)
• Driver (Driver.cpp/.h)
• Frontend: Lexer → Parser
• AST Module
• Semantic Analyzer (SymbolTable, Type Checking)
• Backend: Codegen (LLVM IR generation)
• Standard Library Loader
• Tests Harness
• External: LLVM library, CMake build, Docusaurus for docs
b. Interactions:
1. User invokes CLI →
2. CLI calls Driver
3. Driver reads .les files (including stdlib) →
4. Lexer tokenizes → Parser builds AST →
5. AST is traversed for symbol resolution & type checking →
6. Backend Codegen translates AST to LLVM IR →
7. LLVM JIT or AOT compiles IR to native code →
8. Executable or object files output
9. Tests invoke CLI/Driver, verify outputs or error messages
c. Architectural Patterns:
• Pipeline (staged compilation)
• Visitor pattern in AST traversal
• Modular separation: CLI vs. Library
d. Technologies:
• C++17, LLVM 15
• CMake & vcpkg for build and dependencies
• Google Benchmark for benchmarks
• Docusaurus + React for docs site
Required Elements
• Core compilation stages
• I/O components (CLI, Stdlib, Tests)
• External services (LLVM, Docs)
• Annotations for key patterns (Visitor, Pipeline).