diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-17 08:34:42 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-17 08:34:42 +0000 |
| commit | abd56ef20bc8061bbecec29edd1301d324c2cb34 (patch) | |
| tree | 8da9a14372a60d4df8bf58693c62c187765e7240 /include | |
| parent | 59e3c50bcd58130e81e1f57b21d6e57b4d4aba6d (diff) | |
feat(classes): destroy stack objects at scope exit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/cps/CodeGen.h | 14 | ||||
| -rw-r--r-- | include/cps/FunctionGen.h | 5 |
2 files changed, 19 insertions, 0 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 9d71df7..9a0b2ef 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -46,6 +46,20 @@ class CodeGen { bool emitConstruct(const std::string &TypeName, llvm::Value *Addr, const std::vector<std::unique_ptr<ExprAST>> &Args, int Line); bool emitDefaultConstruct(const std::string &TypeName, llvm::Value *Addr, int Line); + struct StackObject { + llvm::Value *Addr; + std::string TypeName; + llvm::AllocaInst *Alive; + llvm::AllocaInst *Count; // Non-null for an array; Addr then holds its buffer pointer. + int Line; + bool IsCopy; + }; + std::vector<StackObject> StackObjects; + size_t registerStackObject(llvm::Value *Addr, const std::string &TypeName, int Line, + bool IsArray = false, bool IsCopy = false); + void activateStackObject(size_t Index, llvm::Value *Count = nullptr); + void emitStackObjectCleanup(const StackObject &Object); + void finishStackObjects(llvm::Function *F); struct ConstantScope { unsigned ID; IdentifierMap<std::optional<SymbolInfo>> Saved; diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h index 5ff746d..777ab7d 100644 --- a/include/cps/FunctionGen.h +++ b/include/cps/FunctionGen.h @@ -64,6 +64,7 @@ private: IdentifierMap<FuncSig> Signatures; ArrayParamBinder BindArrayParam; + std::function<void(llvm::Value *, const std::string &, int)> RegisterCopy; void createArgumentAllocas(llvm::Function *F, const std::vector<ParamDecl> &Params, bool IsMethod); @@ -81,6 +82,10 @@ public: void setArrayParamBinder(ArrayParamBinder Binder) { BindArrayParam = std::move(Binder); } + void setCopyRegistrar(std::function<void(llvm::Value *, const std::string &, int)> Registrar) { + RegisterCopy = std::move(Registrar); + } + const FuncSig *getSignature(const std::string &Name) const; llvm::Function *emitPrototype(PrototypeAST *Proto); |
