Skip to content

Commit

Permalink
Moved many interactive functions to StaticExp, such that they can be …
Browse files Browse the repository at this point in the history
…evaluated in any sub-expression. Also fixed bug with getIconAnnotation, getDiagramAnnotation.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@933 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Mar 5, 2003
1 parent 472f2e7 commit 6b2bbf1
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 260 deletions.
14 changes: 7 additions & 7 deletions modeq/inst.rml
Expand Up @@ -1601,7 +1601,7 @@ relation elab_arraydim_decl : (Env.Env, Absyn.ArrayDim, bool, Interactive.Intera
PA: This is true for normal models, e.g. model test Real x[n]; end test;
It is NOT true for functions, or other implicit instantiated models.
*)
Static.ceval(env,e,impl,st) => Values.INTEGER(i) &
Static.ceval(env,e,impl,st) => (Values.INTEGER(i),_) &
elab_arraydim_decl(env,ds,impl,st) => l
-------------------------------------------
elab_arraydim_decl(env,Absyn.SUBSCRIPT(d)::ds,impl,st) => SOME(DIMINT(i))::l
Expand All @@ -1613,7 +1613,7 @@ relation elab_arraydim_decl : (Env.Env, Absyn.ArrayDim, bool, Interactive.Intera
PA: This is true for normal models, e.g. model test Real x[n]; end test;
It is NOT true for functions, or other implicit instantiated models.
*)
Static.ceval(env,e,impl,st) => Values.INTEGER(i) &
Static.ceval(env,e,impl,st) => (Values.INTEGER(i),_) &
elab_arraydim_decl(env,ds,impl,st) => l
-------------------------------------------
elab_arraydim_decl(env,Absyn.SUBSCRIPT(d)::ds,impl as true,st) => SOME(DIMINT(i))::l
Expand Down Expand Up @@ -2470,7 +2470,7 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
**)

rule Static.elab_exp(env,e,false,NONE) => (e',Types.PROP(Types.T_BOOL,true),_) &
Static.ceval(env,e',false,NONE) => Values.BOOL(cond) &
Static.ceval(env,e',false,NONE) => (Values.BOOL(cond),_) &
Debug.print("\nEQ_IF: ") &
(*!! print(cond) &
*)
Expand All @@ -2485,7 +2485,7 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
=> (dae,env',csets', ci_state')

rule Static.elab_exp(env,e,false,NONE) => (e',Types.PROP(Types.T_BOOL,true),_) &
Static.ceval(env,e',false,NONE) => Values.BOOL(cond) &
Static.ceval(env,e',false,NONE) => (Values.BOOL(cond),_) &
Debug.print("\nEQ_IF: ") &
(*!! print(cond) &
*)
Expand Down Expand Up @@ -2517,7 +2517,7 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
Types.T_INTEGER),
true),_) &
(* FIXEM: Check bounds *)
Static.ceval (env,e',false,NONE) => v &
Static.ceval (env,e',false,NONE) => (v,_) &
(* Not possilbe for 'when'.unroll(env,mod,pre,csets,ci_state,i,v,el) => (dae, csets') & *)
inst_list(env,mod,pre,csets,ci_state,inst_equation, el)
=> (dae,env',csets', ci_state') (*&
Expand All @@ -2538,7 +2538,7 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
Types.T_INTEGER),
true),_) &
(* FIXEM: Check bounds *)
Static.ceval (env,e',false,NONE) => v &
Static.ceval (env,e',false,NONE) => (v,_) &
(* Not possilbe for 'when'.unroll(env,mod,pre,csets,ci_state,i,v,el) => (dae, csets') & *)
inst_list(env,mod,pre,csets,ci_state,inst_initialequation, el)
=> (dae,env',csets', ci_state') (*&
Expand Down Expand Up @@ -2574,7 +2574,7 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
Debug.fprintln ("insti", "loop variable looked up") &

(* FIXEM: Check bounds *)
Static.ceval (env,e',false,NONE) => v &
Static.ceval (env,e',false,NONE) => (v,_) &
Debug.fprintln ("insti", "for expression evaluated") &
unroll(env',mod,pre,csets,ci_state,i,v,el,initial) => (dae, csets') &
Debug.fprintln ("insti", "for expression unrolled") &
Expand Down
117 changes: 6 additions & 111 deletions modeq/interactive.rml
Expand Up @@ -57,6 +57,8 @@ module Interactive:
relation build_env_from_symboltable: (InteractiveSymbolTable) => Env.Env
relation get_pathed_class_in_program: (Absyn.Path, Absyn.Program) => Absyn.Class

relation get_type_of_variable: (Absyn.Ident, InteractiveVariable list) => Types.Type

end
with "dump.rml"
with "debug.rml"
Expand Down Expand Up @@ -108,43 +110,6 @@ end

relation evaluate2: (InteractiveStmts, InteractiveSymbolTable) => (string,InteractiveSymbolTable) =

rule let newst = SYMBOLTABLE(Absyn.PROGRAM([],Absyn.TOP),[],[],[],[])
-------------------------------------------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("clear",_),_))],_),_)
=> ("true\n", newst)

rule let newst = SYMBOLTABLE(p,fp,ic,[],cf)
-------------------------------------------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("clearVariables",_),_))],_),SYMBOLTABLE(p,fp,ic,iv,cf))
=> ("true\n", newst)

rule Dump.unparse_str(p) => str
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("list",_),Absyn.FUNCTIONARGS([],[])))],_),st as SYMBOLTABLE(p,_,_,_,_))
=> (str,st)

