Skip to content

Commit

Permalink
Added instantiation of reinit in algorithms. Now flattens, and produc…
Browse files Browse the repository at this point in the history
…es error message that when algorithms not supported yet.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2673 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jan 22, 2007
1 parent ac7f111 commit 762d90a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
29 changes: 29 additions & 0 deletions Compiler/Algorithm.mo
Expand Up @@ -124,6 +124,10 @@ uniontype Statement "There are four kinds of statements. Assignments (`a := b;\
Exp.Exp exp2;
end ASSERT;

record REINIT
Exp.Exp var "Variable";
Exp.Exp value "Value ";
end REINIT;
end Statement;

public
Expand Down Expand Up @@ -498,6 +502,31 @@ algorithm
end matchcontinue;
end makeWhenA;

public function makeReinit "creates a reinit statement in an algorithm statement,
only valid in when algorithm sections."
input Exp.Exp inExp1;
input Exp.Exp inExp2;
input Types.Properties inProperties3;
input Types.Properties inProperties4;
output Statement outStatement;
algorithm
outStatement:=
matchcontinue (inExp1,inExp2,inProperties3,inProperties4)
local Exp.Exp var,val,var_1,val_1; Types.Properties prop1,prop2;
Types.Type tp1,tp2;
case (var as Exp.CREF(_,_),val,Types.PROP(tp1,_),Types.PROP(tp2,_)) equation
(val_1,_) = Types.matchType(val,tp2,(Types.T_REAL({}),NONE()));
(var_1,_) = Types.matchType(var,tp1,(Types.T_REAL({}),NONE()));
then REINIT(var_1,val_1);

case (_,_,prop1,prop2) equation
Error.addMessage(Error.INTERNAL_ERROR(),{"reinit called with wrong args"});
then fail();

// TODO: Add checks for reinit here. 1. First argument must be variable. 2. Expressions must be real.
end matchcontinue;
end makeReinit;

public function makeAssert "function: makeAssert
Creates an assert statement from two expressions.
Expand Down
20 changes: 17 additions & 3 deletions Compiler/Inst.mo
Expand Up @@ -7613,13 +7613,13 @@ algorithm
local
Exp.ComponentRef ce,ce_1;
Exp.Type t;
Types.Properties cprop,eprop,prop,msgprop;
Types.Properties cprop,eprop,prop,msgprop,varprop,valprop;
SCode.Accessibility acc;
Exp.Exp e_1,cond_1,msg_1;
Exp.Exp e_1,cond_1,msg_1,var_1,value_1;
Algorithm.Statement stmt;
list<Env.Frame> env,env_1;
Absyn.ComponentRef cr;
Absyn.Exp e,cond,msg, assignComp;
Absyn.Exp e,cond,msg, assignComp,var,value;
Boolean impl;
list<Exp.Exp> expl_1;
list<Types.Properties> cprops;
Expand Down Expand Up @@ -7699,18 +7699,32 @@ algorithm
stmt = Algorithm.makeWhenA(e_1, prop, sl_1) "TODO elsewhen" ;
then
(cache,stmt);

// assert(cond,msg)
case (cache,env,Absyn.ALG_NORETCALL(functionCall = Absyn.CREF_IDENT(name = "assert"),functionArgs = Absyn.FUNCTIONARGS(args = {cond,msg},argNames = {})),impl)
equation
(cache,cond_1,cprop,_) = Static.elabExp(cache,env, cond, impl, NONE,true);
(cache,msg_1,msgprop,_) = Static.elabExp(cache,env, msg, impl, NONE,true);
stmt = Algorithm.makeAssert(cond_1, msg_1, cprop, msgprop);
then
(cache,stmt);

// reinit(variable,value)
case (cache,env,Absyn.ALG_NORETCALL(functionCall = Absyn.CREF_IDENT(name = "reinit"),functionArgs = Absyn.FUNCTIONARGS(args = {var,value},argNames = {})),impl)
equation
(cache,var_1,varprop,_) = Static.elabExp(cache,env, var, impl, NONE,true);
(cache,value_1,valprop,_) = Static.elabExp(cache,env, value, impl, NONE,true);
stmt = Algorithm.makeReinit(var_1, value_1, varprop, valprop);
then
(cache,stmt);

case (cache,env,alg,impl)
equation
Debug.fprint("failtrace", "- inst_statement failed\n alg:");
Debug.fcall("failtrace", Dump.printAlgorithm, alg);
Debug.fprint("failtrace", "\n");
print("instStatement ");print(Dump.unparseAlgorithmStr(0,Absyn.ALGORITHMITEM(alg,NONE())));
print(" failed\n");
then
fail();
end matchcontinue;
Expand Down
12 changes: 12 additions & 0 deletions Compiler/Types.mo
Expand Up @@ -353,6 +353,18 @@ algorithm
end matchcontinue;
end simpleType;

public function isReal "Returns true if type is Real"
input Type tp;
output Boolean res;
algorithm
res := matchcontinue(tp)
case(tp) equation
((T_REAL(_),_)) = arrayElementType(tp);
then true;
case(_) then false;
end matchcontinue;
end isReal;

public function integerOrReal "function: integerOrReal
author: PA
Expand Down

0 comments on commit 762d90a

Please sign in to comment.