Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@292 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x97davka committed Jun 23, 1998
1 parent bfbd36a commit 1a63d12
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 123 deletions.
7 changes: 4 additions & 3 deletions modeq/ast/modgram.g
Expand Up @@ -232,7 +232,8 @@ class_definition[bool is_replaceable,bool is_final] :
restr, Absyn__PARTS(sibling_list(#c)));
>>
| EQUALS dp:name_path
{ da:array_dimensions << has_array_dim=true; >> }
/* FIXME: grammar says array_dimensions */
{ da:array_subscripts << has_array_dim=true; >> }
{ ds:class_modification << has_class_spec=true; >> }
<<
Attrib a = $[CLASS_,"---"];
Expand All @@ -243,7 +244,7 @@ class_definition[bool is_replaceable,bool is_final] :
Absyn__DERIVED(#dp->rml,
(has_array_dim
? #da->rml
: Absyn__NODIM),
: mk_nil()),
(has_class_spec
? #ds->rml
: mk_nil())));
Expand Down Expand Up @@ -364,7 +365,7 @@ declaration :
{ a:array_subscripts }
{ m:modification }
<< #i->rml = Absyn__COMPONENT(mk_scon($i.u.stringval),
#a ? #a->rml : Absyn__NODIM,
#a ? #a->rml : mk_nil(),
#m ? mk_some(#m->rml) : mk_none()); >>
;

Expand Down
2 changes: 1 addition & 1 deletion modeq/builtin.rml
Expand Up @@ -96,7 +96,7 @@ SCode.CLASS("Boolean",false,Absyn.R_PREDEFINED_BOOL,
(* FIXME: Shuold contain components (attributes) from the real Real type *)
val time_var =
Env.FRAMEVAR("time", Absyn.ATTR([] , false, Absyn.VAR, Absyn.BIDIR),
Types.TYPE(ClassInf.TYPE_REAL("time"), []), Env.UNBOUND)
Types.T_COMPLEX(ClassInf.TYPE_REAL("time"), []), Env.UNBOUND)

(** - Initial environment *)

Expand Down
129 changes: 82 additions & 47 deletions modeq/inst.rml
Expand Up @@ -353,7 +353,7 @@ relation inst_element: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,

Lookup.lookup_class(env,t) => cl &
Mod.lookup_modification_p(mods,t) => classmod &
Mod.lookup_modification(mods,n) => mm &
Mod.lookup_modification(mods,n,[(*FIXME*)]) => mm &
print " mod 1: " & SCode.print_mod classmod & print "\n" &
print " mod 2: " & SCode.print_mod mm & print "\n" &
print " mod 3: " & SCode.print_mod m & print "\n" &
Expand All @@ -374,7 +374,8 @@ relation inst_element: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
elab_arraydim(env,ad,eq) => dims &