rule Absyn.cref_to_path(cr) => path &
get_pathed_class_in_program(path,p) => class &
Dump.unparse_str(Absyn.PROGRAM([class],Absyn.TOP)) => str
------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("list",_),Absyn.FUNCTIONARGS([ Absyn.CREF(cr)],[])))],_),st as SYMBOLTABLE(p,_,_,_,_))
=> (str,st)

rule SCode.elaborate(p) => p' &
Absyn.cref_to_path(cr) => path &
Inst.instantiate_class(p',path) => dae &
Print.get_string => s &
DAE.dump_str (dae) => str &
string_append(s,str) => res
--------------------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("translateClass",_),Absyn.FUNCTIONARGS([ Absyn.CREF(cr)],[])))],_),st as SYMBOLTABLE(p,_,_,_,_))
=> ("true\n",st)

rule Print.print_error_buf "#Error instanitating class\n"
--------------------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("translateClass",_),Absyn.FUNCTIONARGS([ Absyn.CREF(cr)],[])))],_),st as SYMBOLTABLE(p,_,_,_,_))
=> ("false\n",st)

rule SCode.elaborate(p) => p' &
Absyn.cref_to_path(cr) => path &
Absyn.path_string path => pathstr &
Expand All @@ -168,83 +133,13 @@ relation evaluate2: (InteractiveStmts, InteractiveSymbolTable) => (string,Inter
axiom evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("generateCode",_),Absyn.FUNCTIONARGS([ Absyn.CREF(cr)],[])))],_),st as SYMBOLTABLE(p,_,_,_,_))
=> ("false\n",st)

rule System.set_c_compiler(str)
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("setCompiler",_),Absyn.FUNCTIONARGS([ Absyn.STRING(str)],[])))],_),st as SYMBOLTABLE(p,_,_,_,_))
=> ("true\n",st)

rule System.set_c_flags(str)
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("setCompilerFlags",_),Absyn.FUNCTIONARGS([ Absyn.STRING(str)],[])))],_),st as SYMBOLTABLE(p,_,_,_,_))
=> ("true\n",st)

rule string_append("+d=",str) => str' &
RTOpts.args [str'] => args
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("setDebugFlags",_),Absyn.FUNCTIONARGS([ Absyn.STRING(str)],[])))],_),st as SYMBOLTABLE(p,_,_,_,_))
=> ("true\n",st)

rule get_type_of_variable(varid,vars) => tp &
Print.clear_buf &
Types.unparse_type tp => str &
Util.string_append_list(["\"",str,"\"\n"]) => str'
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("typeOf",_),Absyn.FUNCTIONARGS([ Absyn.CREF(Absyn.CREF_IDENT(varid,_))],[])))],_),st as SYMBOLTABLE(p,_,_,vars,_))
=> (str',st)

rule System.pwd() => res &
string_append(res,"\n") => res'
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("cd",_),Absyn.FUNCTIONARGS([],[])))],_),st as SYMBOLTABLE(p,_,_,vars,_))
=> ("true\n",st)

rule System.cd(str) => res &
int_eq (res,0) => true &
System.pwd => str' &
string_append(str',"\n") => str''
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("cd",_),Absyn.FUNCTIONARGS([ Absyn.STRING(str)],[])))],_),st as SYMBOLTABLE(p,_,_,vars,_))
=> (str'',st)

