Skip to content

Commit

Permalink
Bug and doc fixes
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@446 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x97davka committed Sep 23, 1998
1 parent f0df895 commit d56b33a
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 215 deletions.
6 changes: 5 additions & 1 deletion modeq/absyn.rml
Expand Up @@ -157,7 +157,11 @@ module Absyn:
datatype Subscript = NOSUB
| SUBSCRIPT of Exp
(** The `Subscript' datatype is used both in array declarations and *)
(** component references. *)
(** component references. This might seem strange, but it is *)
(** inherited from the grammar. The `NOSUB' constructor means that *)
(** the dimension size is undefined when used in a declaration, and *)
(** when it is used in a component reference it means a slice of the *)
(** whole dimension. *)

(** - Component references and paths *)
datatype ComponentRef = CREF_QUAL of Ident * (Subscript list) * ComponentRef
Expand Down
25 changes: 10 additions & 15 deletions modeq/builtin.rml
Expand Up @@ -43,18 +43,20 @@ val bool_type = SCode.CLASS("BooleanType",false,Absyn.R_PREDEFINED_BOOL,

(** - The `Real' type *)

val real_type =
SCode.CLASS("Real",false,Absyn.R_PREDEFINED_REAL,
SCode.PARTS
([(* quantity *)
SCode.COMPONENT("unit",true,false,
val unit = SCode.COMPONENT("unit",true,false,
SCode.ATTR([],
false,
SCode.RW,
Absyn.VAR,
Absyn.BIDIR),
Absyn.IDENT("StringType"),
SCode.NOMOD)],
SCode.MOD(false,[],SOME(Absyn.STRING(""))))

val real_type =
SCode.CLASS("Real",false,Absyn.R_PREDEFINED_REAL,
SCode.PARTS
([(* quantity *)
unit],
(* displayUnit *)
[],
[]))
Expand All @@ -65,14 +67,7 @@ val integer_type =
SCode.CLASS("Integer",false,Absyn.R_PREDEFINED_INT,
SCode.PARTS
([(* quantity *)
SCode.COMPONENT("unit",true,false,
SCode.ATTR([],
false,
SCode.RW,
Absyn.VAR,
Absyn.BIDIR),
Absyn.IDENT("StringType"),
SCode.NOMOD)],
unit],
(* displayUnit *)
[],
[]))
Expand All @@ -98,7 +93,7 @@ SCode.CLASS("Boolean",false,Absyn.R_PREDEFINED_BOOL,
(** - The `time' variable *)

val time_var =
Types.VAR("time", SCode.ATTR([] , false, SCode.RO, Absyn.VAR, Absyn.BIDIR),
Types.VAR("time", Types.ATTR(false, SCode.RO, Absyn.VAR, Absyn.BIDIR),
false, Types.T_REAL, Types.UNBOUND)

(** - Some assorted function types *)
Expand Down
26 changes: 14 additions & 12 deletions modeq/classinf.rml
Expand Up @@ -14,17 +14,6 @@
** `trans' signals transitions in the machine. Finally, the state
** can be checked agains a restriction with the `valid' relation.
**
** The restricted forms are ordered in a hierarchal fashion as
** described by the following diagram:
**
**| CLASS -+- TYPE --- RECORD --- CONNECTOR
**| |
**| +- BLOCK --- FUNCTION
**| |
**| +- PACKAGE
**| |
**| +- MODEL
**
**)

module ClassInf :
Expand Down Expand Up @@ -72,7 +61,10 @@ end
(** - Printing *)
(**)
(** Some relations for printing error and debug information about the *)
(** state machine. *)
(** state machine.
**
** The code is excluded from the report.
**)

(*!ignorecode*)

Expand Down Expand Up @@ -238,6 +230,13 @@ relation trans : (State, Event) => State =
end

(** relation: valid
**
** This is the validity relation which determines if a state is valid
** according to one of the restrictions. This means, that if a class
** definition is to be used as, say, a connector, the state of the
** state machine is checked against the `Absyn.R_CONNECTOR'
** restriction using this relation to find out if it is an error to
** use this class definition as a connector.
**)

relation valid : (State, Absyn.Restriction) => () =
Expand Down Expand Up @@ -279,6 +278,9 @@ relation valid : (State, Absyn.Restriction) => () =
end

(** relation: assert_valid
**
** This relation has the same semantical meaning as the relation
** `valid'. However, it prints an error message when it faild.
**)

relation assert_valid : (State, Absyn.Restriction) => () =
Expand Down
32 changes: 29 additions & 3 deletions modeq/exp.rml
Expand Up @@ -79,7 +79,7 @@ module Exp:
datatype ComponentRef = CREF_QUAL of Ident * (Subscript list) * ComponentRef
| CREF_IDENT of Ident * (Subscript list)

datatype Subscript = NOSUB
datatype Subscript = WHOLEDIM
| SLICE of Exp
| INDEX of Exp
(** the `Subscript' and `ComponentRef' datatypes are simple *)
Expand All @@ -91,6 +91,7 @@ module Exp:
relation simplify : Exp => Exp
relation print_exp : Exp => ()
relation print_component_ref : ComponentRef => ()
relation print_subscript: Subscript => ()
relation print_list : ('a list, 'a => (), string) => ()

end
Expand Down Expand Up @@ -166,7 +167,7 @@ relation simplify : Exp => Exp =
simplify ASUB(e, i) => IFEXP(c,t',f')

rule simplify e => CREF(CREF_IDENT(n,s)) &
list_append(s,[INDEX(ICONST(i))]) => s'
subscripts_append(s,i) => s'
------------------------
simplify ASUB(e, i) => CREF(CREF_IDENT(n,s'))

Expand All @@ -179,6 +180,31 @@ relation simplify : Exp => Exp =

end

(** relation: subscripts_append
**
** This relation takes a subscript list and adds a new subscript.
** But there are a few special cases. When the last existing
** subscript is a slice, it is replaced by the slice indexed by the
** new subscript.
**)

relation subscripts_append : (Subscript list, int) => Subscript list =

axiom subscripts_append([], i) => [INDEX(ICONST(i))]

axiom subscripts_append([WHOLEDIM], i) => [INDEX(ICONST(i))]

rule simplify ASUB(e, i) => e'
-------------------------
subscripts_append([SLICE(e)], i) => [INDEX(e')]

axiom subscripts_append([s as INDEX(_)], i) => [s, INDEX(ICONST(i))]

rule subscripts_append(ss, i) => ss'
-------------------------------
subscripts_append(s::ss, i) => s::ss'

end

(**
** - Printing expressions
Expand Down Expand Up @@ -256,7 +282,7 @@ relation print_subscript: Subscript => () =

rule print ":"
---------
print_subscript(NOSUB)
print_subscript(WHOLEDIM)

rule print_exp(e1)
-------------
Expand Down
62 changes: 38 additions & 24 deletions modeq/inst.rml
Expand Up @@ -406,7 +406,8 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
(** binding. *)

make_binding (env,attr,eq,cl) => binding &
Env.extend_frame_v(env,Types.VAR(n,attr,prot,ty,binding)) => env' &
Env.extend_frame_v(env,Types.VAR(n,Types.ATTR(flow,acc,param,dir),
prot,ty,binding)) => env' &

(** If the type is one of the simple, predifined types a *)
(** simple variable declaration is added to the DAE. *)
Expand All @@ -421,8 +422,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
attr as SCode.ATTR(ad,flow,acc,param,dir),
t,m))
=> (dae, env',csets',ci_state,
[Types.VAR(n,SCode.ATTR([],flow,acc,param,dir),
prot, ty, binding)])
[Types.VAR(n,Types.ATTR(flow,acc,param,dir), prot, ty, binding)])


(** If the class lookup in the previous rule fails, this
Expand Down Expand Up @@ -478,7 +478,8 @@ relation inst_var : (Env.Env,Mod.Mod,Prefix.Prefix,Connect.Sets,Ident,
eq,[],idxs)
=> (dae,csets',ty)

rule inst_array(env,mod,pre,csets,n,(cl,attr),1,dim,dims,idxs)
rule print "= inst_array mod: " & print n & Mod.print_mod mod & print "\n" &
inst_array(env,mod,pre,csets,n,(cl,attr),1,dim,dims,idxs)
=> (dae, csets', ty) &
Types.lift_array(ty,SOME(dim)) => ty'
-------------------------------
Expand Down Expand Up @@ -754,8 +755,7 @@ relation add_package : (Env.Env, Absyn.Ident, Types.Type, ClassInf.State,

rule ClassInf.valid(st, Absyn.R_PACKAGE) &
Env.extend_frame_v(env,
Types.VAR(n, SCode.ATTR([],
false,SCode.RO,Absyn.CONST,
Types.VAR(n, Types.ATTR(false,SCode.RO,Absyn.CONST,
Absyn.BIDIR),
false,
ty,Types.UNBOUND)) => env'
Expand Down Expand Up @@ -909,9 +909,13 @@ relation inst_equation : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
**
** The loop expression is evaluated to a constant array of
** integers, and then the loop is unrolled.
**
**)

rule Static.elab_exp (env,e)
rule Lookup.lookup_var(env, Exp.CREF_IDENT(i,[]))
=> (Types.ATTR(false, SCode.RW, Absyn.VAR, _),
Types.T_INTEGER, Types.UNBOUND) &
Static.elab_exp (env,e)
=> (e',Static.PROP(Types.T_ARRAY(Types.DIM(_),
Types.T_INTEGER),
true)) &
Expand All @@ -923,6 +927,14 @@ relation inst_equation : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
inst_equation(env,mod,pre,csets,ci_state,SCode.EQ_FOR(i,e,el))
=> (dae, env,csets', ci_state')

rule not Lookup.lookup_var(env, Exp.CREF_IDENT(i,[]))
=> (Types.ATTR(false, SCode.RW, Absyn.VAR, _),
Types.T_INTEGER, Types.UNBOUND) &
print "# Invalid loop variable: " & print i & print "\n"
-----------------------------------------------------------
inst_equation(env,mod,pre,csets,ci_state,SCode.EQ_FOR(i,e,el))
=> fail

rule print "- inst_equation failed\n"
----------------------------------
inst_equation(_,_,_,_,_,_) => fail
Expand Down Expand Up @@ -987,6 +999,9 @@ relation inst_eq_equation_2 : (Exp.Exp, Exp.Exp, Types.Type)
=> [DAE.EQUATION(e1,e2)]

rule RTOpts.split_arrays => true &
print " Array equation: " &
Exp.print_exp e1 & print " = " &
Exp.print_exp e2 & print "\n" &
inst_array_equation(e1,e2,ad,t) => dae
-----------------------------------------
inst_eq_equation_2(e1,e2,Types.T_ARRAY(ad,t)) => dae
Expand Down Expand Up @@ -1142,8 +1157,7 @@ relation unroll : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,

rule Env.open_scope env => env' &
Env.extend_frame_v (env',
Types.VAR(i, SCode.ATTR([],
false,
Types.VAR(i, Types.ATTR(false,
SCode.RO,
Absyn.CONST,
Absyn.BIDIR),
Expand Down Expand Up @@ -1270,7 +1284,7 @@ relation inst_connect: (Connect.Sets, Env, Prefix,
Static.canon_cref(env, c1') => c1'' &
Static.canon_cref(env, c2') => c2'' &
Lookup.lookup_var_local(env,c1'')
=> (attr1 as SCode.ATTR(_,flow1,_,_,_),ty1,_) &
=> (attr1 as Types.ATTR(flow1,_,_,_),ty1,_) &
Lookup.lookup_var_local(env,c2'') => (attr2,ty2,_) &

(** Check that the types of the connectors are good. *)
Expand Down Expand Up @@ -1320,45 +1334,45 @@ end
**)

relation check_connect_types : (Exp.ComponentRef, Types.Type,
SCode.Attributes,
Types.Attributes,
Exp.ComponentRef, Types.Type,
SCode.Attributes) => () =
Types.Attributes) => () =

rule print "# Can't connect two input variables\n" &
print " while connecting " & Exp.print_component_ref c1 &
print " to " & Exp.print_component_ref c2 & print "\n"
------------------------------------------------------
check_connect_types(c1,_,SCode.ATTR(_,_,_,_,Absyn.INPUT),
c2,_,SCode.ATTR(_,_,_,_,Absyn.INPUT)) => fail
check_connect_types(c1,_,Types.ATTR(_,_,_,Absyn.INPUT),
c2,_,Types.ATTR(_,_,_,Absyn.INPUT)) => fail

rule print "# Can't connect two output variables\n" &
print " while connecting " & Exp.print_component_ref c1 &
print " to " & Exp.print_component_ref c2 & print "\n"
------------------------------------------------------
check_connect_types(c1,_,SCode.ATTR(_,_,_,_,Absyn.OUTPUT),
c2,_,SCode.ATTR(_,_,_,_,Absyn.OUTPUT)) => fail
check_connect_types(c1,_,Types.ATTR(_,_,_,Absyn.OUTPUT),
c2,_,Types.ATTR(_,_,_,Absyn.OUTPUT)) => fail

rule flow1 = flow2 &
Types.equivtypes(t1, t2) => true
-------------------------------
check_connect_types(_,t1,SCode.ATTR(_,flow1,_,_,_),
_,t2,SCode.ATTR(_,flow2,_,_,_))
check_connect_types(_,t1,Types.ATTR(flow1,_,_,_),
_,t2,Types.ATTR(flow2,_,_,_))

rule print "# Can't connect flow component " &
Exp.print_component_ref c1 &
print " to non-flow component " &
Exp.print_component_ref c2 & print "\n"
------------------------------------------------------
check_connect_types(c1,_,SCode.ATTR(_,true,_,_,_),
c2,_,SCode.ATTR(_,false,_,_,_)) => fail
check_connect_types(c1,_,Types.ATTR(true,_,_,_),
c2,_,Types.ATTR(false,_,_,_)) => fail

rule print "# Can't connect non-flow component " &
Exp.print_component_ref c1 &
print " to flow component " &
Exp.print_component_ref c2 & print "\n"
------------------------------------------------------
check_connect_types(c1,_,SCode.ATTR(_,false,_,_,_),
c2,_,SCode.ATTR(_,true,_,_,_)) => fail
check_connect_types(c1,_,Types.ATTR(false,_,_,_),
c2,_,Types.ATTR(true,_,_,_)) => fail

rule print "- check_connect_types(" & Exp.print_component_ref c1 &
print " <-> " & Exp.print_component_ref c2 & print ") failed\n"
Expand Down Expand Up @@ -1446,9 +1460,9 @@ relation connect_vars : (Connect.Sets,
connect_vars(sets',c1,f1,xs1,c2,f2,xs2) => sets''
--------------------------------------
connect_vars(sets,
c1,f1, Types.VAR(n,attr1 as SCode.ATTR(_,flow1,_,vt1,_),
c1,f1, Types.VAR(n,attr1 as Types.ATTR(flow1,_,vt1,_),
_,ty1,_)::xs1,
c2,f2, Types.VAR(_,attr2 as SCode.ATTR(_,flow2,_,vt2,_),
c2,f2, Types.VAR(_,attr2 as Types.ATTR(flow2,_,vt2,_),
_,ty2,_)::xs2)
=> sets''

Expand Down

0 comments on commit d56b33a

Please sign in to comment.