Skip to content

Commit

Permalink
- Moved some more MetaModelica function definitions to Builtin.mo
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7361 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 12, 2010
1 parent c28cc0a commit c1bf18d
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 154 deletions.
185 changes: 154 additions & 31 deletions Compiler/Builtin.mo
Expand Up @@ -163,7 +163,7 @@ function log10
external \"builtin\";
end log10;

function print
function print \"Not standard Modelica, but very useful for debugging.\"
input String str;
external \"builtin\";
end print;
Expand Down Expand Up @@ -574,7 +574,7 @@ function stringAppend
input String s1;
input String s2;
output String s;
annotation(Inline=true);
annotation(Inline = true);
algorithm
s := s1 + s2;
end stringAppend;
Expand All @@ -583,7 +583,7 @@ function stringEq
input String s1;
input String s2;
output Boolean b;
annotation(Inline=true);
annotation(Inline = true);
algorithm
b := s1 == s2;
end stringEq;
Expand Down Expand Up @@ -612,6 +612,156 @@ function stringHashSdbm
output Integer hash;
external \"builtin\";
end stringHashSdbm;

function arrayLength
input array<TypeA> arr;
output Integer length;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end arrayLength;

function arrayGet
input array<TypeA> arr;
input Integer index;
output TypeA value;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end arrayGet;

function arrayNth
input array<TypeA> arr;
input Integer index;
output TypeA value;
replaceable type TypeA subtypeof Any;
annotation(Inline = true);
algorithm
value := arrayGet(arr,index+1);
end arrayNth;

function arrayCreate
input Integer size;
input TypeA initialValue;
output array<TypeA> arr;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end arrayCreate;

function arrayList
input array<TypeA> arr;
output list<TypeA> lst;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end arrayList;

function listArray
input list<TypeA> lst;
output array<TypeA> arr;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end listArray;

function arrayUpdate
input array<TypeA> arr;
input Integer index;
input TypeA newValue;
output array<TypeA> newArray \"same as the input array; not really needed here\";
replaceable type TypeA subtypeof Any;
external \"builtin\";
end arrayUpdate;

function arrayCopy
input array<TypeA> arr;
output array<TypeA> copy;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end arrayCopy;


function arrayAdd \"An arrayAppend operation would be more useful; this might be slow if used improperly!\"
input array<TypeA> arr;
input TypeA a;
output array<TypeA> copy;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end arrayAdd;

function anyString
input TypeA a;
output String str;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end anyString;

function printAny
input TypeA a;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end printAny;

function debug_print
input String str;
input TypeA a;
replaceable type TypeA subtypeof Any;
annotation(Inline = true);
algorithm
print(str);
print(anyString(a));
end debug_print;

function tick
output Integer t;
external \"builtin\";
end tick;

function equality
input TypeA a1;
input TypeA a2;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end equality;

function setGlobalRoot
input Integer index;
input TypeA value;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end setGlobalRoot;

function valueConstructor
input TypeA value;
output Integer ctor;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end valueConstructor;

function valueSlots
input TypeA value;
output Integer slots;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end valueSlots;

function valueEq
input TypeA a1;
input TypeA a2;
output Boolean b;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end valueEq;

function referenceEq
input TypeA a1;
input TypeA a2;
output Boolean b;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end referenceEq;

function clock
output Real t;
external \"builtin\" t=mmc_clock();
end clock;

"
;

Expand Down Expand Up @@ -3431,7 +3581,6 @@ algorithm
case (env)
equation
true = RTOpts.acceptMetaModelicaGrammar();
env = Env.extendFrameT(env, "mmc_boxes_equal", AA2bool);

// List Operations
env = Env.extendFrameT(env, "listAppend", listAListA2listA);
Expand All @@ -3445,37 +3594,11 @@ algorithm
env = Env.extendFrameT(env, "listEmpty", list2boolean);
env = Env.extendFrameT(env, "cons", AlistA2listA);

// Array Operations
env = Env.extendFrameT(env, "arrayLength", marrayAny2int);
env = Env.extendFrameT(env, "arrayGet", marrayAInt2A);
env = Env.extendFrameT(env, "arrayNth", marrayAInt2A);
env = Env.extendFrameT(env, "arrayCreate", intA2marrayA);
env = Env.extendFrameT(env, "arrayList", marrayA2listA);
env = Env.extendFrameT(env, "listArray", listA2marrayA);
env = Env.extendFrameT(env, "arrayUpdate", marrayAIntA2marrayA);
env = Env.extendFrameT(env, "arrayCopy", marrayA2marrayA);
env = Env.extendFrameT(env, "arrayAdd", marrayAA2marrayA);

