From e04890d0d732c8a9a3d49ad4aa10a76a45eb9b69 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 10 Jan 2025 19:54:04 +0200 Subject: [PATCH] free_signature --- compiler/cf_graph.jou | 5 ++--- compiler/free.jou | 10 +++------- compiler/types.jou | 7 +++++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/compiler/cf_graph.jou b/compiler/cf_graph.jou index 6edfdbf0..aef50992 100644 --- a/compiler/cf_graph.jou +++ b/compiler/cf_graph.jou @@ -8,7 +8,6 @@ import "./errors_and_warnings.jou" import "./structs.jou" import "./typecheck/common.jou" import "./print.jou" -import "./free.jou" import "./types.jou" @@ -200,7 +199,7 @@ class CfInstruction: if self->kind == CfInstructionKind::StringArray: free(self->strarray.str) if self->kind == CfInstructionKind::Call: - free_signature(&self->signature) + self->signature.free() free(self->operands) def add_operand(self, operand: LocalVariable*) -> None: @@ -291,7 +290,7 @@ class CfGraph: printf("\n") def free(self) -> None: - free_signature(&self->signature) + self->signature.free() for b = self->all_blocks; b < &self->all_blocks[self->n_all_blocks]; b++: (*b)->free() if *b != &self->start_block and *b != &self->end_block: diff --git a/compiler/free.jou b/compiler/free.jou index c68f19db..a5eddb45 100644 --- a/compiler/free.jou +++ b/compiler/free.jou @@ -5,25 +5,21 @@ import "stdlib/mem.jou" import "./types.jou" import "./typecheck/common.jou" -def free_signature(sig: Signature*) -> None: - free(sig->argnames) - free(sig->argtypes) - def free_export_symbol(es: ExportSymbol*) -> None: if es->kind == ExportSymbolKind::Function: - free_signature(&es->funcsignature) + es->funcsignature.free() def free_file_types(ft: FileTypes*) -> None: for t = ft->owned_types; t < &ft->owned_types[ft->n_owned_types]; t++: free_type(*t) for func = ft->functions; func < &ft->functions[ft->nfunctions]; func++: - free_signature(&func->signature) + func->signature.free() for fom = ft->fomtypes; fom < &ft->fomtypes[ft->nfomtypes]; fom++: for et = fom->expr_types; et < &fom->expr_types[fom->n_expr_types]; et++: free(*et) free(fom->expr_types) free(fom->locals) # Don't free individual locals because they're owned by CFG now - free_signature(&fom->signature) + fom->signature.free() free(ft->globals) free(ft->types) free(ft->owned_types) diff --git a/compiler/types.jou b/compiler/types.jou index 0e1d7735..4c942b07 100644 --- a/compiler/types.jou +++ b/compiler/types.jou @@ -2,7 +2,6 @@ import "stdlib/mem.jou" import "stdlib/str.jou" import "./errors_and_warnings.jou" -import "./free.jou" class ClassField: name: byte[100] @@ -186,7 +185,7 @@ def free_type(t: Type*) -> None: assert t != NULL if t->kind == TypeKind::Class: for m = t->classdata.methods; m < &t->classdata.methods[t->classdata.nmethods]; m++: - free_signature(m) + m->free() free(t->classdata.fields) free(t->classdata.methods) @@ -246,6 +245,10 @@ class Signature: # TODO: rename to return_type_location returntype_location: Location # meaningful even if returntype is NULL + def free(self) -> None: + free(self->argnames) + free(self->argtypes) + def get_self_class(self) -> Type*: if self->nargs > 0 and strcmp(self->argnames[0], "self") == 0: if self->argtypes[0]->kind == TypeKind::Pointer: