How staplerio/carbon-lang_compiler works
Project type and purpose
• This is a multi‑crate Rust workspace implementing the Carbon programming language compiler plus a CLI front‑end and a small math library.
• Purpose: parse Carbon source files, build an AST, perform optimizations/type checks, generate target packages (assembly or bytecode), and provide a CLI tool (arc) to orchestrate compilation.
File structure
• Top‑level crates:
• executables/arc – command‑line tool
• libraries/compiler – core compiler library
• libraries/apa – auxiliary arithmetic library
• Within the compiler crate, you see four logical subsystems (as per README):
• lexer/ – tokenization rules & tokenizer
• parser/ – AST construction & parsing pipeline
• optimizer – (implied within package_generator/type_inference)
• package_generator/ – transforms IR into final package
• Shared modules under compiler/src/shared hold AST definitions, tokens, errors, utilities, and common package‑generation data structures.
• Tests are co‑located under each subsystem to validate functionality.
README for additional insights
• Confirms four compiler phases: Lexer → Parser → Optimizer → Package generator.
Detail without over‑splitting
• Compiler phase as its own component but avoid drilling down into every single Rust file.
• Only the critical sub‑modules that define major behaviors (e.g., lex_rules in Lexer, builder/blocks in Parser, command_builder in Package Generator).