Skip to content

Commit

Permalink
- Moved more scripting functions into the builtin environment
Browse files Browse the repository at this point in the history
  - Some even have a bit of documentation attached now


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7842 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 1, 2011
1 parent a767bd1 commit 140bca3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 85 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/XMLDump.mo
Expand Up @@ -2008,6 +2008,7 @@ algorithm
_:= matchcontinue (fun)
local
Absyn.Path name;
case DAE.FUNCTION(type_ = (DAE.T_FUNCTION(functionAttributes = DAE.FUNCTION_ATTRIBUTES(isBuiltin = DAE.FUNCTION_BUILTIN(_))),_)) then ();
case(fun)
equation
name = DAEUtil.functionName(fun);
Expand Down
81 changes: 81 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -788,5 +788,86 @@ function checkModel
external "builtin";
end checkModel;

function checkAllModelsRecursive
input TypeName className;
output String result;
external "builtin";
end checkAllModelsRecursive;

function typeOf
input VariableName variableName;
output String result;
external "builtin";
end typeOf;

function instantiateModel
input TypeName className;
output String result;
external "builtin";
end instantiateModel;

function generateCode "The input is a function name for which C-code is generated and compiled into a dll/so"
input TypeName className;
output Boolean success;
external "builtin";
end generateCode;

function loadModel "Parses the getModelicaPath(), and finds the package to load. If the input is Modelica.XXX, the complete Modelica AST is loaded."
input TypeName className;
output Boolean success;
external "builtin";
end loadModel;

function deleteFile "Deletes a file with the given name"
input String fileName;
output Boolean success;
external "builtin";
end deleteFile;

function saveModel
input String fileName;
input TypeName className;
output Boolean success;
external "builtin";
end saveModel;

function saveTotalModel
input String fileName;
input TypeName className;
output Boolean success;
external "builtin";
end saveTotalModel;

function save
input TypeName className;
output Boolean success;
external "builtin";
end save;

function translateGraphics
input TypeName className;
output String result;
external "builtin";
end translateGraphics;

function readSimulationResultSize
input String fileName;
output Integer sz "The number of intervals that are present in the output file";
external "builtin";
end readSimulationResultSize;

function dumpXMLDAE
input TypeName className;
input String translationLevel := "flat";
input Boolean addOriginalIncidenceMatrix := false;
input Boolean addSolvingInfo := false;
input Boolean addMathMLCode := false;
input Boolean dumpResiduals := false;
input String fileNamePrefix := "<default>" "this is the className in string form by default";
input Boolean storeInTemp := false;
output String result[2] "Contents, Message/Filename; why is this an array and not 2 output arguments?";
external "builtin";
end dumpXMLDAE;

end Scripting;
end OpenModelica;
85 changes: 0 additions & 85 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -6784,9 +6784,6 @@ protected function elabCallInteractive "function: elabCallInteractive
ErrorExt.rollBack("Scripting");
then fail();

