Skip to content

Commit

Permalink
- Add capability to OMEdit to link directly against omc (gives a good…
Browse files Browse the repository at this point in the history
… performance increase especially if calling used functions directly without requiring parsing strings)

- Add OMCOutput parser to OMEdit, to parse the most common OMC Values.Value outputs (no records yet; only sequences and values); the output is a QVariant
- Update getClassInformation to use ModelicaBuiltin.mo
- Add a mockup of the OpenModelicaScriptingAPI.mo we should be able to create from ModelicaBuiltin.mo, and OMC_API.{cpp,h} that should be automatically generated Qt/C++ files corresponding to the same API


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23384 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 16, 2014
1 parent 7d1194c commit 68397f7
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 198 deletions.
17 changes: 16 additions & 1 deletion Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -3338,7 +3338,22 @@ annotation(
</html>"));
end sortStrings;

annotation(preferredView="text");
function getClassInformation
input TypeName cl;
output String restriction, comment;
output Boolean partialPrefix, finalPrefix, encapsulatedPrefix;
output String fileName;
output Boolean fileReadOnly;
output Integer lineNumberStart, columnNumberStart, lineNumberEnd, columnNumberEnd;
output String dimensions[:];
external "builtin";
annotation(
Documentation(info="<html>
<p>Returns class information for the given class.</p>
<p>The dimensions are returned as an array of strings. The string is the textual representation of the dimension (they are not evaluated to Integers).</p>
</html>"), preferredView="text");
end getClassInformation;

end Scripting;

package UsersGuide
Expand Down
49 changes: 28 additions & 21 deletions Compiler/Main/Main.mo
Expand Up @@ -676,7 +676,7 @@ algorithm
end if;
end serverLoopCorba;

protected function readSettings
public function readSettings
" author: x02lucpo
Checks if 'settings.mos' exist and uses handleCommand with runScript(...) to execute it.
Checks if '-s <file>.mos' has been
Expand Down Expand Up @@ -788,6 +788,32 @@ algorithm
end try;
end setDefaultCC;

public function init
input list<String> args;
output list<String> args_1;
algorithm
// set glib G_SLICE to always-malloc as is rummored to be better for Boehm GC
System.setEnv("G_SLICE", "always-malloc", true);
// call GC_init() the first thing we do!
System.initGarbageCollector();
// Experimentally found to make the testsuite pass on asap.openmodelica.org.
// 150M for Windows, 300M for others makes the GC try to unmap less and so it crashes less.
// Disabling unmap is another alternative that seems to work well (but could cause the memory consumption to not be released, and requires manually calling collect and unmap
if true then
GC.setForceUnmapOnGcollect(false);
else
GC.expandHeap(if System.os() == "Windows_NT"
then 1024*1024*150
else 1024*1024*300);
end if;
Global.initialize();
ErrorExt.registerModelicaFormatError();
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMULATE_TOTAL);
args_1 := Flags.new(args);
System.gettextInit(if Config.getRunningTestsuite() then "C" else Flags.getConfigString(Flags.LOCALE_FLAG));
setDefaultCC();
end init;

public function main
"This is the main function that the MetaModelica Compiler (MMC) runtime system calls to
start the translation."
Expand All @@ -797,26 +823,7 @@ protected
GC.ProfStats stats;
algorithm
try
// set glib G_SLICE to always-malloc as is rummored to be better for Boehm GC
System.setEnv("G_SLICE", "always-malloc", true);
// call GC_init() the first thing we do!
System.initGarbageCollector();
// Experimentally found to make the testsuite pass on asap.openmodelica.org.
// 150M for Windows, 300M for others makes the GC try to unmap less and so it crashes less.
// Disabling unmap is another alternative that seems to work well (but could cause the memory consumption to not be released, and requires manually calling collect and unmap
if true then
GC.setForceUnmapOnGcollect(false);
else
GC.expandHeap(if System.os() == "Windows_NT"
then 1024*1024*150
else 1024*1024*300);
end if;
Global.initialize();
ErrorExt.registerModelicaFormatError();
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMULATE_TOTAL);
args_1 := Flags.new(args);
System.gettextInit(if Config.getRunningTestsuite() then "C" else Flags.getConfigString(Flags.LOCALE_FLAG));
setDefaultCC();
args_1 := init(args);
if Flags.isSet(Flags.GC_PROF) then
print(GC.profStatsStr(GC.getProfStats(), head="GC stats after initialization:") + "\n");
end if;
Expand Down
92 changes: 90 additions & 2 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -866,7 +866,7 @@ algorithm
end matchcontinue;
end cevalInteractiveFunctions;

protected function cevalInteractiveFunctions2
public function cevalInteractiveFunctions2
"defined in the interactive environment."
input FCore.Cache inCache;
input FCore.Graph inEnv;
Expand Down Expand Up @@ -1078,7 +1078,7 @@ algorithm
case (cache,_,"getClassComment",{Values.CODE(Absyn.C_TYPENAME(path))},st as GlobalScript.SYMBOLTABLE(ast = p),_)
equation
Absyn.CLASS(_,_,_,_,_,cdef,_) = Interactive.getPathedClassInProgram(path, p);
str = Interactive.getClassComment(cdef);
str = getClassComment(cdef);
then
(cache,Values.STRING(str),st);

Expand Down Expand Up @@ -1185,6 +1185,15 @@ algorithm
then
(cache,Values.TUPLE({Values.BOOL(b),Values.REAL(scaleFactor),Values.REAL(offset)}),st);

case (cache,_,"getClassInformation",{Values.CODE(Absyn.C_TYPENAME(className))},st as GlobalScript.SYMBOLTABLE(),_)
equation
v = getClassInformation(className, st.ast);
then (cache,v,st);

case (cache,_,"getClassInformation",_,st,_)
then (cache,Values.TUPLE({Values.STRING(""),Values.STRING(""),Values.BOOL(false),Values.BOOL(false),Values.BOOL(false),Values.STRING(""),
Values.BOOL(false),Values.INTEGER(0),Values.INTEGER(0),Values.INTEGER(0),Values.INTEGER(0),Values.ARRAY({},{0})}),st);

case (cache,_,"list",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT("AllLoadedClasses"))),Values.BOOL(false),Values.BOOL(false),Values.ENUM_LITERAL(name=path)},(st as GlobalScript.SYMBOLTABLE(ast = p)),_)
equation
(scodeP,st) = GlobalScriptUtil.symbolTableToSCode(st);
Expand Down Expand Up @@ -7882,5 +7891,84 @@ algorithm
end match;
end getInterfaceTypeAssocElt;

