From 85093de7415e9410dc5917f8ef6ac489b8198b42 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 28 Oct 2019 22:25:54 +0000 Subject: Add struct type definitions Struct-like types can now be created using the `type` builtin. This creates a constructor function as well as a function for accessing each of the struct's properties. LLVM's type checking makes using these structs a little awkward: they currently cannot be returned by any functions (except the constructor). The aim is to box everything, so that functions can return values they don't know much about. --- scope.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'scope.c') diff --git a/scope.c b/scope.c index 249439d..7936f55 100644 --- a/scope.c +++ b/scope.c @@ -13,8 +13,10 @@ void free_layer(scope_layer *layer) { for (scope_entry *entry = layer->head; entry;) { + scope_entry *x = entry; entry = entry->prev; - free(entry); + free(x->id); + free(x); } free(layer); @@ -40,7 +42,7 @@ void scope_add_entry(scope sc, char *id, LLVMValueRef val, LLVMTypeRef type) { scope_entry *new_entry = malloc(sizeof (*new_entry)); if (!new_entry) error(GENERAL_ERROR, "cannot malloc?"); - new_entry->id = id; + new_entry->id = strdup(id); new_entry->value = val; new_entry->type = type; -- cgit v1.2.1