summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-05-14 20:45:53 -0400
committerAdrian Thurston <thurston@colm.net>2018-05-14 20:45:53 -0400
commitbd0042d9fa75bd7c2c638a747fc7ab03601e859c (patch)
tree2275f1791ae2a9c86586be7e2266bbd2a8cd85f5
parentfbc356e504c162663b33162225ebd2fc16b6076b (diff)
downloadcolm-bd0042d9fa75bd7c2c638a747fc7ab03601e859c.tar.gz
don't use parse finish to pull out parse result, use dedeicated instruction
Working towards unifying the parse frag and parse finish instructions.
-rw-r--r--src/bytecode.c6
-rw-r--r--src/pdarun.c15
-rw-r--r--src/pdarun.h6
-rw-r--r--src/tree.c3
4 files changed, 9 insertions, 21 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index a5fc1ea3..72cd01fa 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -2736,13 +2736,9 @@ again:
debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_W %hd\n", stop_id );
- tree_t *result = 0;
- exec->pcr = colm_parse_finish( &result, prg, sp,
- stream->parser->pda_run,
+ exec->pcr = colm_parse_finish( prg, sp, stream->parser->pda_run,
stream->parser->input, exec->WV, exec->pcr );
- stream->parser->result = result;
-
if ( exec->pcr == PCR_DONE )
instr += SIZEOF_CODE;
break;
diff --git a/src/pdarun.c b/src/pdarun.c
index 0d4483ab..c1d45796 100644
--- a/src/pdarun.c
+++ b/src/pdarun.c
@@ -1194,7 +1194,7 @@ static long scan_token( program_t *prg, struct pda_run *pda_run, struct stream_i
return SCAN_ERROR;
}
-static tree_t *get_parsed_root( struct pda_run *pda_run, int stop )
+tree_t *get_parsed_root( struct pda_run *pda_run, int stop )
{
if ( pda_run->parse_error )
return 0;
@@ -2240,7 +2240,7 @@ long colm_parse_frag( program_t *prg, tree_t **sp, struct pda_run *pda_run,
return PCR_DONE;
}
-long colm_parse_finish( tree_t **result, program_t *prg, tree_t **sp,
+long colm_parse_finish( program_t *prg, tree_t **sp,
struct pda_run *pda_run, stream_t *input , int revert_on, long entry )
{
struct stream_impl *si;
@@ -2288,17 +2288,6 @@ long colm_parse_finish( tree_t **result, program_t *prg, tree_t **sp,
if ( !revert_on )
colm_rcode_downref_all( prg, sp, &pda_run->reverse_code );
-
- tree_t *tree = get_parsed_root( pda_run, pda_run->stop_target > 0 );
-
- if ( pda_run->reducer ) {
- *result = 0;
- }
- else {
- colm_tree_upref( tree );
- *result = tree;
- }
-
/* COROUTINE */
case PCR_DONE:
diff --git a/src/pdarun.h b/src/pdarun.h
index 7736f124..49c95f00 100644
--- a/src/pdarun.h
+++ b/src/pdarun.h
@@ -457,8 +457,8 @@ long colm_parse_loop( struct colm_program *prg, tree_t **sp, struct pda_run *pda
long colm_parse_frag( struct colm_program *prg, tree_t **sp, struct pda_run *pda_run,
stream_t *input, long stop_id, long entry );
-long colm_parse_finish( tree_t **result, struct colm_program *prg, tree_t **sp,
- struct pda_run *pda_run, stream_t *input , int revert_on, long entry );
+long colm_parse_finish( struct colm_program *prg, tree_t **sp, struct pda_run *pda_run,
+ stream_t *input, int revert_on, long entry );
long colm_parse_undo_frag( struct colm_program *prg, tree_t **sp, struct pda_run *pda_run,
stream_t *input, long steps, long entry );
@@ -468,6 +468,8 @@ void commit_clear_parse_tree( program_t *prg, tree_t **sp,
void commit_reduce( program_t *prg, tree_t **root,
struct pda_run *pda_run );
+tree_t *get_parsed_root( struct pda_run *pda_run, int stop );
+
#ifdef __cplusplus
}
#endif
diff --git a/src/tree.c b/src/tree.c
index 165c59f9..45973dcb 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -1435,7 +1435,8 @@ tree_t *get_parser_mem( parser_t *parser, word_t field )
tree_t *result = 0;
switch ( field ) {
case 0: {
- result = parser->result;
+ tree_t *tree = get_parsed_root( parser->pda_run, parser->pda_run->stop_target > 0 );
+ result = tree;
break;
}
case 1: {