case (cache,env,Absyn.CREF_IDENT(name = "typeOf"),{Absyn.CREF(componentRef = Absyn.CREF_IDENT(name = varid,subscripts = {}))},{},impl,SOME(st),_,_) then (cache,DAE.CALL(Absyn.IDENT("typeOf"),
{DAE.CODE(Absyn.C_VARIABLENAME(Absyn.CREF_IDENT(varid,{})),DAE.ET_OTHER())},false,true,DAE.ET_STRING(),DAE.NO_INLINE()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "list"),{},{},impl,SOME(st),_,_)
then (cache, Expression.makeBuiltinCall("list",{},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

Expand All @@ -6796,18 +6793,6 @@ protected function elabCallInteractive "function: elabCallInteractive
then
(cache, Expression.makeBuiltinCall("list",{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "checkAllModelsRecursive"),{Absyn.CREF(componentRef = cr)},{},impl,SOME(st),_,_)
equation
className = Absyn.crefToPath(cr);
then (cache,Expression.makeBuiltinCall("checkAllModelsRecursive",
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "translateGraphics"),{Absyn.CREF(componentRef = cr)},{},impl,SOME(st),_,_)
equation
className = Absyn.crefToPath(cr);
then (cache,Expression.makeBuiltinCall("translateGraphics",
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "translateModel"),{Absyn.CREF(componentRef = cr)},args,impl,SOME(st),pre,_)
equation
className = Absyn.crefToPath(cr);
Expand Down Expand Up @@ -6860,14 +6845,6 @@ protected function elabCallInteractive "function: elabCallInteractive
(cache,Expression.makeBuiltinCall("exportDAEtoMatlab",
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER()),filenameprefix},DAE.ET_STRING()),DAE.PROP(recordtype,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "instantiateModel"),{Absyn.CREF(componentRef = cr)},{},impl,SOME(st),pre,_)
equation
className = Absyn.crefToPath(cr);
(cache,cr_1) = elabUntypedCref(cache,env, cr, impl,pre,info);
then
(cache, Expression.makeBuiltinCall("instantiateModel",
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "buildModel"),{Absyn.CREF(componentRef = cr)},args,impl,SOME(st),pre,_)
equation
(cache, simulationArgs) = getSimulationArguments(cache, env, inExps, args, inBoolean, inInteractiveInteractiveSymbolTableOption, inPrefix, info);
Expand Down Expand Up @@ -6906,11 +6883,6 @@ protected function elabCallInteractive "function: elabCallInteractive
(DAE.T_ARRAY(DAE.DIM_INTEGER(var_len),
(DAE.T_ARRAY(DAE.DIM_INTEGER(size),DAE.T_REAL_DEFAULT),NONE())),NONE()),DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "readSimulationResultSize"),{Absyn.STRING(value = filename)},args,impl,SOME(st),_,_)
/* elab_variablenames(vars) => vars\' & list_length(vars) => var_len */
then (cache, Expression.makeBuiltinCall("readSimulationResultSize",{DAE.SCONST(filename)},DAE.ET_OTHER()),
DAE.PROP(DAE.T_INTEGER_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "plot2"),{e1},{},impl,SOME(st),_,_)
equation
vars_1 = elabVariablenames({e1});
Expand Down Expand Up @@ -7279,44 +7251,10 @@ protected function elabCallInteractive "function: elabCallInteractive
then
(cache,Expression.makeBuiltinCall("timing",{exp_1},DAE.ET_REAL()),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_VAR()),st_1);

case (cache,env,Absyn.CREF_IDENT(name = "generateCode"),{Absyn.CREF(componentRef = cr)},{},impl,SOME(st),_,_)
equation
className = Absyn.crefToPath(cr);
then
(cache,Expression.makeBuiltinCall("generateCode",{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},
DAE.ET_BOOL()),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "listVariables"),{},{},impl,SOME(st),_,_)
then (cache, Expression.makeBuiltinCall("listVariables",{},DAE.ET_OTHER()),
DAE.PROP((DAE.T_ARRAY(DAE.DIM_UNKNOWN(),(DAE.T_NOTYPE(),NONE())),NONE()),DAE.C_VAR()),SOME(st)); /* Returns an array of \"component references\" */