(** Instantiate the component *)
inst_var(env,mod',pre,csets,cl,eq,dims) => (dae1,env',csets',vs,bty) &
inst_var(env,mod',pre,csets,n,cl,eq,dims,[])
=> (dae1,csets',[ty]) &

(** The environment is extended with the new variable *)
(** binding. *)
Expand All @@ -397,8 +398,10 @@ relation inst_element: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
-----------------------------------------------------------
inst_element(env,mods,pre,csets,ci_state,
SCode.COMPONENT(n,final,prot,
attr as Absyn.ATTR(ad,_,_,_),t,m))
=> (dae, env',csets',ci_state,[v])
attr as Absyn.ATTR(ad,flow,param,dir),
t,m))
=> (dae, env',csets',ci_state,
[Types.VAR(n,Absyn.ATTR([],flow,param,dir), ty,eq)])


(** If the class lookup in the previous rule fails, this
Expand All @@ -424,75 +427,72 @@ relation inst_element: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
end

relation inst_var : (Env.Env,SCode.Mod,Prefix.Prefix,Connect.Sets,Ident,
SCode.Class,Absyn.Exp option,int list,
bool,Absyn.VarType,Absyn.Direction,int list)
=> (DAE.DAEcomp list,Connect.Sets,Types.Var list) =
SCode.Class,Absyn.Exp option,int list, int list)
=> (DAE.DAEcomp list,Connect.Sets,Types.Type list) =

rule (** The class is instantiated with the calculated *)
(** modification, and an extended prefix. *)

list_reverse idxs => idxs' &
(* Prefix.prefix_add(n,idxs,pre) => pre' & *)
let pre' = pre &
Prefix.prefix_add(n,idxs,pre) => pre' &
(* let pre' = pre & *)

(* FIXME: Redeclarations! *)

inst_class(env,mod,pre',csets,cl) => (dae,csets',ty,st)
--------------------------
inst_var(env,mod,pre,csets,n,cl,eq,[],flow,param,dir,idxs)
=> (dae,csets',[Types.VAR(n,Absyn.ATTR(Absyn.NODIM,flow,param,dir),
ty,eq)])
inst_var(env,mod,pre,csets,n,cl,eq,[],idxs)
=> (dae,csets',[ty])

rule inst_array(env,mod,pre,csets,n,cl,flow,param,dir,1,dim,dims,idxs)
=> (dae, csets', vs)
rule inst_array(env,mod,pre,csets,n,cl,1,dim,dims,idxs)
=> (dae, csets', tys)
--------------------------
inst_var(env,mod,pre,csets,n,cl,eq,dim::dims,flow,param,dir,idxs)
=> (dae,csets',vs)
inst_var(env,mod,pre,csets,n,cl,eq,dim::dims,idxs)
=> (dae,csets',tys)


end

relation inst_array : (Env.Env,SCode.Mod,Prefix.Prefix,Connect.Sets,Ident,
SCode.Class,bool,Absyn.VarType,Absyn.Direction,
int,int,int list,int list)
=> (DAE.DAEcomp list,Connect.Sets,Types.Var list) =
SCode.Class,int,int,int list,int list)
=> (DAE.DAEcomp list,Connect.Sets,Types.Type list) =

rule int_gt(i,stop) => true
----------------------
inst_array(env,mod,pre,csets,n,cl,f,p,d,i,stop,dims,idxs)
inst_array(env,mod,pre,csets,n,cl,i,stop,dims,idxs)
=> ([], csets, [])

rule inst_var(env,mod,pre,csets,n,cl,NONE(*FIXME*),dims,f,p,d,i::idxs)
rule inst_var(env,mod,pre,csets,n,cl,NONE(*FIXME*),dims,i::idxs)
=> (dae1,csets',v1) &
int_add(i,1) => i' &
inst_array(env,mod,pre,csets',n,cl,f,p,d,i',stop,dims,idxs)
inst_array(env,mod,pre,csets',n,cl,i',stop,dims,idxs)
=> (dae2, csets'',v2) &
list_append(dae1,dae2) => dae &
list_append(v1,v2) => vs
list_append(v1,v2) => tys
-----------------------------
inst_array(env,mod,pre,csets,n,cl,f,p,d,i,stop,dims,idxs)
=> (dae,csets'',vs)
inst_array(env,mod,pre,csets,n,cl,i,stop,dims,idxs)
=> (dae,csets'',tys)

end

relation elab_arraydim : (Env.Env, Absyn.ArrayDim, Absyn.Exp option)
=> int list =

rule elab_arraydim_decl(env,ad) => dim1 &
complete_arraydim(dim1)
rule elab_arraydim_decl(env,ad) => dim &
complete_arraydim(dim) => dim'
---------------------------------
elab_arraydim(env,ad,NONE) => dim1
elab_arraydim(env,ad,NONE) => dim'

rule elab_arraydim_decl(env,ad) => dim1 &
StaticExp.elab_exp(env, d) => (e,t,c) &
StaticExp.elab_exp(env, exp) => (e,t,c) &
elab_arraydim_type(t) => dim2 &
compatible_dim(dim1,dim2) => dim3
compatible_arraydim(dim1,dim2) => dim3
---------------------------------
elab_arraydim(env,ad,SOME(exp)) => dim3

rule print "- elab_arraydim failed\n"
-------------------------------------
elab_arraydim_decl(_,_,_) => fail
elab_arraydim(_,_,_) => fail

end

Expand All @@ -516,7 +516,37 @@ relation elab_arraydim_decl : (Env.Env, Absyn.ArrayDim) => (int option) list =

end

relation elab_arraydim_type : Types.BasicType => (int option) list =
relation complete_arraydim : (int option) list => int list =

axiom complete_arraydim [] => []

rule complete_arraydim xs => xs'
---------------------------
complete_arraydim SOME(x)::xs => x::xs'

end

relation compatible_arraydim : ((int option) list,(int option) list)
=> int list =

axiom compatible_arraydim([],[]) => []

rule compatible_arraydim(xs,ys) => l
-------------------------------
compatible_arraydim(SOME(x)::xs,NONE::ys) => x::l

rule compatible_arraydim(xs,ys) => l
-------------------------------
compatible_arraydim(NONE::xs,SOME(y)::ys) => y::l

rule x = y &
compatible_arraydim(xs,ys) => l
-------------------------------
compatible_arraydim (SOME(x)::xs,SOME(y)::ys) => x::l

end

relation elab_arraydim_type : Types.Type => (int option) list =

rule elab_arraydim_type2(d) => l
---------------------------
Expand Down Expand Up @@ -740,7 +770,7 @@ end
** Instantiate an assertion.
**)

relation inst_assertion : (Env.Env, Exp.Exp, Types.BasicType,
relation inst_assertion : (Env.Env, Exp.Exp, Types.Type,
bool, string, Prefix)
=> DAE.DAEcomp list =

Expand Down Expand Up @@ -785,7 +815,7 @@ relation unroll : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
false,
Absyn.CONST,
Absyn.BIDIR),
Types.TYPE(ClassInf.TYPE_INTEGER
Types.T_COMPLEX(ClassInf.TYPE_INTEGER
("<for loop>"),[]),
Env.VALBOUND(fst))) => env'' &
inst_list(env'',mods,pre,csets,ci_state,inst_equation, eqs)
Expand Down Expand Up @@ -835,9 +865,9 @@ relation inst_connect: (Connect.Sets, Env, Prefix,
StaticExp.canon_cref(env, c1') => c1'' &
StaticExp.canon_cref(env, c2') => c2'' &
Lookup.lookup_var_local(env,c1'')
=> (Absyn.ATTR(_,_,_,_),ty1 as Types.TYPE(st1,_),_) &
=> (Absyn.ATTR(_,_,_,_),ty1 as Types.T_COMPLEX(st1,_),_) &
Lookup.lookup_var_local(env,c2'')
=> (Absyn.ATTR(_,_,_,_),ty2 as Types.TYPE(st2,_),_) &
=> (Absyn.ATTR(_,_,_,_),ty2 as Types.T_COMPLEX(st2,_),_) &
check_connect_vars(c1'',ty1,con1,c2'',ty2,con2) &
ClassInf.assert_valid(st1,Absyn.R_CONNECTOR) &
ClassInf.assert_valid(st2,Absyn.R_CONNECTOR) &
Expand All @@ -856,10 +886,8 @@ end
relation check_connect_vars : (Exp.ComponentRef, Types.Type, bool,
Exp.ComponentRef, Types.Type, bool) => () =

rule Types.simplify_type t1 => t1' &
Types.simplify_type t2 => t2' &
Types.same_type(t1', t2') => true
-----------------------
rule Types.same_type(t1, t2) => true
-------------------------------
check_connect_vars(_,t1,false,_,t2,false)

rule print "# Can't connect " & Exp.print_component_ref c1 &
Expand Down Expand Up @@ -889,7 +917,7 @@ relation connect_components: (Connect.Sets,
print "\n" & *)
Connect.add_flow(sets, c1', f1, c2', f2) => sets'
-----------------------------------------
connect_components(sets, pre, c1, f1, c2, f2, Types.TYPE(st,_), true)
connect_components(sets, pre, c1, f1, c2, f2, Types.T_COMPLEX(st,_), true)
=> sets'

(* non-flow type *)
Expand All @@ -903,7 +931,7 @@ relation connect_components: (Connect.Sets,
print "\n" & *)
Connect.add_equ(sets, c1', c2') => sets'
-----------------------------------------
connect_components(sets, pre, c1, _, c2, _, Types.TYPE(st,_), false)
connect_components(sets, pre, c1, _, c2, _, Types.T_COMPLEX(st,_), false)
=> sets'

(* Not a TYPE *)
Expand All @@ -916,7 +944,7 @@ relation connect_components: (Connect.Sets,
print "\n" & *)
connect_vars(sets,c1',f1,c2',f2, l) => sets'
----------------------------------------
connect_components(sets,pre,c1,f1,c2,f2,Types.TYPE(_,l),_) => sets'
connect_components(sets,pre,c1,f1,c2,f2,Types.T_COMPLEX(_,l),_) => sets'

end

Expand Down Expand Up @@ -949,7 +977,12 @@ end

relation mktype : (ClassInf.State,Types.Var list) => Types.Type =

axiom mktype(st,l) => Types.TYPE(st,l)
axiom mktype(ClassInf.TYPE_INTEGER(_),_) => Types.T_INTEGER
axiom mktype(ClassInf.TYPE_REAL(_),_) => Types.T_REAL
axiom mktype(ClassInf.TYPE_STRING(_),_) => Types.T_STRING
axiom mktype(ClassInf.TYPE_BOOL(_),_) => Types.T_BOOL

axiom mktype(st,l) => Types.T_COMPLEX(st,l)

end

Expand Down Expand Up @@ -1095,7 +1128,7 @@ relation make_binding : (Env.Env, Absyn.VarAttr, Absyn.Exp option, SCode.Class)
end

relation make_const_binding : (Env.Env, Exp.Exp,
Types.BasicType, Types.BasicType, bool)
Types.Type, Types.Type, bool)
=> Env.Binding =

(* Cast the value to real if necessary *)
Expand All @@ -1122,13 +1155,15 @@ relation make_const_binding : (Env.Env, Exp.Exp,

end

relation class_type : SCode.Class => Types.BasicType =
relation class_type : SCode.Class => Types.Type =

axiom class_type SCode.CLASS(_,_,Absyn.R_PREDEFINED_INT,_) => Types.T_INTEGER
axiom class_type SCode.CLASS(_,_,Absyn.R_PREDEFINED_STRING,_)
=> Types.T_STRING
axiom class_type SCode.CLASS(_,_,Absyn.R_PREDEFINED_REAL,_) => Types.T_REAL
axiom class_type SCode.CLASS(_,_,Absyn.R_PREDEFINED_BOOL,_) => Types.T_BOOL
axiom class_type _ => Types.T_COMPLEX([(* FIXME *)])

(* FIXME: Should instantiate the class *)
axiom class_type _ => Types.T_COMPLEX(ClassInf.UNKNOWN("---"),[(* FIXME *)])

end
4 changes: 2 additions & 2 deletions modeq/main.rml
Expand Up @@ -21,10 +21,10 @@ relation main =

print "\n = Instantiating\n\n" &
Inst.instantiate(p') => d &
print "\nResult:\n\n" &
print "\n[result]\n\n" &
DAE.dump d &

print "\n[slut]\n"
print "\n[end result]\n"
----------------
main [f]

Expand Down
26 changes: 22 additions & 4 deletions modeq/prefix.rml
Expand Up @@ -13,9 +13,9 @@ module Prefix:
with "lookup.rml"

datatype Prefix = NOPRE
| PRE of string * Exp.Subscript list * Prefix
| PRE of string * int list * Prefix

relation prefix_add : (Exp.Ident, Exp.Subscript list, Prefix) => Prefix
relation prefix_add : (Exp.Ident, int list, Prefix) => Prefix
relation prefix_cref : (Prefix, Exp.ComponentRef) => Exp.ComponentRef
relation prefix_exp : (Env.Env,Exp.Exp,Prefix) => Exp.Exp
relation prefix_path : (Absyn.Path,Prefix) => Absyn.Path
Expand All @@ -31,7 +31,7 @@ end
** normal order used when displaying them.
**)

relation prefix_add : (Exp.Ident, Exp.Subscript list, Prefix) => Prefix =
relation prefix_add : (Exp.Ident, int list, Prefix) => Prefix =

axiom prefix_add(i,s,p) => PRE(i,s,p)

Expand Down Expand Up @@ -63,12 +63,30 @@ relation prefix_cref : (Prefix, Exp.ComponentRef) => Exp.ComponentRef =

axiom prefix_cref (NOPRE, cref) => cref

rule prefix_cref(xs, Exp.CREF_QUAL(i,s,cref)) => cref'
rule subscript_list s => s' &
prefix_cref(xs, Exp.CREF_QUAL(i,s',cref)) => cref'
---------------------------------
prefix_cref (PRE(i,s,xs), cref) => cref'

end

(** relation: subscript_list
**
** This relations describes the relation between a list of integers
** and a list of `Exp.Subscript' where each integer is converted to
** an integer constant expression.
**)

relation subscript_list : int list => Exp.Subscript list =

axiom subscript_list [] => []

rule subscript_list xs => xs'
------------------------
subscript_list x::xs => Exp.SUB1(Exp.ICONST(x))::xs'

end

(** relation: prefix_exp
**
** Add the supplied prefix to all component references in an
Expand Down

0 comments on commit 1a63d12

Please sign in to comment.