diff options
author | Adrian Thurston <thurston@colm.net> | 2018-07-09 11:50:14 +0800 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2018-07-09 11:50:14 +0800 |
commit | 600e5a8138c3587157294cbca844b60f714bb5e7 (patch) | |
tree | 6c8559e4a0032e99d260e75bc8be53253e63fc68 /src/bytecode.c | |
parent | eda3bb6d45772bfe1d979d415568c515b896006c (diff) | |
download | colm-600e5a8138c3587157294cbca844b60f714bb5e7.tar.gz |
select between parser/plain stream at compile time, switch to "_"
Now that we have multiple parser using the same stream it is not responsible to
set a pointer to parser from stream and rely on that to decide where to send
(or to check if it is a simple stream). Back to making the decision at compile
time.
Also switching from "stds" to "_".
Diffstat (limited to 'src/bytecode.c')
-rw-r--r-- | src/bytecode.c | 110 |
1 files changed, 46 insertions, 64 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 2394ccc7..f64940de 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -2353,43 +2353,42 @@ again: break; } - case IN_SEND_TEXT_W: { - debug( prg, REALM_BYTECODE, "IN_SEND_TEXT_W\n" ); + case IN_PRINT_TREE_W: { + debug( prg, REALM_BYTECODE, "IN_PRINT_TREE_W\n" ); tree_t *to_send = vm_pop_tree(); input_t *input = vm_pop_input(); - if ( input->parser == 0 ) { - struct input_impl *si = input_to_impl( input ); + struct input_impl *si = input_to_impl( input ); + si->funcs->print_tree( prg, sp, si, to_send, false ); + vm_push_input( input ); + colm_tree_downref( prg, sp, to_send ); + break; + } - si->funcs->print_tree( prg, sp, si, to_send, false ); + case IN_SEND_TEXT_W: { + debug( prg, REALM_BYTECODE, "IN_SEND_TEXT_W\n" ); - vm_push_input( input ); + tree_t *to_send = vm_pop_tree(); + input_t *input = vm_pop_input(); - instr += SIZEOF_CODE; + word_t len = stream_append_text( prg, sp, input, to_send ); + vm_push_input( input ); + + if ( !exec->WV ) colm_tree_downref( prg, sp, to_send ); - } else { - word_t len = stream_append_text( prg, sp, input, to_send ); - - vm_push_input( input ); - - if ( !exec->WV ) - colm_tree_downref( prg, sp, to_send ); - else { - rcode_unit_start( exec ); - rcode_code( exec, IN_SEND_TEXT_BKT ); - rcode_word( exec, (word_t) input ); - rcode_word( exec, (word_t) to_send ); - rcode_word( exec, (word_t) len ); - rcode_unit_term( exec ); - } - - exec->steps = input->parser->pda_run->steps; - exec->pcr = PCR_START; + rcode_unit_start( exec ); + rcode_code( exec, IN_SEND_TEXT_BKT ); + rcode_word( exec, (word_t) input ); + rcode_word( exec, (word_t) to_send ); + rcode_word( exec, (word_t) len ); + rcode_unit_term( exec ); } + exec->steps = input->parser->pda_run->steps; + exec->pcr = PCR_START; break; } @@ -2414,54 +2413,41 @@ again: debug( prg, REALM_BYTECODE, "IN_SEND_TREE_W\n" ); tree_t *to_send = vm_pop_tree(); - stream_t *stream = vm_pop_stream(); + input_t *input = vm_pop_input(); - if ( stream->parser == 0 ) { - struct stream_impl *si = stream_to_impl( stream ); + parser_t *parser = input->parser; - si->funcs->print_tree( prg, sp, si, to_send, false ); + word_t len = stream_append_tree( prg, sp, parser->input, to_send ); - vm_push_stream( stream ); + vm_push_input( input ); + if ( !exec->WV ) colm_tree_downref( prg, sp, to_send ); - - instr += SIZEOF_CODE; - } else { - parser_t *parser = stream->parser; - - word_t len = stream_append_tree( prg, sp, parser->input, to_send ); - - vm_push_stream( stream ); - - if ( !exec->WV ) - colm_tree_downref( prg, sp, to_send ); - else { - rcode_unit_start( exec ); - rcode_code( exec, IN_SEND_TREE_BKT ); - rcode_word( exec, (word_t) stream ); - rcode_word( exec, (word_t) to_send ); - rcode_word( exec, (word_t) len ); - rcode_unit_term( exec ); - } - - exec->steps = stream->parser->pda_run->steps; - exec->pcr = PCR_START; + rcode_unit_start( exec ); + rcode_code( exec, IN_SEND_TREE_BKT ); + rcode_word( exec, (word_t) input ); + rcode_word( exec, (word_t) to_send ); + rcode_word( exec, (word_t) len ); + rcode_unit_term( exec ); } + + exec->steps = input->parser->pda_run->steps; + exec->pcr = PCR_START; break; } case IN_SEND_TREE_BKT: { - stream_t *stream; + input_t *input; tree_t *sent; word_t len; - read_stream( stream ); + read_input( input ); read_tree( sent ); read_word( len ); debug( prg, REALM_BYTECODE, "IN_SEND_TREE_BKT\n" ); - struct input_impl *si = input_to_impl( stream->parser->input ); + struct input_impl *si = input_to_impl( input->parser->input ); stream_undo_append( prg, sp, si, sent, len ); colm_tree_downref( prg, sp, sent ); @@ -2499,7 +2485,7 @@ again: word_t len = stream_append_stream( prg, sp, input->parser->input, to_send ); - vm_push_stream( input ); + vm_push_input( input ); if ( exec->WV ) { rcode_unit_start( exec ); @@ -2549,12 +2535,8 @@ again: rcode_unit_term( exec ); } - if ( input->parser == 0 ) - instr += SIZEOF_CODE; - else { - exec->steps = input->parser->pda_run->steps; - exec->pcr = PCR_START; - } + exec->steps = input->parser->pda_run->steps; + exec->pcr = PCR_START; break; } @@ -2835,7 +2817,7 @@ again: debug( prg, REALM_BYTECODE, "IN_INPUT_PUSH_STREAM_BKT %d\n", len ); - input_t *input = vm_pop_stream(); + input_t *input = vm_pop_input(); colm_undo_stream_push( prg, sp, input_to_impl( input ), len ); break; } @@ -3358,7 +3340,7 @@ again: debug( prg, REALM_BYTECODE, "IN_GET_PARSER_MEM_R %hd\n", field ); - input_t *input = vm_pop_stream(); + input_t *input = vm_pop_input(); tree_t *val = get_parser_mem( input->parser, field ); |