diff --git a/src/htab.c b/src/htab.c index 3d2d041..300b74d 100644 --- a/src/htab.c +++ b/src/htab.c @@ -7,12 +7,13 @@ #include HTab* htab_init() { - HTab* htab = calloc(1, sizeof(HTab)); + HTab* htab = malloc(sizeof(HTab)); return htab; } -void htab_destroy(HTab* htab) { free(htab); } +void htab_destroy(HTab* htab) { // free(htab); +} // Get the index of a key. size_t geti(char* key) { diff --git a/src/main.c b/src/main.c index 4c29420..fe5c600 100644 --- a/src/main.c +++ b/src/main.c @@ -4,10 +4,8 @@ #include "include/ast.h" #include "include/dstr.h" #include "include/exec.h" -#include "include/global.h" -#include "include/htab.h" + #include "include/lexer.h" -#include "include/stack.h" #include "include/util.h" #include "../build/grammars/grammar.tab.h" @@ -17,16 +15,11 @@ extern AST* root; extern char* inp; extern int yyparse(); -Stack* scope; - int main(int argc, char** argv) { if (argc - 1 && strlen(argv[1]) > 0 && (inp = argv[1]) && !yyparse()) { log_dbg("Parsed successfully!\n"); ast_print(exec_start(root)); - HTab* global = stack_pop(scope); - htab_destroy(global); - stack_destroy(scope); ast_destroy(root); exit(0); } @@ -63,9 +56,6 @@ int main(int argc, char** argv) { #endif ast_print(exec_start(root)); - HTab* global = stack_pop(scope); - htab_destroy(global); - stack_destroy(scope); ast_destroy(root); } diff --git a/src/scope.c b/src/scope.c index a433bd2..02c1b5f 100644 --- a/src/scope.c +++ b/src/scope.c @@ -12,12 +12,14 @@ Scope* scope_init(Scope* inherit) { } void scope_destroy(Scope* scope) { + if (!scope) return; htab_destroy(scope->here); if (scope->inherit != NULL) scope_destroy(scope->inherit); free(scope); } void scope_destroy_psv(Scope* scope) { + if (!scope) return; htab_destroy(scope->here); scope->inherit = NULL; free(scope);