diff --git a/compiler/free.jou b/compiler/free.jou deleted file mode 100644 index d9ca555a..00000000 --- a/compiler/free.jou +++ /dev/null @@ -1,23 +0,0 @@ -# Boring boilerplate code to free up data structures used in compilation. - -import "stdlib/mem.jou" - -import "./types.jou" -import "./typecheck/common.jou" - -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++: - 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 - fom->signature.free() - free(ft->globals) - free(ft->types) - free(ft->owned_types) - free(ft->functions) - free(ft->fomtypes) diff --git a/compiler/main.jou b/compiler/main.jou index 9433dc29..743862e7 100644 --- a/compiler/main.jou +++ b/compiler/main.jou @@ -19,7 +19,6 @@ import "./typecheck/step3_function_and_method_bodies.jou" import "./target.jou" import "./types.jou" import "./token.jou" -import "./free.jou" import "./parser.jou" import "./paths.jou" import "./errors_and_warnings.jou" @@ -190,7 +189,7 @@ class FileState: def free(self) -> None: self->ast.free() free(self->path) - free_file_types(&self->types) + self->types.free() def add_imported_symbol(self, es: ExportSymbol*, imp: AstImport*) -> None: for i = 0; i < self->ast.body.nstatements; i++: diff --git a/compiler/typecheck/common.jou b/compiler/typecheck/common.jou index b749fa31..2cda6377 100644 --- a/compiler/typecheck/common.jou +++ b/compiler/typecheck/common.jou @@ -118,6 +118,23 @@ class FileTypes: functions: SignatureAndUsedPtr* nfunctions: int + def free(self) -> None: + for t = self->owned_types; t < &self->owned_types[self->n_owned_types]; t++: + free_type(*t) + for func = self->functions; func < &self->functions[self->nfunctions]; func++: + func->signature.free() + for fom = self->fomtypes; fom < &self->fomtypes[self->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 + fom->signature.free() + free(self->globals) + free(self->types) + free(self->owned_types) + free(self->functions) + free(self->fomtypes) + def find_type(self, name: byte*) -> Type*: for t = self->types; t < &self->types[self->ntypes]; t++: if strcmp(t->type->name, name) == 0: