Skip to content

Commit

Permalink
Bugfixes. Cleaned up ceval_builtin.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1597 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
levsa committed Mar 21, 2005
1 parent a907482 commit 53a198f
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 166 deletions.
305 changes: 177 additions & 128 deletions modeq/ceval.rml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions modeq/env.rml
Expand Up @@ -206,7 +206,7 @@ module Env:
relation extend_frame_c : (Env, SCode.Class) => Env
relation extend_frame_classes : (Env, SCode.Program) => Env
relation extend_frame_v : (Env, Types.Var,(SCode.Element*Types.Mod) option,bool) => Env
relation update_frame_v : (Env, Types.Var,bool) => Env
relation update_frame_v : (Env, Types.Var,bool(*encapsulated*)) => Env
relation extend_frame_t : (Env,Ident,Types.Type) => Env
relation extend_frame_i : (Env, Absyn.Import) => Env
relation top_frame : Env => Frame
Expand Down Expand Up @@ -361,7 +361,7 @@ end
**)


relation update_frame_v : (Env,Types.Var,bool) => Env =
relation update_frame_v : (Env,Types.Var,bool(*encapsulated*) ) => Env =
axiom update_frame_v ([],_,i) => []

rule tree_get(ht,n,System.hash) => VAR(_,c,_) &
Expand Down
4 changes: 2 additions & 2 deletions modeq/exp.rml
Expand Up @@ -158,8 +158,8 @@ module Exp:
| RELATION of Exp * Operator * Exp (* Relation, e.g. a <= 0 *)
| IFEXP of Exp * Exp * Exp (* If expressions *)
| CALL of Absyn.Path * Exp list * bool (* tuple *) * bool (* builtin *) (* Function call *)
| ARRAY of Type * bool * Exp list (* Array constructor, e.g. {1,3,4} *)
| MATRIX of Type * int * (Exp*bool) list list (* Matrix constructor. e.g. [1,0;0,1] *)
| ARRAY of Type * bool (*scalar for codegen*) * Exp list (* Array constructor, e.g. {1,3,4} *)
| MATRIX of Type * int * (Exp*bool (*scalar*)) list list (* Matrix constructor. e.g. [1,0;0,1] *)
| RANGE of Type * Exp * Exp option * Exp (* Range constructor, e.g. 1:0.5:10 *)
| TUPLE of Exp list (*PR.*) (* Tuples, used in func calls returning several
arguments *)
Expand Down
52 changes: 26 additions & 26 deletions modeq/inst.rml
Expand Up @@ -409,7 +409,7 @@ relation instantiate_class : (SCode.Program, SCode.Path) => (DAE.DAElist,Env.Env
inst_class_decls(env,cdecls,path)=> (env',_) &
Lookup.lookup_class(env',path,true)
=> (cdef as SCode.CLASS(n,_,_,_,_), env'') &
inst_class(env'', Types.NOMOD, Prefix.NOPRE, [], cdef, [], false,TOP_CALL)
inst_class(env'', Types.NOMOD, Prefix.NOPRE, [], cdef, [], false(*impl*),TOP_CALL)
=> (dae,env'', _, _, _) &
Absyn.path_string path => pathstr
--------------------------------------------
Expand All @@ -425,7 +425,7 @@ end
relation inst_class_in_program: (Env, SCode.Program, SCode.Path ) => (DAE.Element list, Env.Env) =

rule name = name2 &
inst_class(env, Types.NOMOD, Prefix.NOPRE, [], c, [], false,TOP_CALL)
inst_class(env, Types.NOMOD, Prefix.NOPRE, [], c, [], false(*impl*),TOP_CALL)
=> (dae, env', _, _,_)
-------------------------------------------------------------
inst_class_in_program(env,(c as SCode.CLASS(name,_,_,_,_))::cs,Absyn.IDENT(name2))
Expand All @@ -451,7 +451,7 @@ end
**)
relation inst_class_decls:(Env, SCode.Program, SCode.Path) => ( Env.Env, DAE.Element list) =
rule not name = name2 &
inst_class_decl(env, Types.NOMOD, Prefix.NOPRE, [], c, [], false)
inst_class_decl(env, Types.NOMOD, Prefix.NOPRE, [], c, [], false(*packimpl*))
=> (env', dae1) &
inst_class_decls(env',cs,ref) => (env'', dae2) &
list_append(dae1,dae2) => dae
Expand All @@ -465,15 +465,15 @@ relation inst_class_decls:(Env, SCode.Program, SCode.Path) => ( Env.Env, DAE.Ele

rule name = name2 &
(* How should be do here ??? *)
inst_class_decl(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false)
inst_class_decl(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false(*packimpl*))
=> (env',dae1) &
inst_class_decls(env',cs,ref) => (env'', dae2) &
list_append(dae1,dae2) => dae
-----------------------------
inst_class_decls(env, (c as SCode.CLASS(name,_,_,_,_))::cs,ref as Absyn.QUALIFIED(name2,_)) => (env'',dae)

rule not name = name2 &
inst_class_decl(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false)
inst_class_decl(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false(*packimpl*))
=> (env',dae1) &
inst_class_decls(env',cs,ref) => (env'', dae2) &
list_append(dae1,dae2) => dae
Expand Down Expand Up @@ -535,14 +535,14 @@ relation inst_program : (Env, SCode.Program) => DAE.Element list =
Debug.fprint ("insttr", n) &
Debug.fprintln ("insttr", "") &
(* Env.extend_frame_c(env,c) => env' & *)
inst_class(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false,TOP_CALL)
inst_class(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false(*packimp*),TOP_CALL)
=> (dae,env',csets,_,_)
-----------------------------
inst_program(env,[c as SCode.CLASS(n,_,_,_,_)])
=> [DAE.COMP(n,DAE.DAE(dae))]

rule Debug.fprintln ("insttr", "inst_program2") &
inst_class_decl(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false)
inst_class_decl(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false(*packimpl*))
=> (env',dae1) &
(* Env.extend_frame_c(env,c) => env' & *)
inst_program(env',cs) => dae2 &
Expand All @@ -561,7 +561,7 @@ relation inst_program_implicit : (Env, SCode.Program) => (DAE.Element list, Env)
rule Debug.fprint ("insttr", "inst_program_implicit: ") &
Debug.fprint ("insttr", n) &
Debug.fprintln("insttr", "") &
implicit_instantiation(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false)
implicit_instantiation(env,Types.NOMOD,Prefix.NOPRE,[],c,[],false(*packimpl*))
=> (env', dae1) &
inst_program_implicit(env',cs) => (dae2, env'') &
list_append(dae1,dae2) => dae
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 (*packimpl*))
inst_class_in(env', mod, pre, csets, ci_state, c, false(*accesibility*), 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 @@ -805,7 +805,7 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
list_append(initalg,initalg2) => initalg' &
(*3. Instantiate components *)
inst_element_list(env4, mods, pre, csets, ci_state1, compelts'',
inst_dims, impl, false)
inst_dims, impl, packimpl)
=> (dae1,env5, csets1, ci_state2, tys) &
inst_list(env5,mods,pre,csets1,ci_state2,inst_equation, eqs',impl)
=> (dae2,_,csets2, ci_state3) &
Expand All @@ -822,7 +822,7 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
------------------------------------------------------
inst_classdef(env,mods,pre, csets, ci_state,
SCode.PARTS(els,eqs,initeqs,alg,initalg,_), re, prot,
inst_dims, impl, false)
inst_dims, impl, packimpl as false)
=> (dae, env5, csets5, ci_state6, tys)

(** This rule describes how to instantiate an explicit
Expand Down Expand Up @@ -858,12 +858,12 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
list_append(initalg,initalg2) => initalg' &
(*3. Instantiate components *)
inst_element_list(env3,mods,pre,csets,ci_state1, compelts',
inst_dims, impl, true)
inst_dims, impl, true(*packimpl*))
=> (dae1, env4, csets1, ci_state2, tys)
------------------------------------------------------
inst_classdef(env, mods, pre, csets, ci_state,
SCode.PARTS(els,eqs,initeqs,alg,initalg,_), re, prot,
inst_dims, impl, true)
inst_dims, impl, true(*packimpl*))
=> (dae1, env4, csets1, ci_state2, tys)


Expand All @@ -881,7 +881,7 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
ClassInf.start(r, cn2) => new_ci_state &
Mod.merge(mods,m,cenv'',pre) => mods' &
Mod.merge(mods',mod',cenv'',pre) => mods'' &
inst_class_in(cenv'', mods'', pre, csets, new_ci_state, c,prot,inst_dims,impl,false)
inst_class_in(cenv'', mods'', pre, csets, new_ci_state, c,prot,inst_dims,impl,false(*packimpl*))
=> (dae, env'', csets', ci_state', tys) &
(* Check for restriction violations *)
ClassInf.assert_valid(ci_state', re)
Expand Down Expand Up @@ -1289,7 +1289,7 @@ end
**)

relation inst_element_list : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
(SCode.Element*Types.Mod) list, InstDims, bool, bool)
(SCode.Element*Types.Mod) list, InstDims, bool(*impl*), bool(*packimpl*))
=> (DAE.Element list, Env, Connect.Sets, ClassInf.State,
Types.Var list) =

Expand Down Expand Up @@ -1711,7 +1711,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
Debug.fcall ("insttr", print, "\n") &*)
(* true in update_frame means the variable is now instantiated. *)
Env.update_frame_v(env2',Types.VAR(n,Types.ATTR(flow,acc,param,dir),
prot,ty,binding),true) => env'
prot,ty,binding),true(*encapsulated*)) => env'

(* Now we can also put the binding into the dae *)
(** If the type is one of the simple, predifined types a *)
Expand Down Expand Up @@ -1974,18 +1974,18 @@ relation inst_var2 : (Env.Env,

Util.list_map(idxs',int_string) => index_string &

Debug.fprint ("insttr", "\n ******************\n ") &
Debug.fprint ("insttr", "\n index_string ") & Debug.fprintl ("insttr", index_string) &
Debug.fprint ("insttr", "\n component ref ") & Debug.fcall ("insttr", Exp.print_component_ref,cr) &
Debug.fprint ("insttr", "\n ******************\n ") &
Debug.fprint ("insttr", "\n ") &
Debug.fprint ("insttrind", "\n ******************\n ") &
Debug.fprint ("insttrind", "\n index_string ") & Debug.fprintl ("insttr", index_string) &
Debug.fprint ("insttrind", "\n component ref ") & Debug.fcall ("insttr", Exp.print_component_ref,cr) &
Debug.fprint ("insttrind", "\n ******************\n ") &
Debug.fprint ("insttrind", "\n ") &

inst_start_binding_exp(mod,ty,idxs') => start &

(* inst_dae_variable_attributes(mod,ty,idxs') => dae_var_attr & *)
(* DAE.dump_variable_attributes_str(dae_var_attr) => str_tmp & *)
(* Debug.fprint("failtrace", str_tmp) & *)
(* Debug.fprint("failtrace", " <------------\n") & *)
(* Debug.fprint("insttr", str_tmp) & *)
(* Debug.fprint("insttr", " <------------\n") & *)
(* dae_declare(cr,ty,SCode.ATTR([], flow, acc, vt, dir), NONE, *)
(* inst_dims, start, dae_var_attr) => dae3 & *)

Expand Down Expand Up @@ -2300,14 +2300,14 @@ relation update_variable_in_env: (Types.Mod,Absyn.ComponentRef, Env.Env, ClassIn

(** Instantiate the component *)
inst_var(cenv,ci_state, mod''', Prefix.NOPRE, [], n, cl, attr,
dims, [], [], false)
dims, [], [], impl)
=> (dae1, csets', ty) &
(** The environment is extended with the new variable *)
(** binding. *)

make_binding (env2,attr,eq) => binding &
Env.update_frame_v(env2,Types.VAR(n,Types.ATTR(flow,acc,param,dir),
prot,ty,binding),false) => env'
prot,ty,binding),false(*encapsulated*)) => env'
(* & Debug.fprint("insttr","Updated variable ") &
Debug.fprint("insttr", id) &
Debug.fprint("insttr"," in env.\n ") *)
Expand Down Expand Up @@ -2369,7 +2369,7 @@ relation update_variable_in_env: (Types.Mod,Absyn.ComponentRef, Env.Env, ClassIn
make_binding (env2,attr,eq) => binding &

Env.update_frame_v(env2,Types.VAR(n,Types.ATTR(flow,acc,param,dir),
prot,ty,binding),false) => env'
prot,ty,binding),false(*encapsulated*)) => env'
------------
update_variable_in_env(mods, Absyn.CREF_QUAL(id,_,_),env,ci_state, impl)
=> env'
Expand Down
9 changes: 5 additions & 4 deletions modeq/staticexp.rml
Expand Up @@ -459,8 +459,8 @@ relation elab_exp : (Env.Env, Absyn.Exp, bool, Interactive.InteractiveSymbolTabl
elab_exp (env, Absyn.CODE(c),impl,st) => (Exp.CODE(c,tp'),Types.PROP(tp,true),st)

rule Debug.fprint("failtrace", "- elab_exp failed: ") &
Debug.fcall("failtrace", Dump.print_exp, e) &
Debug.fprint("failtrace", "\n")
Debug.fcallret("failtrace", Dump.print_exp_str, e, "") => expstr &
Debug.fprintln("failtrace", expstr)
-----------------------------------------------------------
elab_exp(_,e,_,_) => fail
end
Expand Down Expand Up @@ -832,7 +832,7 @@ relation elab_range_type : (Env.Env, Exp.Exp, Exp.Exp option, Exp.Exp, bool (*co
Util.flatten_option (s2opt,"none") => s2 &
Exp.print_exp_str stop => s3 &
Util.if(const, "const", "non-const") => s4 &
Util.if(const, "impl", "expl") => s5 &
Util.if(impl, "impl", "expl") => s5 &
Exp.type_string expty => s6 &
Util.string_append_list(["(",s1,":",s2,":",s3,") ",s4," ",s5," ",s6]) => str &
Debug.fprintln("failtrace", str)
Expand Down Expand Up @@ -1054,7 +1054,8 @@ relation elab_builtin_size : (Env.Env, Absyn.Exp list, bool (*impl*) ) => (Exp.E
---------------------------------------------------------------
elab_builtin_size (env, [arraycr], impl)
=> (exp,Types.PROP((Types.T_ARRAY(Types.DIM(SOME(1)),(Types.T_INTEGER([]),NONE)),NONE),c))
rule (*Debug.fprint("failtrace", "- elab_builtin_size failed\n")*)

rule Debug.fprint("failtrace", "- elab_builtin_size failed\n")
----------------------------------------------------------
elab_builtin_size (env,expl,impl) => fail
end
Expand Down
6 changes: 3 additions & 3 deletions modeq/test_codegen/equation_funcall12.mo
Expand Up @@ -28,12 +28,12 @@ model mo
parameter Real a=5;
parameter Real b[3]={1,2,3};
Real x1=test(a);
Real x2=size(test2(b),1);
parameter Real x2=size(test2(b),1);
// Real x3=test(size(test2(size(b,1),b),1));
Real y;
Real z;
equation
y = test(x1+x2);
z = test(test3(y));
y = test3(x1+x2);
z = test(y);
end mo;

2 changes: 1 addition & 1 deletion modeq/types.rml
Expand Up @@ -324,7 +324,7 @@ relation ndims : Type => int =
end
relation dimensions_known: Type => bool =

rule not get_dimension_sizes(tp) => _
rule get_dimension_sizes(tp) => []
-----------------------
dimensions_known(tp) => false

Expand Down

0 comments on commit 53a198f

Please sign in to comment.