@@ -604,7 +604,7 @@ algorithm
604604
605605 else
606606 algorithm
607- exp := Expression . BINARY (exp1, Operator . makeMul (Type . UNKNOWN ()), exp2);
607+ exp := Expression . BINARY (exp1, Operator . makeDiv (Type . UNKNOWN ()), exp2);
608608 printFailedEvalError(getInstanceName(), exp, sourceInfo());
609609 then
610610 fail();
@@ -1279,8 +1279,8 @@ algorithm
12791279 case "log10" then evalBuiltinLog10(listHead(args), target);
12801280 case "log" then evalBuiltinLog(listHead(args), target);
12811281 case "matrix" then evalBuiltinMatrix(listHead(args));
1282- case "max" then evalBuiltinMax(args);
1283- case "min" then evalBuiltinMin(args);
1282+ case "max" then evalBuiltinMax(args, fn );
1283+ case "min" then evalBuiltinMin(args, fn );
12841284 case "mod" then evalBuiltinMod(args);
12851285 case "noEvent" then listHead(args); // No events during ceval, just return the argument.
12861286 case "ones" then evalBuiltinOnes(args);
@@ -1755,14 +1755,26 @@ end evalBuiltinMatrix2;
17551755
17561756function evalBuiltinMax
17571757 input list< Expression > args;
1758+ input Function fn;
17581759 output Expression result;
17591760protected
17601761 Expression e1, e2;
17611762 list< Expression > expl;
1763+ Type ty;
17621764algorithm
17631765 result := match args
17641766 case {e1, e2} then evalBuiltinMax2(e1, e2);
1765- case {Expression . ARRAY (elements = expl)} then evalBuiltinMax2(e for e in expl);
1767+ case {e1 as Expression . ARRAY (ty = ty)}
1768+ algorithm
1769+ result := Expression . fold(e1, evalBuiltinMax2, Expression . EMPTY ());
1770+
1771+ if Expression . isEmpty(result) then
1772+ result := Expression . CALL (Call . makeTypedCall(fn,
1773+ {Expression . ARRAY (ty, {})}, Variability . CONSTANT , Type . arrayElementType(ty)));
1774+ end if ;
1775+ then
1776+ result;
1777+
17661778 else algorithm printWrongArgsError(getInstanceName(), args, sourceInfo()); then fail();
17671779 end match;
17681780end evalBuiltinMax;
@@ -1781,25 +1793,34 @@ algorithm
17811793 then if exp1. value < exp2. value then exp2 else exp1;
17821794 case (Expression . ENUM_LITERAL (), Expression . ENUM_LITERAL ())
17831795 then if exp1. index < exp2. index then exp2 else exp1;
1784- case (Expression . ARRAY (), Expression . ARRAY ())
1785- then evalBuiltinMax2(evalBuiltinMax2(e for e in exp1. elements),
1786- evalBuiltinMax2(e for e in exp2. elements));
1787- case (Expression . ARRAY (), _)
1788- then evalBuiltinMax2(evalBuiltinMax2(e for e in exp1. elements), exp2);
1796+ case (Expression . ARRAY (), _) then exp2;
1797+ case (_, Expression . EMPTY ()) then exp1;
17891798 else algorithm printWrongArgsError(getInstanceName(), {exp1, exp2}, sourceInfo()); then fail();
17901799 end match;
17911800end evalBuiltinMax2;
17921801
17931802function evalBuiltinMin
17941803 input list< Expression > args;
1804+ input Function fn;
17951805 output Expression result;
17961806protected
17971807 Expression e1, e2;
17981808 list< Expression > expl;
1809+ Type ty;
17991810algorithm
18001811 result := match args
18011812 case {e1, e2} then evalBuiltinMin2(e1, e2);
1802- case {Expression . ARRAY (elements = expl)} then evalBuiltinMin2(e for e in expl);
1813+ case {e1 as Expression . ARRAY (ty = ty)}
1814+ algorithm
1815+ result := Expression . fold(e1, evalBuiltinMin2, Expression . EMPTY ());
1816+
1817+ if Expression . isEmpty(result) then
1818+ result := Expression . CALL (Call . makeTypedCall(fn,
1819+ {Expression . ARRAY (ty, {})}, Variability . CONSTANT , Type . arrayElementType(ty)));
1820+ end if ;
1821+ then
1822+ result;
1823+
18031824 else algorithm printWrongArgsError(getInstanceName(), args, sourceInfo()); then fail();
18041825 end match;
18051826end evalBuiltinMin;
@@ -1818,11 +1839,8 @@ algorithm
18181839 then if exp1. value > exp2. value then exp2 else exp1;
18191840 case (Expression . ENUM_LITERAL (), Expression . ENUM_LITERAL ())
18201841 then if exp1. index > exp2. index then exp2 else exp1;
1821- case (Expression . ARRAY (), Expression . ARRAY ())
1822- then evalBuiltinMin2(evalBuiltinMin2(e for e in exp1. elements),
1823- evalBuiltinMin2(e for e in exp2. elements));
1824- case (Expression . ARRAY (), _)
1825- then evalBuiltinMin2(evalBuiltinMin2(e for e in exp1. elements), exp2);
1842+ case (Expression . ARRAY (), _) then exp2;
1843+ case (_, Expression . EMPTY ()) then exp1;
18261844 else algorithm printWrongArgsError(getInstanceName(), {exp1, exp2}, sourceInfo()); then fail();
18271845 end match;
18281846end evalBuiltinMin2;
@@ -1857,11 +1875,16 @@ function evalBuiltinProduct
18571875 input Expression arg;
18581876 output Expression result;
18591877algorithm
1860- result := matchcontinue Type . arrayElementType(Expression . typeOf(arg))
1861- case Type . INTEGER () then Expression . INTEGER (Expression . fold(arg, evalBuiltinProductInt, 1 ));
1862- case Type . REAL () then Expression . REAL (Expression . fold(arg, evalBuiltinProductReal, 1 . 0 ));
1878+ result := match arg
1879+ case Expression . ARRAY ()
1880+ then match Type . arrayElementType(Expression . typeOf(arg))
1881+ case Type . INTEGER () then Expression . INTEGER (Expression . fold(arg, evalBuiltinProductInt, 1 ));
1882+ case Type . REAL () then Expression . REAL (Expression . fold(arg, evalBuiltinProductReal, 1 . 0 ));
1883+ else algorithm printWrongArgsError(getInstanceName(), {arg}, sourceInfo()); then fail();
1884+ end match;
1885+
18631886 else algorithm printWrongArgsError(getInstanceName(), {arg}, sourceInfo()); then fail();
1864- end matchcontinue ;
1887+ end match ;
18651888end evalBuiltinProduct;
18661889
18671890function evalBuiltinProductInt
@@ -2073,11 +2096,16 @@ function evalBuiltinSum
20732096 input Expression arg;
20742097 output Expression result;
20752098algorithm
2076- result := matchcontinue Type . arrayElementType(Expression . typeOf(arg))
2077- case Type . INTEGER () then Expression . INTEGER (Expression . fold(arg, evalBuiltinSumInt, 0 ));
2078- case Type . REAL () then Expression . REAL (Expression . fold(arg, evalBuiltinSumReal, 0 . 0 ));
2099+ result := match arg
2100+ case Expression . ARRAY ()
2101+ then match Type . arrayElementType(Expression . typeOf(arg))
2102+ case Type . INTEGER () then Expression . INTEGER (Expression . fold(arg, evalBuiltinSumInt, 0 ));
2103+ case Type . REAL () then Expression . REAL (Expression . fold(arg, evalBuiltinSumReal, 0 . 0 ));
2104+ else algorithm printWrongArgsError(getInstanceName(), {arg}, sourceInfo()); then fail();
2105+ end match;
2106+
20792107 else algorithm printWrongArgsError(getInstanceName(), {arg}, sourceInfo()); then fail();
2080- end matchcontinue ;
2108+ end match ;
20812109end evalBuiltinSum;
20822110
20832111function evalBuiltinSumInt
0 commit comments