From e2c65706e61be09ddb7eeb28cd1957acd4317bcf Mon Sep 17 00:00:00 2001 From: _ov4 Date: Fri, 16 Oct 2026 10:09:47 +0000 Subject: feat(constants): implement literal constants with lexical scope Co-Authored-By: Claude Fable 5.1 --- lib/CodeGen/FunctionGen.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/FunctionGen.cc') diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc index ca8fa45..957a1f5 100644 --- a/lib/CodeGen/FunctionGen.cc +++ b/lib/CodeGen/FunctionGen.cc @@ -178,7 +178,7 @@ Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { } Function *FunctionGen::emitFunctionDef(FunctionDefAST *FuncAST, - const std::function &StmtEmitter) { + const std::function &StmtEmitter, unsigned ScopeID) { PrototypeAST *Proto = FuncAST->getProto(); Function *TheFunction = emitPrototype(Proto); @@ -194,8 +194,15 @@ Function *FunctionGen::emitFunctionDef(FunctionDefAST *FuncAST, std::map OldSymbols = Symbols; Symbols.clear(); + for (const auto &[Name, Info] : OldSymbols) { + if (Info.ConstantValue && Info.ScopeID == 0) Symbols.emplace(Name, Info); + } createArgumentAllocas(TheFunction, Proto->getParams()); + for (const auto &P : Proto->getParams()) { + auto It = Symbols.find(P.Name); + if (It != Symbols.end()) It->second.ScopeID = ScopeID; + } for (const auto &Stmt : FuncAST->getBody()) { StmtEmitter(Stmt.get()); -- cgit v1.3.1-4-g156e