Skip to content

Commit

Permalink
Added several operators and fixed several bugs. EvapIOTest example fr…
Browse files Browse the repository at this point in the history
…om Ruediger Franke now works (174 seconds)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@987 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jun 16, 2003
1 parent da87e92 commit d100b1b
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 119 deletions.
56 changes: 50 additions & 6 deletions modeq/algorithm.rml
Expand Up @@ -45,6 +45,7 @@ module Algorithm:
(** It is simple a list of algorithm statements. *)

datatype Statement = ASSIGN of Exp.Type * Exp.ComponentRef * Exp.Exp
| TUPLE_ASSIGN of Exp.Type * Exp.Exp list * Exp.Exp
| ASSIGN_ARR of Exp.Type * Exp.ComponentRef * Exp.Exp
| IF of Exp.Exp * Statement list * Else
| FOR of Exp.Type * bool * Ident * Exp.Exp * Statement list
Expand All @@ -66,6 +67,9 @@ module Algorithm:
Exp.Exp, Types.Properties,
SCode.Accessibility) => Statement

relation make_tuple_assignment : (Exp.Exp list, Types.Properties list,
Exp.Exp, Types.Properties) => Statement

relation make_if : (Exp.Exp,
Types.Properties,
Statement list,
Expand All @@ -86,10 +90,10 @@ module Algorithm:

end




with "util.rml"
with "print.rml"
with "dump.rml"
with "debug.rml"

(** relation: make_assignment
**
Expand Down Expand Up @@ -129,7 +133,7 @@ predicate
make_assignment(Exp.CREF(c,crt), lhprop,
rhs, rhprop, _) => ASSIGN(t,c,rhs')

rule Types.is_prop_const (lhprop) => false &
rule Types.is_prop_const (lhprop) => false &
Types.match_prop(rhs, rhprop, lhprop) => rhs' &
Types.is_prop_array lhprop => true &
get_prop_exp_type lhprop => t
Expand All @@ -156,6 +160,43 @@ rule Types.is_prop_const (lhprop) => false &

end

(** relation: make_tuple_assignment
**
** This relation creates an `TUPLE_ASSIGN' construct, and checks that the
** assignment is semantically valid, which means that the component
** being assigned is not constant, and that the types match.
**)

relation make_tuple_assignment : (Exp.Exp list, Types.Properties list,
Exp.Exp, Types.Properties) => Statement =

rule Util.list_map(lprop, Types.is_prop_const) => bvals &
Util.bool_or_list(bvals) => true &
Print.print_buf "# Trying to assign to constant component in tuple assignment\n" &
Print.print_buf " " &
Dump.print_list(lhs, Exp.print_exp, ", ") &
Print.print_buf " := " & Exp.print_exp rhs & Print.print_buf "\n"
-------------------------------------------
make_tuple_assignment (lhs,lprop,rhs,rprop) => fail

rule Util.list_map(lhprops, Types.is_prop_const) => bvals &
Util.bool_or_list(bvals) => false &
Util.list_map(lhprops,Types.get_prop_type) => lhrtypes &
Types.match_type_list(rhs,tpl,lhrtypes) => (rhs',_)
(* Don't use the new rhs', since type conversions of several output args
are not clearly defined. *)
----------------------------------------------
make_tuple_assignment(expl, lhprops,
rhs, Types.PROP_TUPLE(Types.T_TUPLE(tpl),Types.TUPLE_CONST(clist)))
=> TUPLE_ASSIGN(Exp.OTHER,expl,rhs)

rule Debug.fprint("failtrace", "- make_tuple_assignment failed\n")
-------------------------------------------
make_tuple_assignment (lhs,lprop,rhs,rprop) => fail

end


relation get_prop_exp_type : Types.Properties => Exp.Type =

rule Types.get_prop_type p => ty &
Expand All @@ -176,7 +217,7 @@ relation get_type_exp_type : Types.Type => Exp.Type =
------------------------
get_type_exp_type Types.T_ARRAY(_,t) => t'

axiom get_type_exp_type _ => fail
axiom get_type_exp_type _ => Exp.OTHER (*was fail but records must be handled somehow *)

end

Expand Down Expand Up @@ -272,8 +313,11 @@ relation make_when_a : (Exp.Exp, Types.Properties,

axiom make_when_a(e,Types.PROP(Types.T_BOOL(_),_),stmts) => WHEN(e,stmts)

axiom make_when_a(e,Types.PROP(Types.T_ARRAY(_,Types.T_BOOL(_)),_),stmts) => WHEN(e,stmts)


rule Print.print_buf "# Type error in when conditional.\n" &
Print.print_buf " Expected Boolean, got " &
Print.print_buf " Expected Boolean scalar or vector, got " &
Types.print_type t & Print.print_buf "\n"
-------------------------------
make_when_a(_,Types.PROP(t,_),_) => fail
Expand Down
42 changes: 37 additions & 5 deletions modeq/builtin.rml
Expand Up @@ -253,18 +253,34 @@ Types.VAR("time", Types.ATTR(false, SCode.RO, SCode.VAR, Absyn.BIDIR),
val nil2real = Types.T_FUNCTION([],
Types.T_REAL([]))

val nil2bool = Types.T_FUNCTION([],
Types.T_REAL([]))

val real2real = Types.T_FUNCTION([("x",Types.T_REAL([]))],
Types.T_REAL([]))

val real2int = Types.T_FUNCTION([("x",Types.T_REAL([]))],
Types.T_INTEGER([]))

val int2real = Types.T_FUNCTION([("x",Types.T_INTEGER([]))],
Types.T_REAL([]))

val real_real2real = Types.T_FUNCTION([("x",Types.T_REAL([])),("y",Types.T_REAL([]))],
Types.T_REAL([]))

val int2int = Types.T_FUNCTION([("x",Types.T_INTEGER([]))],
Types.T_INTEGER([]))

val int_int2int = Types.T_FUNCTION([("x",Types.T_INTEGER([])),("y",Types.T_INTEGER([]))],
Types.T_INTEGER([]))

val bool2bool = Types.T_FUNCTION([("x",Types.T_BOOL([]))],
Types.T_BOOL([]))

val string2string = Types.T_FUNCTION([("x",Types.T_STRING([]))],
Types.T_STRING([]))


val real_real2bool = Types.T_FUNCTION([("x",Types.T_REAL([])),("y",Types.T_REAL([]))],
Types.T_BOOL([]))

Expand Down Expand Up @@ -924,6 +940,10 @@ Env.extend_frame_t(env, "scalar", array1dimint2int) => env &
Env.extend_frame_t(env, "identity", int2array6dimint) => env &
Env.extend_frame_t(env, "identity", int2array7dimint) => env &
Env.extend_frame_t(env, "identity", int2array8dimint) => env &

Env.extend_frame_t(env, "initial", nil2bool) => env &

Env.extend_frame_t(env, "terminal", nil2bool) => env &

Env.extend_frame_t(env, "diagonal", array1dimint2matrixint) => env &
Env.extend_frame_t(env, "diagonal", array1dimreal2matrixreal) => env &
Expand Down Expand Up @@ -976,6 +996,8 @@ Env.extend_frame_t(env, "scalar", array1dimint2int) => env &
*)

Env.extend_frame_t(env, "linspace", int_int2vectorreal) => env &
Env.extend_frame_t(env, "min", int_int2int) => env &
Env.extend_frame_t(env, "min", real_real2real) => env &
Env.extend_frame_t(env, "min", array1dimint2int) => env &
Env.extend_frame_t(env, "min", array2dimint2int) => env &
Env.extend_frame_t(env, "min", array3dimint2int) => env &
Expand All @@ -994,6 +1016,8 @@ Env.extend_frame_t(env, "scalar", array1dimint2int) => env &
Env.extend_frame_t(env, "min", array7dimreal2real) => env &
Env.extend_frame_t(env, "min", array8dimreal2real) => env &

Env.extend_frame_t(env, "max", int_int2int) => env &
Env.extend_frame_t(env, "max", real_real2real) => env &
Env.extend_frame_t(env, "max", array1dimint2int) => env &
Env.extend_frame_t(env, "max", array2dimint2int) => env &
Env.extend_frame_t(env, "max", array3dimint2int) => env &
Expand All @@ -1011,6 +1035,8 @@ Env.extend_frame_t(env, "scalar", array1dimint2int) => env &
Env.extend_frame_t(env, "max", array6dimreal2real) => env &
Env.extend_frame_t(env, "max", array7dimreal2real) => env &
Env.extend_frame_t(env, "max", array8dimreal2real) => env &

Env.extend_frame_t(env, "noEvent", real2real) => env &

Env.extend_frame_t(env, "sum", array1dimint2int) => env &
Env.extend_frame_t(env, "sum", array2dimint2int) => env &
Expand Down Expand Up @@ -1049,6 +1075,10 @@ Env.extend_frame_t(env, "scalar", array1dimint2int) => env &
Env.extend_frame_t(env, "product", array7dimreal2real) => env &
Env.extend_frame_t(env, "product", array8dimreal2real) => env &

Env.extend_frame_t(env, "pre", real2real) => env &
Env.extend_frame_t(env, "pre", int2int) => env &
Env.extend_frame_t(env, "pre", bool2bool) => env &
Env.extend_frame_t(env, "pre", string2string) => env &

Env.extend_frame_t(env, "symmetric", array1dimint2array1dimint) => env &
Env.extend_frame_t(env, "symmetric", array2dimint2array2dimint) => env &
Expand Down Expand Up @@ -1087,12 +1117,14 @@ Env.extend_frame_t(env, "scalar", array1dimint2int) => env &
Env.extend_frame_t(env, "symmetric", array8dimbool2array8dimbool) => env &


Env.extend_frame_t(env, "cross", array1dimint2array1dimint) => env &
Env.extend_frame_t(env, "cross", array1dimreal2array1dimreal) => env &

Env.extend_frame_t(env, "skew", array1dimint2array3dimint) => env &
Env.extend_frame_t(env, "skew", array1dimreal2array3dimreal) => env
Env.extend_frame_t(env, "cross", array1dimint2array1dimint) => env &
Env.extend_frame_t(env, "cross", array1dimreal2array1dimreal) => env &

Env.extend_frame_t(env, "skew", array1dimint2array3dimint) => env &
Env.extend_frame_t(env, "skew", array1dimreal2array3dimreal) => env &

Env.extend_frame_t(env, "sqrt", int2real) => env &
Env.extend_frame_t(env, "sqrt", real2real) => env
(*Debug. Print.print_buf "\n Just AFTER the built in array functions part." *)
----------------------------------------------
initial_env () => env
Expand Down
5 changes: 5 additions & 0 deletions modeq/dump.rml
Expand Up @@ -1218,6 +1218,11 @@ relation print_algorithm: Absyn.Algorithm => () =
-------------------------------------------
print_algorithm(Absyn.ALG_ASSIGN(cr,exp))

rule Print.print_buf "ALG_TUPLE_ASSIGN(" & print_exp(e1) &
Print.print_buf " := " & print_exp(e2) & Print.print_buf ")"
-------------------------------------------
print_algorithm(Absyn.ALG_TUPLE_ASSIGN(e1,e2))

rule Print.print_buf "IF (" & print_exp(e) & Print.print_buf ") THEN " &
print_list_debug("print_algorithm",tb, print_algorithmitem, ";") &
print_list_debug("print_algorithm",eb, print_alg_elseif, " ") &
Expand Down

0 comments on commit d100b1b

Please sign in to comment.