summaryrefslogtreecommitdiff
path: root/src/bytecode.c
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-05-14 11:32:29 -0400
committerAdrian Thurston <thurston@colm.net>2018-05-14 11:32:29 -0400
commit800cf82ad7f7ea638cffe5a3e7a2ad70dd01e791 (patch)
tree7e2674e9b3eacca577fb480a1c2f469c1e6b05d3 /src/bytecode.c
parent07e5747e1cc4364b653a780aaa590dc2e11444d9 (diff)
downloadcolm-800cf82ad7f7ea638cffe5a3e7a2ad70dd01e791.tar.gz
sending trees: converted the TO_STR to a print inside the SEND_TEXT
Removed the convertion to a STR and implemented the send as text inside the SEND_TEXT instructions.
Diffstat (limited to 'src/bytecode.c')
-rw-r--r--src/bytecode.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index e483c049..880c89c3 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -214,6 +214,41 @@ static head_t *tree_to_str_postfix( program_t *prg, tree_t **sp, tree_t *tree, i
}
+static word_t stream_append_text( program_t *prg, tree_t **sp, stream_t *dest, tree_t *input )
+{
+ long length = 0;
+ struct stream_impl *impl = stream_to_impl( dest );
+
+ if ( input->id == LEL_ID_STR ) {
+ /* Collect the tree data. */
+ StrCollect collect;
+ init_str_collect( &collect );
+ colm_print_tree_collect( prg, sp, &collect, input, false );
+
+ /* Load it into the input. */
+ impl->funcs->append_data( impl, collect.data, collect.length );
+ length = collect.length;
+ str_collect_destroy( &collect );
+ }
+ else if ( input->id == LEL_ID_PTR ) {
+ colm_tree_upref( input );
+ impl->funcs->append_stream( impl, input );
+ }
+ else {
+ /* Collect the tree data. */
+ StrCollect collect;
+ init_str_collect( &collect );
+ colm_print_tree_collect( prg, sp, &collect, input, false );
+
+ /* Load it into the input. */
+ impl->funcs->append_data( impl, collect.data, collect.length );
+ length = collect.length;
+ str_collect_destroy( &collect );
+ }
+
+ return length;
+}
+
static word_t stream_append_tree( program_t *prg, tree_t **sp, stream_t *dest, tree_t *input )
{
long length = 0;
@@ -260,8 +295,7 @@ static void stream_undo_append( program_t *prg, tree_t **sp,
else if ( input->id == LEL_ID_PTR )
is->funcs->undo_append_stream( is );
else {
- tree_t *tree = is->funcs->undo_append_tree( is );
- colm_tree_downref( prg, sp, tree );
+ is->funcs->undo_append_data( is, length );
}
}
@@ -2280,7 +2314,7 @@ again:
else {
parser_t *parser = stream->parser;
- stream_append_tree( prg, sp, parser->input, input );
+ stream_append_text( prg, sp, stream, input );
vm_push_stream( stream );
}
@@ -2309,7 +2343,7 @@ again:
else {
parser_t *parser = stream->parser;
- word_t len = stream_append_tree( prg, sp, parser->input, input );
+ word_t len = stream_append_text( prg, sp, parser->input, input );
vm_push_stream( stream );