rule System.cd(str) => res &
int_eq (res,0) => false &
Print.clear_error_buf() &
Print.print_error_buf "No such directory: " & Print.print_error_buf str
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("cd",_),Absyn.FUNCTIONARGS([ Absyn.STRING(str)],[])))],_),st as SYMBOLTABLE(p,_,_,vars,_))
=> ("false\n",st)

rule System.system_call(str) => res &
int_string res => str' &
string_append(str',"\n") => str''
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("system",_),Absyn.FUNCTIONARGS([ Absyn.STRING(str)],[])))],_),st as SYMBOLTABLE(p,_,_,vars,_))
=> (str'',st)

rule System.read_file(str) => str' &
string_append(str',"\n") => str''
---------------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("printFile",_),Absyn.FUNCTIONARGS([ Absyn.STRING(str)],[])))],_),st as SYMBOLTABLE(p,_,_,vars,_))
=> (str'',st)

rule get_variable_names(vars) => vars &
string_append(vars,"\n") => str
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("listVariables",_),Absyn.FUNCTIONARGS([],[])))],_),st as SYMBOLTABLE(_,_,_,vars,_))
=> (str,st)

rule not get_type_of_variable(varid,vars) => tp &
string_append(varid, " is not defined\n") => str
--------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("typeOf",_),Absyn.FUNCTIONARGS([ Absyn.CREF(Absyn.CREF_IDENT(varid,_))],[])))],_),st as SYMBOLTABLE(p,_,_,vars,_))
=> (str,st)

rule Print.get_error_string() => str &
Util.string_append_list(["\"",str,"\"\n"]) => str'
---------------------------
evaluate2(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("getErrorString",_),Absyn.FUNCTIONARGS([],[])))],_),st as SYMBOLTABLE(_,_,_,vars,_))
=> (str',st)

rule evaluate_graphical_api(stmts,st) => (str,newst)
----------------------------------------------------
evaluate2(stmts as ISTMTS([IEXP(Absyn.CALL(_,_))],_),st) => (str,newst)
Expand All @@ -268,16 +163,16 @@ relation evaluate_expr: (InteractiveStmt, InteractiveSymbolTable) =>

rule build_env_from_symboltable(st) => env &
Static.elab_exp(env,exp,true,SOME(st)) => (sexp,prop,SOME(st')) &
Static.ceval (env,sexp,true,SOME(st')) => value &
Static.ceval (env,sexp,true,SOME(st')) => (value,SOME(st'')) &
Values.val_string value => str
-------------------------------
evaluate_expr(IEXP(exp),st as SYMBOLTABLE(p,_,_,_,_)) => (str,st')
evaluate_expr(IEXP(exp),st as SYMBOLTABLE(p,_,_,_,_)) => (str,st'')

rule build_env_from_symboltable(st) => env &
Static.elab_exp(env,exp,true,SOME(st)) => (sexp,Types.PROP(t,_),SOME(st')) &
Static.ceval(env,sexp,true,SOME(st')) => value &
Static.ceval(env,sexp,true,SOME(st')) => (value,SOME(st'')) &
Values.val_string value => str &
add_var_to_symboltable(ident,value,t,st') => newst
add_var_to_symboltable(ident,value,t,st'') => newst
-----------------------------------------------
evaluate_expr(IALG(Absyn.ALGORITHMITEM(Absyn.ALG_ASSIGN(Absyn.CREF_IDENT(ident,[]),exp),_)),st as SYMBOLTABLE(p,_,_,_,_))
=> (str, newst)
Expand Down
4 changes: 2 additions & 2 deletions modeq/runtime/systemimpl.c
Expand Up @@ -154,11 +154,11 @@ RML_BEGIN_LABEL(System__read_5ffile)
file = fopen(filename,"rb");
buf = malloc(statstr.st_size+1);

if( (res = fread(buf, sizeof(char), statstr.st_size, file)) != statstr.st_size){
if( (res = fread(buf, sizeof(char), statstr.st_size, file)) != statstr.st_size){
rmlA0 = (void*) mk_scon("Failed while reading file");
RML_TAILCALLK(rmlSC);
}

buf[statstr.st_size] = '\0';
fclose(file);
rmlA0 = (void*) mk_scon(buf);
RML_TAILCALLK(rmlSC);
Expand Down

0 comments on commit 6b2bbf1

Please sign in to comment.