aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/StatementGen.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-16 10:09:47 +0000
committer_ov4 <ov4@ov4.org>2026-10-16 10:09:47 +0000
commite2c65706e61be09ddb7eeb28cd1957acd4317bcf (patch)
tree15447a03d67d395a722c5be3f0b05bc9f197197a /lib/CodeGen/StatementGen.cc
parent45c9d37eb27d204a6202b33cb37e890af0171357 (diff)
feat(constants): implement literal constants with lexical scope
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/StatementGen.cc')
-rw-r--r--lib/CodeGen/StatementGen.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/CodeGen/StatementGen.cc b/lib/CodeGen/StatementGen.cc
index 8f8711b..8907cfa 100644
--- a/lib/CodeGen/StatementGen.cc
+++ b/lib/CodeGen/StatementGen.cc
@@ -17,9 +17,12 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
// to the emitting function), mirroring FunctionGen's Symbols handling.
auto SavedArrays = Arrays->exchangeTable({});
+ auto SavedScopes = std::move(ConstantScopes);
+ ConstantScopes = {{NextScopeID++, {}}};
FuncGen->emitFunctionDef(FuncDef, [this](StmtAST *S) {
this->emitStmt(S);
- });
+ }, ConstantScopes.back().ID);
+ ConstantScopes = std::move(SavedScopes);
Arrays->exchangeTable(std::move(SavedArrays));
if (SavedBlock) Builder->SetInsertPoint(SavedBlock);
@@ -83,6 +86,11 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
return;
}
+ if (auto *Const = dynamic_cast<ConstantStmtAST*>(Stmt)) {
+ emitConstantStmt(Const);
+ return;
+ }
+
if (auto *Decl = dynamic_cast<DeclareStmtAST*>(Stmt)) {
emitDeclareStmt(Decl);
return;
@@ -98,6 +106,7 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
}
return;
}
+ if (!requireWritable(*Info, Assign->getName())) return;
if (Info->IsArray) {
reportError("Cannot assign array %s without indices", Assign->getName().c_str());
return;
@@ -116,6 +125,7 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
reportError("Unknown variable name %s", In->getName().c_str());
return;
}
+ if (!requireWritable(*Info, In->getName())) return;
if (Info->IsArray) {
reportError("INPUT for entire array %s is not supported", In->getName().c_str());
return;
@@ -204,6 +214,7 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
reportError("Unknown variable name %s", Read->getVarName().c_str());
return;
}
+ if (!requireWritable(*Info, Read->getVarName())) return;
if (Info->IsArray) {
reportError("READFILE into entire array %s is not supported", Read->getVarName().c_str());
return;