summaryrefslogtreecommitdiff
path: root/src/synthesis.cc
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-07-09 11:50:14 +0800
committerAdrian Thurston <thurston@colm.net>2018-07-09 11:50:14 +0800
commit600e5a8138c3587157294cbca844b60f714bb5e7 (patch)
tree6c8559e4a0032e99d260e75bc8be53253e63fc68 /src/synthesis.cc
parenteda3bb6d45772bfe1d979d415568c515b896006c (diff)
downloadcolm-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/synthesis.cc')
-rw-r--r--src/synthesis.cc61
1 files changed, 59 insertions, 2 deletions
diff --git a/src/synthesis.cc b/src/synthesis.cc
index 4eff7e99..201bbd18 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -1637,6 +1637,63 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
return targetUT;
}
+void LangTerm::evaluateSendStream( Compiler *pd, CodeVect &code ) const
+{
+ UniqueType *varUt = varRef->evaluate( pd, code );
+
+ if ( varUt->listOf( pd->uniqueTypeStream ) ) {
+ code.append( IN_GET_VLIST_MEM_R );
+ code.appendHalf( varUt->generic->id );
+ code.appendHalf( 0 );
+ }
+
+ /* Assign bind ids to the variables in the replacement. */
+ for ( ConsItemList::Iter item = *parserText->list; item.lte(); item++ ) {
+ switch ( item->type ) {
+ case ConsItem::LiteralType: {
+ String result;
+ bool unusedCI;
+ prepareLitString( result, unusedCI,
+ item->prodEl->typeRef->pdaLiteral->data,
+ item->prodEl->typeRef->pdaLiteral->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 ConsItem::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 ConsItem::ExprType: {
+ UniqueType *ut = item->expr->evaluate( pd, code );
+ if ( ut->typeId == TYPE_VOID ) {
+ /* Clear it away if return type is void. */
+ code.append( IN_POP_VAL );
+ continue;
+ }
+
+ if ( ut->typeId == TYPE_INT || ut->typeId == TYPE_BOOL )
+ code.append( IN_INT_TO_STR );
+
+ break;
+ }}
+
+ code.append( IN_PRINT_TREE_W );
+ }
+}
+
void LangTerm::evaluateSendParser( Compiler *pd, CodeVect &code, bool strings ) const
{
UniqueType *varUt = varRef->evaluate( pd, code );
@@ -1733,9 +1790,9 @@ UniqueType *LangTerm::evaluateSend( Compiler *pd, CodeVect &code ) const
UniqueType *varUt = varRef->lookup( pd );
if ( varUt == pd->uniqueTypeStream )
- evaluateSendParser( pd, code, true );
+ evaluateSendStream( pd, code );
else if ( varUt->listOf( pd->uniqueTypeStream ) )
- evaluateSendParser( pd, code, true );
+ evaluateSendStream( pd, code );
else if ( varUt->parser() )
evaluateSendParser( pd, code, true );
else