Skip to content

Commit

Permalink
[NF] Function evaluation fixes.
Browse files Browse the repository at this point in the history
- Apply argument replacements recursively.
- Handle cat where all arguments are empty arrays.
- Handle diagonal of an empty array.
- Add EXP_NODE to InstNode.name for easier debugging.
  • Loading branch information
perost committed Feb 7, 2020
1 parent 7e2da71 commit df2744d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -2020,7 +2020,7 @@ function evalBuiltinCat
input EvalTarget target;
output Expression result;
protected
Integer n, nd;
Integer n, nd, sz;
Type ty;
list<Expression> es;
list<Integer> dims;
Expand All @@ -2037,8 +2037,11 @@ algorithm
end if;

es := list(e for e guard not Expression.isEmptyArray(e) in args);
sz := listLength(es);

if listLength(es) == 1 then
if sz == 0 then
result := listHead(args);
elseif sz == 1 then
result := listHead(es);
else
(es,dims) := ExpressionSimplify.evalCat(n, es, getArrayContents=Expression.arrayElements, toString=Expression.toString);
Expand Down Expand Up @@ -2094,6 +2097,8 @@ protected
Boolean e_lit, arg_lit = true;
algorithm
result := match arg
case Expression.ARRAY(elements = {}) then arg;

case Expression.ARRAY(elements = elems)
algorithm
n := listLength(elems);
Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFEvalFunction.mo
Expand Up @@ -390,6 +390,8 @@ algorithm
ComponentRef.toString(cref), sourceInfo());
end try;
end if;

outExp := Expression.map(outExp, function applyReplacements2(repl = repl));
end if;
end applyReplacementCref;

Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFInstNode.mo
Expand Up @@ -504,6 +504,7 @@ uniontype InstNode
case REF_NODE() then "$REF[" + String(node.index) + "]";
case NAME_NODE() then node.name;
case IMPLICIT_SCOPE() then "$IMPLICIT";
case EXP_NODE() then "$EXP(" + Expression.toString(node.exp) + ")";
case EMPTY_NODE() then "$EMPTY";
end match;
end name;
Expand Down

0 comments on commit df2744d

Please sign in to comment.