From f19f1c956780f41f1440b372187770ce0be8efed Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 17:32:24 +0000 Subject: 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 --- include/cps/CodeGen.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'include/cps/CodeGen.h') 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> &Statements); + llvm::Value *emitUserKindBinaryOp(BinaryExprAST *Bin, const TypeInfo *LT, const TypeInfo *RT); bool marshalCallArgs(const std::string &Callee, const std::vector> &ArgExprs, std::vector &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; }; -- cgit v1.3.1-4-g156e