From 392dd64f97b87bd0d10c0ce411615376789c474c Mon Sep 17 00:00:00 2001 From: dimgigov Date: Tue, 9 Jun 2026 16:14:31 +0300 Subject: [PATCH] cleanup(selfhost): remove 17 dead functions across 5 files Remove unused helper functions, factories, accessors, and merge helpers: - c_backend.bux: CBE_Init, CBE_ClearDefers, CBE_EmitLine, CBE_Build, CBackend_Free - hir_lower.bux: Lcx_FreshName, Lcx_LowerType, HirLower_Free - lexer.bux: Lexer_Init, lexIsIdentKind, Lexer_TokenCount, Lexer_GetToken - parser.bux: parserIsBinaryOp, parserPrevious, parserMergeAddDecl, Parser_DiagCount, Parser_Free, Parser_MergeModules - sema.bux: Sema_TypeName None of these functions are referenced anywhere in src/. --- src/c_backend.bux | 22 ----------------- src/hir_lower.bux | 22 ----------------- src/lexer.bux | 40 ------------------------------ src/parser.bux | 63 ----------------------------------------------- src/sema.bux | 15 ----------- 5 files changed, 162 deletions(-) diff --git a/src/c_backend.bux b/src/c_backend.bux index 0d2f059..732b71a 100644 --- a/src/c_backend.bux +++ b/src/c_backend.bux @@ -87,11 +87,6 @@ struct CEmitter { defer7: *HirNode, } -func CBE_Init() -> CEmitter { - var sb: StringBuilder = StringBuilder_NewCap(4096); - return CEmitter { sb: sb, indent: 0, mod: null as *HirModule }; -} - func CBE_PushDefer(cbe: *CEmitter, node: *HirNode) { if cbe.deferCount == 0 { cbe.defer0 = node; } if cbe.deferCount == 1 { cbe.defer1 = node; } @@ -131,10 +126,6 @@ func CBE_EmitDefers(cbe: *CEmitter) -> int { return 1; } -func CBE_ClearDefers(cbe: *CEmitter) { - cbe.deferCount = 0; -} - func CBE_Emit(cbe: *CEmitter, text: String) { var i: int = 0; while i < cbe.indent { @@ -144,15 +135,6 @@ func CBE_Emit(cbe: *CEmitter, text: String) { StringBuilder_Append(&cbe.sb, text); } -func CBE_EmitLine(cbe: *CEmitter, text: String) { - CBE_Emit(cbe, text); - StringBuilder_Append(&cbe.sb, "\n"); -} - -func CBE_Build(cbe: *CEmitter) -> String { - return StringBuilder_Build(&cbe.sb); -} - // --------------------------------------------------------------------------- // Emit HIR node // --------------------------------------------------------------------------- @@ -1096,8 +1078,4 @@ func CBackend_Generate(mod: *HirModule) -> String { return StringBuilder_Build(&cbe.sb); } -func CBackend_Free(cbe: *CEmitter) { - StringBuilder_Free(&cbe.sb); - bux_free(cbe as *void); -} } diff --git a/src/hir_lower.bux b/src/hir_lower.bux index f16e2c5..e21a75e 100644 --- a/src/hir_lower.bux +++ b/src/hir_lower.bux @@ -96,23 +96,6 @@ func Lcx_BuildFuncTypeName(te: *TypeExpr) -> String { return result; } -// --------------------------------------------------------------------------- -// Fresh name generation -// --------------------------------------------------------------------------- - -func Lcx_FreshName(ctx: *LowerCtx) -> String { - ctx.varCounter = ctx.varCounter + 1; - return String_FromInt(ctx.varCounter as int64); -} - -// --------------------------------------------------------------------------- -// Type → HIR type -// --------------------------------------------------------------------------- - -func Lcx_LowerType(typeKind: int, typeName: String) -> int { - return typeKind; -} - // --------------------------------------------------------------------------- // Expression lowering // --------------------------------------------------------------------------- @@ -944,9 +927,4 @@ func HirLower_LowerModule(mod: *Module, sema: *Sema) -> *HirModule { return hm; } -func HirLower_Free(ctx: *LowerCtx) { - bux_free(ctx.funcs as *void); - bux_free(ctx.externFuncs as *void); - bux_free(ctx as *void); -} } diff --git a/src/lexer.bux b/src/lexer.bux index 74951d8..3e3663d 100644 --- a/src/lexer.bux +++ b/src/lexer.bux @@ -73,23 +73,6 @@ struct LexToken { column: uint32; } -// --------------------------------------------------------------------------- -// Init -// --------------------------------------------------------------------------- - -func Lexer_Init(source: String) -> Lexer { - let len: uint = bux_strlen(source); - let tokBuf: *LexToken = bux_alloc(maxTokens as uint * sizeof(LexToken)) as *LexToken; - let diagBuf: *LexerDiag = bux_alloc(maxDiags as uint * sizeof(LexerDiag)) as *LexerDiag; - return Lexer { - source: source, sourceLen: len as int, - pos: 0, line: 1, column: 1, - startLine: 0, startColumn: 0, startPos: 0, - tokenCount: 0, tokens: tokBuf, - diagCount: 0, diags: diagBuf - }; -} - // --------------------------------------------------------------------------- // Core primitives // --------------------------------------------------------------------------- @@ -255,17 +238,6 @@ func lexSkipWhitespace(lex: *Lexer) { // Identifiers // --------------------------------------------------------------------------- -func lexIsIdentKind(tok: int) -> bool { - return tok == tkFunc || tok == tkLet || tok == tkVar || tok == tkConst - || tok == tkType || tok == tkStruct || tok == tkEnum || tok == tkUnion - || tok == tkInterface || tok == tkExtend || tok == tkModule || tok == tkImport - || tok == tkPub || tok == tkExtern || tok == tkIf || tok == tkElse - || tok == tkWhile || tok == tkDo || tok == tkLoop || tok == tkFor - || tok == tkIn || tok == tkBreak || tok == tkContinue || tok == tkReturn - || tok == tkMatch || tok == tkAs || tok == tkIs || tok == tkNull - || tok == tkSelf || tok == tkSuper; -} - func lexKeywordKind(text: String) -> int { if String_Eq(text, "true") { return tkBoolLiteral; } if String_Eq(text, "false") { return tkBoolLiteral; } @@ -801,18 +773,6 @@ func Lexer_Tokenize(source: String) -> *Lexer { return lex; } -func Lexer_TokenCount(lex: *Lexer) -> int { - return lex.tokenCount; -} - -func Lexer_GetToken(lex: *Lexer, index: int) -> LexToken { - if index >= 0 && index < lex.tokenCount { - return lex.tokens[index]; - } - var empty: LexToken = LexToken { kind: tkEndOfFile, text: "", line: 0, column: 0 }; - return empty; -} - func Lexer_DiagCount(lex: *Lexer) -> int { return lex.diagCount; } diff --git a/src/parser.bux b/src/parser.bux index 8489fd2..c283688 100644 --- a/src/parser.bux +++ b/src/parser.bux @@ -97,15 +97,6 @@ func parserMatch(p: *Parser, kind: int) -> bool { return false; } -func parserPrevious(p: *Parser) -> LexToken { - if p.pos > 0 && p.pos <= p.tokenCount { - return p.tokens[p.pos - 1]; - } - var eof: LexToken; - eof.kind = tkEndOfFile; - return eof; -} - func parserExpect(p: *Parser, kind: int, msg: String) -> LexToken { if parserCheck(p, kind) { return parserAdvance(p); @@ -598,17 +589,6 @@ func parserParsePostfixExpr(p: *Parser) -> *Expr { // All binary operators: arithmetic, comparison, logical, bitwise, assignment // --------------------------------------------------------------------------- -func parserIsBinaryOp(kind: int) -> bool { - if kind >= tkPlus && kind <= tkStarStar { return true; } // arithmetic - if kind == tkAmp || kind == tkPipe || kind == tkCaret { return true; } // bitwise (no &|) - if kind >= tkShl && kind <= tkShrAssign { return true; } // shift + assign - if kind >= tkEq && kind <= tkGe { return true; } // comparison - if kind == tkAmpAmp || kind == tkPipePipe { return true; } // logical - if kind >= tkAssign && kind <= tkShrAssign { return true; } // all assigns - if kind == tkDotDot || kind == tkDotDotEqual { return true; } // range - return false; -} - func parserPrecedence(op: int) -> int { if op == tkAssign || op == tkPlusAssign || op == tkMinusAssign || op == tkStarAssign || op == tkSlashAssign || op == tkPercentAssign || op == tkAmpAssign || op == tkPipeAssign || op == tkCaretAssign || op == tkShlAssign || op == tkShrAssign { return 1; } if op == tkPipePipe { return 2; } @@ -1547,47 +1527,4 @@ func Parser_Parse(tokens: *LexToken, tokenCount: int) -> *Module { return mod; } -func Parser_DiagCount(p: *Parser) -> int { - return p.diagCount; -} - -func Parser_Free(p: *Parser) { - bux_free(p.diags as *void); - bux_free(p as *void); -} - -// --------------------------------------------------------------------------- -// Module merging — merge multiple parsed modules into one -// --------------------------------------------------------------------------- - -// Add a single declaration to the merged module (push front to linked list) -func parserMergeAddDecl(mod: *Module, decl: *Decl) { - if decl == null as *Decl { return; } - // Flatten module declarations: extract inner items - if decl.kind == dkModule { - var inner: *Decl = decl.childDecl1; - while inner != null as *Decl { - let next: *Decl = inner.childDecl2; - inner.childDecl2 = mod.firstItem; - mod.firstItem = inner; - mod.itemCount = mod.itemCount + 1; - inner = next; - } - } else { - decl.childDecl2 = mod.firstItem; - mod.firstItem = decl; - mod.itemCount = mod.itemCount + 1; - } -} - -func Parser_MergeModules(modules: *void, count: int) -> *Module { - // This function is kept for future use but not called by Cli_BuildProject - // which does inline merging for simplicity - let merged: *Module = bux_alloc(sizeof(Module)) as *Module; - merged.name = "main"; - merged.path = ""; - merged.itemCount = 0; - merged.firstItem = null as *Decl; - return merged; -} } diff --git a/src/sema.bux b/src/sema.bux index 3e78406..b213b3d 100644 --- a/src/sema.bux +++ b/src/sema.bux @@ -152,21 +152,6 @@ func Sema_IsBool(kind: int) -> bool { return kind == tyBool || kind == tyBool8 || kind == tyBool16 || kind == tyBool32; } -func Sema_TypeName(kind: int) -> String { - if kind == tyUnknown { return "?"; } - if kind == tyVoid { return "void"; } - if kind == tyBool { return "bool"; } - if kind == tyInt{ return "int"; } - if kind == tyInt64 { return "int64"; } - if kind == tyUInt { return "uint"; } - if kind == tyFloat64 { return "float64"; } - if kind == tyStr { return "String"; } - if kind == tyPointer { return "*ptr"; } - if kind == tyNamed { return "user-type"; } - if kind == tyTypeParam { return "type-param"; } - return "?"; -} - // --------------------------------------------------------------------------- // Block checking helper // ---------------------------------------------------------------------------