diff --git a/modeq/ceval.rml b/modeq/ceval.rml index 77c22f0c03d..e3ed7965497 100644 --- a/modeq/ceval.rml +++ b/modeq/ceval.rml @@ -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 *) @@ -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" *) @@ -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 @@ -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)) & @@ -2237,15 +2242,17 @@ 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 *) @@ -2253,7 +2260,7 @@ relation ceval_cref : (Env.Env, Exp.ComponentRef, bool (*impl*) ) => Values.Valu 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 @@ -2261,28 +2268,30 @@ relation ceval_cref_binding : (Env.Env, Exp.ComponentRef,Types.Binding, bool (*i (* 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 & @@ -2292,7 +2301,7 @@ 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, _) & @@ -2300,13 +2309,13 @@ 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 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 diff --git a/modeq/dae.rml b/modeq/dae.rml index 82bda243c2b..8e64a305ae1 100644 --- a/modeq/dae.rml +++ b/modeq/dae.rml @@ -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) => [] diff --git a/modeq/inst.rml b/modeq/inst.rml index bd83c984eaa..03d56717c2c 100644 --- a/modeq/inst.rml +++ b/modeq/inst.rml @@ -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, @@ -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' & @@ -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") &*) diff --git a/modeq/interactive.rml b/modeq/interactive.rml index b6e8ccbf53a..942ad567c32 100644 --- a/modeq/interactive.rml +++ b/modeq/interactive.rml @@ -3594,7 +3594,7 @@ 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 & @@ -3602,6 +3602,26 @@ relation get_annotation_string: (string,Absyn.Annotation) => string = ----------------------------------- 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 *) @@ -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 diff --git a/modeq/staticexp.rml b/modeq/staticexp.rml index b8db8938c9c..54f0fa8a7a0 100644 --- a/modeq/staticexp.rml +++ b/modeq/staticexp.rml @@ -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 @@ -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),_) & @@ -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),_) & @@ -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),_) & @@ -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: ") &