diff options
-rw-r--r-- | src/lmparse.kl | 38 | ||||
-rw-r--r-- | src/parsetree.h | 24 | ||||
-rw-r--r-- | src/resolve.cc | 23 | ||||
-rw-r--r-- | src/synthesis.cc | 154 |
4 files changed, 121 insertions, 118 deletions
diff --git a/src/lmparse.kl b/src/lmparse.kl index 07988dd7..4789bad1 100644 --- a/src/lmparse.kl +++ b/src/lmparse.kl @@ -1441,24 +1441,6 @@ statement: KW_Yield var_ref final { $$->stmt = LangStmt::cons( LangStmt::YieldType, $2->varRef ); }; -statement: var_ref TK_LtLt accumulate - final { - Namespace *nspace = namespaceStack.top(); - TokenRegion *region = regionStack.top(); - ParserText *parserText = ParserText::cons( $2->loc, nspace, region, replItemList ); - pd->parserTextList.append( parserText ); - - $$->stmt = LangStmt::cons( LangStmt::SendType, $1->varRef, parserText ); - }; -statement: KW_Send var_ref accumulate - final { - Namespace *nspace = namespaceStack.top(); - TokenRegion *region = regionStack.top(); - ParserText *parserText = ParserText::cons( $1->loc, nspace, region, replItemList ); - pd->parserTextList.append( parserText ); - - $$->stmt = LangStmt::cons( LangStmt::SendType, $2->varRef, parserText ); - }; nonterm opt_require_stmt uses statement; @@ -1974,6 +1956,26 @@ code_factor: KW_ParseStop opt_capture type_ref '(' opt_code_expr_list ')' } }; +code_factor: + var_ref TK_LtLt accumulate + final { + Namespace *nspace = namespaceStack.top(); + TokenRegion *region = regionStack.top(); + ParserText *parserText = ParserText::cons( $2->loc, nspace, region, replItemList ); + pd->parserTextList.append( parserText ); + + $$->expr = LangExpr::cons( LangTerm::cons( LangTerm::SendType, $1->varRef, parserText ) ); + }; +code_factor: + KW_Send var_ref accumulate + final { + Namespace *nspace = namespaceStack.top(); + TokenRegion *region = regionStack.top(); + ParserText *parserText = ParserText::cons( $1->loc, nspace, region, replItemList ); + pd->parserTextList.append( parserText ); + + $$->expr = LangExpr::cons( LangTerm::cons( LangTerm::SendType, $2->varRef, parserText ) ); + }; code_factor: KW_TypeId '<' type_ref '>' final { $$->expr = LangExpr::cons( LangTerm::cons( $1->loc, diff --git a/src/parsetree.h b/src/parsetree.h index 60028476..0701cf1d 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -2342,6 +2342,7 @@ struct LangTerm OrigParseType, OrigParseStopType, Parse2Type, + SendType, MakeTreeType, MakeTokenType, EmbedStringType, @@ -2518,6 +2519,15 @@ struct LangTerm t->replacement = (replacement); return t; } + + static LangTerm *cons( Type type, LangVarRef *varRef, ParserText *parserText ) + { + LangTerm *s = new LangTerm; + s->type = type; + s->varRef = varRef; + s->parserText = parserText; + return s; + } void resolve( Compiler *pd ); @@ -2525,6 +2535,7 @@ struct LangTerm UniqueType *evaluateNew( Compiler *pd, CodeVect &code ) const; UniqueType *evaluateConstruct( Compiler *pd, CodeVect &code ) const; UniqueType *evaluateParse2( Compiler *pd, CodeVect &code ) const; + UniqueType *evaluateSend( Compiler *pd, CodeVect &code ) const; UniqueType *evaluateMatch( Compiler *pd, CodeVect &code ) const; UniqueType *evaluate( Compiler *pd, CodeVect &code ) const; void assignFieldArgs( Compiler *pd, CodeVect &code, UniqueType *replUT ) const; @@ -2619,8 +2630,7 @@ struct LangStmt ReturnType, YieldType, ForIterType, - BreakType, - SendType + BreakType }; LangStmt() @@ -2743,15 +2753,6 @@ struct LangStmt return s; } - static LangStmt *cons( Type type, LangVarRef *varRef, ParserText *parserText ) - { - LangStmt *s = new LangStmt; - s->type = (type); - s->varRef = (varRef); - s->parserText = (parserText); - return s; - } - static LangStmt *cons( const InputLoc &loc, Type type, ObjField *objField, TypeRef *typeRef, LangTerm *langTerm, StmtList *stmtList ) { @@ -2775,7 +2776,6 @@ struct LangStmt void resolve( Compiler *pd ) const; void resolveParserItems( Compiler *pd ) const; - void evaluateSend( Compiler *pd, CodeVect &code ) const; LangTerm *chooseDefaultIter( Compiler *pd, LangTerm *fromVarRef ) const; void compileWhile( Compiler *pd, CodeVect &code ) const; void compileForIterBody( Compiler *pd, CodeVect &code, UniqueType *iterUT ) const; diff --git a/src/resolve.cc b/src/resolve.cc index bfb5b9d9..7ca06203 100644 --- a/src/resolve.cc +++ b/src/resolve.cc @@ -333,14 +333,6 @@ void LangTerm::resolve( Compiler *pd ) (*pi)->expr->resolve( pd ); } break; - case Parse2Type: - typeRef->lookupType( pd ); - /* Evaluate the initialization expressions. */ - if ( fieldInitArgs != 0 ) { - for ( FieldInitVect::Iter pi = *fieldInitArgs; pi.lte(); pi++ ) - (*pi)->expr->resolve( pd ); - } - break; case VarRefType: break; @@ -378,6 +370,18 @@ void LangTerm::resolve( Compiler *pd ) generic = parserTypeRef->generic; break; + case Parse2Type: + typeRef->lookupType( pd ); + /* Evaluate the initialization expressions. */ + if ( fieldInitArgs != 0 ) { + for ( FieldInitVect::Iter pi = *fieldInitArgs; pi.lte(); pi++ ) + (*pi)->expr->resolve( pd ); + } + break; + + case SendType: + break; + case EmbedStringType: break; } @@ -500,9 +504,6 @@ void LangStmt::resolve( Compiler *pd ) const varRef->resolve( pd ); break; } - case SendType: { - break; - } } } diff --git a/src/synthesis.cc b/src/synthesis.cc index 8b014ffc..88bdf00c 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -1423,6 +1423,81 @@ UniqueType *LangTerm::evaluateParse2( Compiler *pd, CodeVect &code ) const return replUT; } +UniqueType *LangTerm::evaluateSend( Compiler *pd, CodeVect &code ) const +{ + UniqueType *varUt = varRef->evaluate( pd, code ); + + /* Assign bind ids to the variables in the replacement. */ + for ( ReplItemList::Iter item = *parserText->list; item.lte(); item++ ) { + switch ( item->type ) { + case ReplItem::FactorType: { + String result; + bool unusedCI; + prepareLitString( result, unusedCI, + item->factor->typeRef->pdaLiteral->token.data, + item->factor->typeRef->pdaLiteral->token.loc ); + + /* Make sure we have this string. */ + StringMapEl *mapEl = 0; + if ( pd->literalStrings.insert( result, &mapEl ) ) + mapEl->value = pd->literalStrings.length()-1; + + code.append( IN_LOAD_STR ); + code.appendWord( mapEl->value ); + break; + } + case ReplItem::InputText: { + /* Make sure we have this string. */ + StringMapEl *mapEl = 0; + if ( pd->literalStrings.insert( item->data, &mapEl ) ) + mapEl->value = pd->literalStrings.length()-1; + + code.append( IN_LOAD_STR ); + code.appendWord( mapEl->value ); + break; + } + case ReplItem::ExprType: + item->expr->evaluate( pd, code ); + break; + } + + code.append( IN_DUP_TOP_OFF ); + code.appendHalf( 1 ); + + /* Not a stream. Get the input first. */ + code.append( IN_GET_INPUT ); + if ( pd->revertOn ) + code.append( IN_INPUT_APPEND_WV ); + else + code.append( IN_INPUT_APPEND_WC ); + code.append( IN_POP ); + + code.append( IN_DUP_TOP ); + + /* Parse instruction, dependent on whether or not we are producing + * revert or commit code. */ + if ( pd->revertOn ) { + code.append( IN_PARSE_SAVE_STEPS ); + code.append( IN_PARSE_LOAD_START ); + code.append( IN_PARSE_FRAG_WV ); + code.appendHalf( 0 ); + code.append( IN_PCR_CALL ); + code.append( IN_PARSE_FRAG_WV3 ); + } + else { + code.append( IN_PARSE_SAVE_STEPS ); + code.append( IN_PARSE_LOAD_START ); + code.append( IN_PARSE_FRAG_WC ); + code.appendHalf( 0 ); + code.append( IN_PCR_CALL ); + code.append( IN_PARSE_FRAG_WC3 ); + } + } + + return varUt; +} + + UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code, bool stop ) const { UniqueType *ut = typeRef->uniqueType; @@ -1658,6 +1733,8 @@ UniqueType *LangTerm::evaluate( Compiler *pd, CodeVect &code ) const return evaluateConstruct( pd, code ); case Parse2Type: return evaluateParse2( pd, code ); + case SendType: + return evaluateSend( pd, code ); case NewType: return evaluateNew( pd, code ); case TypeIdType: { @@ -2181,79 +2258,6 @@ void LangStmt::compileWhile( Compiler *pd, CodeVect &code ) const pd->curLocalFrame->iterPopScope(); } -void LangStmt::evaluateSend( Compiler *pd, CodeVect &code ) const -{ - varRef->evaluate( pd, code ); - - /* Assign bind ids to the variables in the replacement. */ - for ( ReplItemList::Iter item = *parserText->list; item.lte(); item++ ) { - switch ( item->type ) { - case ReplItem::FactorType: { - String result; - bool unusedCI; - prepareLitString( result, unusedCI, - item->factor->typeRef->pdaLiteral->token.data, - item->factor->typeRef->pdaLiteral->token.loc ); - - /* Make sure we have this string. */ - StringMapEl *mapEl = 0; - if ( pd->literalStrings.insert( result, &mapEl ) ) - mapEl->value = pd->literalStrings.length()-1; - - code.append( IN_LOAD_STR ); - code.appendWord( mapEl->value ); - break; - } - case ReplItem::InputText: { - /* Make sure we have this string. */ - StringMapEl *mapEl = 0; - if ( pd->literalStrings.insert( item->data, &mapEl ) ) - mapEl->value = pd->literalStrings.length()-1; - - code.append( IN_LOAD_STR ); - code.appendWord( mapEl->value ); - break; - } - case ReplItem::ExprType: - item->expr->evaluate( pd, code ); - break; - } - - code.append( IN_DUP_TOP_OFF ); - code.appendHalf( 1 ); - - /* Not a stream. Get the input first. */ - code.append( IN_GET_INPUT ); - if ( pd->revertOn ) - code.append( IN_INPUT_APPEND_WV ); - else - code.append( IN_INPUT_APPEND_WC ); - code.append( IN_POP ); - - code.append( IN_DUP_TOP ); - - /* Parse instruction, dependent on whether or not we are producing - * revert or commit code. */ - if ( pd->revertOn ) { - code.append( IN_PARSE_SAVE_STEPS ); - code.append( IN_PARSE_LOAD_START ); - code.append( IN_PARSE_FRAG_WV ); - code.appendHalf( 0 ); - code.append( IN_PCR_CALL ); - code.append( IN_PARSE_FRAG_WV3 ); - } - else { - code.append( IN_PARSE_SAVE_STEPS ); - code.append( IN_PARSE_LOAD_START ); - code.append( IN_PARSE_FRAG_WC ); - code.appendHalf( 0 ); - code.append( IN_PCR_CALL ); - code.append( IN_PARSE_FRAG_WC3 ); - } - } - code.append( IN_POP ); -} - void LangStmt::compile( Compiler *pd, CodeVect &code ) const { switch ( type ) { @@ -2415,10 +2419,6 @@ void LangStmt::compile( Compiler *pd, CodeVect &code ) const objField->refActive = false; break; } - case SendType: { - evaluateSend( pd, code ); - break; - } } } |