From a44f1246dbe24fc813a212a5ef3f5811b1d6402a Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 17:42:08 +0000 Subject: feat: whole arrays (and records) as FUNCTION/PROCEDURE parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 with field writes through the parameter, bounds-contract mismatches at compile time and run time. Co-Authored-By: Claude Fable 5 --- lib/Parser/ParserFunction.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/Parser') diff --git a/lib/Parser/ParserFunction.cc b/lib/Parser/ParserFunction.cc index a46cd0f..776a980 100644 --- a/lib/Parser/ParserFunction.cc +++ b/lib/Parser/ParserFunction.cc @@ -135,6 +135,11 @@ std::unique_ptr Parser::ParseFunction() { std::string RetType = "INTEGER"; if (CurTok == tok_returns) { getNextToken(); + if (CurTok == tok_array) { + fprintf(stderr, "Error: A FUNCTION cannot RETURN an array; use a BYREF PROCEDURE parameter instead at line %d\n", + Lex.getLine()); + return nullptr; + } RetType = ParseTypeName(true); if (RetType.empty()) { fprintf(stderr, "Error: Expected return type for function '%s'\n", Name.c_str()); @@ -181,6 +186,7 @@ std::unique_ptr Parser::ParseProcedure() { } std::unique_ptr Parser::ParseCallStmt() { + int Line = Lex.getLine(); getNextToken(); if (CurTok != tok_identifier) { fprintf(stderr, "Error: Expected callee name after CALL\n"); @@ -198,7 +204,7 @@ std::unique_ptr Parser::ParseCallStmt() { Args = std::move(*Parsed); } - return std::make_unique(Callee, std::move(Args)); + return std::make_unique(Callee, std::move(Args), Line); } std::unique_ptr Parser::ParseReturnStmt() { -- cgit v1.3.1-4-g156e