summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-05-11 18:21:09 -0400
committerAdrian Thurston <thurston@colm.net>2018-05-11 18:21:09 -0400
commita6920ce0f199c772ede76f0ae475cbf99d9f58bf (patch)
tree4a72c9835f2a0eaa7504fd456fe0f70daecc0b5d /src
parent4391ff975a49a0f416bde7c82307989424ef3ff5 (diff)
downloadcolm-a6920ce0f199c772ede76f0ae475cbf99d9f58bf.tar.gz
merged the WC and WV versions of parse instructions
Diffstat (limited to 'src')
-rw-r--r--src/bytecode.c131
-rw-r--r--src/bytecode.h16
-rw-r--r--src/declare.cc4
-rw-r--r--src/synthesis.cc44
4 files changed, 53 insertions, 142 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 99bff1c6..185bb728 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -2517,15 +2517,14 @@ again:
break;
}
- case IN_PARSE_FRAG_WC: {
+ case IN_PARSE_FRAG_W: {
half_t stop_id;
read_half( stop_id );
stream_t *stream = vm_pop_stream();
vm_push_stream( stream );
- debug( prg, REALM_BYTECODE, "IN_PARSE_FRAG_WC %hd\n", stop_id );
- assert( !exec->WV );
+ debug( prg, REALM_BYTECODE, "IN_PARSE_FRAG_W %hd\n", stop_id );
exec->pcr = colm_parse_frag( prg, sp, stream->parser->pda_run,
stream->parser->input, stop_id, exec->pcr );
@@ -2537,57 +2536,25 @@ again:
break;
}
- case IN_PARSE_FRAG_EXIT_WC: {
- debug( prg, REALM_BYTECODE, "IN_PARSE_FRAG_EXIT_WC\n" );
- assert( !exec->WV );
+ case IN_PARSE_FRAG_EXIT_W: {
+ debug( prg, REALM_BYTECODE, "IN_PARSE_FRAG_EXIT_W \n" );
stream_t *stream = vm_pop_stream();
vm_push_stream( stream );
- if ( prg->induce_exit )
- goto out;
-
- break;
- }
-
- case IN_PARSE_FRAG_WV: {
- half_t stop_id;
- read_half( stop_id );
-
- stream_t *stream = vm_pop_stream();
- vm_push_stream( stream );
-
- debug( prg, REALM_BYTECODE, "IN_PARSE_FRAG_WV %hd\n", stop_id );
- assert( exec->WV );
-
- exec->pcr = colm_parse_frag( prg, sp, stream->parser->pda_run,
- stream->parser->input, stop_id, exec->pcr );
-
- /* If done, jump to the terminating instruction, otherwise fall
- * through to call some code, then jump back here. */
- if ( exec->pcr == PCR_DONE )
- instr += SIZEOF_CODE;
- break;
- }
-
- case IN_PARSE_FRAG_EXIT_WV: {
- debug( prg, REALM_BYTECODE, "IN_PARSE_FRAG_EXIT_WV \n" );
- assert( exec->WV );
-
- stream_t *stream = vm_pop_stream();
- vm_push_stream( stream );
-
- rcode_unit_start( exec );
- rcode_code( exec, IN_PARSE_INIT_BKT );
- rcode_word( exec, (word_t)stream );
- rcode_word( exec, (word_t)exec->steps );
+ if ( exec->WV ) {
+ rcode_unit_start( exec );
+ rcode_code( exec, IN_PARSE_INIT_BKT );
+ rcode_word( exec, (word_t)stream );
+ rcode_word( exec, (word_t)exec->steps );
- rcode_code( exec, IN_PARSE_FRAG_BKT );
- rcode_half( exec, 0 );
+ rcode_code( exec, IN_PARSE_FRAG_BKT );
+ rcode_half( exec, 0 );
- rcode_code( exec, IN_PCR_CALL );
- rcode_code( exec, IN_PARSE_FRAG_EXIT_BKT );
- rcode_unit_term( exec );
+ rcode_code( exec, IN_PCR_CALL );
+ rcode_code( exec, IN_PARSE_FRAG_EXIT_BKT );
+ rcode_unit_term( exec );
+ }
if ( prg->induce_exit )
goto out;
@@ -2618,57 +2585,20 @@ again:
break;
}
- case IN_PARSE_FINISH_WC: {
- half_t stop_id;
- read_half( stop_id );
-
- stream_t *stream = vm_pop_stream();
- vm_push_stream( stream );
-
- debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_WC %hd\n", stop_id );
- assert( !exec->WV );
-
- tree_t *result = 0;
- exec->pcr = colm_parse_finish( &result, prg, sp,
- stream->parser->pda_run,
- stream->parser->input, false, exec->pcr );
-
- stream->parser->result = result;
-
- /* If done, jump to the terminating instruction, otherwise fall
- * through to call some code, then jump back here. */
- if ( exec->pcr == PCR_DONE )
- instr += SIZEOF_CODE;
- break;
- }
-
- case IN_PARSE_FINISH_EXIT_WC: {
- debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_EXIT_WC\n" );
- assert( !exec->WV );
-
- stream_t *stream = vm_pop_stream();
- vm_push_stream( stream );
-
- if ( prg->induce_exit )
- goto out;
-
- break;
- }
- case IN_PARSE_FINISH_WV: {
+ case IN_PARSE_FINISH_W: {
half_t stop_id;
read_half( stop_id );
stream_t *stream = vm_pop_stream();
vm_push_stream( stream );
- debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_WV %hd\n", stop_id );
- assert( exec->WV );
+ 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,
- stream->parser->input, true, exec->pcr );
+ stream->parser->input, exec->WV, exec->pcr );
stream->parser->result = result;
@@ -2677,25 +2607,26 @@ again:
break;
}
- case IN_PARSE_FINISH_EXIT_WV: {
- debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_EXIT_WV\n" );
- assert( exec->WV );
+ case IN_PARSE_FINISH_EXIT_W: {
+ debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_EXIT_W\n" );
stream_t *stream = vm_pop_stream();
vm_push_stream( stream );
- rcode_unit_start( exec );
+ if ( exec->WV ) {
+ rcode_unit_start( exec );
- rcode_code( exec, IN_PARSE_INIT_BKT );
- rcode_word( exec, (word_t)stream );
- rcode_word( exec, (word_t)exec->steps );
+ rcode_code( exec, IN_PARSE_INIT_BKT );
+ rcode_word( exec, (word_t)stream );
+ rcode_word( exec, (word_t)exec->steps );
- rcode_code( exec, IN_PARSE_FINISH_BKT );
- rcode_half( exec, 0 );
+ rcode_code( exec, IN_PARSE_FINISH_BKT );
+ rcode_half( exec, 0 );
- rcode_code( exec, IN_PCR_CALL );
- rcode_code( exec, IN_PARSE_FINISH_EXIT_BKT );
- rcode_unit_term( exec );
+ rcode_code( exec, IN_PCR_CALL );
+ rcode_code( exec, IN_PARSE_FINISH_EXIT_BKT );
+ rcode_unit_term( exec );
+ }
if ( prg->induce_exit )
goto out;
diff --git a/src/bytecode.h b/src/bytecode.h
index adfb38bd..4e013ce4 100644
--- a/src/bytecode.h
+++ b/src/bytecode.h
@@ -260,11 +260,11 @@ typedef unsigned char uchar;
#define IN_PARSE_LOAD 0xa0
#define IN_PARSE_INIT_BKT 0xa1
-#define IN_PARSE_FRAG_WC 0xa2
-#define IN_PARSE_FRAG_EXIT_WC 0xa3
+#define IN_PARSE_FRAG_W 0xa2
+#define IN_PARSE_FRAG_EXIT_W 0xa3
-#define IN_PARSE_FRAG_WV 0xa4
-#define IN_PARSE_FRAG_EXIT_WV 0xa5
+//#define IN_PARSE_FRAG_WV 0xa4
+//#define IN_PARSE_FRAG_EXIT_WV 0xa5
#define IN_PARSE_FRAG_BKT 0xa6
#define IN_PARSE_FRAG_EXIT_BKT 0xa7
@@ -277,11 +277,11 @@ typedef unsigned char uchar;
#define IN_SEND_STREAM_WV 0x90
#define IN_SEND_STREAM_BKT 0x1c
-#define IN_PARSE_FINISH_WC 0xab
-#define IN_PARSE_FINISH_EXIT_WC 0xac
+#define IN_PARSE_FINISH_W 0xab
+#define IN_PARSE_FINISH_EXIT_W 0xac
-#define IN_PARSE_FINISH_WV 0xad
-#define IN_PARSE_FINISH_EXIT_WV 0xae
+//#define IN_PARSE_FINISH_WV 0xad
+//#define IN_PARSE_FINISH_EXIT_WV 0xae
#define IN_PARSE_FINISH_BKT 0xaf
#define IN_PARSE_FINISH_EXIT_BKT 0xb0
diff --git a/src/declare.cc b/src/declare.cc
index b840882c..b1afda38 100644
--- a/src/declare.cc
+++ b/src/declare.cc
@@ -1399,10 +1399,10 @@ void Compiler::initListFields( GenericType *gen )
void Compiler::initParserFunctions( GenericType *gen )
{
initFunction( gen->elUt, gen->objDef, "finish",
- IN_PARSE_FINISH_WV, IN_PARSE_FINISH_WC, true );
+ IN_PARSE_FINISH_W, IN_PARSE_FINISH_W, true );
initFunction( gen->elUt, gen->objDef, "eof",
- IN_PARSE_FINISH_WV, IN_PARSE_FINISH_WC, true );
+ IN_PARSE_FINISH_W, IN_PARSE_FINISH_W, true );
initFunction( uniqueTypeStream, gen->objDef, "gets",
IN_GET_PARSER_STREAM, IN_GET_PARSER_STREAM, true );
diff --git a/src/synthesis.cc b/src/synthesis.cc
index d641e9ee..c40c25dc 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -1025,8 +1025,7 @@ void LangVarRef::resetActiveRefs( Compiler *pd, VarRefLookup &lookup,
bool LangVarRef::isFinishCall( VarRefLookup &lookup ) const
{
- if ( lookup.objMethod->opcodeWV == IN_PARSE_FINISH_WV ||
- lookup.objMethod->opcodeWC == IN_PARSE_FINISH_WC )
+ if ( lookup.objMethod->opcodeWV == IN_PARSE_FINISH_W )
{
return true;
}
@@ -1424,40 +1423,21 @@ UniqueType *LangTerm::evaluateConstruct( Compiler *pd, CodeVect &code ) const
void LangTerm::parseFrag( Compiler *pd, CodeVect &code, int stopId )
{
- /* Parse instruction, dependent on whether or not we are producing
- * revert or commit code. */
- if ( pd->revertOn ) {
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FRAG_WV );
- code.appendHalf( stopId );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FRAG_EXIT_WV );
- }
- else {
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FRAG_WC );
- code.appendHalf( stopId );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FRAG_EXIT_WC );
- }
+ /* Parse instruction. */
+ code.append( IN_PARSE_LOAD );
+ code.append( IN_PARSE_FRAG_W );
+ code.appendHalf( stopId );
+ code.append( IN_PCR_CALL );
+ code.append( IN_PARSE_FRAG_EXIT_W );
}
void LangTerm::parseFinish( Compiler *pd, CodeVect &code, int stopId )
{
- if ( pd->revertOn ) {
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FINISH_WV );
- code.appendHalf( stopId );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FINISH_EXIT_WV );
- }
- else {
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FINISH_WC );
- code.appendHalf( stopId );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FINISH_EXIT_WC );
- }
+ code.append( IN_PARSE_LOAD );
+ code.append( IN_PARSE_FINISH_W );
+ code.appendHalf( stopId );
+ code.append( IN_PCR_CALL );
+ code.append( IN_PARSE_FINISH_EXIT_W );
}
UniqueType *LangTerm::evaluateReadReduce( Compiler *pd, CodeVect &code ) const