diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-06-14 14:22:01 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-06-14 14:22:01 -0400 |
commit | a04ee9ff196726d48da67d5b95611c118184a815 (patch) | |
tree | a588de90b96a85be2101698052370070db21c01a | |
parent | 0b1e2a7a7be5722d21e7f817620016ceefd82262 (diff) |
Redo print statements to generate a sequence of to_string()s
followed by a print node containing information about how many strings
are on the stack.
-rw-r--r-- | ast.h | 4 | ||||
-rw-r--r-- | graph.c | 5 | ||||
-rw-r--r-- | interpret.c | 11 | ||||
-rw-r--r-- | node.c | 6 |
4 files changed, 15 insertions, 11 deletions
@@ -549,7 +549,7 @@ struct print_node_t { node_common_t common; - ast_type_spec_t * type_spec; + int n_exprs; }; struct call_node_t @@ -621,7 +621,7 @@ node_t *node_new_dyn_label (label_node_t *label, node_t *node_new_dyn_closure (ast_function_definition_t *function, node_t *pred, ast_t *ast); -node_t *node_new_print (ast_type_spec_t *type_spec, +node_t *node_new_print (int n_exprs, node_t *pred, ast_t *ast); node_t *node_new_to_string (ast_type_spec_t *type_spec, @@ -701,8 +701,9 @@ graph_statement (ast_statement_t *statement, case AST_PRINT_STATEMENT: node = graph_expression (statement->print.expr, node); - node = node_new_print (statement->print.expr->common.type_spec, - node, ast); + node = node_new_to_string (statement->print.expr->common.type_spec, + node, ast); + node = node_new_print (1, node, ast); break; case AST_EXPRESSION_STATEMENT: diff --git a/interpret.c b/interpret.c index 8c76b4d..26cd923 100644 --- a/interpret.c +++ b/interpret.c @@ -287,15 +287,18 @@ interpret (ast_t *ast) case NODE_TO_STRING: val = stack_pop (stack); - val.pointer_val = value_to_string (&val, current->print.type_spec); + val.pointer_val = value_to_string (&val, current->to_string.type_spec); stack_push (stack, val); break; case NODE_PRINT: - val = stack_pop (stack); - - print_value (&val, current->print.type_spec); + for (i = 0; i < current->print.n_exprs; ++i) + { + val = stack_pop (stack); + + g_print ("%s\n", (char *)val.pointer_val); + } break; case NODE_POP: @@ -211,14 +211,14 @@ node_new_dyn_closure (ast_function_definition_t *function, } node_t * -node_new_print (ast_type_spec_t *type_spec, +node_new_print (int n_exprs, node_t *pred, ast_t *ast) { node_t *node = node_new (NODE_PRINT, pred, ast); - node->print.type_spec = type_spec; - + node->print.n_exprs = n_exprs; + return node; } |