Phase 7.10: buxc2 now compiles multi-statement Bux programs

Parser (src_bux/parser.bux):
- Block stores statements as linked list (firstStmt/lastStmt/nextStmt)
- Block struct: added firstStmt, lastStmt fields
- Stmt struct: added nextStmt field

HIR Lowering (src_bux/hir_lower.bux):
- Lcx_LowerBlock: iterates statement linked list, chains HirNodes via child3
- hIf: else block stored in extraData (child3 reserved for block chaining)

C Backend (src_bux/c_backend.bux):
- hBlock: emits statements via child3 linked list with proper indentation
- hStore: combines alloca + value into single declaration (int x = value;)
- hIf: full if/else emission with proper newlines
- Function decl: proper return types and parameter types (not just "int")
- int main() wrapper: generated when Main function exists
- No duplicate return 0 when body already has return

Tested:
- buxc2 compiles hello world program → runs correctly
- buxc2 compiles multi-statement program (let, if, function calls) → runs correctly
- All 18 examples still pass, all unit tests pass
This commit is contained in:
2026-05-31 17:25:03 +03:00
parent e8084b2840
commit 35b856bab4
8 changed files with 354 additions and 40 deletions
+10
View File
@@ -583,6 +583,8 @@ func parserParseBlock(p: *Parser) -> *Block {
b.line = parserCurToken(p).line;
b.column = parserCurToken(p).column;
b.stmtCount = 0;
b.firstStmt = null as *Stmt;
b.lastStmt = null as *Stmt;
while !parserCheck(p, tkRBrace) && parserPeek(p, 0) != tkEndOfFile {
if parserCheck(p, tkNewLine) || parserCheck(p, tkSemicolon) {
@@ -591,6 +593,14 @@ func parserParseBlock(p: *Parser) -> *Block {
}
let s: *Stmt = parserParseStmt(p);
if s != null as *Stmt {
s.nextStmt = null as *Stmt;
if b.firstStmt == null as *Stmt {
b.firstStmt = s;
b.lastStmt = s;
} else {
b.lastStmt.nextStmt = s;
b.lastStmt = s;
}
b.stmtCount = b.stmtCount + 1;
}
}