Skip to content

Commit

Permalink
Consider that sample may have just one argument
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Dec 16, 2015
1 parent 9297bf0 commit eb50a09
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -427,39 +427,37 @@ protected function transformBuiltinExpression "author: lochel
output DAE.Exp outExp;
output tuple<HashTableExpToIndex.HashTable, Integer /*iDelay*/, Integer /*iSample*/, list<BackendDAE.TimeEvent>> outTuple;
algorithm
(outExp,outTuple) := matchcontinue (inExp,inTuple)
(outExp,outTuple) := matchcontinue (inExp, inTuple)
local
DAE.Exp e, start, interval;
DAE.Exp start, interval;
list<DAE.Exp> es;
HashTableExpToIndex.HashTable ht;
Integer iDelay, iSample, i;
list<BackendDAE.TimeEvent> timeEvents;
DAE.CallAttributes attr;

// delay [already in ht]
case (e as DAE.CALL(Absyn.IDENT("delay"), es, attr), (ht, iDelay, iSample, timeEvents)) equation
i = BaseHashTable.get(e, ht);
case (DAE.CALL(Absyn.IDENT("delay"), es, attr), (ht, iDelay, iSample, timeEvents)) equation
i = BaseHashTable.get(inExp, ht);
then (DAE.CALL(Absyn.IDENT("delay"), DAE.ICONST(i)::es, attr), (ht, iDelay, iSample, timeEvents));

// delay [not yet in ht]
case (e as DAE.CALL(Absyn.IDENT("delay"), es, attr), (ht, iDelay, iSample, timeEvents)) equation
ht = BaseHashTable.add((e, iDelay+1), ht);
case (DAE.CALL(Absyn.IDENT("delay"), es, attr), (ht, iDelay, iSample, timeEvents)) equation
ht = BaseHashTable.add((inExp, iDelay+1), ht);
then (DAE.CALL(Absyn.IDENT("delay"), DAE.ICONST(iDelay)::es, attr), (ht, iDelay+1, iSample, timeEvents));

// sample [already in ht]
case (e as DAE.CALL(Absyn.IDENT("sample"), es, attr), (ht, iDelay, iSample, timeEvents))
guard (not Types.isClockOrSubTypeClock(Expression.typeof(listGet(es, 2))))
equation
i = BaseHashTable.get(e, ht);
case (DAE.CALL(Absyn.IDENT("sample"), es as {start, interval}, attr), (ht, iDelay, iSample, timeEvents))
guard (not Types.isClockOrSubTypeClock(Expression.typeof(interval))) equation
i = BaseHashTable.get(inExp, ht);
then (DAE.CALL(Absyn.IDENT("sample"), DAE.ICONST(i)::es, attr), (ht, iDelay, iSample, timeEvents));

// sample [not yet in ht]
case (e as DAE.CALL(Absyn.IDENT("sample"), es as {start, interval}, attr), (ht, iDelay, iSample, timeEvents))
guard (not Types.isClockOrSubTypeClock(Expression.typeof(listGet(es, 2))))
equation
iSample = iSample+1;
timeEvents = listAppend(timeEvents, {BackendDAE.SAMPLE_TIME_EVENT(iSample, start, interval)});
ht = BaseHashTable.add((e, iSample), ht);
case (DAE.CALL(Absyn.IDENT("sample"), es as {start, interval}, attr), (ht, iDelay, iSample, timeEvents))
guard (not Types.isClockOrSubTypeClock(Expression.typeof(interval))) equation
iSample = iSample+1;
timeEvents = listAppend(timeEvents, {BackendDAE.SAMPLE_TIME_EVENT(iSample, start, interval)});
ht = BaseHashTable.add((inExp, iSample), ht);
then (DAE.CALL(Absyn.IDENT("sample"), DAE.ICONST(iSample)::es, attr), (ht, iDelay, iSample, timeEvents));

else (inExp,inTuple);
Expand Down

0 comments on commit eb50a09

Please sign in to comment.