From b97063f65017cad107c870fefd39069f34bbf7ab Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 6 Oct 2016 16:58:33 +0200 Subject: Adds a trace code --- interpreter/code.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'interpreter/code.c') diff --git a/interpreter/code.c b/interpreter/code.c index e623ff4..be9ece0 100644 --- a/interpreter/code.c +++ b/interpreter/code.c @@ -3,7 +3,9 @@ #include #include +#include "graphs.h" #include "mem.h" +#include "print.h" void fill_node_int(struct node** node, int i) { unsigned int used_count = (*node)->used_count; @@ -11,7 +13,7 @@ void fill_node_int(struct node** node, int i) { (*node)->kind = NODE_INT; (*node)->var1 = my_calloc(1, sizeof(int)); *((int*) (*node)->var1) = i; - use_node(*node, used_count - 1); + use_node(*node, used_count); } void fill_node_bool(struct node** node, int i) { @@ -24,13 +26,21 @@ void fill_node_name(struct node** node, char* s) { (*node)->kind = NODE_NAME; (*node)->var1 = my_calloc(1, strlen(s) + 1); strcpy((*node)->var1, s); - use_node(*node, used_count - 1); + use_node(*node, used_count); } void code_time(struct node** result) { fill_node_int(result, (int) time(NULL)); } +void code_trace(struct node** result, struct node *p, struct node *r) { + print_node(p); + printf("\n"); + use_node(r, (*result)->used_count); + free_node(*result, (*result)->used_count, 1); + *result = r; +} + void code_add(struct node** result, struct node* a, struct node* b) { if (a->kind != NODE_INT || b->kind != NODE_INT) fill_node_name(result, "add on non-ints"); @@ -98,6 +108,9 @@ unsigned char code_find(char* name, void** function) { if (!strcmp(name, "time")) { *function = (void(*)(void)) code_time; return 0; + } else if (!strcmp(name, "trace")) { + *function = (void(*)(void)) code_trace; + return 2; } else if (!strcmp(name, "add")) { *function = (void(*)(void)) code_add; return 2; -- cgit v1.2.3