- Sema zum Lowering-Pass umgebaut: typisiertes HIR (Slots, explizite Konvertierungsknoten) als Codegen-Eingabe; BYREF verlangt exakten Typ - Bytecode-Feindesign umgesetzt: monomorpher Opcode-Satz, .tbc-Container (Formatversion 1) mit eigenem Writer/Reader - Codegenerator HIR -> Bytecode (Fixup-Listen, keine globalen Passes) - TBVM-Interpreter: Kontrollfluss, GOSUB-Stack je Frame, BYREF/BYVAL, STATIC, DEF FN, DATA/READ/RESTORE, ON [LOCAL] ERROR/RESUME/ERR/ERL, Breakpoints/Einzelschritt/Inspektion, STOP fortsetzbar - Runtime-Scheibe: Host-Trait (Konsole/Capture), Builtin-Tabelle, Konvertierungsmatrix, PRINT-Formatierung/Druckzonen, Stringfunktionen - tbc run/build/check mit Exit-Codes nach Entscheidung D6 - Korpus-Harness (byte-genauer Vergleich) + 3 neue Korpusdateien (konvertierung, fehlerbehandlung, byref); 137 Tests gruen - Benchmarks: Einzelmodul 1,2 ms / Projekt 49.760 Zeilen 124 ms (Budgets eingehalten), VM ~5 Mio Schleifeniterationen/s - Doku fortgeschrieben (tbvm-design, sprachreferenz, PLAN); verlagerte Punkte als explizite Aufgaben in Phase 3 - OpenSpec-Change phase-2-bytecode-vm (27/27 Tasks) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
//! Frontend des Terminal-Basic-Compilers.
|
|
//!
|
|
//! Enthält Lexer, Parser, AST-Definitionen und die semantische Analyse
|
|
//! (Symboltabellen, Typprüfung, implizite Deklarationen, `DEFINT`-Regeln usw.).
|
|
//! Ausgabe des Frontends ist ein typgeprüfter AST, den `tb-vm` in Bytecode
|
|
//! übersetzt.
|
|
|
|
pub mod ast;
|
|
pub mod hir;
|
|
pub mod lexer;
|
|
pub mod parser;
|
|
pub mod sema;
|
|
|
|
/// Quelltextposition für Diagnostik (1-basiert, wie im IDE-Vorbild).
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
|
pub struct SourcePos {
|
|
pub line: u32,
|
|
pub column: u32,
|
|
}
|
|
|
|
/// Eine Diagnosemeldung mit Position. Die Texte folgen den (englischen)
|
|
/// Meldungen des Vorbilds, wo es eine Entsprechung gibt.
|
|
#[derive(Debug, Clone)]
|
|
pub struct Diagnostic {
|
|
pub pos: SourcePos,
|
|
pub message: String,
|
|
}
|
|
|
|
impl std::fmt::Display for Diagnostic {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{}:{}: {}", self.pos.line, self.pos.column, self.message)
|
|
}
|
|
}
|
|
|
|
/// Ergebnis der Frontend-Pipeline für ein Modul.
|
|
pub struct Analysis {
|
|
pub module: ast::Module,
|
|
pub diagnostics: Vec<Diagnostic>,
|
|
/// Typisiertes HIR (vollständig nur bei leeren Diagnosen).
|
|
pub hir: Option<hir::HirModule>,
|
|
}
|
|
|
|
/// Komplette Pipeline: Lexen → Parsen → semantische Prüfung + Lowering.
|
|
pub fn analyze_source(module_name: &str, source: &str) -> Analysis {
|
|
let lexed = lexer::lex(source);
|
|
let mut diagnostics = lexed.diagnostics;
|
|
let parsed = parser::parse(module_name, &lexed.tokens);
|
|
diagnostics.extend(parsed.diagnostics);
|
|
let (hir, sema_diags) = sema::lower(&parsed.module);
|
|
diagnostics.extend(sema_diags);
|
|
diagnostics.sort_by_key(|d| (d.pos.line, d.pos.column));
|
|
Analysis { module: parsed.module, diagnostics, hir }
|
|
}
|