case (cache,env,Absyn.CREF_IDENT(name = "loadModel"),{Absyn.CREF(componentRef = cr)},{},impl,SOME(st),_,_)
equation
className = Absyn.crefToPath(cr);
then
(cache,Expression.makeBuiltinCall("loadModel",{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},DAE.ET_BOOL()),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "deleteFile"),{Absyn.STRING(value = str)},{},impl,SOME(st),_,_)
then (cache, Expression.makeBuiltinCall("deleteFile",{DAE.SCONST(str)},DAE.ET_BOOL()),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "saveModel"),{Absyn.STRING(value = str),Absyn.CREF(componentRef = cr)},{},impl,SOME(st),_,_)
equation
className = Absyn.crefToPath(cr);
then
(cache,Expression.makeBuiltinCall("saveModel",{DAE.SCONST(str),DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},DAE.ET_BOOL()),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "saveTotalModel"),{Absyn.STRING(value = str),Absyn.CREF(componentRef = cr)},{},impl,SOME(st),_,_)
equation
className = Absyn.crefToPath(cr);
then
(cache,Expression.makeBuiltinCall("saveTotalModel",{DAE.SCONST(str),DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},DAE.ET_BOOL()),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "save"),{Absyn.CREF(componentRef = cr)},{},impl,SOME(st),_,_)
equation
className = Absyn.crefToPath(cr);
then
(cache,Expression.makeBuiltinCall("save",{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER())},DAE.ET_BOOL()),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getUnit"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
Expand Down Expand Up @@ -7426,29 +7364,6 @@ protected function elabCallInteractive "function: elabCallInteractive
excludeListSize = listLength(excludeList);
then (cache,Expression.makeBuiltinCall("checkExamplePackages",{DAE.ARRAY(DAE.ET_ARRAY(DAE.ET_OTHER(),{DAE.DIM_INTEGER(excludeListSize)}),false,excludeList),DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER()),DAE.SCONST(str)},DAE.ET_STRING()),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "dumpXMLDAE"),{Absyn.CREF(componentRef = cr)},args,impl,SOME(st),pre,_)
equation
className = Absyn.crefToPath(cr);
cname_str = Absyn.pathString(className);
(cache,translationLevel) = getOptionalNamedArg(cache, env, SOME(st), impl, "translationLevel",
DAE.T_STRING_DEFAULT, args, DAE.SCONST("flat"),pre,info);
(cache,addOriginalIncidenceMatrix) = getOptionalNamedArg(cache,env, SOME(st), impl, "addOriginalIncidenceMatrix",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false),pre,info);
(cache,addSolvingInfo) = getOptionalNamedArg(cache,env, SOME(st), impl, "addSolvingInfo",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false),pre,info);
(cache,addMathMLCode) = getOptionalNamedArg(cache,env, SOME(st), impl, "addMathMLCode",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false),pre,info);
(cache,dumpResiduals) = getOptionalNamedArg(cache,env, SOME(st), impl, "dumpResiduals",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false),pre,info);
(cache,filenameprefix) = getOptionalNamedArg(cache,env, SOME(st), impl, "fileNamePrefix",
DAE.T_STRING_DEFAULT, args, DAE.SCONST(cname_str),pre,info);
(cache,storeInTemp) = getOptionalNamedArg(cache,env, SOME(st), impl, "storeInTemp",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false),pre,info);
then
(cache,Expression.makeBuiltinCall("dumpXMLDAE",
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER()),translationLevel,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,filenameprefix,storeInTemp},DAE.ET_OTHER()),DAE.PROP(
(
DAE.T_ARRAY(DAE.DIM_INTEGER(2),DAE.T_STRING_DEFAULT),NONE()),DAE.C_VAR()),SOME(st));
end matchcontinue;
end elabCallInteractive;

Expand Down
1 change: 1 addition & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -3994,6 +3994,7 @@ algorithm
oldDir = System.pwd();
changeToTempDirectory(cdToTemp);
(cache,filenameprefix) = extractFilePrefix(cache,env, fileprefix, st, msg);
filenameprefix = Util.if_(filenameprefix ==& "<default>", Absyn.pathString(classname), filenameprefix);
cname_str = Absyn.pathString(classname);
p_1 = SCodeUtil.translateAbsyn2SCode(p);
(cache,env,_,dae_1) = Inst.instantiateClass(cache, InnerOuter.emptyInstHierarchy, p_1, classname);
Expand Down

0 comments on commit 140bca3

Please sign in to comment.