Skip to content

Commit

Permalink
Impl flag bugfixes. Fixed elab_range_type. Fixed matching problem for…
Browse files Browse the repository at this point in the history
… Icon in get_annotation_string

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1570 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
levsa committed Mar 16, 2005
1 parent a9b37b2 commit 1f4a394
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 29 deletions.
39 changes: 24 additions & 15 deletions modeq/ceval.rml
Expand Up @@ -329,7 +329,7 @@ relation ceval : (Env.Env, Exp.Exp, bool (*impl*),


(* end luc_pop *)

(*
(* FIXME: disabled calling of functions during ceval for now. Some
* functions call other functions, which must be generated together in
* order that compilation works *)
Expand Down Expand Up @@ -358,18 +358,18 @@ relation ceval : (Env.Env, Exp.Exp, bool (*impl*),

(* ceval (env, e as Exp.CALL(funcpath,expl,_,_),false,st as SOME(Interactive.SYMBOLTABLE(_,_,_,_,cflist)),_) => (newval,st)
*)

*)

(* FIXME: Fix this in order to allow calling of constant-marked function
* calls. One should call the function as if we were in interactive
* mode, and put the result instead of the function call *)
(*


rule Print.print_buf "# Can't call functions at compile time\n" &
Print.print_buf " expression: " & Exp.print_exp e & Print.print_buf "\n"
-------------------------------------------------------
ceval (env, e as Exp.CALL(_,_,_,_),impl as false,NONE,_) => fail
*)


rule (* Print.print_buf "implicit evaluation of function calls without symbol table, exp: " &
Exp.print_exp e & Print.print_buf "\n" *)
Expand Down Expand Up @@ -709,8 +709,13 @@ relation ceval_function: (Env.Env, Absyn.Path, Values.Value list, bool (*impl*)
Print.get_string => s & print s & print "\n" &
DAE.dae_to_record_value(funcname,dae,impl) => value
----------------------
ceval_function(env,funcname,vallst,impl) => value
ceval_function(env,funcname,vallst,impl as false) => value

rule Debug.fprint("failtrace", "ceval_function: Don't know what to do. impl was always false before:")
& Absyn.path_string funcname => s
& Debug.fprintln("failtrace", s)
--------------------------------------------------------------------------------------------------
ceval_function(env,funcname,vallst,impl as true) => fail
end


Expand Down Expand Up @@ -1072,8 +1077,8 @@ relation ceval_interactive_functions: (Env.Env, Exp.Exp, Interactive.Interactive
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("translateModel"),[Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf))
=> (Values.STRING("The environment variable MOSHHOME was not set"),st)



(* FIXME: Should ceval be called with impl=true here? *)
rule (* Build and simulate model *)
ceval(env,starttime,true,SOME(st),NONE)
=> (Values.REAL(starttime_r),SOME(st)) &
Expand Down Expand Up @@ -2237,52 +2242,56 @@ relation ceval_cref : (Env.Env, Exp.ComponentRef, bool (*impl*) ) => Values.Valu

(* FIXME: For now, we don't try to check binding if implicit instantiation *)

(*
rule Debug.fprintln("ceval", "ceval_cref: Skipping ceval_cref_binding because implicit inst")
----------------------------------------------------------------------------
ceval_cref (env,c,impl as true) => fail
*)


rule Lookup.lookup_var (env, c) => (_,_,binding) &
ceval_cref_binding (env,c,binding,impl) => v
-------------------------------------
ceval_cref (env,c,impl as false) => v
ceval_cref (env,c,impl (*as false*)) => v

(* default *)

rule Print.print_error_buf "# No constant binding for " &
Exp.print_component_ref_str c => str &
Print.print_error_buf str & Print.print_error_buf "\n"
-------------------------------------
ceval_cref (_,c,impl as false ) => fail
ceval_cref (_,c,impl (*as false*) ) => fail

end

relation ceval_cref_binding : (Env.Env, Exp.ComponentRef,Types.Binding, bool (*impl*) ) => Values.Value =

(* FIXME: For now, we don't try to check binding if implicit instantiation *)

(*
rule Debug.fprintln("ceval", "ceval_cref_binding: shouldn't have been called.") &
Debug.fprintln("ceval", "Skipping because implicit inst")
----------------------------------------------------------------------------
ceval_cref_binding (_,_,_,impl as true ) => fail
*)

rule Lookup.lookup_var(env,Exp.CREF_IDENT(id,[])) => (_, tp, _) &
Types.get_dimension_sizes(tp) => sizelst &
ceval_subscript_value(env,subsc,v, sizelst,impl) => res
-----------------------------------------
ceval_cref_binding (env,Exp.CREF_IDENT(id,subsc),Types.VALBOUND(v),impl as false)
ceval_cref_binding (env,Exp.CREF_IDENT(id,subsc),Types.VALBOUND(v),impl (*as false*))
=> res

rule Print.print_buf "- ceval_cref_binding failed (UNBOUND)\n"
-------------------------------------
ceval_cref_binding (env,_,Types.UNBOUND,impl as false) => fail
ceval_cref_binding (env,_,Types.UNBOUND,impl (*as false*)) => fail


rule let Exp.REDUCTION(Absyn.IDENT(rfn),elexp,iter,iterexp) = exp &
rfn = "array" &
Print.print_buf "#-- ceval_cref_binding Array evaluation\n"
---------------------------
ceval_cref_binding (env,Exp.CREF_IDENT(id,subsc),Types.EQBOUND(exp,true),impl as false)
ceval_cref_binding (env,Exp.CREF_IDENT(id,subsc),Types.EQBOUND(exp,true),impl (*as false*))
=> fail

rule let Exp.REDUCTION(Absyn.IDENT(rfn),elexp,iter,iterexp) = exp &
Expand All @@ -2292,21 +2301,21 @@ relation ceval_cref_binding : (Env.Env, Exp.ComponentRef,Types.Binding, bool (*i
ceval (env,exp,impl,NONE,NONE) => (v,_) &
ceval_subscript_value (env,subsc,v,sizelst,impl) => res
---------------------------
ceval_cref_binding (env,Exp.CREF_IDENT(id,subsc),Types.EQBOUND(exp,true),impl as false)
ceval_cref_binding (env,Exp.CREF_IDENT(id,subsc),Types.EQBOUND(exp,true),impl (*as false*))
=> res

rule Lookup.lookup_var(env,Exp.CREF_IDENT(id,[])) => (_, tp, _) &
Types.get_dimension_sizes(tp) => sizelst &
ceval (env,exp,impl,NONE,NONE) => (v,_) &
ceval_subscript_value(env,subsc,v,sizelst,impl) => res
------------------------
ceval_cref_binding (env,Exp.CREF_IDENT(id,subsc),Types.EQBOUND(exp,true),impl as false)
ceval_cref_binding (env,Exp.CREF_IDENT(id,subsc),Types.EQBOUND(exp,true),impl (*as false*))
=> res

rule Print.print_buf "- ceval_cref__binding failed (nonconstant EQBOUND(" &
Exp.print_exp exp & Print.print_buf ")\n"
--------------------------------
ceval_cref_binding (env,_,Types.EQBOUND(exp,false),impl as false) => fail
ceval_cref_binding (env,_,Types.EQBOUND(exp,false),impl (*as false*)) => fail

end

Expand Down
2 changes: 1 addition & 1 deletion modeq/dae.rml
Expand Up @@ -1861,7 +1861,7 @@ relation get_flow_variables: Element list => Exp.ComponentRef list =
get_flow_variables(_::xs) => res
end

relation get_flow_variables_2: (Exp.ComponentRef list ,Ident)
relation get_flow_variables_2: (Exp.ComponentRef list ,Ident)
=> Exp.ComponentRef list =

axiom get_flow_variables_2([],id) => []
Expand Down
6 changes: 3 additions & 3 deletions modeq/inst.rml
Expand Up @@ -214,7 +214,7 @@ module Inst:


relation inst_class_decl : ( Env.Env, Types.Mod, Prefix.Prefix,
Connect.Sets, SCode.Class, InstDims, bool (*impl*))
Connect.Sets, SCode.Class, InstDims, bool (*packimpl?*))
=> ( Env.Env, DAE.Element list)

relation inst_class_in: ( Env.Env, Types.Mod, Prefix.Prefix,
Expand Down Expand Up @@ -602,7 +602,7 @@ relation inst_class : (Env, Mod, Prefix, Connect.Sets, SCode.Class,

rule Env.open_scope(env,encflag,SOME(n)) => env' &
ClassInf.start(r,n) => ci_state &
inst_class_in(env', mod, pre, csets, ci_state, c, false, inst_dims, impl,false)
inst_class_in(env', mod, pre, csets, ci_state, c, false, inst_dims, impl,false (*packimpl*))
=> (dae1, env''', csets', ci_state', tys) &
fully_qualified(Absyn.IDENT(n),env) => fq_class &
DAE.set_component_type(dae1,fq_class) => dae1' &
Expand Down Expand Up @@ -2902,7 +2902,7 @@ end
**)

relation inst_class_decl : (Env.Env, Types.Mod, Prefix.Prefix,
Connect.Sets, SCode.Class,InstDims, bool)
Connect.Sets, SCode.Class,InstDims, bool (*packimpl*) )
=> (Env.Env, DAE.Element list) =

rule (*Debug.fprint("insttr","+\tinst_class_decl called\n") &*)
Expand Down
24 changes: 22 additions & 2 deletions modeq/interactive.rml
Expand Up @@ -3594,14 +3594,34 @@ relation get_annotation_string: (string,Absyn.Annotation) => string =
(* Put bindings of variables as expressions inside variable elements of the dae instead of equations *)
Inst.init_vars_modelica_output dae => dae' &
DAE.get_variable_bindings_str dae' => str &
Static.elab_graphics_exp(env,graphicexp,true (*impl*) ) => (graphicexp2,prop) &
Static.elab_graphics_exp(env,graphicexp,false (*impl*) ) => (graphicexp2,prop) &

Exp.print_exp_str(graphicexp2) => gexpstr &
string_append(str,",") => s1 &
string_append(s1,gexpstr) => totstr
-----------------------------------
get_annotation_string(totstring,Absyn.ANNOTATION([(Absyn.MODIFICATION(_,_,Absyn.CREF_IDENT("Icon",_),SOME(Absyn.CLASSMOD(mod,_)),_))])) => totstr

(* First line in the first rule above fails if return value from strip_graphics_modification doesn't match the rhs of => *)
rule strip_graphics_modification(mod) => (stripmod, gxmods) &
SCode.build_mod(SOME(Absyn.CLASSMOD(stripmod,NONE)),false) => mod' &
Parser.parsestring totstring => (p,parsestr) & (* Always succeeds, check parsestr for errors *)
parsestr = "Ok" &
SCode.elaborate(p) => p' &
Inst.make_simple_env_from_program(p',Absyn.IDENT("Icon")) => env &
get_class_in_program("Icon",p) => placementc &
SCode.elab_class(placementc) => placementclass &
Mod.elab_mod (env,Prefix.NOPRE,mod',true) => mod'' &
Inst.inst_class(env, mod'', Prefix.NOPRE, [], placementclass,
[], true,Inst.TOP_CALL)
=> (dae, _, cs, t, state) &
(* Put bindings of variables as expressions inside variable elements of the dae instead of equations *)
Inst.init_vars_modelica_output dae => dae' &
DAE.get_variable_bindings_str dae' => str
-----------------------------------
get_annotation_string(totstring,Absyn.ANNOTATION([(Absyn.MODIFICATION(_,_,Absyn.CREF_IDENT("Icon",_),SOME(Absyn.CLASSMOD(mod,_)),_))])) => str


rule strip_graphics_modification(mod) => (stripmod,[Absyn.MODIFICATION(_,_,_,SOME(Absyn.CLASSMOD(_,SOME(graphicexp))),_)]) &
SCode.build_mod(SOME(Absyn.CLASSMOD(stripmod,NONE)),false) => mod' &
Parser.parsestring totstring => (p,parsestr) & (* Always succeeds, check parsestr for errors *)
Expand All @@ -3619,7 +3639,7 @@ relation get_annotation_string: (string,Absyn.Annotation) => string =
Inst.init_vars_modelica_output dae => dae' &
DAE.get_variable_bindings_str dae' => str &

Static.elab_graphics_exp(env,graphicexp,true(*impl*)) => (graphicexp2,prop) &
Static.elab_graphics_exp(env,graphicexp,false (*impl*)) => (graphicexp2,prop) &
Exp.print_exp_str(graphicexp2) => gexpstr &
string_append(str,",") => s1 &
string_append(s1,gexpstr) => totstr
Expand Down
23 changes: 15 additions & 8 deletions modeq/staticexp.rml
Expand Up @@ -255,12 +255,17 @@ end
relation ceval_if_constant: (Exp.Exp,bool (* constant *), bool (* impl *), Env.Env) => Exp.Exp =

axiom ceval_if_constant(e,cnst as false,_,_) => e

axiom ceval_if_constant(e,cnst as true ,impl as true,_) => e



rule Ceval.ceval(env,e,impl,NONE,NONE) => (v,_) &
value_exp(v) => e'
---------------------------------
ceval_if_constant(e,cnst as true,impl as false,env) => e'
ceval_if_constant(e,cnst as true,impl (*as false*),env) => e'

axiom ceval_if_constant(e,_,_,_) => e

end

(** relation: elab_exp
Expand Down Expand Up @@ -772,7 +777,7 @@ relation elab_range_type : (Env.Env, Exp.Exp, Exp.Exp option, Exp.Exp, bool (*co
Ceval.ceval (env,stop,impl,NONE,NONE) => (Values.INTEGER(stopv),_) &
int_sub (stopv,startv) => n & int_add (n,1) => n'
-------------------------------------------------
elab_range_type (env,start,NONE,stop,const as true,_,impl as false)
elab_range_type (env,start,NONE,stop,const as true,_,impl (*as false*))
=> ((Types.T_ARRAY(Types.DIM(SOME(n')), (Types.T_INTEGER([]),NONE)),NONE))

rule Ceval.ceval (env,start,impl,NONE,NONE) => (Values.INTEGER(startv),_) &
Expand All @@ -782,7 +787,7 @@ relation elab_range_type : (Env.Env, Exp.Exp, Exp.Exp option, Exp.Exp, bool (*co
int_div (n,stepv) => n' &
int_add (n',1) => n''
-------------------------------------------------
elab_range_type (env,start,SOME(step),stop,const as true,_,impl as false)
elab_range_type (env,start,SOME(step),stop,const as true,_,impl (*as false*))
=> ((Types.T_ARRAY(Types.DIM(SOME(n'')), (Types.T_INTEGER([]),NONE)),NONE))

rule Ceval.ceval (env,start,impl,NONE,NONE) => (Values.REAL(startv),_) &
Expand All @@ -792,7 +797,7 @@ relation elab_range_type : (Env.Env, Exp.Exp, Exp.Exp option, Exp.Exp, bool (*co
real_int n'' => n''' &
int_add (n''',1) => n'
-------------------------------------------------
elab_range_type (env,start,NONE,stop,const as true,_,impl as false)
elab_range_type (env,start,NONE,stop,const as true,_,impl (*as false*))
=> ((Types.T_ARRAY(Types.DIM(SOME(n')), (Types.T_REAL([]),NONE)),NONE))

rule Ceval.ceval (env,start,impl,NONE,NONE) => (Values.REAL(startv),_) &
Expand All @@ -804,19 +809,21 @@ relation elab_range_type : (Env.Env, Exp.Exp, Exp.Exp option, Exp.Exp, bool (*co
real_int n''' => n'''' &
int_add (n'''',1) => n''
-------------------------------------------------
elab_range_type (env,start,SOME(step),stop,const as true,_,impl as false)
elab_range_type (env,start,SOME(step),stop,const as true,_,impl (*as false*))
=> ((Types.T_ARRAY(Types.DIM(SOME(n'')), (Types.T_REAL([]),NONE)),NONE))

(*
axiom elab_range_type (_,_,_,_,const,Exp.INT,impl as true)
=> ((Types.T_ARRAY(Types.DIM(NONE), (Types.T_INTEGER([]),NONE)),NONE))

axiom elab_range_type (_,_,_,_,const,Exp.REAL,impl as true)
=> ((Types.T_ARRAY(Types.DIM(NONE), (Types.T_REAL([]),NONE)),NONE))
*)

axiom elab_range_type (_,_,_,_,const as false,Exp.INT,impl)
axiom elab_range_type (_,_,_,_,const as false,Exp.INT,impl as true)
=> ((Types.T_ARRAY(Types.DIM(NONE), (Types.T_INTEGER([]),NONE)),NONE))

axiom elab_range_type (_,_,_,_,const as false,Exp.REAL,impl)
axiom elab_range_type (_,_,_,_,const as false,Exp.REAL,impl as true)
=> ((Types.T_ARRAY(Types.DIM(NONE), (Types.T_REAL([]),NONE)),NONE))

rule Debug.fprint("failtrace", "- elab_range_type failed: ") &
Expand Down

0 comments on commit 1f4a394

Please sign in to comment.