diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-06-14 14:16:32 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-06-14 14:16:32 -0400 |
commit | 0b1e2a7a7be5722d21e7f817620016ceefd82262 (patch) | |
tree | 7cf53bf2e55f382a36af994759d7eb5e5046d1e2 | |
parent | 2687be2fc53b946e29b562d8d0f4eb3da6eaf80b (diff) |
Add to_string node
-rw-r--r-- | ast.h | 14 | ||||
-rw-r--r-- | interpret.c | 8 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | node.c | 12 |
4 files changed, 36 insertions, 1 deletions
@@ -119,6 +119,7 @@ typedef struct call_node_t call_node_t; typedef struct new_node_t new_node_t; typedef struct new_array_node_t new_array_node_t; typedef struct this_node_t this_node_t; +typedef struct to_string_node_t to_string_node_t; typedef union node_t node_t; typedef struct set_t set_t; @@ -317,6 +318,7 @@ typedef enum NODE_UNARY, NODE_LITERAL, NODE_PRINT, + NODE_TO_STRING, NODE_POP, NODE_DUP, NODE_RETURN, @@ -536,6 +538,13 @@ struct this_node_t ast_expression_t * expression; }; +struct to_string_node_t +{ + node_common_t common; + + ast_type_spec_t * type_spec; +}; + struct print_node_t { node_common_t common; @@ -570,6 +579,7 @@ union node_t new_node_t new; new_array_node_t new_array; this_node_t this; + to_string_node_t to_string; dyn_closure_node_t dyn_closure; prolog_node_t prolog; fun_ref_node_t fun_ref; @@ -614,6 +624,9 @@ node_t *node_new_dyn_closure (ast_function_definition_t *function, node_t *node_new_print (ast_type_spec_t *type_spec, node_t *pred, ast_t *ast); +node_t *node_new_to_string (ast_type_spec_t *type_spec, + node_t *pred, + ast_t *ast); node_t *node_new_call (node_t *pred, ast_t *ast); node_t *node_new_pop (node_t *pred, @@ -668,7 +681,6 @@ node_t *node_new_this (ast_class_definition_t *class, ast_expression_t *expr, node_t *pred, ast_t *ast); - node_t *node_insert_after (node_t *node, node_t *pred); diff --git a/interpret.c b/interpret.c index ea77c0e..8c76b4d 100644 --- a/interpret.c +++ b/interpret.c @@ -284,6 +284,14 @@ interpret (ast_t *ast) stack_push (stack, val); break; + case NODE_TO_STRING: + val = stack_pop (stack); + + val.pointer_val = value_to_string (&val, current->print.type_spec); + + stack_push (stack, val); + break; + case NODE_PRINT: val = stack_pop (stack); @@ -553,6 +553,9 @@ real_dump_graph (node_t *node) case NODE_PRINT: g_print (" print\n"); break; + case NODE_TO_STRING: + g_print (" to_string\n"); + break; case NODE_POP: g_print (" pop\n"); break; @@ -223,6 +223,18 @@ node_new_print (ast_type_spec_t *type_spec, } node_t * +node_new_to_string (ast_type_spec_t *type_spec, + node_t *pred, + ast_t *ast) +{ + node_t *node = node_new (NODE_TO_STRING, pred, ast); + + node->to_string.type_spec = type_spec; + + return node; +} + +node_t * node_new_call (node_t *pred, ast_t *ast) { |