aboutsummaryrefslogtreecommitdiff
path: root/include/cps/RuntimeCheck.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-07-26 17:42:08 +0000
committer_ov4 <ov4@ov4.org>2026-07-26 17:42:08 +0000
commita44f1246dbe24fc813a212a5ef3f5811b1d6402a (patch)
treef0894af7daa0bac56471c4dae684ec87588c055d /include/cps/RuntimeCheck.h
parentd65c296a0ad8d335aa076aab48a8b198fa934a2d (diff)
feat: whole arrays (and records) as FUNCTION/PROCEDURE parameters
- Parameter syntax lands end-to-end: ARRAY OF T (rank 1, bounds travel with the argument) and ARRAY[l:u,...] OF T (any rank, literal bounds as a checked contract). Element type and rank must match exactly. - Flattened ABI: each rank-R array parameter becomes a data pointer plus kBoundArgsPerDim i64 bounds per dimension. The callee rebuilds ArrayMetadata from those bounds (ArrayHandler::bindArrayParameter via a binder callback injected by CodeGen, so FunctionGen stays ignorant of the array subsystem); the checked-indexing pipeline is reused unchanged. - BYVAL (the CIE default) copies the whole buffer at callee entry (malloc+memcpy, never freed — consistent with the string policy) so callee writes stay invisible; BYREF binds the caller's buffer. - Bounded-parameter contract: compile-time comparison when the caller's bounds are constants, else a runtime [Fatal] check (RuntimeCheck::emitArrayArgBoundsCheck). - marshalCallArgs gains the array branch and a call-site line number (CallStmtAST now carries one); whole-array-to-scalar keeps a clear error, FUNCTION RETURNS ARRAY is a dedicated parse error. - Verified: BYREF fill/sort-style mutation, BYVAL copy invisibility, 2-D bounded params, ARRAY OF <record> with field writes through the parameter, bounds-contract mismatches at compile time and run time. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/RuntimeCheck.h')
-rw-r--r--include/cps/RuntimeCheck.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/include/cps/RuntimeCheck.h b/include/cps/RuntimeCheck.h
index 5996409..51a07aa 100644
--- a/include/cps/RuntimeCheck.h
+++ b/include/cps/RuntimeCheck.h
@@ -18,6 +18,7 @@ class RuntimeCheck {
llvm::Value *OutOfBoundsMsg;
llvm::Value *EnumRangeMsg;
llvm::Value *NullDerefMsg;
+ llvm::Value *ArrayArgBoundsMsg;
void setupExternalFunctions();
void emitErrorAndExit(llvm::Value *Condition, llvm::Value *Msg, int Line);
@@ -35,6 +36,11 @@ public:
// Dereferencing an unset (null) pointer dies instead of segfaulting.
void emitNullDerefCheck(llvm::Value *Ptr, int Line);
+ // A bounded array parameter is a contract: the argument's runtime bounds
+ // must equal the declared ones.
+ void emitArrayArgBoundsCheck(llvm::Value *ActualLower, llvm::Value *ActualUpper,
+ int64_t DeclaredLower, int64_t DeclaredUpper, int Line);
+
// Runtime-computed variant: FmtArgs are the printf varargs after Msg
// (e.g. {i32 line, ptr filename}). Needed when the failure site is inside
// a synthesized helper function, where the line number is an argument