Skip to content

Commit

Permalink
Reorganize some NFExpression records (#8547)
Browse files Browse the repository at this point in the history
- Rename NFExpression.ARRAY to NFExpression.LIST in order to prepare for
  adding an array expression based on actual arrays and not lists.
- Move NFExpression.MULTARY to where it should be.
- Update the bootstrapping header and ffi interface to reflect the
  NFExpression changes made.
  • Loading branch information
perost committed Feb 15, 2022
1 parent bf2fb17 commit 8d0b1ce
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 210 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NBackEnd/Util/NBBackendUtil.mo
Expand Up @@ -522,7 +522,7 @@ public
var := BVariable.getVar(exp.cref);
then stringHashDjb2Mod(BackendExtension.BackendInfo.toString(var.backendinfo), mod);
case Expression.TYPENAME() then 1; // ty !!
case Expression.ARRAY() algorithm // ty !!
case Expression.LIST() algorithm // ty !!
for elem in exp.elements loop
hash := hash + noNameHashExp(elem, mod);
end for;
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NBackEnd/Util/NBDifferentiate.mo
Expand Up @@ -351,12 +351,12 @@ public
case Expression.CREF() then differentiateComponentRef(exp, diffArguments);

// [a, b, c, ...]' = [a', b', c', ...]
case Expression.ARRAY() algorithm
case Expression.LIST() algorithm
for element in exp.elements loop
(element, diffArguments) := differentiateExpression(element, diffArguments);
new_elements := element :: new_elements;
end for;
then (Expression.ARRAY(exp.ty, listReverse(new_elements), exp.literal), diffArguments);
then (Expression.LIST(exp.ty, listReverse(new_elements), exp.literal), diffArguments);

// |a, b, c|' |a', b', c'|
// |d, e, f| = |d', e', f'|
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFBuiltinCall.mo
Expand Up @@ -2024,7 +2024,7 @@ protected
then
Expression.CALL(Call.makeTypedCall(fn, {arg}, var, Purity.IMPURE, arg.ty));

case Expression.ARRAY()
case Expression.LIST()
algorithm
arg.elements := list(typeActualInStreamCall2(name, fn, e, var, info) for e in arg.elements);
then
Expand Down
76 changes: 38 additions & 38 deletions OMCompiler/Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -186,7 +186,7 @@ algorithm
case Expression.TYPENAME()
then evalTypename(exp.ty, exp, target);

case Expression.ARRAY()
case Expression.LIST()
then if exp.literal then exp
else
Expression.makeArray(exp.ty,
Expand Down Expand Up @@ -1003,7 +1003,7 @@ algorithm
case (Expression.STRING(), Expression.STRING())
then Expression.STRING(exp1.value + exp2.value);

case (Expression.ARRAY(), Expression.ARRAY())
case (Expression.LIST(), Expression.LIST())
guard listLength(exp1.elements) == listLength(exp2.elements)
then Expression.makeArray(exp1.ty,
list(evalBinaryAdd(e1, e2) threaded for e1 in exp1.elements, e2 in exp2.elements),
Expand All @@ -1030,7 +1030,7 @@ algorithm
case (Expression.REAL(), Expression.REAL())
then Expression.REAL(exp1.value - exp2.value);

case (Expression.ARRAY(), Expression.ARRAY())
case (Expression.LIST(), Expression.LIST())
guard listLength(exp1.elements) == listLength(exp2.elements)
then Expression.makeArray(exp1.ty,
list(evalBinarySub(e1, e2) threaded for e1 in exp1.elements, e2 in exp2.elements),
Expand All @@ -1057,7 +1057,7 @@ algorithm
case (Expression.REAL(), Expression.REAL())
then Expression.REAL(exp1.value * exp2.value);

case (Expression.ARRAY(), Expression.ARRAY())
case (Expression.LIST(), Expression.LIST())
guard listLength(exp1.elements) == listLength(exp2.elements)
then Expression.makeArray(exp1.ty,
list(evalBinaryMul(e1, e2) threaded for e1 in exp1.elements, e2 in exp2.elements),
Expand Down Expand Up @@ -1094,7 +1094,7 @@ algorithm
case (Expression.REAL(), Expression.REAL())
then Expression.REAL(exp1.value / exp2.value);

case (Expression.ARRAY(), Expression.ARRAY())
case (Expression.LIST(), Expression.LIST())
guard listLength(exp1.elements) == listLength(exp2.elements)
then Expression.makeArray(exp1.ty,
list(evalBinaryDiv(e1, e2, target) threaded for e1 in exp1.elements, e2 in exp2.elements),
Expand All @@ -1118,7 +1118,7 @@ algorithm
case (Expression.REAL(), Expression.REAL())
then Expression.REAL(exp1.value ^ exp2.value);

case (Expression.ARRAY(), Expression.ARRAY())
case (Expression.LIST(), Expression.LIST())
guard listLength(exp1.elements) == listLength(exp2.elements)
then Expression.makeArray(exp1.ty,
list(evalBinaryPow(e1, e2) threaded for e1 in exp1.elements, e2 in exp2.elements),
Expand Down Expand Up @@ -1146,7 +1146,7 @@ function evalBinaryScalarArray
end FuncT;
algorithm
exp := match arrayExp
case Expression.ARRAY()
case Expression.LIST()
then Expression.makeArray(arrayExp.ty,
list(evalBinaryScalarArray(scalarExp, e, opFunc) for e in arrayExp.elements),
literal = true);
Expand All @@ -1168,7 +1168,7 @@ function evalBinaryArrayScalar
end FuncT;
algorithm
exp := match arrayExp
case Expression.ARRAY()
case Expression.LIST()
then Expression.makeArray(arrayExp.ty,
list(evalBinaryArrayScalar(e, scalarExp, opFunc) for e in arrayExp.elements),
literal = true);
Expand All @@ -1187,7 +1187,7 @@ protected
Type ty;
algorithm
exp := match Expression.transposeArray(matrixExp)
case Expression.ARRAY(Type.ARRAY(ty, {m, _}), expl)
case Expression.LIST(Type.ARRAY(ty, {m, _}), expl)
algorithm
expl := list(evalBinaryScalarProduct(vectorExp, e) for e in expl);
then
Expand All @@ -1213,7 +1213,7 @@ protected
Type ty;
algorithm
exp := match matrixExp
case Expression.ARRAY(Type.ARRAY(ty, {n, _}), expl)
case Expression.LIST(Type.ARRAY(ty, {n, _}), expl)
algorithm
expl := list(evalBinaryScalarProduct(e, vectorExp) for e in expl);
then
Expand All @@ -1240,7 +1240,7 @@ algorithm
Expression e2;
list<Expression> rest_e2;

case (Expression.ARRAY(ty = Type.ARRAY(elem_ty)), Expression.ARRAY())
case (Expression.LIST(ty = Type.ARRAY(elem_ty)), Expression.LIST())
guard listLength(exp1.elements) == listLength(exp2.elements)
algorithm
exp := Expression.makeZero(elem_ty);
Expand Down Expand Up @@ -1276,8 +1276,8 @@ algorithm
e2 := Expression.transposeArray(exp2);

exp := match (exp1, e2)
case (Expression.ARRAY(Type.ARRAY(elem_ty, {n, _}), expl1),
Expression.ARRAY(Type.ARRAY(_, {p, _}), expl2))
case (Expression.LIST(Type.ARRAY(elem_ty, {n, _}), expl1),
Expression.LIST(Type.ARRAY(_, {p, _}), expl2))
algorithm
mat_ty := Type.ARRAY(elem_ty, {n, p});

Expand Down Expand Up @@ -1310,7 +1310,7 @@ protected
Integer n;
algorithm
exp := match (matrixExp, nExp)
case (Expression.ARRAY(), Expression.INTEGER(value = 0))
case (Expression.LIST(), Expression.INTEGER(value = 0))
algorithm
n := Dimension.size(listHead(Type.arrayDims(matrixExp.ty)));
then
Expand Down Expand Up @@ -1382,7 +1382,7 @@ algorithm
exp := match exp1
case Expression.INTEGER() then Expression.INTEGER(-exp1.value);
case Expression.REAL() then Expression.REAL(-exp1.value);
case Expression.ARRAY()
case Expression.LIST()
algorithm
exp1.elements := list(evalUnaryMinus(e) for e in exp1.elements);
then
Expand Down Expand Up @@ -1452,9 +1452,9 @@ algorithm
case Expression.BOOLEAN()
then if exp1.value then evalExp(exp2, target) else exp1;

case Expression.ARRAY()
case Expression.LIST()
algorithm
Expression.ARRAY(elements = expl) := evalExp(exp2, target);
Expression.LIST(elements = expl) := evalExp(exp2, target);
expl := list(evalLogicBinaryAnd(e1, e2, target)
threaded for e1 in exp1.elements, e2 in expl);
then
Expand Down Expand Up @@ -1482,9 +1482,9 @@ algorithm
case Expression.BOOLEAN()
then if exp1.value then exp1 else evalExp(exp2, target);

case Expression.ARRAY()
case Expression.LIST()
algorithm
Expression.ARRAY(elements = expl) := evalExp(exp2, target);
Expression.LIST(elements = expl) := evalExp(exp2, target);
expl := list(evalLogicBinaryOr(e1, e2, target)
threaded for e1 in exp1.elements, e2 in expl);
then
Expand Down Expand Up @@ -1521,7 +1521,7 @@ function evalLogicUnaryNot
algorithm
exp := match exp1
case Expression.BOOLEAN() then Expression.BOOLEAN(not exp1.value);
case Expression.ARRAY() then Expression.mapArrayElements(exp1, evalLogicUnaryNot);
case Expression.LIST() then Expression.mapArrayElements(exp1, evalLogicUnaryNot);

else
algorithm
Expand Down Expand Up @@ -2129,9 +2129,9 @@ protected
Boolean e_lit, arg_lit = true;
algorithm
result := match arg
case Expression.ARRAY(elements = {}) then arg;
case Expression.LIST(elements = {}) then arg;

case Expression.ARRAY(elements = elems)
case Expression.LIST(elements = elems)
algorithm
n := listLength(elems);

Expand Down Expand Up @@ -2337,7 +2337,7 @@ algorithm
Dimension dim1, dim2;
Type ty;

case Expression.ARRAY(ty = ty)
case Expression.LIST(ty = ty)
algorithm
dim_count := Type.dimensionCount(ty);

Expand Down Expand Up @@ -2377,7 +2377,7 @@ function evalBuiltinMatrix2
output Expression result;
algorithm
result := match arg
case Expression.ARRAY()
case Expression.LIST()
then Expression.makeArray(ty,
list(Expression.toScalar(e) for e in arg.elements),
arg.literal);
Expand All @@ -2397,7 +2397,7 @@ protected
algorithm
result := match args
case {e1, e2} then evalBuiltinMax2(e1, e2);
case {e1 as Expression.ARRAY(ty = ty)}
case {e1 as Expression.LIST(ty = ty)}
algorithm
result := Expression.fold(e1, evalBuiltinMax2, Expression.EMPTY(ty));

Expand Down Expand Up @@ -2426,7 +2426,7 @@ algorithm
then if exp1.value < exp2.value then exp2 else exp1;
case (Expression.ENUM_LITERAL(), Expression.ENUM_LITERAL())
then if exp1.index < exp2.index then exp2 else exp1;
case (Expression.ARRAY(), _) then exp2;
case (Expression.LIST(), _) then exp2;
case (_, Expression.EMPTY()) then exp1;
else algorithm printWrongArgsError(getInstanceName(), {exp1, exp2}, sourceInfo()); then fail();
end match;
Expand All @@ -2443,7 +2443,7 @@ protected
algorithm
result := match args
case {e1, e2} then evalBuiltinMin2(e1, e2);
case {e1 as Expression.ARRAY(ty = ty)}
case {e1 as Expression.LIST(ty = ty)}
algorithm
result := Expression.fold(e1, evalBuiltinMin2, Expression.EMPTY(ty));

Expand Down Expand Up @@ -2472,7 +2472,7 @@ algorithm
then if exp1.value > exp2.value then exp2 else exp1;
case (Expression.ENUM_LITERAL(), Expression.ENUM_LITERAL())
then if exp1.index > exp2.index then exp2 else exp1;
case (Expression.ARRAY(), _) then exp2;
case (Expression.LIST(), _) then exp2;
case (_, Expression.EMPTY()) then exp1;
else algorithm printWrongArgsError(getInstanceName(), {exp1, exp2}, sourceInfo()); then fail();
end match;
Expand Down Expand Up @@ -2530,7 +2530,7 @@ function evalBuiltinProduct
output Expression result;
algorithm
result := match arg
case Expression.ARRAY()
case Expression.LIST()
then match Type.arrayElementType(Expression.typeOf(arg))
case Type.INTEGER() then Expression.INTEGER(Expression.fold(arg, evalBuiltinProductInt, 1));
case Type.REAL() then Expression.REAL(Expression.fold(arg, evalBuiltinProductReal, 1.0));
Expand All @@ -2547,7 +2547,7 @@ function evalBuiltinProductInt
algorithm
result := match exp
case Expression.INTEGER() then result * exp.value;
case Expression.ARRAY() then result;
case Expression.LIST() then result;
else fail();
end match;
end evalBuiltinProductInt;
Expand All @@ -2558,7 +2558,7 @@ function evalBuiltinProductReal
algorithm
result := match exp
case Expression.REAL() then result * exp.value;
case Expression.ARRAY() then result;
case Expression.LIST() then result;
else fail();
end match;
end evalBuiltinProductReal;
Expand Down Expand Up @@ -2625,7 +2625,7 @@ protected
Expression exp = listHead(args);
algorithm
result := match exp
case Expression.ARRAY() then evalBuiltinScalar(exp.elements);
case Expression.LIST() then evalBuiltinScalar(exp.elements);
else exp;
end match;
end evalBuiltinScalar;
Expand Down Expand Up @@ -2673,7 +2673,7 @@ protected
Boolean literal;
algorithm
result := match arg
case Expression.ARRAY(ty = ty, elements = {x1, x2, x3}, literal = literal)
case Expression.LIST(ty = ty, elements = {x1, x2, x3}, literal = literal)
algorithm
zero := Expression.makeZero(Type.arrayElementType(ty));
y1 := Expression.makeArray(ty, {zero, Expression.negate(x3), x2}, literal);
Expand Down Expand Up @@ -2752,7 +2752,7 @@ function evalBuiltinSum
output Expression result;
algorithm
result := match arg
case Expression.ARRAY()
case Expression.LIST()
then match Type.arrayElementType(Expression.typeOf(arg))
case Type.INTEGER() then Expression.INTEGER(Expression.fold(arg, evalBuiltinSumInt, 0));
case Type.REAL() then Expression.REAL(Expression.fold(arg, evalBuiltinSumReal, 0.0));
Expand All @@ -2769,7 +2769,7 @@ function evalBuiltinSumInt
algorithm
result := match exp
case Expression.INTEGER() then result + exp.value;
case Expression.ARRAY() then result;
case Expression.LIST() then result;
else fail();
end match;
end evalBuiltinSumInt;
Expand All @@ -2780,7 +2780,7 @@ function evalBuiltinSumReal
algorithm
result := match exp
case Expression.REAL() then result + exp.value;
case Expression.ARRAY() then result;
case Expression.LIST() then result;
else fail();
end match;
end evalBuiltinSumReal;
Expand All @@ -2795,7 +2795,7 @@ protected
list<Expression> expl, accum = {};
algorithm
result := match arg
case Expression.ARRAY() guard Type.isMatrix(arg.ty)
case Expression.LIST() guard Type.isMatrix(arg.ty)
algorithm
mat := listArray(list(listArray(Expression.arrayElements(row))
for row in Expression.arrayElements(arg)));
Expand Down Expand Up @@ -2849,7 +2849,7 @@ protected
Boolean literal;
algorithm
result := match arg
case Expression.ARRAY(ty = Type.ARRAY(elementType = ty,
case Expression.LIST(ty = Type.ARRAY(elementType = ty,
dimensions = dim1 :: dim2 :: rest_dims),
elements = arr,
literal = literal)
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFConnector.mo
Expand Up @@ -100,7 +100,7 @@ public
algorithm
conns := match exp
case Expression.CREF() then fromCref(exp.cref, exp.ty, source) :: conns;
case Expression.ARRAY()
case Expression.LIST()
algorithm
for e in listReverse(exp.elements) loop
conns := fromExp(e, source, conns);
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFDimension.mo
Expand Up @@ -104,7 +104,7 @@ public
fail();
end match;

case Expression.ARRAY()
case Expression.LIST()
guard Expression.arrayAllEqual(exp)
then fromExp(Expression.arrayFirstScalar(exp), var);

Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFEvalFunction.mo
Expand Up @@ -774,7 +774,7 @@ protected
list<Expression> subs, vals;
algorithm
result := match (arrayExp, subscripts)
case (Expression.ARRAY(), Subscript.INDEX(sub) :: rest_subs) guard Expression.isScalarLiteral(sub)
case (Expression.LIST(), Subscript.INDEX(sub) :: rest_subs) guard Expression.isScalarLiteral(sub)
algorithm
idx := Expression.toInteger(sub);

Expand All @@ -787,7 +787,7 @@ algorithm
then
arrayExp;

case (Expression.ARRAY(), Subscript.SLICE(sub) :: rest_subs)
case (Expression.LIST(), Subscript.SLICE(sub) :: rest_subs)
algorithm
subs := Expression.arrayElements(sub);
vals := Expression.arrayElements(value);
Expand All @@ -809,7 +809,7 @@ algorithm
then
arrayExp;

case (Expression.ARRAY(), Subscript.WHOLE() :: rest_subs)
case (Expression.LIST(), Subscript.WHOLE() :: rest_subs)
algorithm
if listEmpty(rest_subs) then
arrayExp.elements := Expression.arrayElements(value);
Expand Down

0 comments on commit 8d0b1ce

Please sign in to comment.