Skip to content

Commit

Permalink
Partial external function support (records missing)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@921 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
levsa committed Feb 20, 2003
1 parent 9cb3e7a commit b715396
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 13 deletions.
123 changes: 112 additions & 11 deletions modeq/inst.rml
Expand Up @@ -802,6 +802,10 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
(* environment (top frame of env'), by inst_class_in, should be *)
(* copied into the resulting environment *)

(* Instantiation of the extended class is done in an environment *)
(* that is combined of the environment of the class itself and *)
(* the class it is instantiated in. *)

inst_class_in(newcenv,mods'',pre,csets,ci_state,c,false,inst_dims,impl)
=> (dae,fr::env',csets',ci_state',vars) &
Env.merge_inherited_content(fr,env) => env''
Expand Down Expand Up @@ -931,11 +935,27 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,

Mod.merge(classmod',mm') => mod &
Mod.merge(mod,m') => mod1 &
<<<<<<< inst.rml
Debug.fprintln ("redecl", "Merged modifications") &
Debug.fcall ("redecl", Mod.print_mod, mod1) &
print "inst_element :" & print n & print "before redeclare\n" &
redeclare_type(mod1,comp,env2,pre,impl) => (SCode.COMPONENT(n,final,repl,prot,
=======

redeclare_type(mod1,comp,env2,pre,impl) => (SCode.COMPONENT(n,final,repl,prot,
>>>>>>> 1.127
attr as SCode.ATTR(ad,flow,acc,param,dir),
<<<<<<< inst.rml
t,m),mod',env2') &
print "inst_element :" & print n & print "after redeclare\n" &
Debug.fprintln ("redecl", "Merged modifications") &
Debug.fcall ("redecl", Mod.print_mod, mod') &


=======
t,m),mod',env2') &

>>>>>>> 1.127
Debug.fprint("insttr", "looking for type") &
Debug.fcall("insttr",Dump.print_path,t) &
Debug.fprint("insttr"," in env:") &
Expand Down Expand Up @@ -1842,7 +1862,7 @@ Removed *)

Env.extend_frame_t(env, n, ty) => env' &
Prefix.prefix_path (Absyn.IDENT(n), pre) => fpath &
inst_element_list (env,mod,pre,csets,ClassInf.UNKNOWN(n),els,inst_dims,false) =>
inst_element_list (env,mod,pre,csets,ClassInf.UNKNOWN(n),els,inst_dims,true) =>
(_,tempenv,_,_,_) &
inst_ext_decl(tempenv, n, parts) => extdecl
--------------------------------------
Expand Down Expand Up @@ -1937,18 +1957,22 @@ end
relation inst_ext_make_externaldecl: (Ident, SCode.Element list, Absyn.ExternalDecl)
=> Absyn.ExternalDecl =

(* the case with only one output var *)
(* the case with only one output var, and that cannot be array, otherwise
inst_ext_make_crefs outvar will fail *)
rule Util.list_matching (els, is_output_var) => outvar::[] &
(* is_not_array_type_var outvar & *)
Util.list_matching (els, is_input_var) => invars &
Util.list_map (invars, inst_ext_make_cref) => exps &
inst_ext_make_cref outvar => Absyn.CREF(retcref) &
Util.list_map (invars, inst_ext_make_crefs) => explists &
Util.list_flatten explists => exps &
inst_ext_make_crefs outvar => [Absyn.CREF(retcref)] &
let extdecl = Absyn.EXTERNALDECL(SOME(id),lang,SOME(retcref),exps)
------------------------------------------------
inst_ext_make_externaldecl (id, els, Absyn.EXTERNALDECL(_,lang,_,_))
=> extdecl

rule Util.list_matching (els, is_inout_var) => inoutvars &
Util.list_map (inoutvars, inst_ext_make_cref) => exps &
Util.list_map (inoutvars, inst_ext_make_crefs) => explists &
Util.list_flatten explists => exps &
let extdecl = Absyn.EXTERNALDECL(SOME(id),lang,NONE,exps)
------------------------------------------------
inst_ext_make_externaldecl (id, els, Absyn.EXTERNALDECL(_,lang,_,_))
Expand All @@ -1975,13 +1999,36 @@ relation is_output_var : SCode.Element => () =
axiom is_output_var SCode.COMPONENT(_,_,_,_,SCode.ATTR(_,_,_,_,Absyn.OUTPUT),_,_)
end

(* subscript list is empty => not an array type *)
relation is_not_array_type_var : SCode.Element => () =
axiom is_not_array_type_var SCode.COMPONENT(_,_,_,_,SCode.ATTR([],_,_,_,_),_,_)
end

relation is_input_var : SCode.Element => () =
axiom is_input_var SCode.COMPONENT(_,_,_,_,SCode.ATTR(_,_,_,_,Absyn.INPUT),_,_)
end

relation inst_ext_make_cref : SCode.Element => Absyn.Exp =
axiom inst_ext_make_cref SCode.COMPONENT(id,_,_,_,_,_,_)
=> Absyn.CREF(Absyn.CREF_IDENT(id,[]))
relation inst_ext_make_crefs : SCode.Element => Absyn.Exp list =

rule inst_ext_make_crefs_2 (id,dims,1) => sizelist &
let crlist = Absyn.CREF(Absyn.CREF_IDENT(id,[]))::sizelist
-----------------------------------------------
inst_ext_make_crefs SCode.COMPONENT(id,fi,re,pr,SCode.ATTR(dims,_,_,_,_),path,mod)
=> crlist
end

relation inst_ext_make_crefs_2 : (SCode.Ident, Absyn.ArrayDim, int) => Absyn.Exp list =

axiom inst_ext_make_crefs_2 (id, [], _) => []

rule int_add(dimno,1) => nextdimno &
inst_ext_make_crefs_2 (id, restdim, nextdimno) => restlist &
let exps = Absyn.CALL(Absyn.CREF_IDENT("size",[]),
Absyn.FUNCTIONARGS([Absyn.CREF(Absyn.CREF_IDENT(id,[])),
Absyn.INTEGER(dimno)], []))::restlist
---------------------------------------
inst_ext_make_crefs_2 (id,dim::restdim,dimno) => exps

end

relation inst_ext_get_fname : (Absyn.ExternalDecl, Ident) => Ident =
Expand All @@ -1991,9 +2038,56 @@ relation inst_ext_get_fname : (Absyn.ExternalDecl, Ident) => Ident =

end

(* special elab_exp for explicit external calls. This special relation calls
elab_exp_ext which handles size builtin calls specially, and uses the ordinary
Static.elab_exp for other expressions *)
relation elab_exp_list_ext : (Env.Env, Absyn.Exp list, bool,
Interactive.InteractiveSymbolTable option) =>
(Exp.Exp list, Types.Properties list, Interactive.InteractiveSymbolTable option) =

axiom elab_exp_list_ext (_,[],impl,st) => ([],[],st)

rule elab_exp_ext (env, e,impl,st) => (exp,p,st') &
elab_exp_list_ext (env, rest,impl,st') => (exps, props,st'')
-----------------------------------------
elab_exp_list_ext (env, e::rest,impl,st) => (exp::exps, p::props,st'')

end

(* special elab_exp for explicit external calls. This special relation calls
elab_exp_ext which handles size builtin calls specially, and uses the ordinary
Static.elab_exp for other expressions *)

relation elab_exp_ext : (Env.Env, Absyn.Exp, bool, Interactive.InteractiveSymbolTable option)
=> (Exp.Exp, Types.Properties,Interactive.InteractiveSymbolTable option) =

rule Print.print_buf "// elab_exp_ext success for " &
(* Static.elab_builtin_size(env,args) => (e,prop) & *)
Static.elab_exp(env,dim,impl,NONE) => (dimp, Types.PROP(dimty,dim_const),_) &
Static.elab_exp(env,arraycr,impl,NONE) => (arraycrefe, arraycrprop,_) &
let exp = Exp.SIZE(arraycrefe,dimp) &
Exp.print_exp exp &
Print.print_buf "\n"
----------------------------------------------------
elab_exp_ext (env,
call as Absyn.CALL(Absyn.CREF_IDENT("size",_),
Absyn.FUNCTIONARGS(args as [arraycr,dim],nargs)),impl,st)
=> (exp,Types.PROP(Types.T_INTEGER,false),st)

rule Print.print_buf "// elab_exp_ext failed for " &
Absyn.print_absyn_exp exp &
Print.print_buf " calling Static.elab_exp: " &
Static.elab_exp (env,exp,impl,st) => (e,prop,st) &
Exp.print_exp e &
Print.print_buf "\n"
---------------------------------------------------
elab_exp_ext (env,exp,impl,st) => (e,prop,st)

end

relation inst_ext_get_fargs : (Env.Env, Absyn.ExternalDecl) => DAE.ExtArg list =

rule Static.elab_exp_list (env, absexps, false, NONE) => (exps,props,_) &
rule elab_exp_list_ext (env, absexps, false, NONE) => (exps,props,_) &
inst_ext_get_fargs2 (env, exps, props) => extargs
---------------------------------------------------------
inst_ext_get_fargs (env, Absyn.EXTERNALDECL(id,lang,retcr,absexps)) => extargs
Expand Down Expand Up @@ -2028,10 +2122,17 @@ relation inst_ext_get_fargs_single : (Env.Env, Exp.Exp, Types.Properties) => DAE
--------------------------------------------------------
inst_ext_get_fargs_single (env, Exp.CREF(cref,crty), Types.PROP(ty,cnst)) => fail

rule Lookup.lookup_var_local (env, cref) => (attr, varty, bnd)
------------------------------------------------------
inst_ext_get_fargs_single (env, Exp.SIZE(Exp.CREF(cref,crty), dim), Types.PROP(ty,cnst))
=> DAE.EXTARGSIZE(cref,attr,varty,dim)

rule Print.print_buf "#-- inst_ext_get_fargs_single failed\n"
rule Print.print_buf "#-- inst_ext_get_fargs_single failed\n" &
Exp.print_exp_str exp => estr &
Print.print_buf estr &
Print.print_buf "\n"
--------------------------------------------------------
inst_ext_get_fargs_single (_,_,_) => fail
inst_ext_get_fargs_single (_,exp,prop) => fail
end


Expand Down
7 changes: 7 additions & 0 deletions modeq/staticexp.rml
Expand Up @@ -695,6 +695,13 @@ relation elab_builtin_size : (Env.Env, Absyn.Exp list) => (Exp.Exp, Types.Proper

(** LS: size(A) that returns an array of sizes for all dimensions is not *)
(** implemented, just size(A,x) that returns size of x:th dimension *)
(*
rule elab_exp(env,dim,false,NONE) => (dimp,_,_) &
elab_exp(env,arraycr,false,NONE) => (arraycrefe,_,_) &
let exp = Exp.SIZE(arraycrefe,dimp)
---------------------------------------------------------------
elab_builtin_size (env, [arraycr,dim]) => (exp,Types.PROP(Types.T_INTEGER,false))
*)

rule elab_exp (env,ind,false,NONE) => (indexp, Types.PROP(indty, true),_) &
ceval (env, indexp,false,NONE) => Values.INTEGER(value) &
Expand Down
49 changes: 47 additions & 2 deletions modeq/types.rml
Expand Up @@ -139,6 +139,8 @@ returns multiple arguments. *)
relation get_vars: (Var list, Var => () ) => Var list
relation get_type_name: Type => string
relation is_array : Type => bool
relation is_input_attr : Attributes => bool
relation is_output_attr : Attributes => bool
relation ndims : Type => int

relation is_prop_const : Properties => bool
Expand All @@ -151,11 +153,15 @@ returns multiple arguments. *)
relation type_convert : (Exp.Exp, Type, Type) => (Exp.Exp, Type)
relation type_convert_array : (Exp.Exp list, Type, Type) => Exp.Exp list
relation match_with_promote : (Properties, Properties) => Properties

relation flatten_array_type : Type => (Type, int list)

end

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

relation is_array : Type => bool =

Expand Down Expand Up @@ -821,14 +827,30 @@ end
relation is_input_var: Var => () =

(* LS: false means not protected, hence we ignore protected variables *)
axiom is_input_var VAR(n, ATTR(fl,ac,var,Absyn.INPUT), false, ty, bnd)
rule is_input_attr attr => true
--------------------------
is_input_var VAR(n, attr, false, ty, bnd)

end

relation is_output_var: Var => () =

(* LS: false means not protected, hence we ignore protected variables *)
axiom is_output_var VAR(n, ATTR(fl,ac,var,Absyn.OUTPUT), false, ty, bnd)
rule is_output_attr attr => true
---------------------------
is_output_var VAR(n, attr, false, ty, bnd)

end

relation is_input_attr : Attributes => bool =

axiom is_input_attr ATTR(_,_,_,Absyn.INPUT) => true

end

relation is_output_attr : Attributes => bool =

axiom is_output_attr ATTR(_,_,_,Absyn.OUTPUT) => true

end

Expand Down Expand Up @@ -889,6 +911,21 @@ relation is_parameter: Var => () =

end

relation flatten_array_type : Type => (Type, int list) =

rule flatten_array_type ty => (ty', dimlist')
--------------------------------------
flatten_array_type T_ARRAY(DIM(NONE), ty) => (ty', dimlist')

rule flatten_array_type ty => (ty', dimlist) &
list_append (dimlist,[dim]) => dimlist'
--------------------------------------
flatten_array_type T_ARRAY(DIM(SOME(dim)), ty) => (ty', dimlist')

axiom flatten_array_type ty => (ty, [])

end

relation get_type_name: Type => string =

axiom get_type_name T_INTEGER => "Integer"
Expand All @@ -900,6 +937,14 @@ relation get_type_name: Type => string =
-------------------------------
get_type_name T_COMPLEX(st, _) => n

rule flatten_array_type arrayty => (ty, dims) &
Util.list_map(dims, int_string) => dimstrs &
Util.string_delimit_list(dimstrs,", ") => dimstr &
get_type_name ty => tystr &
Util.string_append_list([tystr,"[",dimstr,"]"]) => str
------------------------------------------------------
get_type_name (arrayty as T_ARRAY(_,_)) => str

axiom get_type_name _ => "Not nameable type or no type"


Expand Down

0 comments on commit b715396

Please sign in to comment.