From 59e3c50bcd58130e81e1f57b21d6e57b4d4aba6d Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 08:32:43 +0000 Subject: feat(classes): destroy and release heap objects with DELETE Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/StatementGen.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/CodeGen/StatementGen.cc') 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(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(Stmt)) { emitTryStmt(Try); return; -- cgit v1.3.1-4-g156e