Skip to content

Commit

Permalink
Implement more operators in ModelicaBuiltin.mo
Browse files Browse the repository at this point in the history
The Clock constructor has a special work-around since it is both a
built-in type and a function (so we search OpenModelica.Internal when
looking for the Clock function). It then uses ExpressionSimplify to
convert DAE.CALL into DAE.CLKCONST.
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Feb 10, 2017
1 parent 06e3ebd commit c77eae8
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 385 deletions.
17 changes: 17 additions & 0 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -1392,6 +1392,23 @@ algorithm
e = Expression.makePureBuiltinCall("cat", DAE.ICONST(1)::es, tp);
then e;

/* Current design uses a special DAE.Expression */

case (DAE.CALL(path=Absyn.IDENT("inferredClock"),expLst={}))
then DAE.CLKCONST(DAE.INFERRED_CLOCK());

case (DAE.CALL(path=Absyn.IDENT("realClock"),expLst={e1}))
then DAE.CLKCONST(DAE.REAL_CLOCK(e1));

case (DAE.CALL(path=Absyn.IDENT("booleanClock"),expLst={e1,e2}))
then DAE.CLKCONST(DAE.BOOLEAN_CLOCK(e1,e2));

case (DAE.CALL(path=Absyn.IDENT("rationalClock"),expLst={e1,e2}))
then DAE.CLKCONST(DAE.INTEGER_CLOCK(e1, e2));

case (DAE.CALL(path=Absyn.IDENT("solverClock"),expLst={e1,e2}))
then DAE.CLKCONST(DAE.SOLVER_CLOCK(e1, e2));

end matchcontinue;
end simplifyBuiltinCalls;

Expand Down
4 changes: 4 additions & 0 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -2026,6 +2026,10 @@ algorithm

case (cache,env,id,_)
equation
id = match id
case Absyn.IDENT("Clock") then Absyn.QUALIFIED("OpenModelica",Absyn.QUALIFIED("Internal",Absyn.IDENT("ClockConstructor")));
else id;
end match;
(cache,SCode.CLASS(classDef=SCode.OVERLOAD(pathLst=names),info=info),env_1) = lookupClass(cache,env,id);
(cache,res) = lookupFunctionsListInEnv(cache,env_1,names,info,{});
// print(stringDelimitList(List.map(res,Types.unparseType),"\n###\n"));
Expand Down
125 changes: 90 additions & 35 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -495,13 +495,6 @@ function sample "Overloaded operator to either trigger time events or to convert
</html>"));
end sample;

function hold "Conversion from clocked discrete-time to continuous time"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'hold()'\">hold()</a>
</html>"));
end hold;

function shiftSample "First activation of clock is shifted in time"
external "builtin";
annotation(Documentation(info="<html>
Expand All @@ -516,20 +509,6 @@ function backSample "First activation of clock is shifted in time before activat
</html>"));
end backSample;

function noClock "Clock of y=Clock(u) is always inferred"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'noClock()'\">noClock()</a>
</html>"));
end noClock;

function interval "Returns the interval between the previous and present tick of the clock of its argument"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'interval()'\">interval()</a>
</html>"));
end interval;

function transition "Define state machine transition"
external "builtin";
annotation(Documentation(info="<html>
Expand All @@ -551,20 +530,6 @@ function activeState "Return true if instance of a state machine is active, othe
</html>"));
end activeState;

function ticksInState "Returns the number of clock ticks since a transition was made to the currently active state"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ticksInState()'\">ticksInState()</a>
</html>"));
end ticksInState;

function timeInState "Returns the time duration as Real in [s] since a transition was made to the currently active state"
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ticksInState()'\">ticksInState()</a>
</html>"));
end timeInState;

function change "Indicate discrete variable changing"
external "builtin";
annotation(Documentation(info="<html>
Expand Down Expand Up @@ -815,6 +780,46 @@ function superSample = $overload(OpenModelica.Internal.superSampleExpression, Op
See <a href=\"modelica://ModelicaReference.Operators.'superSample()'\">superSample()</a>
</html>"));

function hold<T> "Conversion from clocked discrete-time to continuous time"
input T u;
output T y;
external "builtin";
annotation(__OpenModelica_UnboxArguments=true, version="Modelica 3.3", Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'hold()'\">hold()</a>
</html>"));
end hold;

function noClock<T> "Clock of y=Clock(u) is always inferred"
input T u;
output T y;
external "builtin";
annotation(__OpenModelica_UnboxArguments=true, version="Modelica 3.3", Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'noClock()'\">noClock()</a>
</html>"));
end noClock;

function interval = $overload(OpenModelica.Internal.intervalInferred, OpenModelica.Internal.intervalExpression)
"Returns the interval between the previous and present tick of the clock of its argument"
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'interval()'\">interval()</a>
</html>"));

impure function ticksInState "Returns the number of clock ticks since a transition was made to the currently active state"
output Integer ticks;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ticksInState()'\">ticksInState()</a>
</html>"));
end ticksInState;

impure function timeInState "Returns the time duration as Real in [s] since a transition was made to the currently active state"
output Real t;
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"modelica://ModelicaReference.Operators.'ticksInState()'\">ticksInState()</a>
</html>"));
end timeInState;

/* Actually contains more...
record SimulationResult
String resultFile;
Expand Down Expand Up @@ -850,6 +855,56 @@ package Internal "Contains internal implementations, e.g. overloaded builtin fun
type BuiltinType "Integer,Real,String,enumeration or array of some kind"
end BuiltinType;

function ClockConstructor = $overload(OpenModelica.Internal.inferredClock, OpenModelica.Internal.rationalClock, OpenModelica.Internal.realClock, OpenModelica.Internal.booleanClock, OpenModelica.Internal.solverClock)
"Overloaded clock constructor"
annotation(version="Modelica 3.3", Documentation(info="<html>
The Clock constructors.</a>
</html>"));

function inferredClock
output Clock c;
external "builtin";
end inferredClock;

function rationalClock
input Integer intervalCounter(min=0);
parameter input Integer resolution(unit="Hz", min=1)=1;
output Clock c;
external "builtin";
end rationalClock;

function realClock
input Real interval(unit="s", min=0);
output Clock c;
external "builtin";
end realClock;

function booleanClock
input Boolean condition;
input Real startInterval=0.0;
output Clock c;
external "builtin";
end booleanClock;

function solverClock
input Clock c;
input String solverMethod;
output Clock clk;
external "builtin";
end solverClock;

function intervalInferred
output Real interval;
external "builtin" interval=interval();
end intervalInferred;

function intervalExpression<T>
input T u;
output Real y;
external "builtin" y=interval(u);
annotation(__OpenModelica_UnboxArguments=true);
end intervalExpression;

impure function subSampleExpression<T>
input T u;
parameter input Integer factor(min=0)=0;
Expand Down

0 comments on commit c77eae8

Please sign in to comment.