diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-17 08:32:43 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-17 08:32:43 +0000 |
| commit | 59e3c50bcd58130e81e1f57b21d6e57b4d4aba6d (patch) | |
| tree | c5f6c5b1bd367feadca0c2e7d0f47c8dedb91b20 /lib/CodeGen/StatementGen.cc | |
| parent | e847e4c53cf21fcb96f7ed7765e305a7ec8e6c19 (diff) | |
feat(classes): destroy and release heap objects with DELETE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/StatementGen.cc')
| -rw-r--r-- | lib/CodeGen/StatementGen.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/CodeGen/StatementGen.cc b/lib/CodeGen/StatementGen.cc index bd1f7c5..a7c8eda 100644 --- a/lib/CodeGen/StatementGen.cc +++ b/lib/CodeGen/StatementGen.cc @@ -2,6 +2,7 @@ #include "cps/ArrayHandler.h" #include "cps/FileAST.h" #include "cps/FileHandler.h" +#include "cps/MemoryHandler.h" #include "cps/ExceptionHandler.h" #include "cps/TypeAST.h" @@ -49,6 +50,19 @@ void CodeGen::emitStmt(StmtAST *Stmt) { Builder->SetInsertPoint(BasicBlock::Create(*TheContext, "unreachable_code", F)); } + if (auto *Delete = dynamic_cast<DeleteStmtAST*>(Stmt)) { + LValueInfo Object; + if (!emitLValue(Delete->getTarget(), Object)) return; + const TypeInfo *Info = resolveType(Object.TypeName); + if (!Info || !Info->IsClass) { + reportError("DELETE requires a class object"); + return; + } + Memory->emitValidate(Object.Addr, Stmt->getLine()); + if (emitDestroy(Object.TypeName, Object.Addr, Stmt->getLine())) + Memory->emitRelease(Object.Addr, Stmt->getLine()); + return; + } if (auto *Try = dynamic_cast<TryStmtAST*>(Stmt)) { emitTryStmt(Try); return; |
