diff options
author | Adrian Thurston <thurston@colm.net> | 2018-06-17 11:05:50 +0700 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2018-06-17 11:05:50 +0700 |
commit | 302c0393753677906959ccfd6180ef75c2294d0a (patch) | |
tree | cf387dffa05deaa6f0b0a70e7015b834f21e9077 /src/bytecode.c | |
parent | 3ac567074f3caf75c7e523ed638c22beda2019d0 (diff) | |
download | colm-302c0393753677906959ccfd6180ef75c2294d0a.tar.gz |
elimination of the PTR case from stream append/prepend
Diffstat (limited to 'src/bytecode.c')
-rw-r--r-- | src/bytecode.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 43e831d8..0d580ca2 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -220,8 +220,7 @@ static word_t stream_append_text( program_t *prg, tree_t **sp, stream_t *dest, t struct stream_impl *impl = stream_to_impl( dest ); if ( input->id == LEL_ID_PTR ) { - colm_tree_upref( prg, input ); - impl->funcs->append_stream( impl, input ); + assert(false); } else { /* Collect the tree data. */ @@ -243,7 +242,10 @@ static word_t stream_append_tree( program_t *prg, tree_t **sp, stream_t *dest, t long length = 0; struct stream_impl *impl = stream_to_impl( dest ); - if ( input->id == LEL_ID_STR ) { + if ( input->id == LEL_ID_PTR ) { + assert(false); + } + else if ( input->id == LEL_ID_STR ) { /* Collect the tree data. */ StrCollect collect; init_str_collect( &collect ); @@ -254,10 +256,6 @@ static word_t stream_append_tree( program_t *prg, tree_t **sp, stream_t *dest, t length = collect.length; str_collect_destroy( &collect ); } - else if ( input->id == LEL_ID_PTR ) { - colm_tree_upref( prg, input ); - impl->funcs->append_stream( impl, input ); - } else { colm_tree_upref( prg, input ); impl->funcs->append_tree( impl, input ); @@ -279,10 +277,10 @@ static word_t stream_append_stream( program_t *prg, tree_t **sp, stream_t *dest, static void stream_undo_append( program_t *prg, tree_t **sp, struct stream_impl *is, tree_t *input, long length ) { - if ( input->id == LEL_ID_STR ) + if ( input->id == LEL_ID_PTR ) + assert(false); + else if ( input->id == LEL_ID_STR ) is->funcs->undo_append_data( is, length ); - else if ( input->id == LEL_ID_PTR ) - is->funcs->undo_append_stream( is ); else { is->funcs->undo_append_data( is, length ); } @@ -313,7 +311,11 @@ static void undo_pull( program_t *prg, stream_t *stream, tree_t *str ) static long stream_push( program_t *prg, tree_t **sp, struct stream_impl *in, tree_t *tree, int ignore ) { - if ( tree->id == LEL_ID_STR ) { + long length = -1; + if ( tree->id == LEL_ID_PTR ) { + assert(false); + } + else if ( tree->id == LEL_ID_STR ) { /* This should become a compile error. If it's text, it's up to the * scanner to decide. Want to force it then send a token. */ assert( !ignore ); @@ -324,21 +326,16 @@ static long stream_push( program_t *prg, tree_t **sp, struct stream_impl *in, tr colm_print_tree_collect( prg, sp, &collect, tree, false ); colm_stream_push_text( in, collect.data, collect.length ); - long length = collect.length; + length = collect.length; str_collect_destroy( &collect ); - return length; - } - else if ( tree->id == LEL_ID_PTR ) { - colm_tree_upref( prg, tree ); - colm_stream_push_stream( in, tree ); - return -1; } else { colm_tree_upref( prg, tree ); colm_stream_push_tree( in, tree, ignore ); - return -1; } + + return length; } static long stream_push_stream( program_t *prg, tree_t **sp, |