From efc86b5c7625cf4c7074319f42f68807a25bde9d Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 12:04:56 +0000 Subject: refactor: single builtin registry, retire keyword route for builtins All 11 builtins now live in one static {Name, Arity, ReturnTypeName} table in CodeGen.cc: emitExpr checks arity against it (uniform "Error: X expects N args" diagnostics) and getExprTypeInfo reads return types from it, removing the duplicated hard-coded table. LENGTH/MID/RIGHT/LEFT/LCASE/UCASE lose their lexer tokens and ParseStringBuiltin; they parse as ordinary identifier calls exactly like ASC/CHR/IS_NUM/NUM_TO_STR/STR_TO_NUM already did. Behavior note: these six names are no longer reserved words. AGENTS docs updated for the new builtin story and the batch-1 error contract (exit codes, verifyModule, fixed descending FOR). Co-Authored-By: Claude Fable 5 --- lib/Parser/Parser.cc | 35 ----------------------------------- 1 file changed, 35 deletions(-) (limited to 'lib/Parser/Parser.cc') diff --git a/lib/Parser/Parser.cc b/lib/Parser/Parser.cc index 049f99d..320fdf4 100644 --- a/lib/Parser/Parser.cc +++ b/lib/Parser/Parser.cc @@ -132,34 +132,6 @@ std::string Parser::ParseTypeName(bool AllowVoid) { return ""; } -std::unique_ptr Parser::ParseStringBuiltin(const std::string &FuncName) { - getNextToken(); - if (CurTok != '(') { - fprintf(stderr, "Error: Expected '(' after %s\n", FuncName.c_str()); - return nullptr; - } - getNextToken(); - - std::vector> Args; - if (CurTok != ')') { - while (true) { - if (auto Arg = ParseExpression()) - Args.push_back(std::move(Arg)); - else - return nullptr; - - if (CurTok == ')') break; - if (CurTok != ',') { - fprintf(stderr, "Error: Expected ',' or ')' in %s\n", FuncName.c_str()); - return nullptr; - } - getNextToken(); - } - } - getNextToken(); - return std::make_unique(FuncName, std::move(Args)); -} - std::unique_ptr Parser::ParseParenExpr() { getNextToken(); auto V = ParseExpression(); @@ -187,13 +159,6 @@ std::unique_ptr Parser::ParsePrimary() { getNextToken(); return Res; } - case tok_length: return ParseStringBuiltin("LENGTH"); - case tok_mid: return ParseStringBuiltin("MID"); - case tok_right: return ParseStringBuiltin("RIGHT"); - case tok_left: return ParseStringBuiltin("LEFT"); - case tok_lcase: return ParseStringBuiltin("LCASE"); - case tok_ucase: return ParseStringBuiltin("UCASE"); - case tok_true: { getNextToken(); return std::make_unique(true); -- cgit v1.3.1-4-g156e