summaryrefslogtreecommitdiff
path: root/src/synthesis.cc
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2017-07-27 12:11:13 -0400
committerAdrian Thurston <thurston@colm.net>2017-07-27 12:11:13 -0400
commit3f74fc17cee81774ddcc29c0a3560f81f7b60b7d (patch)
treedd3cc86a2cbc0b6eceb2755f084800718842fb1c /src/synthesis.cc
parent1395ab646772f3c37e3fbad207d9f12a9d3f3140 (diff)
downloadcolm-3f74fc17cee81774ddcc29c0a3560f81f7b60b7d.tar.gz
added a read_reduce statement to call postfix reducer
Triggers the generation of the reducer. Accepts a stream.
Diffstat (limited to 'src/synthesis.cc')
-rw-r--r--src/synthesis.cc37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/synthesis.cc b/src/synthesis.cc
index c839a9cb..aa140794 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -1404,9 +1404,42 @@ void LangTerm::parseFrag( Compiler *pd, CodeVect &code, int stopId ) const
}
}
+UniqueType *LangTerm::evaluateReadReduce( Compiler *pd, CodeVect &code ) const
+{
+ UniqueType *parserUT = typeRef->uniqueType;
+ UniqueType *targetUT = parserUT->generic->elUt;
+
+ /* Should be one arg and it should be a stream. */
+
+ /* Assign bind ids to the variables in the replacement. */
+ for ( ConsItemList::Iter item = *parserText->list; item.lte(); item++ ) {
+ switch ( item->type ) {
+ case ConsItem::LiteralType: {
+ break;
+ }
+ case ConsItem::InputText: {
+ break;
+ }
+ case ConsItem::ExprType: {
+ item->expr->evaluate( pd, code );
+ break;
+ }}
+ }
+
+ code.append( IN_READ_REDUCE );
+ code.appendHalf( parserUT->generic->id );
+ code.appendHalf( parserText->reducerId );
+
+ return targetUT;
+}
+
UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
bool tree, bool stop ) const
{
+ if ( parserText->reduce && parserText->read ) {
+ return evaluateReadReduce( pd, code );
+ }
+
UniqueType *parserUT = typeRef->uniqueType;
UniqueType *targetUT = parserUT->generic->elUt;
@@ -1493,7 +1526,7 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
code.appendWord( mapEl->value );
break;
}
- case ConsItem::ExprType:
+ case ConsItem::ExprType: {
UniqueType *ut = item->expr->evaluate( pd, code );
if ( ut->typeId == TYPE_TREE && ut->langEl == pd->voidLangEl ) {
@@ -1515,7 +1548,7 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
code.append( IN_TREE_TO_STR_TRIM );
}
break;
- }
+ }}
if ( isStream ) {
if ( pd->revertOn )