Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 26cb184

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Improved instantiateModel
- Report execStat for the frontend - Support the silent flag `-q` for the instantiateModel API, avoiding calling the dumping routine if the result is not desired (the output is still non-empty to allow checking for empty string to signify success) Belonging to [master]: - #2404
1 parent 7fc85eb commit 26cb184

File tree

2 files changed

+27
-38
lines changed

2 files changed

+27
-38
lines changed

Compiler/Script/CevalScriptBackend.mo

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,10 +1702,17 @@ algorithm
17021702

17031703
case (cache,env,"instantiateModel",{Values.CODE(Absyn.C_TYPENAME(className))},_)
17041704
equation
1705-
(cache,env,odae) = runFrontEnd(cache,env,className,true);
17061705
ExecStat.execStatReset();
1707-
str = if isNone(odae) then "" else DAEDump.dumpStr(Util.getOption(odae),FCore.getFunctionTree(cache));
1708-
ExecStat.execStat("DAEDump.dumpStr(" + Absyn.pathString(className) + ")");
1706+
(cache,env,odae) = runFrontEnd(cache,env,className,true);
1707+
ExecStat.execStat("runFrontEnd");
1708+
if isNone(odae) then
1709+
str = "";
1710+
elseif Config.silent() then
1711+
str = "model " + Absyn.pathString(className) + "\n /* Silent mode */\nend" + Absyn.pathString(className) + ";\n"; // Not the empty string, so we can
1712+
else
1713+
str = DAEDump.dumpStr(Util.getOption(odae),FCore.getFunctionTree(cache));
1714+
ExecStat.execStat("DAEDump.dumpStr");
1715+
end if;
17091716
then
17101717
(cache,Values.STRING(str));
17111718

Compiler/Script/Interactive.mo

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -178,41 +178,23 @@ public function evaluateToStdOut
178178
The resulting string after evaluation is printed.
179179
If an error has occurred, this string will be empty.
180180
The error messages can be retrieved by calling print_messages_str() in Error.mo."
181-
input GlobalScript.Statements inStatements;
182-
input Boolean inBoolean;
183-
algorithm
184-
_ := match (inStatements,inBoolean)
185-
local
186-
String res,res_1;
187-
Boolean echo,semicolon,verbose;
188-
GlobalScript.Statement x;
189-
GlobalScript.Statements new;
190-
list<GlobalScript.Statement> xs;
191-
192-
case (GlobalScript.ISTMTS(interactiveStmtLst = {x},semicolon = semicolon),verbose)
193-
equation
194-
showStatement(x, semicolon, true);
195-
new = GlobalScript.ISTMTS({x},verbose);
196-
res = evaluate2(new);
197-
echo = getEcho();
198-
res_1 = selectResultstr(res, semicolon, verbose, echo);
199-
print(res_1);
200-
showStatement(x, semicolon, false);
201-
then ();
202-
203-
case (GlobalScript.ISTMTS(interactiveStmtLst = (x :: xs),semicolon = semicolon),verbose)
204-
equation
205-
showStatement(x, semicolon, true);
206-
new = GlobalScript.ISTMTS({x},semicolon);
207-
res = evaluate2(new);
208-
echo = getEcho();
209-
res_1 = selectResultstr(res, semicolon, verbose, echo);
210-
print(res_1);
211-
showStatement(x, semicolon, false);
212-
213-
evaluateToStdOut(GlobalScript.ISTMTS(xs,semicolon), verbose);
214-
then ();
215-
end match;
181+
input GlobalScript.Statements statements;
182+
input Boolean verbose;
183+
protected
184+
GlobalScript.Statement x;
185+
list<GlobalScript.Statement> xs;
186+
Boolean semicolon;
187+
String res;
188+
algorithm
189+
xs := statements.interactiveStmtLst;
190+
semicolon := statements.semicolon;
191+
while not listEmpty(xs) loop
192+
x::xs := xs;
193+
showStatement(x, semicolon, true);
194+
res := evaluate2(GlobalScript.ISTMTS({x},if listEmpty(xs) then verbose else semicolon));
195+
print(selectResultstr(res, semicolon, verbose, getEcho()));
196+
showStatement(x, semicolon, false);
197+
end while;
216198
end evaluateToStdOut;
217199

218200
public function evaluateFork

0 commit comments

Comments
 (0)