aboutsummaryrefslogtreecommitdiff
path: root/include/cps/CodeGen.h
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 /include/cps/CodeGen.h
parent45c9d37eb27d204a6202b33cb37e890af0171357 (diff)
feat(constants): implement literal constants with lexical scope
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/CodeGen.h')
-rw-r--r--include/cps/CodeGen.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index 4259d63..2ba5e79 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -13,6 +13,7 @@
#include <map>
#include <memory>
+#include <optional>
#include <string>
namespace cps {
@@ -27,6 +28,16 @@ class CodeGen {
std::unique_ptr<llvm::Module> TheModule;
std::unique_ptr<llvm::IRBuilder<>> Builder;
std::map<std::string, SymbolInfo> Symbols;
+ struct ConstantScope {
+ unsigned ID;
+ std::map<std::string, std::optional<SymbolInfo>> Saved;
+ };
+ std::vector<ConstantScope> ConstantScopes = {{0, {}}};
+ unsigned NextScopeID = 1;
+ void emitScopedBlock(const std::vector<std::unique_ptr<StmtAST>> &Body);
+ bool prepareSymbolDeclaration(const std::string &Name, bool IsConstant = false);
+ bool requireWritable(const SymbolInfo &Info, const std::string &Name);
+ void emitConstantStmt(ConstantStmtAST *Stmt);
std::unique_ptr<TypeSystem> Types;
std::unique_ptr<ArrayHandler> Arrays;