Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 60e8e0a

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Evaluation of reductions and SUBSCRIPTED_EXP.
Belonging to [master]: - #2413 - OpenModelica/OpenModelica-testsuite#939
1 parent 5feb832 commit 60e8e0a

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ import NFFunction.Function;
5252
import EvalFunction = NFEvalFunction;
5353
import List;
5454
import System;
55+
import ExpressionIterator = NFExpressionIterator;
56+
import MetaModelica.Dangerous.*;
5557

5658
public
5759
uniontype EvalTarget
@@ -229,6 +231,17 @@ algorithm
229231
then
230232
exp1;
231233

234+
case Expression.SUBSCRIPTED_EXP()
235+
algorithm
236+
exp1 := evalExp(exp.exp, target);
237+
238+
for s in exp.subscripts loop
239+
exp2 := evalExp(s, target);
240+
exp1 := Expression.applyIndexSubscript(exp2, exp1);
241+
end for;
242+
then
243+
exp1;
244+
232245
else exp;
233246
end match;
234247
end evalExp;
@@ -1140,10 +1153,7 @@ algorithm
11401153
evalNormalCall(call.fn, args, call);
11411154

11421155
case Call.TYPED_MAP_CALL()
1143-
algorithm
1144-
Error.addInternalError(getInstanceName() + ": unimplemented case for mapcall", sourceInfo());
1145-
then
1146-
fail();
1156+
then evalReduction(call.exp, call.ty, call.iters);
11471157

11481158
else
11491159
algorithm
@@ -2105,5 +2115,61 @@ algorithm
21052115
end match;
21062116
end evalUriToFilename;
21072117

2118+
function evalReduction
2119+
input Expression exp;
2120+
input Type ty;
2121+
input list<tuple<InstNode, Expression>> iterators;
2122+
output Expression result;
2123+
protected
2124+
Expression e = exp, range;
2125+
InstNode node;
2126+
list<Expression> ranges = {}, expl;
2127+
Mutable<Expression> iter;
2128+
list<Mutable<Expression>> iters = {};
2129+
algorithm
2130+
for i in iterators loop
2131+
(node, range) := i;
2132+
iter := Mutable.create(Expression.INTEGER(0));
2133+
e := Expression.replaceIterator(e, node, Expression.MUTABLE(iter));
2134+
iters := iter :: iters;
2135+
ranges := evalExp(range) :: ranges;
2136+
end for;
2137+
2138+
result := evalReduction2(e, ty, ranges, iters);
2139+
end evalReduction;
2140+
2141+
function evalReduction2
2142+
input Expression exp;
2143+
input Type ty;
2144+
input list<Expression> ranges;
2145+
input list<Mutable<Expression>> iterators;
2146+
output Expression result;
2147+
protected
2148+
Expression range;
2149+
list<Expression> ranges_rest, expl = {};
2150+
Mutable<Expression> iter;
2151+
list<Mutable<Expression>> iters_rest;
2152+
ExpressionIterator range_iter;
2153+
Expression value;
2154+
Type el_ty;
2155+
algorithm
2156+
if listEmpty(ranges) then
2157+
result := evalExp(exp);
2158+
else
2159+
range :: ranges_rest := ranges;
2160+
iter :: iters_rest := iterators;
2161+
range_iter := ExpressionIterator.fromExp(range);
2162+
el_ty := Type.unliftArray(ty);
2163+
2164+
while ExpressionIterator.hasNext(range_iter) loop
2165+
(range_iter, value) := ExpressionIterator.next(range_iter);
2166+
Mutable.update(iter, value);
2167+
expl := evalReduction2(exp, el_ty, ranges_rest, iters_rest) :: expl;
2168+
end while;
2169+
2170+
result := Expression.ARRAY(el_ty, listReverseInPlace(expl));
2171+
end if;
2172+
end evalReduction2;
2173+
21082174
annotation(__OpenModelica_Interface="frontend");
21092175
end NFCeval;

0 commit comments

Comments
 (0)