protected function getClassInformation
"author: PA
Returns all the possible class information.
changed by adrpo 2006-02-24 (latest 2006-03-14) to return more info and in a different format:
{\"restriction\",\"comment\",\"filename.mo\",{bool,bool,bool},{\"readonly|writable\",int,int,int,int}}
if you like more named attributes, use getClassAttributes API which uses get_class_attributes function
change by sjoelund.se 2014-11-14 to actually be sane. Using the typed API.
"
input Absyn.Path path;
input Absyn.Program p;
output Values.Value res_1;
protected
String name,file,strPartial,strFinal,strEncapsulated,res,cmt,str_readonly,str_sline,str_scol,str_eline,str_ecol;
String dim_str;
Boolean partialPrefix,finalPrefix,encapsulatedPrefix,isReadOnly;
Absyn.Restriction restr;
Absyn.ClassDef cdef;
Absyn.Class c;
Integer sl,sc,el,ec;
algorithm
Absyn.CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,restr,cdef,SOURCEINFO(file,isReadOnly,sl,sc,el,ec,_)) := Interactive.getPathedClassInProgram(path, p);
res := Dump.unparseRestrictionStr(restr);
cmt := getClassComment(cdef);
file := Util.testsuiteFriendly(file);
res_1 := Values.TUPLE({
Values.STRING(res),
Values.STRING(cmt),
Values.BOOL(partialPrefix),
Values.BOOL(finalPrefix),
Values.BOOL(encapsulatedPrefix),
Values.STRING(file),
Values.BOOL(isReadOnly),
Values.INTEGER(sl),
Values.INTEGER(sc),
Values.INTEGER(el),
Values.INTEGER(ec),
getClassDimensions(cdef)
});
end getClassInformation;

function getClassDimensions
"return the dimensions of a class
as vector of dimension sizes in a string.
Note: A class can only have dimensions if it is a short class definition."
input Absyn.ClassDef cdef;
output Values.Value v;
algorithm
v := match cdef
local
Absyn.ArrayDim ad;
case(Absyn.DERIVED(typeSpec=Absyn.TPATH(arrayDim=SOME(ad))))
then ValuesUtil.makeArray(list(Values.STRING(Dump.printSubscriptStr(d)) for d in ad));
else ValuesUtil.makeArray({});
end match;
end getClassDimensions;

function getClassComment "Returns the class comment of a Absyn.ClassDef"
input Absyn.ClassDef inClassDef;
output String outString;
algorithm
outString:=
matchcontinue (inClassDef)
local
String str,res;
Option<Absyn.Comment> cmt;
case (Absyn.PARTS(comment = SOME(str))) then str;
case (Absyn.DERIVED(comment = cmt))
then Interactive.getStringComment2(cmt);
case (Absyn.ENUMERATION(comment = cmt))
then Interactive.getStringComment2(cmt);
case (Absyn.ENUMERATION(comment = cmt))
then Interactive.getStringComment2(cmt);
case (Absyn.OVERLOAD(comment = cmt))
then Interactive.getStringComment2(cmt);
case (Absyn.CLASS_EXTENDS(comment = SOME(str))) then str;
else "";
end matchcontinue;
end getClassComment;

annotation(__OpenModelica_Interface="backend");
end CevalScript;

0 comments on commit 68397f7

Please sign in to comment.