diff options
| author | _ov4 <ov4@ov4.org> | 2026-07-26 12:07:51 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-07-26 12:07:51 +0000 |
| commit | 4a25b279d8f6c662fa8152cfe42e038d1ea06901 (patch) | |
| tree | 58223f2db133a10827e0a6d0c18c33f04bbc2527 /include/cps | |
| parent | efc86b5c7625cf4c7074319f42f68807a25bde9d (diff) | |
refactor: keep pseudocode signatures, single call-marshalling path
emitPrototype now records each FUNCTION/PROCEDURE's pseudocode signature
(FuncSig: return type + per-param type/BYREF flag). CodeGen::
marshalCallArgs replaces the two verbatim-duplicated marshalling blocks
and dispatches on the declared signature instead of inferring BYREF from
pointer-typed LLVM params: BYVAL STRING params now receive the string
data pointer (no more runtime garbage), and BYVAL args are coerced to
the declared type (INTEGER->REAL args no longer emit invalid IR).
Top-level prototypes are pre-registered in compile(), so calls may
precede definitions; GenerateCall no longer fabricates i64 externs for
unknown names - an unregistered callee is a compile error. OUTPUT
reports an error when it cannot infer the expression type instead of
printing with the INTEGER format.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps')
| -rw-r--r-- | include/cps/CodeGen.h | 3 | ||||
| -rw-r--r-- | include/cps/FunctionGen.h | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 268ba7e..b1d3831 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -69,6 +69,9 @@ class CodeGen { const SymbolInfo *getSymbolInfo(const std::string &Name) const; const TypeInfo *getExprTypeInfo(ExprAST *Expr) const; llvm::Value *coerceValueToType(llvm::Value *Val, const TypeInfo *TargetInfo); + bool marshalCallArgs(const std::string &Callee, + const std::vector<std::unique_ptr<ExprAST>> &ArgExprs, + std::vector<llvm::Value*> &Out); void emitDeclareStmt(DeclareStmtAST *Stmt); void emitOutputValue(llvm::Value *Val, const TypeInfo *TypeInfo, bool AppendNewline = true); diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h index 1dc3901..f55db1b 100644 --- a/include/cps/FunctionGen.h +++ b/include/cps/FunctionGen.h @@ -11,6 +11,14 @@ namespace cps { +// Pseudocode-level signature of a FUNCTION/PROCEDURE, kept so call sites can +// dispatch on declared parameter types and BYREF flags instead of inferring +// them back from LLVM types. +struct FuncSig { + std::string ReturnTypeName; + std::vector<std::pair<std::string, bool>> Params; // (TypeName, IsByRef) +}; + class FunctionGen { llvm::LLVMContext &Context; llvm::Module &Module; @@ -21,6 +29,8 @@ class FunctionGen { std::map<std::string, SymbolInfo> &Symbols; bool &HadError; + std::map<std::string, FuncSig> Signatures; + void createArgumentAllocas(llvm::Function *F, const std::vector<std::tuple<std::string, std::string, bool>> &Args); public: @@ -35,6 +45,8 @@ public: llvm::Type *getLLVMType(const std::string &TypeName); + const FuncSig *getSignature(const std::string &Name) const; + llvm::Function *emitPrototype(PrototypeAST *Proto); llvm::Function *emitFunctionDef(FunctionDefAST *FuncAST, const std::function<void(StmtAST*)> &StmtEmitter); |
