diff --git a/src/exec.c b/src/exec.c index 33611c0..f1d208c 100644 --- a/src/exec.c +++ b/src/exec.c @@ -18,33 +18,16 @@ AST* exec_start(AST* ast) { Scope* global = scope_init(NULL); global->uses = 1; - // Keep track of built-in function ASTs, as they arent part of the main - // tree. - // DList* builtins = dlist_init(); - - for (int i = 0; i < BUILTIN_FNS_LN; i++) { - - // AST* builtin_ast = - // ast_init(AST_TYPE_BIF, ast_bif_data_init(BUILTIN_FNS[i].fn)); - - // dlist_append(builtins, builtin_ast); - + for (int i = 0; i < BUILTIN_FNS_LN; i++) htab_ins( global->here, BUILTIN_FNS[i].name, ast_init(AST_TYPE_BIF, ast_bif_data_init(BUILTIN_FNS[i].fn)) ); - } log_dbg("Completed startup sequence."); AST* res = exec_exp(ast, global); - // Clean up built-in function ASTs. - /*for (int i = 0; i < builtins->ln; i++) ast_destroy(builtins->buf[i]); - dlist_destroy(builtins); - */ - - // scope_destroy_psv(global); return res; } @@ -66,10 +49,6 @@ AST* exec_exp(AST* ast, Scope* parent) { AST* exec_block(AST* ast, Scope* parent) { ASTBlockData* block = (ASTBlockData*)ast->data; - // Blocks create their own scope, shared among their expressions. - // ast->scope = scope_init(parent); - - // HERE exec_new_scope(ast, parent); // Loop through all but last ast. @@ -120,9 +99,6 @@ AST* exec_cf(AST* ast, size_t argc, AST** argv) { AST* exec_vdef(AST* ast, Scope* parent) { // Use parent's scope. - // ast->scope = parent; - - // HERE exec_inherit_scope(ast, parent); ASTVDefData* data = (ASTVDefData*)ast->data; @@ -134,9 +110,6 @@ AST* exec_vdef(AST* ast, Scope* parent) { AST* exec_vref(AST* ast, Scope* parent) { // Use parent's scope. - // ast->scope = parent; - - // HERE exec_inherit_scope(ast, parent); log_dbg("attempting to reference var"); ASTVrefData* vref = (ASTVrefData*)ast->data; @@ -159,10 +132,12 @@ AST* exec_vref(AST* ast, Scope* parent) { AST* exec_fdef(AST* ast, Scope* parent) { ast->scope = scope_init(parent); ASTFDefData* fdef = (ASTFDefData*)ast->data; - AST* val = fdef->body; + log_dbgf("IS THIS SUSPICIOUS??? %i", fdef->body->type); + AST* val = ast; char* key = fdef->name; scope_add(parent, key, val); - return val; // Function definitions return function body. + // TODO: Create lambda functions. + return fdef->body; // Function definitions return function body. } void exec_print(double n) { printf("= %lf\n", n); } diff --git a/src/gc.c b/src/gc.c index 6624e9b..72ba818 100644 --- a/src/gc.c +++ b/src/gc.c @@ -2,6 +2,7 @@ #include "include/ast.h" #include "include/scope.h" #include "include/util.h" +#include #include #include @@ -13,6 +14,8 @@ void gc_destroy(GC* gc) { free(gc); } void f() {} void* gc_alloc(size_t sz, GCType type) { + assert(type <= GC_TYPE_MAX); + void* mem = malloc(sz); GC* gc = malloc(sizeof(GC)); @@ -22,6 +25,12 @@ void* gc_alloc(size_t sz, GCType type) { gc->nxt = gclist; gclist = gc; + if (type == GC_TYPE_AST) { + log_dbgf("Alloc'd AST for GC: %p", mem); + } else if (type == GC_TYPE_SCOPE) { + log_dbgf("Alloc'd scope for GC: %p", mem); + } + return mem; } diff --git a/src/htab.c b/src/htab.c index 76a8cfc..052ef75 100644 --- a/src/htab.c +++ b/src/htab.c @@ -9,6 +9,8 @@ HTab* htab_init() { HTab* htab = malloc(sizeof(HTab)); + log_dbgf("HTAB %p", htab); + return htab; } diff --git a/src/lexer.c b/src/lexer.c index 8ea1be8..5c909d7 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -26,7 +26,7 @@ void argarr_destroy(ArgArr* argarr) { void argarr_destroypsv(ArgArr* argarr) { free(argarr); } void argarr_add(ArgArr* argarr, AST* arg) { - if ((argarr->ln + 1) * argarr->sz > argarr->sz) { + if ((argarr->ln + 1) * sizeof(AST*) > argarr->sz) { argarr->sz *= 2; argarr->buf = realloc(argarr->buf, argarr->sz); log_dbgf( diff --git a/src/main.c b/src/main.c index d4499ff..0cd57dc 100644 --- a/src/main.c +++ b/src/main.c @@ -61,8 +61,6 @@ int main(int argc, char** argv) { AST* eval = exec_start(root); ast_print(eval); - // ast_destroy(eval); - // ast_destroy(root); gc_hack_free(); }