summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-05-06 20:37:56 -0400
committerAdrian Thurston <thurston@colm.net>2018-05-06 20:37:56 -0400
commita1efe9f9d40c0150591df9960421684babe7ff5e (patch)
tree20e2d3ba7eef15c6bf37f76e69414ec94c861f1e
parentd6b4b6dc9985849cecb44a0e397f9bfbb8bc89b2 (diff)
downloadcolm-a1efe9f9d40c0150591df9960421684babe7ff5e.tar.gz
made the postfix print into a function
-rw-r--r--src/bytecode.c27
-rw-r--r--src/bytecode.h1
-rw-r--r--src/declare.cc4
-rw-r--r--src/tree.h6
4 files changed, 38 insertions, 0 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index fbd3891e..69b30eac 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -185,6 +185,22 @@ static head_t *tree_to_str_xml_ac( program_t *prg, tree_t **sp, tree_t *tree, in
return ret;
}
+static head_t *tree_to_str_postfix( program_t *prg, tree_t **sp, tree_t *tree, int trim, int attrs )
+{
+ /* Collect the tree data. */
+ StrCollect collect;
+ init_str_collect( &collect );
+
+ colm_postfix_tree_collect( prg, sp, &collect, tree, trim );
+
+ /* Set up the input stream. */
+ head_t *ret = string_alloc_full( prg, collect.data, collect.length );
+
+ str_collect_destroy( &collect );
+
+ return ret;
+}
+
static word_t stream_append_tree( program_t *prg, tree_t **sp, stream_t *dest, tree_t *input )
{
@@ -1596,6 +1612,17 @@ again:
colm_tree_downref( prg, sp, tree );
break;
}
+ case IN_TREE_TO_STR_POSTFIX: {
+ debug( prg, REALM_BYTECODE, "IN_TREE_TO_STR_XML_AC\n" );
+
+ tree_t *tree = vm_pop_tree();
+ head_t *res = tree_to_str_postfix( prg, sp, tree, false, false );
+ tree_t *str = construct_string( prg, res );
+ colm_tree_upref( str );
+ vm_push_tree( str );
+ colm_tree_downref( prg, sp, tree );
+ break;
+ }
case IN_TREE_TO_STR: {
debug( prg, REALM_BYTECODE, "IN_TREE_TO_STR\n" );
diff --git a/src/bytecode.h b/src/bytecode.h
index d4bec751..09f80a28 100644
--- a/src/bytecode.h
+++ b/src/bytecode.h
@@ -237,6 +237,7 @@ typedef unsigned char uchar;
#define IN_TREE_TO_STR_XML 0x6e
#define IN_TREE_TO_STR_XML_AC 0x6f
+#define IN_TREE_TO_STR_POSTFIX 0xb6
#define IN_HOST 0xea
diff --git a/src/declare.cc b/src/declare.cc
index e7357e6e..5ee08895 100644
--- a/src/declare.cc
+++ b/src/declare.cc
@@ -1032,6 +1032,10 @@ void Compiler::declareGlobalFields()
IN_TREE_TO_STR_XML_AC, IN_TREE_TO_STR_XML_AC, uniqueTypeAny, true );
method->useCallObj = false;
+ method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "postfix",
+ IN_TREE_TO_STR_POSTFIX, IN_TREE_TO_STR_POSTFIX, uniqueTypeAny, true );
+ method->useCallObj = false;
+
addStdin();
addStdout();
addStderr();
diff --git a/src/tree.h b/src/tree.h
index a0eeff6a..33e7aabf 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -372,6 +372,12 @@ tree_t *construct_string( struct colm_program *prg, head_t *s );
void free_kid_list( program_t *prg, kid_t *kid );
+void colm_print_tree_collect_xml( program_t *prg, tree_t **sp,
+ StrCollect *collect, tree_t *tree, int trim );
+
+void colm_print_tree_collect_xml_ac( program_t *prg, tree_t **sp,
+ StrCollect *collect, tree_t *tree, int trim );
+
#if defined(__cplusplus)
}
#endif