From 3366a2e0fae05d9e792169e74471c7282bf18681 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 17:21:14 +0000 Subject: feat: TYPE-system front end — tokens, designators, ParamDecl grammar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Reserve TYPE/ENDTYPE/SET/DEFINE (-600 token block); SET/DEFINE parse to dedicated not-implemented errors (RANDOM precedent). - New TypeAST.h: enum/pointer/record decl nodes, designator chain (DesignatorExprAST + Index/Field/Deref accessors), AddrOfExprAST, DesignatorAssignStmtAST. Bare-name and single-index shapes degrade to their legacy nodes, so existing programs produce identical ASTs. - ParserType.cc: TYPE declarations (top-level only, enforced via a ParseBlock depth counter), DECLARE-only record bodies with local field-level error recovery. - Postfix [ ] . ^ chain in ParseIdentifierExpr; prefix ^ (address-of, designator operand only) in ParseUnary; assignment targets rebuilt on the same suffix parser. - Parameters: ParamDecl{name, type, mode, array rank/bounds} replaces the (name, type, byref) tuple. Pass mode is sticky across parameters and BYREF is rejected in FUNCTIONs, both per guide §8.3 (the old per-param reset made the guide's own SWAP example pass Y by value). ARRAY OF T / ARRAY[l:u,...] OF T parameter syntax parses; codegen rejects it until the parameter-passing phase lands. - CodeGen stubs report clear not-implemented errors for the new nodes so nothing is silently ignored. Co-Authored-By: Claude Fable 5 --- include/cps/FunctionAST.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'include/cps/FunctionAST.h') diff --git a/include/cps/FunctionAST.h b/include/cps/FunctionAST.h index 613079c..f663867 100644 --- a/include/cps/FunctionAST.h +++ b/include/cps/FunctionAST.h @@ -1,27 +1,43 @@ #pragma once #include "cps/AST.h" +#include #include #include #include -#include +#include namespace cps { +enum class PassMode : uint8_t { ByVal, ByRef }; + +// One declared FUNCTION/PROCEDURE parameter. For array parameters TypeName +// is the ELEMENT type; DeclaredBounds holds literal per-dimension bounds for +// the bounded form (empty for `ARRAY OF T`, which is rank 1 with the bounds +// travelling alongside the argument). +struct ParamDecl { + std::string Name; + std::string TypeName; + PassMode Mode = PassMode::ByVal; + bool IsArray = false; + int Rank = 0; // 0 = scalar + std::vector> DeclaredBounds; +}; + class PrototypeAST { std::string Name; - std::vector> Args; + std::vector Params; std::string ReturnType; bool IsExternal; public: - PrototypeAST(const std::string &Name, - std::vector> Args, + PrototypeAST(const std::string &Name, + std::vector Params, const std::string &ReturnType, bool IsExternal = false) - : Name(Name), Args(std::move(Args)), ReturnType(ReturnType), IsExternal(IsExternal) {} + : Name(Name), Params(std::move(Params)), ReturnType(ReturnType), IsExternal(IsExternal) {} const std::string &getName() const { return Name; } - const std::vector> &getArgs() const { return Args; } + const std::vector &getParams() const { return Params; } const std::string &getReturnType() const { return ReturnType; } bool isExternal() const { return IsExternal; } }; -- cgit v1.3.1-4-g156e