Skip to content

Commit

Permalink
[NF] Evaluation of reductions and SUBSCRIPTED_EXP.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed May 7, 2018
1 parent 5feb832 commit 60e8e0a
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 additions & 4 deletions Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -52,6 +52,8 @@ import NFFunction.Function;
import EvalFunction = NFEvalFunction;
import List;
import System;
import ExpressionIterator = NFExpressionIterator;
import MetaModelica.Dangerous.*;

public
uniontype EvalTarget
Expand Down Expand Up @@ -229,6 +231,17 @@ algorithm
then
exp1;

case Expression.SUBSCRIPTED_EXP()
algorithm
exp1 := evalExp(exp.exp, target);

for s in exp.subscripts loop
exp2 := evalExp(s, target);
exp1 := Expression.applyIndexSubscript(exp2, exp1);
end for;
then
exp1;

else exp;
end match;
end evalExp;
Expand Down Expand Up @@ -1140,10 +1153,7 @@ algorithm
evalNormalCall(call.fn, args, call);

case Call.TYPED_MAP_CALL()
algorithm
Error.addInternalError(getInstanceName() + ": unimplemented case for mapcall", sourceInfo());
then
fail();
then evalReduction(call.exp, call.ty, call.iters);

else
algorithm
Expand Down Expand Up @@ -2105,5 +2115,61 @@ algorithm
end match;
end evalUriToFilename;

function evalReduction
input Expression exp;
input Type ty;
input list<tuple<InstNode, Expression>> iterators;
output Expression result;
protected
Expression e = exp, range;
InstNode node;
list<Expression> ranges = {}, expl;
Mutable<Expression> iter;
list<Mutable<Expression>> iters = {};
algorithm
for i in iterators loop
(node, range) := i;
iter := Mutable.create(Expression.INTEGER(0));
e := Expression.replaceIterator(e, node, Expression.MUTABLE(iter));
iters := iter :: iters;
ranges := evalExp(range) :: ranges;
end for;

result := evalReduction2(e, ty, ranges, iters);
end evalReduction;

function evalReduction2
input Expression exp;
input Type ty;
input list<Expression> ranges;
input list<Mutable<Expression>> iterators;
output Expression result;
protected
Expression range;
list<Expression> ranges_rest, expl = {};
Mutable<Expression> iter;
list<Mutable<Expression>> iters_rest;
ExpressionIterator range_iter;
Expression value;
Type el_ty;
algorithm
if listEmpty(ranges) then
result := evalExp(exp);
else
range :: ranges_rest := ranges;
iter :: iters_rest := iterators;
range_iter := ExpressionIterator.fromExp(range);
el_ty := Type.unliftArray(ty);

while ExpressionIterator.hasNext(range_iter) loop
(range_iter, value) := ExpressionIterator.next(range_iter);
Mutable.update(iter, value);
expl := evalReduction2(exp, el_ty, ranges_rest, iters_rest) :: expl;
end while;

result := Expression.ARRAY(el_ty, listReverseInPlace(expl));
end if;
end evalReduction2;

annotation(__OpenModelica_Interface="frontend");
end NFCeval;

0 comments on commit 60e8e0a

Please sign in to comment.