Skip to content

Commit

Permalink
- Fixed assignments in Interactive.mo to use the value to determine t…
Browse files Browse the repository at this point in the history
…he type of a binding (since the elaborated type may contain unknown dimensions, but the Value certainly does not)

- Fixed a bug in the handling of readSimulationResult (if the input size does not conform to the expected value, we now fail instead of writing to the error buffer and succeeding anyway)
- Moved list() to ModelicaBuiltin.mo
  - Added support for default bindings of type OpenModelica.Code.TypeName


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8005 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 24, 2011
1 parent ae0fa6c commit fc2f87f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 18 deletions.
18 changes: 14 additions & 4 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -995,24 +995,34 @@ function dumpXMLDAE
external "builtin";
end dumpXMLDAE;

function listVariables
function listVariables "Lists the names of the active variables in the scripting environment."
output TypeName variables[:];
external "builtin";
end listVariables;

function val
input VariableName exp;
function val "Works on the filename pointed to by the scripting variable currentSimulationResult.
The result is the value of the variable at a certain time point.
For parameters, any time may be given. For variables the startTime<=time<=stopTime needs to hold.
On error, nan (Not a Number) is returned and the error buffer contains the message."
input VariableName var;
input Real time;
output Real valAtTime;
external "builtin";
end val;

function strtok
function strtok "Splits the strings at the places given by the token, for example:
strtok(\"abcbdef\",\"b\") => {\"a\",\"c\",\"def\"}"
input String string;
input String token;
output String[:] strings;
external "builtin";
end strtok;

function list "Lists the contents of the given class, or all loaded classes"
input TypeName class_ := $TypeName(AllLoadedClasses);
output String contents;
external "builtin";
end list;

end Scripting;
end OpenModelica;
14 changes: 2 additions & 12 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -1422,9 +1422,8 @@ algorithm
outType:=
match (inEnv,inCode)
local list<Env.Frame> env;
case (env,Absyn.C_TYPENAME(path = _)) then ((DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("TypeName")),{},NONE(),NONE()),NONE()));
case (env,Absyn.C_VARIABLENAME(componentRef = _)) then ((DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("VariableName")),{},NONE(),NONE()),
NONE()));
case (env,Absyn.C_TYPENAME(path = _)) then ((DAE.T_CODE(DAE.C_TYPENAME()),NONE()));
case (env,Absyn.C_VARIABLENAME(componentRef = _)) then ((DAE.T_CODE(DAE.C_VARIABLENAME()),NONE()));
case (env,Absyn.C_EQUATIONSECTION(boolean = _)) then ((
DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("EquationSection")),{},NONE(),NONE()),NONE()));
case (env,Absyn.C_ALGORITHMSECTION(boolean = _)) then ((
Expand Down Expand Up @@ -6804,15 +6803,6 @@ protected function elabCallInteractive "function: elabCallInteractive
ErrorExt.rollBack("Scripting");
then fail();

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));

case (cache,env,Absyn.CREF_IDENT(name = "list"),{Absyn.CREF(componentRef = cr)},{},impl,SOME(st),_,_)
equation
className = Absyn.crefToPath(cr);
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 = "translateModel"),{Absyn.CREF(componentRef = cr)},args,impl,SOME(st),pre,_)
equation
className = Absyn.crefToPath(cr);
Expand Down
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1483,6 +1483,7 @@ algorithm
list<String> names1, names2;
DAE.Dimension dim1,dim2;
list<FuncArg> farg1,farg2;
DAE.CodeType c1,c2;

case ((DAE.T_ANYTYPE(_),_),(_,_)) then true;
case ((_,_),(DAE.T_ANYTYPE(_),_)) then true;
Expand Down Expand Up @@ -1624,6 +1625,8 @@ algorithm
case((DAE.T_UNIONTYPE(_),SOME(p1)),(DAE.T_COMPLEX(complexClassType=ClassInf.UNIONTYPE(_)),SOME(p2)))
then Absyn.pathEqual(p1,p2);

case ((DAE.T_CODE(c1),_),(DAE.T_CODE(c2),_)) then valueEq(c1,c2);

