Skip to content

Commit

Permalink
implemented DIV_ARRAY_SCALAR
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1313 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x02lucpo committed Oct 13, 2004
1 parent dadccc4 commit 3e567d5
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 28 deletions.
7 changes: 7 additions & 0 deletions modeq/ceval.rml
Expand Up @@ -269,6 +269,13 @@ relation ceval : (Env.Env, Exp.Exp, bool, Interactive.InteractiveSymbolTable opt
ceval (env, Exp.BINARY(lh, Exp.MUL_ARRAY_SCALAR(_), rh),impl,st,dim)
=> (Values.ARRAY(reslst),st'')

rule ceval (env,rh,impl,st,dim) => (sval,st') &
ceval (env,lh,impl,st',dim) => (Values.ARRAY(aval),st'') &
Values.div_arrayelt_scalar(sval,aval) => reslst
------------------------------------------------
ceval (env, Exp.BINARY(lh, Exp.DIV_ARRAY_SCALAR(_), rh),impl,st,dim)
=> (Values.ARRAY(reslst),st'')

rule ceval (env,rh,impl,st,dim) => (Values.ARRAY(rhvals),st') &
ceval (env,lh,impl,st',dim) => (Values.ARRAY(lhvals),st'') &
Values.mult_scalar_product(rhvals,lhvals) => res
Expand Down
26 changes: 25 additions & 1 deletion modeq/codegen.rml
Expand Up @@ -2458,7 +2458,31 @@ relation generate_binary : (Exp.Exp, Exp.Operator, Exp.Exp, int)
generate_binary(e1,Exp.MUL_MATRIX_PRODUCT(Exp.INT),e2, tnr)
=> (cfn,var,tnr3)

rule Print.print_buf "# div_array_scalar not implemented\n"
rule generate_expression(e1, tnr) => (cfn1,var1,tnr1) &
generate_expression(e2, tnr1) =>(cfn2,var2,tnr2) &
generate_temp_decl("real_array",tnr2) => (decl, var, tnr3) &
Util.string_append_list(["div_alloc_real_array_scalar(&",var1,
", ",var2,", &", var,");"]) => stmt &
c_merge_fn(cfn1,cfn2) => cfn' &
c_add_variables(cfn',[decl]) => cfn'' &
c_add_statements(cfn'',[stmt]) => cfn
----------------------
generate_binary(e1,Exp.DIV_ARRAY_SCALAR(Exp.REAL),e2, tnr)
=> (cfn,var,tnr3)

rule generate_expression(e1, tnr) => (cfn1,var1,tnr1) &
generate_expression(e2, tnr1) =>(cfn2,var2, tnr2) &
generate_temp_decl("integer_array",tnr2) => (decl, var, tnr3) &
Util.string_append_list(["div_alloc_integer_array_scalar(&",var1,
", ",var2,", &",var,");"]) => stmt &
c_merge_fn(cfn1,cfn2) => cfn' &
c_add_variables(cfn',[decl]) => cfn'' &
c_add_statements(cfn'',[stmt]) => cfn
----------------------
generate_binary(e1,Exp.DIV_ARRAY_SCALAR(Exp.INT),e2, tnr)
=> (cfn,var,tnr3)

rule Print.print_buf "# div_array_scalar FAILING BECAUSE IT SUX\n"
-------------------------
generate_binary(_,Exp.DIV_ARRAY_SCALAR(_),_,_) => fail

Expand Down
15 changes: 12 additions & 3 deletions modeq/dae.rml
Expand Up @@ -363,14 +363,20 @@ end
relation dump_comp_element : Element => () =

rule RTOpts.modelica_output => false &
Print.print_buf "fclass " & Print.print_buf n & Print.print_buf "\n" &
(* luc_pop: to work with mof2ff2 *)
(* Print.print_buf "fclass " & Print.print_buf n & Print.print_buf "\n" & *)
Print.print_buf "model " & Print.print_buf n & Print.print_buf "\n" &
(* end luc_pop *)
dump_elements(l) &
Print.print_buf "end " & Print.print_buf n & Print.print_buf ";\n"
-----------------------------------
dump_comp_element COMP(n,DAE(l))

rule RTOpts.modelica_output => true &
Print.print_buf "class " & Print.print_buf n & Print.print_buf "\n" &
(* luc_pop: to work with mof2ff2 *)
(* Print.print_buf "fclass " & Print.print_buf n & Print.print_buf "\n" & *)
Print.print_buf "model " & Print.print_buf n & Print.print_buf "\n" &
(* end luc_pop *)
dump_elements(l) &
Print.print_buf "end " & Print.print_buf n & Print.print_buf ";\n"
-----------------------------------
Expand All @@ -384,7 +390,10 @@ end
relation dump_comp_element_str : Element => string =

rule RTOpts.modelica_output => false &
string_append("fclass ",n) => s1 &
(* luc_pop: to work with mof2ff2 *)
(* string_append("fclass ",n) => s1 & *)
string_append("model ",n) => s1 &
(* end luc_pop *)
string_append(s1,"\n") => s2 &
dump_elements_str(l) => s3 &
string_append(s2,s3) => s4 &
Expand Down
13 changes: 10 additions & 3 deletions modeq/inst.rml
Expand Up @@ -1486,7 +1486,6 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
Mod.merge(mod,m',env2,pre) => mod1 &
Mod.merge(cmod,mod1,env2,pre) => mod1' &


redeclare_type(mod1',comp,env2,pre,ci_state,impl)
=> (SCode.COMPONENT(n,final,repl,prot,
attr as SCode.ATTR(ad,flow,acc,param,dir),
Expand All @@ -1495,14 +1494,17 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
(* Debug.fprint("insttr", "looking for type ") &
Debug.fcall("insttr",Dump.print_path,t) &
Debug.fprint("insttr"," \n") &*)

get_derived_env(env,bc) => env' &
Lookup.lookup_class(env',t,true) => (cl,cenv) &

(* Debug.fprintl ("insttr", ["found type for: ", n, "\n"]) &*)

(** If the element is `protected', and an external *)
(** modification is applied, it is an error. *)

check_prot(prot, mm', vn) &

(* Debug.fprintln ("insttr", "Protection checked") &*)

Debug.fcall("myeqmod",Mod.print_mod, mod') & Debug.fprintln ("myeqmod", "\n") &
Expand All @@ -1512,15 +1514,20 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
Debug.fcall("insttr",Mod.print_mod, mod') & Debug.fprintln ("insttr", "\n") &*)
(** The variable declaration and the (optional) equation *)
(** modification are inspected for array dimensions. *)

elab_arraydim(env2',owncref,ad,eq,impl,NONE) => dims &

(* Debug.fprintln ("insttr", "arraydim elabed") &
Debug.fprintln ("arraydim", "arraydim elabed :") &
Debug.fcall("arraydim",print_dim2, dims) &*)

(** Instantiate the component *)
(*Dump.select_string(impl,"IMPLICIT!!!\n","") => s &
print s &*)

inst_var(cenv,ci_state, mod', pre, csets, n, cl, attr, dims, [], inst_dims, impl)
=> (dae, csets', ty) &

(* Debug.fprintl ("insttr", ["instantiated: ", n, "\n"]) &*)

(** The environment is extended (updated) with the new variable *)
Expand Down Expand Up @@ -1631,7 +1638,7 @@ relation redeclare_type: (Types.Mod,
redeclare_type(Types.REDECL(redfin,rest),comp,env,pre,ci_state,impl)
=> (newcomp,mod,env')
-------------
redeclare_type (Types.REDECL(redfin,((redecl as SCode.COMPONENT(n1,final,repl,prot,_,t,_,bc)),rmod)::rest),
redeclare_type (mod as Types.REDECL(redfin,((redecl as SCode.COMPONENT(n1,final,repl,prot,_,t,_,bc)),rmod)::rest),
comp as SCode.COMPONENT(n2,false,repl2,prot2,_,t2,_,_),env,pre,ci_state,impl)
=> (newcomp,mod,env')

Expand All @@ -1643,7 +1650,7 @@ relation redeclare_type: (Types.Mod,

axiom redeclare_type(Types.REDECL(redfin,[]),comp,env,pre,ci_state,impl) => (comp,Types.NOMOD,env)

axiom redeclare_type(mod,comp,env,pre,ci_state,impl) => (comp,mod,env)
axiom redeclare_type(mod,comp,env,pre,ci_state,impl) => (comp,mod,env)

rule Debug.fprint("failtrace", "- redeclare_type failed\n")
------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions modeq/main.rml
Expand Up @@ -253,6 +253,7 @@ relation translate_file : string list => () =
rule (*Print.print_buf "Parsing\n" &
*) is_modelica_file(f)
& Parser.parse f => p
& print "1"
& Debug.fprint ("dump", "\n--------------- Parsed program ---------------\n")
& Debug.fcall ("dumpgraphviz", DumpGraphviz.dump, p)
& Debug.fcall ("dump", Dump.dump, p)
Expand Down Expand Up @@ -303,8 +304,8 @@ relation translate_file : string list => () =
translate_file [] => fail

rule Print.print_buf "# An error occured\n" &
Print.get_string () => str (*&
print str *)
Print.get_string () => str
& print str
----------------------------
translate_file _ => fail

Expand Down
2 changes: 2 additions & 0 deletions modeq/staticexp.rml
Expand Up @@ -3644,6 +3644,8 @@ relation compute_return_type : (Exp.Operator, Types.Type list, Types.Type) => Ty

axiom compute_return_type (Exp.MUL_ARRAY_SCALAR(_),[typ1,typ2],rtype) => typ1(* rtype*)

axiom compute_return_type (Exp.DIV_ARRAY_SCALAR(_),[typ1,typ2],rtype) => typ1(* rtype*)


axiom compute_return_type (Exp.ADD(_),_,typ) => typ
axiom compute_return_type (Exp.SUB(_),_,typ) => typ
Expand Down
10 changes: 10 additions & 0 deletions modeq/system.rml
Expand Up @@ -90,4 +90,14 @@ relation regular_file_exist: (string) => int

relation directory_exist: (string) => int

relation getDebugString: (string) => string

relation startDebug: () => ()

relation endDebug: () => ()

relation incDebugLevel: () => ()

relation decDebugLevel: () => ()

end
41 changes: 22 additions & 19 deletions modeq/types.rml
Expand Up @@ -220,7 +220,7 @@ relation is_array_or_string : Type => bool =
-------------------
is_array_or_string ty => true

axiom is_array_or_string _ => false
rule ----------------- is_array_or_string _ => false

end

Expand Down Expand Up @@ -359,29 +359,32 @@ relation subtype : (Type, Type) => bool =

axiom subtype ((T_ENUMERATION([],_),_),(T_ENUMERATION(_,_),_))=> true

rule subtype (t1,t2) => true
rule Debug.fprint ("failtrace", "PIGS1 \n") &
subtype (t1,t2) => true
-----------------------
subtype((T_ARRAY(_,t1),_),(T_ARRAY(DIM(NONE),t2),_)) => true

rule subtype (t1,t2) => true
-----------------------
subtype((T_ARRAY(DIM(NONE),t1),_),(T_ARRAY(_,t2),_)) => true

rule i1 = i2 &
subtype (t1,t2) => true
---------------------------------------------------------
subtype((T_ARRAY(DIM(SOME(i1)),t1),_),(T_ARRAY(DIM(SOME(i2)),t2),_)) => true


rule Debug.fprint ("failtrace", "PIGS2 \n") &
subtype (t1,t2) => true
-----------------------
subtype((T_ARRAY(DIM(NONE),t1),_),(T_ARRAY(_,t2),_)) => true

rule Debug.fprint ("failtrace", "PIGS3 \n") &
i1 = i2 &
subtype (t1,t2) => true
---------------------------------------------------------
subtype((T_ARRAY(DIM(SOME(i1)),t1),_),(T_ARRAY(DIM(SOME(i2)),t2),_)) => true

rule subtype_varlist(els1, els2) => true
-----------------------------------
subtype((T_COMPLEX(st1,els1),_), (T_COMPLEX(st2,els2),_)) => true

(* PR. Check of tuples, similar to complex. Just that
identifier name do not have to be checked. Only types are
checked. *)
-----------------------------------
subtype((T_COMPLEX(st1,els1),_), (T_COMPLEX(st2,els2),_)) => true
(* PR. Check of tuples, similar to complex. Just that
identifier name do not have to be checked. Only types are
checked. *)
rule subtype_typelist(type_list1,type_list2) => true
-----------------------------------
subtype((T_TUPLE(type_list1),_), (T_TUPLE(type_list2),_)) => true
subtype((T_TUPLE(type_list1),_), (T_TUPLE(type_list2),_)) => true

axiom subtype(t1,t2) => false

Expand Down
47 changes: 47 additions & 0 deletions modeq/values.rml
Expand Up @@ -56,6 +56,7 @@ with "absyn.rml"
relation mult_scalar_arrayelt: (Value, Value list) => Value list
relation mult_scalar_product: (Value list, Value list) => Value
relation mult_matrix: (Value list,Value list) => Value list
relation div_arrayelt_scalar: (Value, Value list) => Value list
relation intlist_to_value : int list => Value
relation is_array : Value => bool
relation write_to_file_as_args: (Value list,string) => ()
Expand Down Expand Up @@ -435,6 +436,52 @@ relation mult_matrix: (Value list,Value list) => Value list =

end


relation div_arrayelt_scalar: (Value, Value list) => Value list =

rule v1 = 0.0 &
Print.print_buf "# Error, division by zero.\n"
------------------------------------
div_arrayelt_scalar (sval as REAL(v1),_) => fail

rule v1 = 0 &
Print.print_buf "# Error, division by zero.\n"
------------------------------------
div_arrayelt_scalar (sval as INTEGER(v1),_) => fail

rule div_arrayelt_scalar(sval,vals) => r1 &
div_arrayelt_scalar(sval,rest) => r2
------------------------------------
div_arrayelt_scalar (sval,ARRAY(vals)::rest) => ARRAY(r1)::r2

rule int_div(v2,v1) => r1 &
div_arrayelt_scalar(sval,rest) => r2
------------------------------------
div_arrayelt_scalar (sval as INTEGER(v1),INTEGER(v2)::rest) => INTEGER(r1)::r2


rule int_real(v2) => v2' &
real_div(v2',v1) => r1 &
div_arrayelt_scalar(sval,rest) => r2
------------------------------------
div_arrayelt_scalar (sval as REAL(v1),INTEGER(v2)::rest) => REAL(r1)::r2

rule int_real(v1) => v1' &
real_div(v2,v1') => r1 &
div_arrayelt_scalar(sval,rest) => r2
------------------------------------
div_arrayelt_scalar (sval as INTEGER(v1),REAL(v2)::rest) => REAL(r1)::r2

rule real_div(v2,v1) => r1 &
div_arrayelt_scalar(sval,rest) => r2
------------------------------------
div_arrayelt_scalar (sval as REAL(v1),REAL(v2)::rest) => REAL(r1)::r2

axiom div_arrayelt_scalar(_,[]) => []
end



(** This relation takes a Value list representing a matrix and strips the first column of the matrix, i.e. for each sub list it removes the first element. Returning both the stripped column and the resulting matrix.**)
relation matrix_strip_first_column: Value list => (Value,Value list) =

Expand Down

0 comments on commit 3e567d5

Please sign in to comment.