summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-06-14 14:22:01 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-06-14 14:22:01 -0400
commita04ee9ff196726d48da67d5b95611c118184a815 (patch)
treea588de90b96a85be2101698052370070db21c01a
parent0b1e2a7a7be5722d21e7f817620016ceefd82262 (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.h4
-rw-r--r--graph.c5
-rw-r--r--interpret.c11
-rw-r--r--node.c6
4 files changed, 15 insertions, 11 deletions
diff --git a/ast.h b/ast.h
index c581cd5..c391fe2 100644
--- a/ast.h
+++ b/ast.h
@@ -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,
diff --git a/graph.c b/graph.c
index fa5ca0f..f7b13ba 100644
--- a/graph.c
+++ b/graph.c
@@ -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:
diff --git a/node.c b/node.c
index 8b0814a..bed23dd 100644
--- a/node.c
+++ b/node.c
@@ -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;
}