aboutsummaryrefslogtreecommitdiff
path: root/include/cps/CodeGen.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-07-26 17:32:24 +0000
committer_ov4 <ov4@ov4.org>2026-07-26 17:32:24 +0000
commitf19f1c956780f41f1440b372187770ce0be8efed (patch)
treefe0c2fe47a2cddb1bd8bd92206d47136bfcbfd37 /include/cps/CodeGen.h
parent3366a2e0fae05d9e792169e74471c7282bf18681 (diff)
feat: user type registry and enumerated types (CIE 4.1/4.2)
- TypeSystem: TypeKinds Enum/Record/Pointer with per-kind payloads and checked accessors; two-pass registration (names first, then definitions in source order) so pointer TYPEs may forward-reference; enum-constant table owned by TypeSystem so constants stay visible inside function bodies across the Symbols save/clear/restore. Dead surface removed (Custom kind, Printable/Builtin/ReferenceLike, ElementSize, hasType, CodeGen::getNamedValue/getLLVMType). - Enums are i64 with 0-based ordinals (constexpr kEnumOrdinalBase); all type identity is by NAME. New emitCoercedExpr is the single admission gate, replacing raw coercion at assignments, array stores, BYVAL args, RETURN, IF/WHILE/REPEAT/FOR operands, file operands and builtin args; coerceValueToType now hard-errors if a user-kind target reaches it. - Binary ops with user-kind operands are intercepted ahead of ArithmeticHandler ('&'-intercept precedent): same-enum comparisons, enum +/- INTEGER (with a runtime range check, [Fatal] on overflow, the only site that can manufacture an invalid ordinal), same-name pointer =/<>; everything else is a compile error naming the operator. - OUTPUT is an exhaustive switch over TypeKind (enum prints its ordinal; record/pointer are compile errors, also covering whole-array OUTPUT); INPUT's silent %lld fallback for unknown kinds is now an explicit error. - Enum value names are globally reserved: collisions with DECLARE, array names, parameters and function names are compile errors. - RuntimeCheck: emitEnumRangeCheck + emitNullDerefCheck (used by the pointer phase) following the emitIndexCheck recipe. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/CodeGen.h')
-rw-r--r--include/cps/CodeGen.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index 2451cbd..713d02b 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -64,6 +64,10 @@ class CodeGen {
bool isWholeArrayVar(ExprAST *Expr) const;
const TypeInfo *getExprTypeInfo(ExprAST *Expr) const;
llvm::Value *coerceValueToType(llvm::Value *Val, const TypeInfo *TargetInfo);
+
+ // TYPE-system helpers (Designator.cc).
+ void runTypePrePass(const std::vector<std::unique_ptr<StmtAST>> &Statements);
+ llvm::Value *emitUserKindBinaryOp(BinaryExprAST *Bin, const TypeInfo *LT, const TypeInfo *RT);
bool marshalCallArgs(const std::string &Callee,
const std::vector<std::unique_ptr<ExprAST>> &ArgExprs,
std::vector<llvm::Value*> &Out);
@@ -90,10 +94,14 @@ public:
// STRING slots zero-init to null; normalize null to "" at load/print sites.
llvm::Value *emitStringNullGuard(llvm::Value *StrVal);
+ // Name-level admission gate for Enum/Record/Pointer plus the existing
+ // representation coercion for builtin targets. The ONLY door through
+ // which assignments, BYVAL args, RETURN values and file/builtin operands
+ // may produce a typed value. (Designator.cc)
+ llvm::Value *emitCoercedExpr(ExprAST *E, const TypeInfo *TargetInfo);
+
const TypeInfo *resolveType(const std::string &TypeName) const;
- llvm::Type *getLLVMType(const std::string &TypeName) const;
- llvm::Value *getNamedValue(const std::string &Name) const;
-
+
friend class ArrayHandler;
};