summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-05-15 13:14:28 -0400
committerAdrian Thurston <thurston@colm.net>2018-05-15 13:14:28 -0400
commit2d8d299939bbdabad5cc06d4a55c826540f073f3 (patch)
tree916cbc1f67c8d0e2aff46babe0d480b1e235c48e
parentb911a8b4cac2b335b4e093c0ebbd36fbc56495fe (diff)
downloadcolm-2d8d299939bbdabad5cc06d4a55c826540f073f3.tar.gz
unified parse frag and finish
-rw-r--r--src/bytecode.c82
-rw-r--r--src/bytecode.h6
-rw-r--r--src/compiler.h12
-rw-r--r--src/declare.cc164
-rw-r--r--src/parsetree.h9
-rw-r--r--src/pdarun.c23
-rw-r--r--src/pdarun.h8
-rw-r--r--src/synthesis.cc20
8 files changed, 118 insertions, 206 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 938d7b7b..7957c6c4 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -2692,7 +2692,7 @@ again:
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 );
+ stream->parser->input, exec->pcr );
/* If done, jump to the terminating instruction, otherwise fall
* through to call some code, then jump back here. */
@@ -2709,6 +2709,7 @@ again:
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 );
@@ -2723,6 +2724,7 @@ again:
if ( prg->induce_exit )
goto out;
+
break;
}
@@ -2750,74 +2752,6 @@ again:
break;
}
- 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_W %hd\n", stop_id );
-
- exec->pcr = colm_parse_finish( prg, sp, stream->parser->pda_run,
- stream->parser->input, exec->WV, exec->pcr );
-
- if ( exec->pcr == PCR_DONE )
- instr += SIZEOF_CODE;
- break;
- }
-
- 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 );
-
- 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_FINISH_BKT );
- rcode_half( exec, 0 );
-
- rcode_code( exec, IN_PCR_CALL );
- rcode_code( exec, IN_PARSE_FINISH_EXIT_BKT );
- rcode_unit_term( exec );
- }
-
- if ( prg->induce_exit )
- goto out;
-
- break;
- }
-
- case IN_PARSE_FINISH_BKT: {
- 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_BKT %hd\n", stop_id );
-
- exec->pcr = colm_parse_undo_frag( prg, sp, stream->parser->pda_run,
- stream->parser->input, exec->steps, exec->pcr );
-
- if ( exec->pcr == PCR_DONE )
- instr += SIZEOF_CODE;
- break;
- }
-
- case IN_PARSE_FINISH_EXIT_BKT: {
- debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_EXIT_BKT\n" );
-
- vm_pop_stream();
- break;
- }
-
case IN_REDUCE_COMMIT: {
stream_t *stream = vm_pop_stream();
vm_push_stream( stream );
@@ -4798,16 +4732,6 @@ again:
debug( prg, REALM_BYTECODE, "IN_PARSE_FRAG_EXIT_BKT\n" );
break;
}
- case IN_PARSE_FINISH_BKT: {
- half_t stop_id;
- read_half( stop_id );
- debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_BKT\n" );
- break;
- }
- case IN_PARSE_FINISH_EXIT_BKT: {
- debug( prg, REALM_BYTECODE, "IN_PARSE_FINISH_EXIT_BKT\n" );
- break;
- }
case IN_PCR_CALL: {
debug( prg, REALM_BYTECODE, "IN_PCR_CALL\n" );
break;
diff --git a/src/bytecode.h b/src/bytecode.h
index d8fb6fe0..daadb8d4 100644
--- a/src/bytecode.h
+++ b/src/bytecode.h
@@ -281,12 +281,6 @@ typedef unsigned char uchar;
#define IN_SEND_EOF_W 0x87
#define IN_SEND_EOF_BKT 0xa4
-#define IN_PARSE_FINISH_W 0xab
-#define IN_PARSE_FINISH_EXIT_W 0xac
-
-#define IN_PARSE_FINISH_BKT 0xaf
-#define IN_PARSE_FINISH_EXIT_BKT 0xb0
-
#define IN_REDUCE_COMMIT 0xa5
#define IN_PCR_CALL 0xb1
diff --git a/src/compiler.h b/src/compiler.h
index fa82a6cc..175b4772 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -1108,30 +1108,30 @@ void declareTypeAlias( Compiler *pd, Namespace *nspace,
LangEl *findType( Compiler *pd, Namespace *nspace, const String &data );
ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
bool isConst, bool useFnInstr = false, GenericType *useGeneric = 0 );
ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
UniqueType *arg1, bool isConst, bool useFnInstr = false,
GenericType *useGeneric = 0 );
ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
UniqueType *arg1, UniqueType *arg2, bool isConst,
bool useFnInstr = false, GenericType *useGeneric = 0 );
ObjectMethod *initFunction( UniqueType *retType, Namespace *nspace, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
bool isConst, bool useFnInstr = false, GenericType *useGeneric = 0 );
ObjectMethod *initFunction( UniqueType *retType, Namespace *nspace, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
UniqueType *arg1, bool isConst, bool useFnInstr = false,
GenericType *useGeneric = 0 );
ObjectMethod *initFunction( UniqueType *retType, Namespace *nspace, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
UniqueType *arg1, UniqueType *arg2, bool isConst,
bool useFnInstr = false, GenericType *useGeneric = 0 );
diff --git a/src/declare.cc b/src/declare.cc
index 066f574a..0bd98e8b 100644
--- a/src/declare.cc
+++ b/src/declare.cc
@@ -53,12 +53,13 @@ void Compiler::initUniqueTypes( )
}
ObjectMethod *initFunction( UniqueType *retType, Namespace *nspace, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
int nargs, UniqueType **args, bool isConst, bool useFnInstr,
GenericType *useGeneric )
{
ObjectMethod *objMethod = new ObjectMethod( retType, name,
methIdWV, methIdWC, nargs, args, 0, isConst );
+ objMethod->type = type;
objMethod->useFnInstr = useFnInstr;
if ( nspace != 0 )
@@ -75,29 +76,29 @@ ObjectMethod *initFunction( UniqueType *retType, Namespace *nspace, ObjectDef *o
}
ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC, bool isConst,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC, bool isConst,
bool useFnInstr, GenericType *useGeneric )
{
- return initFunction( retType, 0, obj, name, methIdWV, methIdWC,
+ return initFunction( retType, 0, obj, type, name, methIdWV, methIdWC,
0, 0, isConst, useFnInstr, useGeneric );
}
ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC, UniqueType *arg1,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC, UniqueType *arg1,
bool isConst, bool useFnInstr, GenericType *useGeneric )
{
UniqueType *args[] = { arg1 };
- return initFunction( retType, 0, obj, name, methIdWV, methIdWC,
+ return initFunction( retType, 0, obj, type, name, methIdWV, methIdWC,
1, args, isConst, useFnInstr, useGeneric );
}
ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
UniqueType *arg1, UniqueType *arg2,
bool isConst, bool useFnInstr, GenericType *useGeneric )
{
UniqueType *args[] = { arg1, arg2 };
- return initFunction( retType, 0, obj, name, methIdWV, methIdWC,
+ return initFunction( retType, 0, obj, type, name, methIdWV, methIdWC,
2, args, isConst, useFnInstr, useGeneric );
}
@@ -106,29 +107,29 @@ ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj,
*/
ObjectMethod *initFunction( UniqueType *retType, Namespace *nspace, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC, bool isConst,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC, bool isConst,
bool useFnInstr, GenericType *useGeneric )
{
- return initFunction( retType, nspace, obj, name, methIdWV, methIdWC,
+ return initFunction( retType, nspace, obj, type, name, methIdWV, methIdWC,
0, 0, isConst, useFnInstr, useGeneric );
}
ObjectMethod *initFunction( UniqueType *retType, Namespace *nspace, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC, UniqueType *arg1,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC, UniqueType *arg1,
bool isConst, bool useFnInstr, GenericType *useGeneric )
{
UniqueType *args[] = { arg1 };
- return initFunction( retType, nspace, obj, name, methIdWV, methIdWC,
+ return initFunction( retType, nspace, obj, type, name, methIdWV, methIdWC,
1, args, isConst, useFnInstr, useGeneric );
}
ObjectMethod *initFunction( UniqueType *retType, Namespace *nspace, ObjectDef *obj,
- const String &name, int methIdWV, int methIdWC,
+ ObjectMethod::Type type, const String &name, int methIdWV, int methIdWC,
UniqueType *arg1, UniqueType *arg2,
bool isConst, bool useFnInstr, GenericType *useGeneric )
{
UniqueType *args[] = { arg1, arg2 };
- return initFunction( retType, nspace, obj, name, methIdWV, methIdWC,
+ return initFunction( retType, nspace, obj, type, name, methIdWV, methIdWC,
2, args, isConst, useFnInstr, useGeneric );
}
@@ -652,7 +653,7 @@ void Compiler::makeDefaultIterators()
{
UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl );
ObjectMethod *objMethod = initFunction( uniqueTypeAny, rootNamespace, globalObjectDef,
- "triter", IN_HALT, IN_HALT, anyRefUT, true );
+ ObjectMethod::Call, "triter", IN_HALT, IN_HALT, anyRefUT, true );
IterDef *triter = findIterDef( IterDef::Tree );
objMethod->iterDef = triter;
@@ -662,7 +663,7 @@ void Compiler::makeDefaultIterators()
{
UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl );
ObjectMethod *objMethod = initFunction( uniqueTypeAny, rootNamespace, globalObjectDef,
- "child", IN_HALT, IN_HALT, anyRefUT, true );
+ ObjectMethod::Call, "child", IN_HALT, IN_HALT, anyRefUT, true );
IterDef *triter = findIterDef( IterDef::Child );
objMethod->iterDef = triter;
@@ -672,7 +673,7 @@ void Compiler::makeDefaultIterators()
{
UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl );
ObjectMethod *objMethod = initFunction( uniqueTypeAny, rootNamespace, globalObjectDef,
- "rev_child", IN_HALT, IN_HALT, anyRefUT, true );
+ ObjectMethod::Call, "rev_child", IN_HALT, IN_HALT, anyRefUT, true );
IterDef *triter = findIterDef( IterDef::RevChild );
objMethod->iterDef = triter;
@@ -682,7 +683,7 @@ void Compiler::makeDefaultIterators()
{
UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl );
ObjectMethod *objMethod = initFunction( uniqueTypeAny, rootNamespace, globalObjectDef,
- "repeat", IN_HALT, IN_HALT, anyRefUT, true );
+ ObjectMethod::Call, "repeat", IN_HALT, IN_HALT, anyRefUT, true );
IterDef *triter = findIterDef( IterDef::Repeat );
objMethod->iterDef = triter;
@@ -692,7 +693,7 @@ void Compiler::makeDefaultIterators()
{
UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl );
ObjectMethod *objMethod = initFunction( uniqueTypeAny, rootNamespace, globalObjectDef,
- "rev_repeat", IN_HALT, IN_HALT, anyRefUT, true );
+ ObjectMethod::Call, "rev_repeat", IN_HALT, IN_HALT, anyRefUT, true );
IterDef *triter = findIterDef( IterDef::RevRepeat );
objMethod->iterDef = triter;
@@ -702,7 +703,7 @@ void Compiler::makeDefaultIterators()
{
UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl );
ObjectMethod *objMethod = initFunction( uniqueTypeAny, rootNamespace, globalObjectDef,
- "list_iter", IN_HALT, IN_HALT, anyRefUT, true );
+ ObjectMethod::Call, "list_iter", IN_HALT, IN_HALT, anyRefUT, true );
IterDef *triter = findIterDef( IterDef::ListEl );
objMethod->iterDef = triter;
@@ -712,7 +713,7 @@ void Compiler::makeDefaultIterators()
{
UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl );
ObjectMethod *objMethod = initFunction( uniqueTypeAny, rootNamespace, globalObjectDef,
- "rev_list_iter", IN_HALT, IN_HALT, anyRefUT, true );
+ ObjectMethod::Call, "rev_list_iter", IN_HALT, IN_HALT, anyRefUT, true );
IterDef *triter = findIterDef( IterDef::RevListVal );
objMethod->iterDef = triter;
@@ -722,7 +723,7 @@ void Compiler::makeDefaultIterators()
{
UniqueType *anyRefUT = findUniqueType( TYPE_REF, anyLangEl );
ObjectMethod *objMethod = initFunction( uniqueTypeAny, rootNamespace, globalObjectDef,
- "map_iter", IN_HALT, IN_HALT, anyRefUT, true );
+ ObjectMethod::Call, "map_iter", IN_HALT, IN_HALT, anyRefUT, true );
IterDef *triter = findIterDef( IterDef::MapEl );
objMethod->iterDef = triter;
@@ -796,7 +797,7 @@ void Compiler::declareIntFields( )
intObj = ObjectDef::cons( ObjectDef::BuiltinType, "int", nextObjectId++ );
// intLangEl->objectDef = intObj;
- initFunction( uniqueTypeStr, intObj, "to_string", IN_INT_TO_STR, IN_INT_TO_STR, true );
+ initFunction( uniqueTypeStr, intObj, ObjectMethod::Call, "to_string", IN_INT_TO_STR, IN_INT_TO_STR, true );
}
void Compiler::declareStrFields( )
@@ -804,38 +805,39 @@ void Compiler::declareStrFields( )
strObj = ObjectDef::cons( ObjectDef::BuiltinType, "str", nextObjectId++ );
strLangEl->objectDef = strObj;
- initFunction( uniqueTypeInt, strObj, "atoi",
+ initFunction( uniqueTypeInt, strObj, ObjectMethod::Call, "atoi",
IN_STR_ATOI, IN_STR_ATOI, true, true );
- initFunction( uniqueTypeInt, strObj, "atoo",
+ initFunction( uniqueTypeInt, strObj, ObjectMethod::Call, "atoo",
IN_STR_ATOO, IN_STR_ATOO, true, true );
- initFunction( uniqueTypeInt, strObj, "uord8",
+ initFunction( uniqueTypeInt, strObj, ObjectMethod::Call, "uord8",
IN_STR_UORD8, IN_STR_UORD8, true, true );
- initFunction( uniqueTypeInt, strObj, "sord8",
+ initFunction( uniqueTypeInt, strObj, ObjectMethod::Call, "sord8",
IN_STR_SORD8, IN_STR_SORD8, true, true );
- initFunction( uniqueTypeInt, strObj, "uord16",
+ initFunction( uniqueTypeInt, strObj, ObjectMethod::Call, "uord16",
IN_STR_UORD16, IN_STR_UORD16, true, true );
- initFunction( uniqueTypeInt, strObj, "sord16",
+ initFunction( uniqueTypeInt, strObj, ObjectMethod::Call, "sord16",
IN_STR_SORD16, IN_STR_SORD16, true, true );
- initFunction( uniqueTypeInt, strObj, "uord32",
+ initFunction( uniqueTypeInt, strObj, ObjectMethod::Call, "uord32",
IN_STR_UORD32, IN_STR_UORD32, true, true );
- initFunction( uniqueTypeInt, strObj, "sord32",
+ initFunction( uniqueTypeInt, strObj, ObjectMethod::Call, "sord32",
IN_STR_SORD32, IN_STR_SORD32, true, true );
- initFunction( uniqueTypeStr, strObj, "prefix",
+ initFunction( uniqueTypeStr, strObj, ObjectMethod::Call, "prefix",
IN_STR_PREFIX, IN_STR_PREFIX, uniqueTypeInt, true, true );
- initFunction( uniqueTypeStr, strObj, "suffix",
+ initFunction( uniqueTypeStr, strObj, ObjectMethod::Call, "suffix",
IN_STR_SUFFIX, IN_STR_SUFFIX, uniqueTypeInt, true, true );
- initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "sprintf",
- IN_SPRINTF, IN_SPRINTF, uniqueTypeStr, uniqueTypeInt, true );
+ initFunction( uniqueTypeStr, rootNamespace, globalObjectDef,
+ ObjectMethod::Call, "sprintf", IN_SPRINTF, IN_SPRINTF,
+ uniqueTypeStr, uniqueTypeInt, true );
addLengthField( strObj, IN_STR_LENGTH );
}
@@ -857,19 +859,19 @@ void Compiler::declareStreamFields( )
{
streamObj = streamSel->structDef->objectDef;
- initFunction( uniqueTypeStr, streamObj, "pull",
+ initFunction( uniqueTypeStr, streamObj, ObjectMethod::Call, "pull",
IN_INPUT_PULL_WV, IN_INPUT_PULL_WC, uniqueTypeInt, false );
- initFunction( uniqueTypeStr, streamObj, "push",
+ initFunction( uniqueTypeStr, streamObj, ObjectMethod::Call, "push",
IN_INPUT_PUSH_WV, IN_INPUT_PUSH_WV, uniqueTypeAny, false );
- initFunction( uniqueTypeStr, streamObj, "push_ignore",
+ initFunction( uniqueTypeStr, streamObj, ObjectMethod::Call, "push_ignore",
IN_INPUT_PUSH_IGNORE_WV, IN_INPUT_PUSH_IGNORE_WV, uniqueTypeAny, false );
- initFunction( uniqueTypeStr, streamObj, "push_stream",
+ initFunction( uniqueTypeStr, streamObj, ObjectMethod::Call, "push_stream",
IN_INPUT_PUSH_STREAM_WV, IN_INPUT_PUSH_STREAM_WV, uniqueTypeStream, false );
- initFunction( uniqueTypeVoid, streamObj, "close",
+ initFunction( uniqueTypeVoid, streamObj, ObjectMethod::Call, "close",
IN_INPUT_CLOSE_WC, IN_INPUT_CLOSE_WC, false );
declareStreamField( streamObj, 0 );
@@ -955,77 +957,77 @@ void Compiler::declareGlobalFields()
{
ObjectMethod *method;
- method = initFunction( uniqueTypeStream, rootNamespace, globalObjectDef, "open",
+ method = initFunction( uniqueTypeStream, rootNamespace, globalObjectDef, ObjectMethod::Call, "open",
IN_OPEN_FILE, IN_OPEN_FILE, uniqueTypeStr, uniqueTypeStr, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "tolower",
+ method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, ObjectMethod::Call, "tolower",
IN_TO_LOWER, IN_TO_LOWER, uniqueTypeStr, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "toupper",
+ method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, ObjectMethod::Call, "toupper",
IN_TO_UPPER, IN_TO_UPPER, uniqueTypeStr, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "atoi",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "atoi",
IN_STR_ATOI, IN_STR_ATOI, uniqueTypeStr, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "atoo",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "atoo",
IN_STR_ATOO, IN_STR_ATOO, uniqueTypeStr, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "prefix",
+ method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, ObjectMethod::Call, "prefix",
IN_PREFIX, IN_PREFIX, uniqueTypeStr, uniqueTypeInt, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "suffix",
+ method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, ObjectMethod::Call, "suffix",
IN_SUFFIX, IN_SUFFIX, uniqueTypeStr, uniqueTypeInt, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "uord8",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "uord8",
IN_STR_UORD8, IN_STR_UORD8, uniqueTypeStr, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "sord8",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "sord8",
IN_STR_SORD8, IN_STR_SORD8, uniqueTypeStr, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "uord16",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "uord16",
IN_STR_UORD16, IN_STR_UORD16, uniqueTypeStr, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "sord16",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "sord16",
IN_STR_SORD16, IN_STR_SORD16, uniqueTypeStr, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "uord32",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "uord32",
IN_STR_UORD32, IN_STR_UORD32, uniqueTypeStr, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "sord32",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "sord32",
IN_STR_SORD32, IN_STR_SORD32, uniqueTypeStr, true, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "exit",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "exit",
IN_EXIT, IN_EXIT, uniqueTypeInt, true, true );
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "exit_hard",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "exit_hard",
IN_EXIT_HARD, IN_EXIT_HARD, uniqueTypeInt, true, true );
- method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, "system",
+ method = initFunction( uniqueTypeInt, rootNamespace, globalObjectDef, ObjectMethod::Call, "system",
IN_SYSTEM, IN_SYSTEM, uniqueTypeStr, true );
- method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "xml",
+ method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, ObjectMethod::Call, "xml",
IN_TREE_TO_STR_XML, IN_TREE_TO_STR_XML, uniqueTypeAny, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "xmlac",
+ method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, ObjectMethod::Call, "xmlac",
IN_TREE_TO_STR_XML_AC, IN_TREE_TO_STR_XML_AC, uniqueTypeAny, true );
method->useCallObj = false;
- method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, "postfix",
+ method = initFunction( uniqueTypeStr, rootNamespace, globalObjectDef, ObjectMethod::Call, "postfix",
IN_TREE_TO_STR_POSTFIX, IN_TREE_TO_STR_POSTFIX, uniqueTypeAny, true );
method->useCallObj = false;
@@ -1178,26 +1180,26 @@ void Compiler::addDefineArgs()
void Compiler::initMapFunctions( GenericType *gen )
{
/* Value functions. */
- initFunction( gen->valueUt, gen->objDef, "find",
+ initFunction( gen->valueUt, gen->objDef, ObjectMethod::Call, "find",
IN_VMAP_FIND, IN_VMAP_FIND, gen->keyUt, true, true, gen );
- initFunction( uniqueTypeInt, gen->objDef, "insert",
+ initFunction( uniqueTypeInt, gen->objDef, ObjectMethod::Call, "insert",
IN_VMAP_INSERT_WV, IN_VMAP_INSERT_WC, gen->keyUt, gen->valueUt,
false, true, gen );
- initFunction( gen->elUt, gen->objDef, "remove",
+ initFunction( gen->elUt, gen->objDef, ObjectMethod::Call, "remove",
IN_VMAP_REMOVE_WV, IN_VMAP_REMOVE_WC, gen->keyUt, false, true, gen );
/*
* Element Functions
*/
- initFunction( gen->elUt, gen->objDef, "find_el",
+ initFunction( gen->elUt, gen->objDef, ObjectMethod::Call, "find_el",
IN_MAP_FIND, IN_MAP_FIND, gen->keyUt, true, true, gen );
- initFunction( uniqueTypeInt, gen->objDef, "insert_el",
+ initFunction( uniqueTypeInt, gen->objDef, ObjectMethod::Call, "insert_el",
IN_MAP_INSERT_WV, IN_MAP_INSERT_WC, gen->elUt, false, true, gen );
- initFunction( gen->elUt, gen->objDef, "detach_el",
+ initFunction( gen->elUt, gen->objDef, ObjectMethod::Call, "detach_el",
IN_MAP_DETACH_WV, IN_MAP_DETACH_WC, gen->elUt, false, true, gen );
}
@@ -1277,40 +1279,40 @@ void Compiler::initMapElField( GenericType *gen, const char *name, int offset )
void Compiler::initListFunctions( GenericType *gen )
{
- initFunction( uniqueTypeInt, gen->objDef, "push_head",
+ initFunction( uniqueTypeInt, gen->objDef, ObjectMethod::Call, "push_head",
IN_VLIST_PUSH_HEAD_WV, IN_VLIST_PUSH_HEAD_WC, gen->valueUt, false, true, gen );
- initFunction( uniqueTypeInt, gen->objDef, "push_tail",
+ initFunction( uniqueTypeInt, gen->objDef, ObjectMethod::Call, "push_tail",
IN_VLIST_PUSH_TAIL_WV, IN_VLIST_PUSH_TAIL_WC, gen->valueUt, false, true, gen );
- initFunction( uniqueTypeInt, gen->objDef, "push",
+ initFunction( uniqueTypeInt, gen->objDef, ObjectMethod::Call, "push",
IN_VLIST_PUSH_HEAD_WV, IN_VLIST_PUSH_HEAD_WC, gen->valueUt, false, true, gen );
- initFunction( gen->valueUt, gen->objDef, "pop_head",
+ initFunction( gen->valueUt, gen->objDef, ObjectMethod::Call, "pop_head",
IN_VLIST_POP_HEAD_WV, IN_VLIST_POP_HEAD_WC, false, true, gen );
- initFunction( gen->valueUt, gen->objDef, "pop_tail",
+ initFunction( gen->valueUt, gen->objDef, ObjectMethod::Call, "pop_tail",
IN_VLIST_POP_TAIL_WV, IN_VLIST_POP_TAIL_WC, false, true, gen );
- initFunction( gen->valueUt, gen->objDef, "pop",
+ initFunction( gen->valueUt, gen->objDef, ObjectMethod::Call, "pop",
IN_VLIST_POP_HEAD_WV, IN_VLIST_POP_HEAD_WC, false, true, gen );
- initFunction( uniqueTypeInt, gen->objDef, "push_head_el",
+ initFunction( uniqueTypeInt, gen->objDef, ObjectMethod::Call, "push_head_el",
IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->elUt, false, true, gen );
- initFunction( uniqueTypeInt, gen->objDef, "push_tail_el",
+ initFunction( uniqueTypeInt, gen->objDef, ObjectMethod::Call, "push_tail_el",
IN_LIST_PUSH_TAIL_WV, IN_LIST_PUSH_TAIL_WC, gen->elUt, false, true, gen );
- initFunction( uniqueTypeInt, gen->objDef, "push_el",
+ initFunction( uniqueTypeInt, gen->objDef, ObjectMethod::Call, "push_el",
IN_LIST_PUSH_HEAD_WV, IN_LIST_PUSH_HEAD_WC, gen->elUt, false, true, gen );
- initFunction( gen->elUt, gen->objDef, "pop_head_el",
+ initFunction( gen->elUt, gen->objDef, ObjectMethod::Call, "pop_head_el",
IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false, true, gen );
- initFunction( gen->elUt, gen->objDef, "pop_tail_el",
+ initFunction( gen->elUt, gen->objDef, ObjectMethod::Call, "pop_tail_el",
IN_LIST_POP_TAIL_WV, IN_LIST_POP_TAIL_WC, false, true, gen );
- initFunction( gen->elUt, gen->objDef, "pop_el",
+ initFunction( gen->elUt, gen->objDef, ObjectMethod::Call, "pop_el",
IN_LIST_POP_HEAD_WV, IN_LIST_POP_HEAD_WC, false, true, gen );
}
@@ -1407,13 +1409,13 @@ void Compiler::initListFields( GenericType *gen )
void Compiler::initParserFunctions( GenericType *gen )
{
- initFunction( gen->elUt, gen->objDef, "finish",
- IN_PARSE_FINISH_W, IN_PARSE_FINISH_W, true );
+ initFunction( gen->elUt, gen->objDef, ObjectMethod::ParseFinish, "finish",
+ IN_PARSE_FRAG_W, IN_PARSE_FRAG_W, true );
- initFunction( gen->elUt, gen->objDef, "eof",
- IN_PARSE_FINISH_W, IN_PARSE_FINISH_W, true );
+ initFunction( gen->elUt, gen->objDef, ObjectMethod::ParseFinish, "eof",
+ IN_PARSE_FRAG_W, IN_PARSE_FRAG_W, true );
- initFunction( uniqueTypeStream, gen->objDef, "gets",
+ initFunction( uniqueTypeStream, gen->objDef, ObjectMethod::Call, "gets",
IN_GET_PARSER_STREAM, IN_GET_PARSER_STREAM, true );
}
diff --git a/src/parsetree.h b/src/parsetree.h
index 81157aee..38ed154e 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -2425,10 +2425,17 @@ typedef DList<ObjectField> ParameterList;
struct ObjectMethod
{
+ enum Type
+ {
+ Call,
+ ParseFinish
+ };
+
ObjectMethod( TypeRef *returnTypeRef, String name,
int opcodeWV, int opcodeWC, int numParams,
UniqueType **types, ParameterList *paramList, bool isConst )
:
+ type(Call),
returnUT(0),
returnTypeRef(returnTypeRef),
returnTypeId(0),
@@ -2454,6 +2461,7 @@ struct ObjectMethod
UniqueType **types, ParameterList *paramList,
bool isConst )
:
+ type(Call),
returnUT(returnUT),
returnTypeRef(0),
returnTypeId(0),
@@ -2476,6 +2484,7 @@ struct ObjectMethod
memcpy( this->paramUTs, types, sizeof(UniqueType*)*numParams );
}
+ Type type;
UniqueType *returnUT;
TypeRef *returnTypeRef;
long returnTypeId;
diff --git a/src/pdarun.c b/src/pdarun.c
index 227dd3bd..6d88fff6 100644
--- a/src/pdarun.c
+++ b/src/pdarun.c
@@ -2206,15 +2206,15 @@ skip_send:
}
-long colm_parse_frag( program_t *prg, tree_t **sp, struct pda_run *pda_run,
- stream_t *input, long stop_id, long entry )
+long colm_parse_frag( program_t *prg, tree_t **sp,
+ struct pda_run *pda_run, stream_t *input, long entry )
{
/* COROUTINE */
switch ( entry ) {
case PCR_START:
if ( ! pda_run->parse_error ) {
- long pcr = colm_parse_loop( prg, sp, pda_run,
+ long pcr = colm_parse_loop( prg, sp, pda_run,
stream_to_impl( input ), entry );
while ( pcr != PCR_DONE ) {
@@ -2226,7 +2226,7 @@ long colm_parse_frag( program_t *prg, tree_t **sp, struct pda_run *pda_run,
case PCR_PRE_EOF:
case PCR_REVERSE:
- pcr = colm_parse_loop( prg, sp, pda_run,
+ pcr = colm_parse_loop( prg, sp, pda_run,
stream_to_impl( input ), entry );
}
}
@@ -2239,20 +2239,15 @@ long colm_parse_frag( program_t *prg, tree_t **sp, struct pda_run *pda_run,
}
long colm_parse_finish( program_t *prg, tree_t **sp,
- struct pda_run *pda_run, stream_t *input,
- int revert_on, long entry )
+ struct pda_run *pda_run, stream_t *input, long entry )
{
- struct stream_impl *si;
-
/* COROUTINE */
switch ( entry ) {
case PCR_START:
- si = stream_to_impl( input );
-
if ( ! pda_run->parse_error ) {
- si = stream_to_impl( input );
- long pcr = colm_parse_loop( prg, sp, pda_run, si, entry );
+ long pcr = colm_parse_loop( prg, sp, pda_run,
+ stream_to_impl( input ), entry );
while ( pcr != PCR_DONE ) {
@@ -2263,8 +2258,8 @@ long colm_parse_finish( program_t *prg, tree_t **sp,
case PCR_PRE_EOF:
case PCR_REVERSE:
- si = stream_to_impl( input );
- pcr = colm_parse_loop( prg, sp, pda_run, si, entry );
+ pcr = colm_parse_loop( prg, sp, pda_run,
+ stream_to_impl( input ), entry );
}
}
diff --git a/src/pdarun.h b/src/pdarun.h
index fa73af2c..094e2d26 100644
--- a/src/pdarun.h
+++ b/src/pdarun.h
@@ -455,10 +455,10 @@ kid_t *make_token_with_data( struct colm_program *prg, struct pda_run *pda_run,
long colm_parse_loop( struct colm_program *prg, tree_t **sp, struct pda_run *pda_run,
struct stream_impl *input_stream, long entry );
-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( struct colm_program *prg, tree_t **sp, struct pda_run *pda_run,
- stream_t *input, int revert_on, long entry );
+long colm_parse_frag( struct colm_program *prg, tree_t **sp,
+ struct pda_run *pda_run, stream_t *input, long entry );
+long colm_parse_finish( struct colm_program *prg, tree_t **sp,
+ struct pda_run *pda_run, stream_t *input, 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 );
diff --git a/src/synthesis.cc b/src/synthesis.cc
index 8a5fb218..7abfe500 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -1025,11 +1025,7 @@ void LangVarRef::resetActiveRefs( Compiler *pd, VarRefLookup &lookup,
bool LangVarRef::isFinishCall( VarRefLookup &lookup ) const
{
- if ( lookup.objMethod->opcodeWV == IN_PARSE_FINISH_W )
- {
- return true;
- }
- return false;
+ return lookup.objMethod->type == ObjectMethod::ParseFinish;
}
void LangVarRef::callOperation( Compiler *pd, CodeVect &code, VarRefLookup &lookup ) const
@@ -1052,7 +1048,7 @@ void LangVarRef::callOperation( Compiler *pd, CodeVect &code, VarRefLookup &look
code.append( IN_GET_PARSER_STREAM );
code.append( IN_SEND_EOF_W );
- LangTerm::parseFinish( pd, code, 0 );
+ LangTerm::parseFrag( pd, code, 0 );
code.append( IN_GET_STREAM_MEM_R );
code.appendHalf( 0 );
@@ -1432,14 +1428,6 @@ void LangTerm::parseFrag( Compiler *pd, CodeVect &code, int stopId )
code.append( IN_PARSE_FRAG_EXIT_W );
}
-void LangTerm::parseFinish( Compiler *pd, CodeVect &code, int stopId )
-{
- 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
{
@@ -1613,7 +1601,7 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
if ( !stop ) {
code.append( IN_SEND_EOF_W );
- parseFinish( pd, code, stopId );
+ parseFrag( pd, code, stopId );
}
if ( parserText->reduce ) {
@@ -1720,7 +1708,7 @@ void LangTerm::evaluateSendParser( Compiler *pd, CodeVect &code, bool strings )
if ( eof ) {
code.append( IN_SEND_EOF_W );
- parseFinish( pd, code, 0 );
+ parseFrag( pd, code, 0 );
}
}