Skip to content

Commit

Permalink
Fixed constant evaluation of REDUCTION for simple case (only one iter…
Browse files Browse the repository at this point in the history
…ator)

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/MathCoreOSMC@3811 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Björn Zachrisson committed Jan 22, 2009
1 parent 64dc403 commit e9b8db2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Compiler/Absyn.mo
Expand Up @@ -81,7 +81,7 @@ type ForIterator = tuple<Ident, Option<Exp>>
see 3.3.3.2 Several Iterators from Modelica Specification.
* in array iterators where the expression should always be SOME(Exp),
see 3.4.4.2 Array constructor with iterators from Specification";
type ForIterators = list<ForIterator>
public type ForIterators = list<ForIterator>
"For Iterators -
these are used in:
* for loops where the expression part can be NONE and then the range
Expand Down
44 changes: 17 additions & 27 deletions Compiler/Static.mo
Expand Up @@ -522,10 +522,10 @@ algorithm
(types,consts) = splitProps(props);
then
(cache,Exp.TUPLE(e_1),Types.PROP_TUPLE((Types.T_TUPLE(types),NONE),Types.TUPLE_CONST(consts)),st);
case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FOR_ITER_FARG(exp = exp,iterators=iterators)),impl,st,doVect) /* Array-related expressions Elab reduction expressions, including array() constructor */
case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FOR_ITER_FARG(exp = exp, iterators=iterators)),impl,st,doVect) /* Array-related expressions Elab reduction expressions, including array() constructor */
local
Exp.Exp e;
Absyn.Exp exp;
Absyn.Exp exp;
equation
(cache,e,prop,st_1) = elabCallReduction(cache,env, fn, exp, iterators, impl, st,doVect);
then
Expand Down Expand Up @@ -1088,25 +1088,13 @@ algorithm
Boolean b;
list<Exp.Exp> expl;
list<Values.Value> vallst;
case (cache,env,fn,exp,{(iter,SOME(iterexp))},impl,st,doVect)
equation
(cache,iterexp_1,Types.PROP((Types.T_ARRAY((arraydim as Types.DIM(_)),iterty),_),iterconst),_)
= elabExp(cache,env, iterexp, impl, st,doVect);
env_1 = addForLoopScopeConst(env, iter, iterty);
(cache,exp_1,Types.PROP(expty,expconst),st) = elabExp(cache,env_1, exp, impl, st,doVect) "const so that expr is elaborated to const" ;
const = Types.constAnd(expconst, iterconst);
prop = Types.PROP((Types.T_ARRAY(arraydim,expty),NONE),const);
fn_1 = Absyn.crefToPath(fn);
then
(cache,Exp.REDUCTION(fn_1,exp_1,iter,iterexp_1),prop,st);
case (cache,env,fn,exp,iterators,impl,st,doVect)
equation
Debug.fprint("failtrace", "Static.elabCallReduction - multiple iterators, not yet handled!\n");
then fail();

/* MathCore cases
Symbolically expand arrays if iterator is parameter or constant
case (cache,env,Absyn.CREF_IDENT("array",{}),exp,iter,iterexp,impl,st,doVect)
/*Symbolically expand arrays if iterator is parameter or constant
NOTE: This only works for one iterator.
TODO: Implement support for more iterators.
*/
case (cache,env,Absyn.CREF_IDENT("array",{}),exp,(afis as (iter,SOME(iterexp))::{}),impl,st,doVect)
local
Absyn.ForIterators afis;
equation
(cache,iterexp_1,Types.PROP((Types.T_ARRAY((arraydim as Types.DIM(_)),iterty),_),iterconst),_)
= elabExp(cache,env, iterexp, impl, st,doVect);
Expand All @@ -1122,19 +1110,21 @@ algorithm
prop = Types.PROP(ty,const);
then
(cache,Exp.ARRAY(etp,b,expl),prop,st);
case (cache,env,fn,exp,iter,iterexp,impl,st,doVect)
equation
(cache,iterexp_1,Types.PROP((Types.T_ARRAY((arraydim as Types.DIM(_)),iterty),_),iterconst),_)
case (cache,env,fn,exp,{(iter,SOME(iterexp))},impl,st,doVect)
equation
(cache,iterexp_1,Types.PROP((Types.T_ARRAY((arraydim as Types.DIM(_)),iterty),_),iterconst),_)
= elabExp(cache,env, iterexp, impl, st,doVect);
env_1 = addForLoopScopeConst(env, iter, iterty);
(cache,exp_1,Types.PROP(expty,expconst),st) = elabExp(cache,env_1, exp, impl, st,doVect) "const so that expr is elaborated to const" ;
const = Types.constAnd(expconst, iterconst);
prop = Types.PROP((Types.T_ARRAY(arraydim,expty),NONE),const);
fn_1 = Absyn.crefToPath(fn);
then
then
(cache,Exp.REDUCTION(fn_1,exp_1,iter,iterexp_1),prop,st);
*/
case (cache,env,fn,exp,iterators,impl,st,doVect)
equation
Debug.fprint("failtrace", "Static.elabCallReduction - multiple iterators, not yet handled!\n");
then fail();
end matchcontinue;
end elabCallReduction;

Expand Down

0 comments on commit e9b8db2

Please sign in to comment.