case (t1,t2)
equation
/* Uncomment for debugging
Expand Down Expand Up @@ -2106,6 +2109,7 @@ algorithm
TType t;
Absyn.Path path,p;
list<Type> tys;
DAE.CodeType codeType;

case ((DAE.T_INTEGER(varLstInt = {}),_)) then "Integer";
case ((DAE.T_REAL(varLstReal = {}),_)) then "Real";
Expand Down Expand Up @@ -2254,6 +2258,7 @@ algorithm
case ((DAE.T_NORETCALL(),_)) then "#NORETCALL#";
case ((DAE.T_NOTYPE(),_)) then "#NOTYPE#";
case ((DAE.T_ANYTYPE(anyClassType = _),_)) then "#ANYTYPE#";
case ((DAE.T_CODE(ty = codeType),_)) then printCodeTypeStr(codeType);
case (ty) then "Internal error Types.unparseType: not implemented yet\n";
end match;
end unparseType;
Expand Down
4 changes: 4 additions & 0 deletions Compiler/FrontEnd/ValuesUtil.mo
Expand Up @@ -908,6 +908,7 @@ algorithm
list<DAE.ExpVar> varlst;
Integer ix;
Absyn.Path path;
Absyn.CodeNode code;

case (Values.INTEGER(integer = i)) then DAE.ICONST(i);
case (Values.REAL(real = r)) then DAE.RCONST(r);
Expand Down Expand Up @@ -1022,6 +1023,9 @@ algorithm
e = valueExp(v);
then DAE.BOX(e);

case (Values.CODE(A=code))
then DAE.CODE(code,DAE.ET_OTHER());

case (v)
equation
s = "ValuesUtil.valueExp failed for " +& valString(v);
Expand Down
4 changes: 3 additions & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -745,7 +745,7 @@ algorithm
then
(cache,Values.TUPLE({Values.INTEGER(-1),v}),st);

case (cache,env,"list",{},(st as Interactive.SYMBOLTABLE(ast = p)),msg)
case (cache,env,"list",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT("AllLoadedClasses")))},(st as Interactive.SYMBOLTABLE(ast = p)),msg)
equation
str = Dump.unparseStr(p,false);
then
Expand All @@ -758,6 +758,8 @@ algorithm
then
(cache,Values.STRING(str),st);

case (cache,env,"list",_,st,msg) then (cache,Values.STRING(""),st);

case (cache,env,"jacobian",{Values.CODE(Absyn.C_TYPENAME(path))},
(st as Interactive.SYMBOLTABLE(
ast = p,depends=aDep,explodedAst = sp,instClsLst = ic,
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Script/Interactive.mo
Expand Up @@ -582,8 +582,9 @@ algorithm
(st as SYMBOLTABLE(ast = p)))
equation
env = buildEnvFromSymboltable(st);
(cache,sexp,DAE.PROP(t,_),SOME(st_1)) = Static.elabExp(Env.emptyCache(),env, exp, true, SOME(st),true,Prefix.NOPRE(),info);
(cache,sexp,DAE.PROP(_,_),SOME(st_1)) = Static.elabExp(Env.emptyCache(),env, exp, true, SOME(st),true,Prefix.NOPRE(),info);
(_,value,SOME(st_2)) = Ceval.ceval(cache,env, sexp, true, SOME(st_1),NONE(), Ceval.MSG());
t = Types.typeOfValue(value) "This type can be more specific than the elaborated type; if the dimensions are unknown...";
str = ValuesUtil.valString(value);
newst = addVarToSymboltable(ident, value, t, st_2);
then
Expand Down
1 change: 1 addition & 0 deletions Compiler/runtime/SimulationResults.c
Expand Up @@ -208,6 +208,7 @@ static void* SimulationResultsImpl__readDataset(const char *filename, void *vars
} else if (matReader.nrows != dimsize) {
fprintf(stderr, "dimsize: %d, rows %d\n", dimsize, matReader.nrows);
c_add_message(-1, "SCRIPT", "Error", "readDataset(...): Expected and actual dimension sizes do not match.", NULL, 0);
return NULL;
}
while (RML_NILHDR != RML_GETHDR(vars)) {
var = RML_STRINGDATA(RML_CAR(vars));
Expand Down
2 changes: 2 additions & 0 deletions Parser/BaseModelica_Lexer.g
Expand Up @@ -41,6 +41,7 @@ T_ANNOTATION;
BLOCK;
CODE;
CODE_EXP;
CODE_NAME;
CODE_VAR;
CLASS;
CONNECT;
Expand Down Expand Up @@ -262,6 +263,7 @@ NL: '\r\n' | '\n';
/* OpenModelica extensions */
CODE : 'Code' | '$Code';
CODE_NAME : '$TypeName';
CODE_EXP : '$Exp';
CODE_VAR : '$Var';
Expand Down
1 change: 1 addition & 0 deletions Parser/Modelica.g
Expand Up @@ -1213,6 +1213,7 @@ code_expression returns [void* ast] :
ast = Absyn__CODE(Absyn__C_5fELEMENT(el.ast));
}
}
| CODE_NAME LPAR name=name_path RPAR {ast = Absyn__CODE(Absyn__C_5fTYPENAME(name));}
)
;
Expand Down

0 comments on commit fc2f87f

Please sign in to comment.