diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-18 08:07:50 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-18 08:07:50 +0000 |
| commit | 345e3d419eafb0e234aecb4a33f37efe2afbbf53 (patch) | |
| tree | 9330322103f26f15c6df91cbbd62bf5a1f6e72da /include/cps | |
| parent | 927e3fc0384c941f9ad313a28768660c3cdb1777 (diff) | |
feat(classes): add copy constructors and statement-scoped temporaries
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps')
| -rw-r--r-- | include/cps/CodeGen.h | 9 | ||||
| -rw-r--r-- | include/cps/ExceptionHandler.h | 3 | ||||
| -rw-r--r-- | include/cps/Parser.h | 1 |
3 files changed, 12 insertions, 1 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 9b2d6c5..30f4135 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -66,6 +66,7 @@ class CodeGen { llvm::AllocaInst *Count; // Non-null for an array; Addr then holds its buffer pointer. int Line; bool IsCopy; + bool Temporary = false; }; std::vector<StackObject> StackObjects; size_t registerStackObject(llvm::Value *Addr, const std::string &TypeName, int Line, @@ -73,6 +74,14 @@ class CodeGen { void activateStackObject(size_t Index, llvm::Value *Count = nullptr); void emitStackObjectCleanup(const StackObject &Object); void finishStackObjects(llvm::Function *F); + void cleanupTemporaries(size_t Start = 0); + bool isObjectLValue(ExprAST *Expr) const; + llvm::Value *emitOwnedValue(ExprAST *Expr, const TypeInfo *Type, + std::vector<size_t> &Transfers); + llvm::Value *copyClassValue(const TypeInfo *Type, llvm::Value *Address, + std::vector<size_t> &Transfers); + void transferObjects(const std::vector<size_t> &Objects); + void emitStmtImpl(StmtAST *Stmt); struct ConstantScope { unsigned ID; IdentifierMap<std::optional<SymbolInfo>> Saved; diff --git a/include/cps/ExceptionHandler.h b/include/cps/ExceptionHandler.h index a2dc5d0..f55526b 100644 --- a/include/cps/ExceptionHandler.h +++ b/include/cps/ExceptionHandler.h @@ -25,6 +25,7 @@ class ExceptionHandler { llvm::Instruction *Before; FunctionState State; bool Unwinding; + bool TemporariesOnly = false; }; std::map<llvm::Function *, std::vector<CleanupPoint>> CleanupPoints; bool FillingUnwind = false; @@ -50,7 +51,7 @@ public: llvm::Instruction *emitReturnCleanup(); void enableCleanups(llvm::Function *F); void recordExit(llvm::Instruction *Before, bool Unwinding = false); - void fillCleanups(llvm::Function *F, const std::function<void()> &Destroy); + void fillCleanups(llvm::Function *F, const std::function<void(bool)> &Destroy); llvm::Value *emitCall(llvm::FunctionCallee Callee, llvm::ArrayRef<llvm::Value *> Args, const llvm::Twine &Name = ""); diff --git a/include/cps/Parser.h b/include/cps/Parser.h index ad80876..eedc3f8 100644 --- a/include/cps/Parser.h +++ b/include/cps/Parser.h @@ -38,6 +38,7 @@ class Parser { std::unique_ptr<ExprAST> ParseUnaryImpl(); std::unique_ptr<ExprAST> ParseUnary(); std::unique_ptr<ExprAST> ParsePrimaryImpl(); + std::unique_ptr<ExprAST> ParseResultMethods(std::unique_ptr<ExprAST> Expr, int Line); std::unique_ptr<ExprAST> ParsePrimary(); std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec, std::unique_ptr<ExprAST> LHS); |
