diff options
Diffstat (limited to 'interpreter')
| -rw-r--r-- | interpreter/code.c | 17 | ||||
| -rw-r--r-- | interpreter/eval.c | 2 | 
2 files changed, 15 insertions, 4 deletions
| 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 <string.h>  #include <time.h> +#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; diff --git a/interpreter/eval.c b/interpreter/eval.c index 6933c0d..cd72f40 100644 --- a/interpreter/eval.c +++ b/interpreter/eval.c @@ -232,8 +232,6 @@ void eval_code_app(fuspel* rules, struct node** node) {  			f2(node, *args[1], *args[2]);  	} -	use_node(*node, 1); -  	my_free(args);  } | 
