How aavtic/pine works
1. Top-level architecture
This is a Rust workspace for a compiled language toolchain. The repository is split into small crates that map directly to compiler stages, plus a CLI compiler (tools/pinec), C runtime support (runtime/c), Pine-language standard library (stdlib/), examples, and tests.
2. Compiler pipeline boundary
Pine’s flow is intentionally linear and inspectable: source .alp files are tokenized, parsed into an AST, semantically analyzed, lowered toward an internal IR, code generated to LLVM IR / object code, and then linked into a native executable. The CLI can stop at intermediate stages for debugging and teaching.
3. Lexing front end
crates/lexer is the first stage and produces the token stream from Pine source text. This is the syntax boundary of the system: everything after this stage works on structured compiler data rather than raw text.
4. Parsing and syntax model
crates/parser consumes tokens and builds the AST defined in crates/ast. The AST crate centralizes the language’s syntax nodes and type representations, making it the shared contract between parser, analyzer, and later lowering/codegen stages.
5. Semantic analysis and type checking
crates/analyzer performs static checks over the AST: type validation, scope resolution, and likely symbol tracking for functions, locals, and foreign declarations. This is where the “statically typed” nature of Pine is enforced before any backend work happens.
6. Lowering / intermediate representation
crates/ir is a dedicated boundary for a lower-level internal model used between analysis and backend emission. In architecture terms, it separates language semantics from target-specific code generation, so later stages can reason about a simplified compiler IR instead of full syntax trees.
7. Backend code generation
crates/codegen turns the compiler’s internal representation into LLVM-facing output and related backend artifacts. The presence of function.rs and variable.rs suggests the backend is organized around emitting function bodies and local/storage handling rather than monolithic code emission.
8. Linking and native output
crates/linker handles the final packaging step: combining generated object code with the runtime and producing the final executable. This is the boundary where Pine transitions from compiler output to an operating-system binary.
9. Runtime and FFI boundary
runtime/c contains C implementations of low-level services such as printing, string comparison, and stdin reading. Pine exposes these through alien "c" declarations, so the language runtime is split across Pine source wrappers in stdlib/ and native C functions linked at build time.
10. Standard library as Pine source
stdlib/ is not a separate compiled binary; it is language-level library code organized by domain (io, math, time). These modules wrap runtime/FFI primitives and provide the user-facing library surface that user programs import with use.
11. CLI orchestration
tools/pinec is the user entry point that drives the pipeline. It appears to support build modes that can emit tokens, AST, analysis output, LLVM IR, object files, or a final executable, making it the central control plane over the compiler stages.
12. Cross-cutting support and tests
crates/errors, crates/config, and crates/utils provide shared infrastructure: diagnostics, built-in constants/stdlib wiring, and common helpers. The tests/ tree is organized by stage (parser, test_analyzer, test_codegen, codegen/ir.rs), which mirrors the architecture and validates each boundary independently.
13. How to draw the diagram
A good diagram would place user .alp source on the left, then show a pipeline through lexer → parser → AST → analyzer → IR/codegen → linker, with a side branch to the Pine stdlib and C runtime through FFI. The CLI should sit above the pipeline as the orchestrator, and tests should be shown as stage-specific verification around the corresponding compiler components.
Main entry points: pinec pinec · parser Parser · analyzer Analyzer · codegen Codegen
Components 19
Compiler pipeline
Core Rust crates that implement the Pine compilation stages.
- Pine source · User-authored .alp programs and library code.
- Lexer · Tokenizes Pine source text into a token stream.
crates/lexer - Parser · Consumes tokens and builds the AST.
crates/parser - AST · Shared syntax and type structures used across the compiler.
crates/ast - Analyzer · Performs scope resolution, type checking, and static validation.
crates/analyzer - IR · Lower-level intermediate representation between semantics and backend.
crates/ir - Codegen · Emits LLVM-facing output and handles function and variable emission.
crates/codegen - Linker · Combines generated objects with runtime pieces into a native executable.
crates/linker - Errors · Diagnostics and error handling shared across stages.
crates/errors - Config · Compiler constants and standard library wiring.
crates/config - Utils · Common helpers used by multiple crates.
crates/utils
Runtime boundary
Native runtime and language-level standard library surface.
Tooling and tests
CLI entrypoint and stage-specific validation binaries.
- pinec · Compiler entrypoint that drives the pipeline and can stop at intermediate stages.
tools/pinec - Examples · Representative Pine programs demonstrating language features.
examples - Parser tests · Stage-specific checks for parsing behavior.
tests/parser - Analyzer tests · Stage-specific checks for semantic analysis.
tests/test_analyzer - Codegen tests · Stage-specific checks for backend emission.
tests/test_codegen
Connections 22
- Pine source → Lexer: tokens · Source text enters the front end.
- Lexer → Parser: tokens · Parser consumes the lexer output.
- Parser → AST: builds · Parser materializes the shared AST.
- AST → Analyzer: analyzes · Analyzer validates the syntax tree.
- Analyzer → IR: lowers to · Semantically valid programs are lowered into IR.
- IR → Codegen: emits · Backend turns IR into LLVM-facing output and objects.
- Codegen → Linker: objects · Generated code is packaged for linking.
- pinec → Lexer: drives · CLI can invoke and inspect the lexer stage.
- pinec → Parser: drives · CLI can stop after parsing for inspection.
- pinec → Analyzer: drives · CLI exposes semantic analysis output.
- pinec → Codegen: drives · CLI can emit backend artifacts and object code.
- pinec → Linker: drives · CLI can produce a final executable.
- Parser → Errors: reports · Parsing diagnostics use shared error handling.
- Analyzer → Errors: reports · Semantic diagnostics use shared error handling.
- Codegen → Errors: reports · Backend errors are surfaced through shared diagnostics.
- Config → Stdlib: maps · Configuration wires in standard library structure and constants.
- Stdlib → FFI bridge: wraps · Stdlib modules expose native capabilities through FFI.
- FFI bridge → C runtime: calls · Alien declarations bind to C runtime functions.
- Examples → pinec: driven by · Examples are compiled and run through the CLI.
- Parser tests → Parser: verifies · Parser tests exercise syntax handling.
- Analyzer tests → Analyzer: verifies · Analyzer tests exercise semantic checks.
- Codegen tests → Codegen: verifies · Codegen tests exercise backend emission.