// Option Operations
env = Env.extendFrameT(env, "optionNone", option2boolean);

// Misc Operations
env = Env.extendFrameT(env, "if_exp", boolBoxedBoxed2boxed);
env = Env.extendFrameT(env, "printAny", a2void);
env = Env.extendFrameT(env, "debug_print", stringBoxed2void);
env = Env.extendFrameT(env, "tick", void2int);
env = Env.extendFrameT(env, "equality", AA2void);
// There is a C function called clock which does not return a double...
env = Env.extendFrameT(env, "mmc_clock", void2real);
env = Env.extendFrameT(env, "clock", void2real);

// Global State
// getGlobalRoot can not be represented by a regular function...
env = Env.extendFrameT(env, "getGlobalRoot", int2boxed);
env = Env.extendFrameT(env, "setGlobalRoot", intBoxedNoRetcall);
env = Env.extendFrameT(env, "valueConstructor", boxed2int);
env = Env.extendFrameT(env, "valueSlots", boxed2int);
env = Env.extendFrameT(env, "valueEq", AA2bool);
env = Env.extendFrameT(env, "referenceEq", AA2bool);

then env;
case env then env;
Expand Down
24 changes: 12 additions & 12 deletions Compiler/Ceval.mo
Expand Up @@ -996,7 +996,7 @@ algorithm
(cache,v,st) = cevalBuiltinSizeMatrix(cache,env, exp, impl, st, msg);
then
(cache,v,st);
case (cache,env,DAE.CALL(path = path,expLst = args,builtin = builtin),impl,st,_,msg) /* buildin: as true */
case (cache,env,DAE.CALL(path = path,expLst = args,builtin = true),impl,st,_,msg)
equation
id = Absyn.pathString(path);
handler = cevalBuiltinHandler(id);
Expand Down Expand Up @@ -1034,9 +1034,9 @@ protected function cevalBuiltinHandler
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
end HandlerFunc;
algorithm
handler :=
matchcontinue (inIdent)
local String id;
handler := match (inIdent)
local
String id,str;
case "floor" then cevalBuiltinFloor;
case "ceil" then cevalBuiltinCeil;
case "abs" then cevalBuiltinAbs;
Expand Down Expand Up @@ -1105,11 +1105,11 @@ algorithm
//case "delay" then cevalBuiltinDelay;
case id
equation
Debug.fprint("ceval", "No Ceval.cevalBuiltinHandler found for: ");
Debug.fprintln("ceval", id);
true = RTOpts.debugFlag("ceval");
Debug.traceln("No cevalBuiltinHandler found for " +& id);
then
fail();
end matchcontinue;
end match;
end cevalBuiltinHandler;

protected function cevalCallFunction "function: cevalCallFunction
Expand Down Expand Up @@ -1203,7 +1203,7 @@ algorithm
then
fail();

case (cache,env, DAE.CALL(path = funcpath), vallst, impl, st, dim, msg)
case (cache,env, DAE.CALL(path = funcpath, builtin = false), vallst, impl, st, dim, msg)
equation
false = RTOpts.debugFlag("noevalfunc");
failure(cevalIsExternalObjectConstructor(cache, funcpath, env));
Expand Down Expand Up @@ -1244,7 +1244,7 @@ algorithm

// adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem
// see if function is in CF list and the build time is less than the edit time
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl)),vallst,impl,// (impl as true)
case (cache,env,(e as DAE.CALL(path = funcpath, expLst = expl, builtin = false)),vallst,impl,// (impl as true)
(st as SOME(Interactive.SYMBOLTABLE(p as Absyn.PROGRAM(globalBuildTimes=Absyn.TIMESTAMP(_,edit)),_,_,_,_,cflist,_))),dim,msg)
equation
false = RTOpts.debugFlag("nogen");
Expand All @@ -1266,7 +1266,7 @@ algorithm

// adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem
// see if function is in CF list and the build time is less than the edit time
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl)),vallst,impl,// impl as true
case (cache,env,(e as DAE.CALL(path = funcpath, expLst = expl, builtin = false)),vallst,impl,// impl as true
(st as SOME(Interactive.SYMBOLTABLE(p as Absyn.PROGRAM(globalBuildTimes=Absyn.TIMESTAMP(_,edit)),_,_,_,_,cflist,_))),dim,msg)
equation
false = RTOpts.debugFlag("nogen");
Expand Down Expand Up @@ -1294,7 +1294,7 @@ algorithm
// Put back the check and write another rule for the false case that generates the function
// 2007-10-20 partially fixed BZ*
// adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl,builtin = builtin)),vallst,impl,
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl,builtin = false)),vallst,impl,
SOME(Interactive.SYMBOLTABLE(p as Absyn.PROGRAM(globalBuildTimes=ts),aDep,a,b,c,cf,lf)),dim,msg) // yeha! we have a symboltable!
equation
false = RTOpts.debugFlag("nogen");
Expand Down Expand Up @@ -1337,7 +1337,7 @@ algorithm
then
(cache,newval,NONE());*/

case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl,builtin = builtin)),vallst,impl,NONE(),dim,msg) // crap! we have no symboltable!
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl,builtin = false)),vallst,impl,NONE(),dim,msg) // crap! we have no symboltable!
equation
false = RTOpts.debugFlag("nogen");
failure(cevalIsExternalObjectConstructor(cache,funcpath,env));
Expand Down
9 changes: 9 additions & 0 deletions Compiler/SimCodeC.mo
Expand Up @@ -26812,6 +26812,15 @@ algorithm
txt = Tpl.writeTok(txt, Tpl.ST_STRING(")"));
then (txt, a_preExp, a_varDecls);

case ( txt,
DAE.CALL(tuple_ = false, builtin = true, path = Absyn.IDENT(name = "clock"), expLst = {}),
_,
a_preExp,
a_varDecls )
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("mmc_clock()"));
then (txt, a_preExp, a_varDecls);

case ( txt,
DAE.CALL(tuple_ = false, builtin = true, path = Absyn.IDENT(name = "mmc_get_field"), expLst = {i_s1, DAE.ICONST(integer = i_i)}),
a_context,
Expand Down
42 changes: 0 additions & 42 deletions Compiler/Static.mo
Expand Up @@ -4094,47 +4094,6 @@ algorithm
end matchcontinue;
end elabBuiltinMMC_Uniontype_MetaRecord_Typedefs_Equal;

protected function elabBuiltinClock " => x"
input Env.Cache inCache;
input Env.Env inEnv;
input list<Absyn.Exp> inAbsynExpLst;
input list<Absyn.NamedArg> inNamedArg;
input Boolean inBoolean;
input Prefix.Prefix inPrefix;
input Absyn.Info info;
output Env.Cache outCache;
output DAE.Exp outExp;
output DAE.Properties outProperties;
algorithm
(outCache,outExp,outProperties):=
matchcontinue (inCache,inEnv,inAbsynExpLst,inNamedArg,inBoolean,inPrefix,info)
local
DAE.Exp s1_1, s2_1;
DAE.ExpType tp;
list<Env.Frame> env;
Absyn.Exp s1,s2,s;
Boolean impl;
DAE.Type ty;
Env.Cache cache;
DAE.Properties prop;
DAE.Const c, c1, c2;
list<DAE.Exp> expList;
String fnName;
Prefix.Prefix pre;
case (cache,env,{},{},impl,pre,info)
equation
s = Absyn.CALL(Absyn.CREF_IDENT("mmc_clock", {}), Absyn.FUNCTIONARGS({},{}));
(cache,s1_1,prop,_) = elabExp(cache, env, s, impl,NONE(), true,pre,info);
then
(cache,s1_1,prop);

case (_,_,_,_,_,_,_)
equation
Debug.fprintln("failtrace", "- elabBuiltinClock failed");
then fail();
end matchcontinue;
end elabBuiltinClock;

protected function makePreLst
"function: makePreLst
Takes a list of expressions and makes a list of pre - expressions"
Expand Down Expand Up @@ -6756,7 +6715,6 @@ algorithm
case "Integer" then elabBuiltinIntegerEnum;
case "inStream" then elabBuiltinInStream;
case "actualStream" then elabBuiltinActualStream;
case "clock" equation true = RTOpts.acceptMetaModelicaGrammar(); then elabBuiltinClock;
end match;
end elabBuiltinHandler;

Expand Down

0 comments on commit c1bf18d

Please sign in to comment.