Skip to content

Commit

Permalink
[NF] Improve constant evaluation.
Browse files Browse the repository at this point in the history
- Implemented evaluation of more operators and expressions.
- Implemented evaluation of the String function.
- Added Expression.contains utility function.
- Improved unrolling of for equations.
- Added System.sprintff to print Real values of any size.

Belonging to [master]:
  - OpenModelica/OMCompiler#2398
  - OpenModelica/OpenModelica-testsuite#934
  • Loading branch information
perost authored and OpenModelica-Hudson committed Apr 26, 2018
1 parent 2718416 commit 338d1df
Show file tree
Hide file tree
Showing 13 changed files with 1,317 additions and 133 deletions.
37 changes: 37 additions & 0 deletions Compiler/NFFrontEnd/NFBinding.mo
Expand Up @@ -159,6 +159,43 @@ public
end match;
end setTypedExp;

function getExp
input Binding binding;
output Expression exp;
algorithm
exp := match binding
case UNTYPED_BINDING() then binding.bindingExp;
case TYPED_BINDING() then binding.bindingExp;
case FLAT_BINDING() then binding.bindingExp;
end match;
end getExp;

function setExp
input Expression exp;
input output Binding binding;
algorithm
() := match binding
case UNTYPED_BINDING()
algorithm
binding.bindingExp := exp;
then
();

case TYPED_BINDING()
algorithm
binding.bindingExp := exp;
then
();

case FLAT_BINDING()
algorithm
binding.bindingExp := exp;
then
();

end match;
end setExp;

function isRecordExp
input Binding binding;
output Boolean isRecordExp;
Expand Down
22 changes: 9 additions & 13 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -339,25 +339,22 @@ uniontype Call
input list<Absyn.ForIterator> inIters;
input InstNode scope;
input SourceInfo info;
output InstNode iter_scope;
output list<InstNode> outIters;
output InstNode outScope = scope;
output list<InstNode> outIters = {};
protected
Binding binding;
InstNode iter;
algorithm
outIters := {};
iter_scope := scope;
for Absiter in inIters loop
binding := Binding.fromAbsyn(Absiter.range, false, 0, iter_scope, info);
for i in inIters loop
binding := Binding.fromAbsyn(i.range, false, 0, outScope, info);
binding := Inst.instBinding(binding);
(iter_scope, iter) := Inst.addIteratorToScope(Absiter.name, binding, iter_scope);
outIters := iter::outIters;
(outScope, iter) := Inst.addIteratorToScope(i.name, binding, outScope, info);
outIters := iter :: outIters;
end for;

outIters := listReverse(outIters);
end instIterators;


function builtinSpecialHandling
input Call call;
output Boolean special;
Expand Down Expand Up @@ -503,7 +500,7 @@ uniontype Call
case UNTYPED_MAP_CALL() algorithm

for iter in call.iters loop
Typing.typeIterator(iter, info, ExpOrigin.FUNCTION, structural = false);
Typing.typeIterator(iter, ExpOrigin.FUNCTION, structural = false);
end for;
(arg, arg_ty, arg_var) := Typing.typeExp(call.exp, origin, info);

Expand Down Expand Up @@ -678,7 +675,7 @@ uniontype Call
bind := Binding.TYPED_BINDING(exp, ty, Variability.CONSTANT, origin, false);

// Add an iterator to the call scope.
(iter_scope, iter) := Inst.addIteratorToScope("$i" + intString(i), bind, iter_scope, Type.INTEGER());
(iter_scope, iter) := Inst.addIteratorToScope("$i" + intString(i), bind, iter_scope, info, Type.INTEGER());
iters := iter::iters;

// Now that iterator is ready apply it, as a subscript, to each argument that is supposed to be vectorized
Expand Down Expand Up @@ -2181,8 +2178,7 @@ protected
if variability > Variability.PARAMETER then
Error.addSourceMessageAndFail(Error.NF_CAT_FIRST_ARG_EVAL, {Expression.toString(arg), Prefixes.variabilityString(variability)}, info);
end if;
arg := Ceval.evalExp(arg, Ceval.EvalTarget.GENERIC(info));
Expression.INTEGER(n) := SimplifyExp.simplifyExp(arg);
Expression.INTEGER(n) := Ceval.evalExp(arg, Ceval.EvalTarget.GENERIC(info));

res := {};
tys := {};
Expand Down

0 comments on commit 338d1df

Please sign in to comment.