How smx-smx/valasharp works
Project Type & Purpose
• ValaSharp is a compiler toolchain for the Vala language, fully re-written in C#/.NET.
• It consists of a core compiler library, a CLI front-end (ValaCompiler), auxiliary tools (VapiGen, ValaConfig), an experimental Language Server (for VS Code), and a large test harness.
Top-Level Components (from file tree)
a. Core Libraries (blue)
– Lang: lexer, parser, AST, semantic analysis, symbol table, flow analyzer.
– CLanguage: C-AST model & writer (represents the generated C code).
– CCodeGen: modules that walk the C-AST and emit C source (a plugin/pipeline architecture for code generation).
– GLibPorts: .NET bindings to GLib and related low-level native interop.
– Utils: misc. helpers (memory mapping, fast views, extensions).
b. Compiler Host (green)
– ValaCompilerLib: exposes CompilerOptions + compile pipeline (invokes Lang → semantic → CCodeGen → writes C files).
– ValaCompiler: console app; parses args (App.config), invokes ValaCompilerLib, then shells out to a C compiler (e.g., gcc/clang).
– ValaConfig: configuration reader (searches compile options, pkg-config integration).
– VapiGen: tool that generates VAPI metadata by leveraging CompilerLib.
c. Language Server (orange)
– ValaLanguageServer: LSP server implementation (handles text-document/didChange, validation, code search, AST traversal).
– client/extension.ts: VS Code extension that communicates with the server over the Language Server Protocol.
d. Test Harness (yellow)
– ValaTests: test spec files (.vala, .test), ValaTestRunner (C# runner), regression scripts (PHP, shell).
• Lay out components in logical layers from left to right or top to bottom:
1. Input & Configuration
• Vala source files + CLI args (ValaCompiler)
• ValaConfig (reads .vala files, include paths, pkg-config data)
2. Frontend (Lang)
• Scanner → Parser → AST (Lang/Parser, Lang/CodeNodes)
• Semantic Analyzer & FlowAnalyzer → SymbolResolver → type checking
3. Backend
• CodeGenerator (Lang/CodeGenerator) → emits intermediate C-AST (CLanguage)
• CCodeGen Modules → emit .c/.h source files
• GLibPorts library (runtime) linked in generated code
• External C Compiler (gcc/clang) → final native binary
4. Host Tools
• ValaCompilerLib (pipeline orchestrator)
• ValaCompiler CLI (shell front-end)
• VapiGen & other tooling
5. Language Server
• LSP Server (ValaLanguageServer) uses CompilerLib pipeline for parse/analysis
• VS Code Extension (client) ↔ Server (via JSON-RPC over stdio or socket)
6. Tests
• ValaTestRunner & test scripts invoke ValaCompilerLib for each test case
Relationships & Data Flows
• CLI → CompilerLib → Lang(frontend) → Semantic → CodeGen → writes C code → native compiler
• CompilerLib → VapiGen (reads AST, emits VAPI)
• Language Server ↔ CompilerLib for on-the-fly parsing and validation
• VS Code client → LSP server (bidirectional JSON-RPC)
• Tests → ValaTestRunner → CompilerLib → compare expected output
Key Architectural Patterns
• Layered pipeline (lexer → parser → AST → semantic → codegen)
• Plugin-style codegen modules in CCodeGen (each module handles one feature)
• Shared core library (ValaCompilerLib) reused by CLI, VapiGen, Language Server, Tests
• Clear separation between front-end (Lang) and back-end (CLanguage + CCodeGen)