diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hash_table.c | 4 | ||||
-rw-r--r-- | src/main.c | 15 | ||||
-rw-r--r-- | src/parser.c | 5 | ||||
-rw-r--r-- | src/stack.c | 4 | ||||
-rw-r--r-- | src/visitor.c | 2 |
5 files changed, 6 insertions, 24 deletions
diff --git a/src/hash_table.c b/src/hash_table.c index 7a978e2..bd947c0 100644 --- a/src/hash_table.c +++ b/src/hash_table.c @@ -65,7 +65,6 @@ sl_list_t *init_sl_list() { /* } */ void sl_list_add(sl_list_t *l, char *key, ast_t *value) { - printf("sl list add %s\n", key); sl_node_t *cur = l->head; if (cur == NULL) { l->head = init_sl_node(key, value); @@ -75,7 +74,6 @@ void sl_list_add(sl_list_t *l, char *key, ast_t *value) { cur = cur->next; } cur->next = init_sl_node(key, value); - printf("sl list cur->next %s\n", cur->next->value->key); l->size++; } } @@ -123,7 +121,6 @@ hash_table_t *init_hash_table(int size) { } void hash_table_add(hash_table_t *h, char *key, ast_t *value) { - printf("entering here? %s\n", key); sl_list_t *l = h->buckets[hash(key, h->size)]; sl_list_add(l, key, value); } @@ -134,7 +131,6 @@ ast_t *hash_table_get(hash_table_t *h, char *key) { } bool hash_table_exists(hash_table_t *h, char *key) { - printf("entering here? %s\n", key); sl_list_t *l = h->buckets[hash(key, h->size)]; return sl_list_exists(l, key); } @@ -78,21 +78,14 @@ int main(int argc, char **argv) { /* print(res); */ /* DONE: TEST NON-BUILTIN FUNCTIONS (stack frame) */ - lexer_t *lexer = init_lexer("(bind my_func (lambda (x y) (+ x " - "y))) (my_func (+ 3 4) 4) (+ 3 4)"); - printf("%ld\n", hash("my_func", 100)); - printf("%ld\n", hash("my_func", 100)); - printf("debug 1\n"); + lexer_t *lexer = init_lexer("(bind my_var 3) (bind hello (lambda (x y) (+ x " + "y))) (hello (+ my_var 4) 4) (+ my_var 4)"); parser_t *parser = init_parser(lexer); - printf("debug 2\n"); visitor_t *visitor = init_visitor(parser); - printf("debug 3\n"); ast_t *root = eval(visitor); - printf("debug 4\n"); print_root(root); - printf("debug 5\n"); - ast_t *res = root->subnodes[0]; - print(res); + /* ast_t *res = root->subnodes[0]; */ + /* print(res); */ /* lexer_t *lexer = init_lexer("((lambda (x y) (+ x y)) (+ 3 4) 4) (+ 3 * 4)"); */ diff --git a/src/parser.c b/src/parser.c index ba9788a..0997f18 100644 --- a/src/parser.c +++ b/src/parser.c @@ -129,14 +129,12 @@ void parse_bind(parser_t *parser) { parser_error(parser); token_t *t = parser->tokens[parser->i]; char *name = t->value; - printf("%s\n", name); parser_move(parser); ast_t *expr = parse_expr(parser); /* unevaluated expr will be evaluated when hash table transfers to visitor JIT */ if (expr == NULL) parser_error(parser); hash_table_add(parser->symbol_table, name, expr); - printf("after add\n"); if (parser->tokens[parser->i]->type != TOKEN_RPAREN) parser_error(parser); @@ -154,7 +152,6 @@ ast_t *parse_list(parser_t *parser) { while (current_token->type != TOKEN_RPAREN) { if (current_token->type == TOKEN_ID) { if (strcmp(current_token->value, "lambda") == 0 && first_entry) { - printf("lambda here\n"); return parse_function(parser); } else if (strcmp(current_token->value, "bind") == 0 && first_entry) { parse_bind(parser); @@ -208,7 +205,6 @@ ast_t *parse_expr(parser_t *parser) { else if (t->type == TOKEN_LPAREN) return parse_list(parser); else { - printf("DEBUG\n"); printf("%d", t->type); parser_error(parser); } @@ -223,7 +219,6 @@ ast_t *parse_all(parser_t *parser) { while (t != NULL) { cur = parse_expr(parser); if (cur == NULL) { - printf("this is happening\n"); t = parser->tokens[parser->i]; continue; } diff --git a/src/stack.c b/src/stack.c index c5e753e..2438792 100644 --- a/src/stack.c +++ b/src/stack.c @@ -24,9 +24,9 @@ void stack_push(stack_t *s, hash_table_t *h) { s->cur++; s->stack[s->cur] = h; } - +/* fix heap buffer overflow */ hash_table_t *stack_peek(stack_t *s) { - if (s->stack == NULL) + if (s->cur == -1) return NULL; return s->stack[s->cur]; } diff --git a/src/visitor.c b/src/visitor.c index 4a4d87f..736ce03 100644 --- a/src/visitor.c +++ b/src/visitor.c @@ -68,7 +68,6 @@ bool is_built_in(ast_t *e) { ast_t *eval_symbol(visitor_t *v, ast_t *e) { /* hash_table_t *lmao = stack_peek(v->stack_frame); */ hash_table_t *h = stack_peek(v->stack_frame); - printf("%s\n", e->string_value); if (is_built_in(e)) return e; /* first, it looks in the stack frame for a variable */ @@ -87,7 +86,6 @@ ast_t *eval_symbol(visitor_t *v, ast_t *e) { hash_table_add(v->eval_table, e->string_value, eval); return eval; } else { - printf("this eval error\n"); eval_error(v, e); return NULL; } |