aboutsummaryrefslogtreecommitdiff
path: root/interpreter/code.c
diff options
context:
space:
mode:
authorCamil Staps2016-10-06 16:58:33 +0200
committerCamil Staps2016-10-06 16:58:33 +0200
commitb97063f65017cad107c870fefd39069f34bbf7ab (patch)
tree0b07569b026873076b7c21c7b3c0a9d4494a24c7 /interpreter/code.c
parentExamples (diff)
Adds a trace code
Diffstat (limited to 'interpreter/code.c')
-rw-r--r--interpreter/code.c17
1 files changed, 15 insertions, 2 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;