From aff03ffb5ac25a0dd7fa94ac664dd3ab39bd151f Mon Sep 17 00:00:00 2001 From: dimgigov Date: Sat, 6 Jun 2026 05:34:19 +0300 Subject: [PATCH] =?UTF-8?q?fix(selfhost):=20resolve=20all=20sema=20errors?= =?UTF-8?q?=20=E2=80=94=200=20undeclared=20identifiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add forward declarations for mutually-recursive parser functions (parserParseExpr, parserParseStmt, parserParseBlock, parserParsePrimary, parserParsePostfixExpr, parserParseBinaryPrec) - Fix HIR lowering: skip forward decls (refBody==null) to avoid duplicate function entries and array overflow - Bump funcs/externFuncs array size 256→512 to handle large modules - Update PLAN.md with progress Sema: 0 errors (was 7, then 2, now 0) Remaining: C backend struct ordering (pre-existing, Iter/StringBuilder) --- src/hir_lower.bux | 8 ++++---- src/parser.bux | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/hir_lower.bux b/src/hir_lower.bux index d783a37..c83b7f9 100644 --- a/src/hir_lower.bux +++ b/src/hir_lower.bux @@ -601,9 +601,9 @@ func HirLower_LowerModule(mod: *Module, sema: *Sema) -> *HirModule { let ctx: *LowerCtx = bux_alloc(sizeof(LowerCtx)) as *LowerCtx; ctx.module = mod; ctx.scope = sema.scope; - ctx.funcs = bux_alloc(256 as uint * sizeof(HirFunc)) as *HirFunc; + ctx.funcs = bux_alloc(512 as uint * sizeof(HirFunc)) as *HirFunc; ctx.funcCount = 0; - ctx.externFuncs = bux_alloc(256 as uint * sizeof(HirFunc)) as *HirFunc; + ctx.externFuncs = bux_alloc(512 as uint * sizeof(HirFunc)) as *HirFunc; ctx.externCount = 0; ctx.varCounter = 0; @@ -624,7 +624,7 @@ func HirLower_LowerModule(mod: *Module, sema: *Sema) -> *HirModule { // Iterate declarations var decl: *Decl = mod.firstItem; while decl != null as *Decl { - if decl.kind == dkFunc { + if decl.kind == dkFunc && decl.refBody != null as *Block { let f: *HirFunc = Lcx_LowerFunc(ctx, decl); ctx.funcs[ctx.funcCount] = *f; ctx.funcCount = ctx.funcCount + 1; @@ -633,7 +633,7 @@ func HirLower_LowerModule(mod: *Module, sema: *Sema) -> *HirModule { let implTypeName: String = decl.strValue; var implDecl: *Decl = decl.childDecl1; while implDecl != null as *Decl { - if implDecl.kind == dkFunc { + if implDecl.kind == dkFunc && implDecl.refBody != null as *Block { let mangled: String = String_Concat(implTypeName, "_"); implDecl.strValue = String_Concat(mangled, implDecl.strValue); let f: *HirFunc = Lcx_LowerFunc(ctx, implDecl); diff --git a/src/parser.bux b/src/parser.bux index ce699a8..187c1b2 100644 --- a/src/parser.bux +++ b/src/parser.bux @@ -4,6 +4,14 @@ module Parser { extern func bux_strlen(s: String) -> uint; +// Forward declarations for mutual recursion +func parserParseExpr(p: *Parser) -> *Expr; +func parserParseStmt(p: *Parser) -> *Stmt; +func parserParseBlock(p: *Parser) -> *Block; +func parserParsePrimary(p: *Parser) -> *Expr; +func parserParsePostfixExpr(p: *Parser) -> *Expr; +func parserParseBinaryPrec(p: *Parser, minPrec: int) -> *Expr; + // --------------------------------------------------------------------------- // Parser state // --------------------------------------------------------------------------- @@ -326,7 +334,7 @@ func parserParsePrimary(p: *Parser) -> *Expr { // Postfix: call, index, field access, as, is, ? // --------------------------------------------------------------------------- -func parserParsePostfix(p: *Parser) -> *Expr { +func parserParsePostfixExpr(p: *Parser) -> *Expr { var left: *Expr = parserParsePrimary(p); while true { @@ -566,7 +574,7 @@ func parserPrecedence(op: int) -> int { } func parserParseBinaryPrec(p: *Parser, minPrec: int) -> *Expr { - var left: *Expr = parserParsePostfix(p); + var left: *Expr = parserParsePostfixExpr(p); while true { let op: int = parserPeek(p, 0); let prec: int = parserPrecedence(op);