Skip to content

Commit

Permalink
free_signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Jan 10, 2025
1 parent 7bd1d31 commit e04890d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions compiler/cf_graph.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 3 additions & 7 deletions compiler/free.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions compiler/types.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e04890d

Please sign in to comment.