aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/ArrayHandler.cc
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 /lib/CodeGen/ArrayHandler.cc
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 'lib/CodeGen/ArrayHandler.cc')
-rw-r--r--lib/CodeGen/ArrayHandler.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/CodeGen/ArrayHandler.cc b/lib/CodeGen/ArrayHandler.cc
index 7977563..d21d91c 100644
--- a/lib/CodeGen/ArrayHandler.cc
+++ b/lib/CodeGen/ArrayHandler.cc
@@ -84,6 +84,10 @@ void ArrayHandler::emitArrayDeclare(ArrayDeclareStmtAST *Stmt, CodeGen &CG) {
CG.reportError("Unknown array element type %s", Stmt->getType().c_str());
return;
}
+ if (Types.lookupEnumConstant(Name)) {
+ CG.reportError("'%s' is an enum value and cannot be declared as an array", Name.c_str());
+ return;
+ }
std::vector<Value*> Lows;
std::vector<Value*> Highs;
@@ -199,8 +203,7 @@ void ArrayHandler::emitArrayAssign(ArrayAssignStmtAST *Stmt, CodeGen &CG) {
Stmt->getLine(), CG, ElemTypeName);
if (!ElemPtr) return;
- Value *Val = CG.emitExpr(Stmt->getExpr());
- Val = CG.coerceValueToType(Val, Types.resolve(ElemTypeName));
+ Value *Val = CG.emitCoercedExpr(Stmt->getExpr(), Types.resolve(ElemTypeName));
if (!Val) return;
Builder->CreateStore(Val, ElemPtr);
@@ -256,6 +259,13 @@ bool ArrayHandler::tryEmitArrayOutput(ExprAST *Expr, CodeGen &CG) {
return false;
}
+ const TypeInfo *ElemInfo = Types.resolve(getMetadata(Name)->ElementTypeName);
+ if (ElemInfo && !ElemInfo->isOutputtable()) {
+ CG.reportError("Cannot OUTPUT array %s of type %s; output individual fields",
+ Name.c_str(), ElemInfo->Name.c_str());
+ return true; // diagnosed
+ }
+
std::vector<Value*> Indices;
if (IndexExprs && !emitCheckedIndices(Name, *IndexExprs, Line, false, CG, Indices)) {
return true; // diagnosed