I try.
This commit is contained in:
parent
a4afd3b58a
commit
80122b6572
35
src/exec.c
35
src/exec.c
@ -18,33 +18,16 @@ AST* exec_start(AST* ast) {
|
|||||||
Scope* global = scope_init(NULL);
|
Scope* global = scope_init(NULL);
|
||||||
global->uses = 1;
|
global->uses = 1;
|
||||||
|
|
||||||
// Keep track of built-in function ASTs, as they arent part of the main
|
for (int i = 0; i < BUILTIN_FNS_LN; i++)
|
||||||
// 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);
|
|
||||||
|
|
||||||
htab_ins(
|
htab_ins(
|
||||||
global->here, BUILTIN_FNS[i].name,
|
global->here, BUILTIN_FNS[i].name,
|
||||||
ast_init(AST_TYPE_BIF, ast_bif_data_init(BUILTIN_FNS[i].fn))
|
ast_init(AST_TYPE_BIF, ast_bif_data_init(BUILTIN_FNS[i].fn))
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
log_dbg("Completed startup sequence.");
|
log_dbg("Completed startup sequence.");
|
||||||
|
|
||||||
AST* res = exec_exp(ast, global);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,10 +49,6 @@ AST* exec_exp(AST* ast, Scope* parent) {
|
|||||||
AST* exec_block(AST* ast, Scope* parent) {
|
AST* exec_block(AST* ast, Scope* parent) {
|
||||||
ASTBlockData* block = (ASTBlockData*)ast->data;
|
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);
|
exec_new_scope(ast, parent);
|
||||||
|
|
||||||
// Loop through all but last ast.
|
// 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) {
|
AST* exec_vdef(AST* ast, Scope* parent) {
|
||||||
// Use parent's scope.
|
// Use parent's scope.
|
||||||
// ast->scope = parent;
|
|
||||||
|
|
||||||
// HERE
|
|
||||||
exec_inherit_scope(ast, parent);
|
exec_inherit_scope(ast, parent);
|
||||||
|
|
||||||
ASTVDefData* data = (ASTVDefData*)ast->data;
|
ASTVDefData* data = (ASTVDefData*)ast->data;
|
||||||
@ -134,9 +110,6 @@ AST* exec_vdef(AST* ast, Scope* parent) {
|
|||||||
|
|
||||||
AST* exec_vref(AST* ast, Scope* parent) {
|
AST* exec_vref(AST* ast, Scope* parent) {
|
||||||
// Use parent's scope.
|
// Use parent's scope.
|
||||||
// ast->scope = parent;
|
|
||||||
|
|
||||||
// HERE
|
|
||||||
exec_inherit_scope(ast, parent);
|
exec_inherit_scope(ast, parent);
|
||||||
log_dbg("attempting to reference var");
|
log_dbg("attempting to reference var");
|
||||||
ASTVrefData* vref = (ASTVrefData*)ast->data;
|
ASTVrefData* vref = (ASTVrefData*)ast->data;
|
||||||
@ -159,10 +132,12 @@ AST* exec_vref(AST* ast, Scope* parent) {
|
|||||||
AST* exec_fdef(AST* ast, Scope* parent) {
|
AST* exec_fdef(AST* ast, Scope* parent) {
|
||||||
ast->scope = scope_init(parent);
|
ast->scope = scope_init(parent);
|
||||||
ASTFDefData* fdef = (ASTFDefData*)ast->data;
|
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;
|
char* key = fdef->name;
|
||||||
scope_add(parent, key, val);
|
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); }
|
void exec_print(double n) { printf("= %lf\n", n); }
|
||||||
|
9
src/gc.c
9
src/gc.c
@ -2,6 +2,7 @@
|
|||||||
#include "include/ast.h"
|
#include "include/ast.h"
|
||||||
#include "include/scope.h"
|
#include "include/scope.h"
|
||||||
#include "include/util.h"
|
#include "include/util.h"
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -13,6 +14,8 @@ void gc_destroy(GC* gc) { free(gc); }
|
|||||||
void f() {}
|
void f() {}
|
||||||
|
|
||||||
void* gc_alloc(size_t sz, GCType type) {
|
void* gc_alloc(size_t sz, GCType type) {
|
||||||
|
assert(type <= GC_TYPE_MAX);
|
||||||
|
|
||||||
void* mem = malloc(sz);
|
void* mem = malloc(sz);
|
||||||
GC* gc = malloc(sizeof(GC));
|
GC* gc = malloc(sizeof(GC));
|
||||||
|
|
||||||
@ -22,6 +25,12 @@ void* gc_alloc(size_t sz, GCType type) {
|
|||||||
gc->nxt = gclist;
|
gc->nxt = gclist;
|
||||||
gclist = gc;
|
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;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
HTab* htab_init() {
|
HTab* htab_init() {
|
||||||
HTab* htab = malloc(sizeof(HTab));
|
HTab* htab = malloc(sizeof(HTab));
|
||||||
|
|
||||||
|
log_dbgf("HTAB %p", htab);
|
||||||
|
|
||||||
return htab;
|
return htab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ void argarr_destroy(ArgArr* argarr) {
|
|||||||
void argarr_destroypsv(ArgArr* argarr) { free(argarr); }
|
void argarr_destroypsv(ArgArr* argarr) { free(argarr); }
|
||||||
|
|
||||||
void argarr_add(ArgArr* argarr, AST* arg) {
|
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->sz *= 2;
|
||||||
argarr->buf = realloc(argarr->buf, argarr->sz);
|
argarr->buf = realloc(argarr->buf, argarr->sz);
|
||||||
log_dbgf(
|
log_dbgf(
|
||||||
|
@ -61,8 +61,6 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
AST* eval = exec_start(root);
|
AST* eval = exec_start(root);
|
||||||
ast_print(eval);
|
ast_print(eval);
|
||||||
// ast_destroy(eval);
|
|
||||||
// ast_destroy(root);
|
|
||||||
gc_hack_free();
|
gc_hack_free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user