Skip to content

Commit

Permalink
Some function call tests added to testsuite
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1643 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
levsa committed Mar 30, 2005
1 parent adaf3cb commit d507d2d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
3 changes: 3 additions & 0 deletions modeq/builtin.rml
Expand Up @@ -815,6 +815,9 @@ relation initial_env =
Env.extend_frame_t(env, "sin", real2real) => env &
Env.extend_frame_t(env, "cos", real2real) => env &
Env.extend_frame_t(env, "tan", real2real) => env &
Env.extend_frame_t(env, "asin", real2real) => env &
Env.extend_frame_t(env, "acos", real2real) => env &
Env.extend_frame_t(env, "atan", real2real) => env &
Env.extend_frame_t(env, "exp", real2real) => env &
(* PR. Add the built in array functions here.*)
(* Also do it for real, string and bool*)
Expand Down
48 changes: 33 additions & 15 deletions modeq/ceval.rml
Expand Up @@ -200,6 +200,11 @@ relation ceval_builtin : (Env.Env, Exp.Exp, bool (*impl*),
-----------------------------------------
ceval_builtin (env,Exp.CALL(Absyn.IDENT(id),args,_,builtin (*as true*)),impl,st,_) => (v,st)

rule ceval_list(env,expl,impl,st) => vallst &
ceval_call_function (env,e,vallst) => newval
-------------------------------------------------------
ceval_builtin (env, e as Exp.CALL(funcpath,expl,_,builtin as true),impl,st as NONE,_) => (newval,st)

(* It's ok if ceval_builtin fails. Just means the call wasn't a builtin function *)

end
Expand Down Expand Up @@ -346,19 +351,8 @@ relation ceval : (Env.Env, Exp.Exp, bool (*impl*),
(* Call functions in non-interactive mode. *)
(* FIXME: functions are always generated. Put back the check
and write another rule for the false case that generates the function *)
rule (* Static.is_function_in_cflist(cflist,funcpath) => true & *)
Debug.fprintln("ceval", "- ceval call begin") &
ceval_generate_function(env, funcpath) &
Debug.fprintln("ceval", "- ceval func generated") &
ceval_list(env,expl,impl,st) => vallst &
Debug.fprintln("ceval", "- ceval args evaluated") &
ModUtil.path_string2(funcpath,"_") => funcstr &
string_append(funcstr,"_in.txt") => infilename &
string_append(funcstr,"_out.txt") => outfilename &
Values.write_to_file_as_args(vallst,infilename) &
System.execute_function(funcstr) &
System.read_values_from_file(outfilename) => newval
& Debug.fprintln("ceval", "- ceval call success")
rule ceval_list(env,expl,impl,st) => vallst &
ceval_call_function (env,e,vallst) => newval
-------------------------------------------------------
ceval (env, e as Exp.CALL(funcpath,expl,_,builtin as false),impl as false,st as NONE,_) => (newval,st)

Expand All @@ -369,13 +363,14 @@ relation ceval : (Env.Env, Exp.Exp, bool (*impl*),
(* FIXME: Fix this in order to allow calling of constant-marked function
* calls. One should call the function as if we were in interactive
* mode, and put the result instead of the function call *)


(*

rule Print.print_buf "# Can't call builtin functions at compile time\n" &
Print.print_buf " expression: " & Exp.print_exp e & Print.print_buf "\n"
-------------------------------------------------------
ceval (env, e as Exp.CALL(_,_,_,builtin as true),impl as false,NONE,_) => fail

*)

rule Print.print_buf "# Can't call functions at compile time\n" &
Print.print_buf " expression: " & Exp.print_exp e & Print.print_buf "\n"
Expand Down Expand Up @@ -701,6 +696,29 @@ relation ceval : (Env.Env, Exp.Exp, bool (*impl*),
end


relation ceval_call_function : (Env.Env, Exp.Exp, Values.Value list) => Values.Value =

(* Call functions in non-interactive mode. *)
(* FIXME: functions are always generated. Put back the check
and write another rule for the false case that generates the function *)
rule (* Static.is_function_in_cflist(cflist,funcpath) => true & *)
ceval_generate_function(env, funcpath) &
ModUtil.path_string2(funcpath,"_") => funcstr &
string_append(funcstr,"_in.txt") => infilename &
string_append(funcstr,"_out.txt") => outfilename &
Values.write_to_file_as_args(vallst,infilename) &
System.execute_function(funcstr) &
System.read_values_from_file(outfilename) => newval
-------------------------------------------------------
ceval_call_function (env, e as Exp.CALL(funcpath,expl,_,builtin), vallst) => newval

rule Debug.fprint("failtrace", "- ceval_call_function failed: ")
& Exp.print_exp_str e => str
& Debug.fprintln("failtrace",str)
-----------------------------------------------------
ceval_call_function (env,e,_) => fail

end

(** relation: ceval_function
**
Expand Down
2 changes: 1 addition & 1 deletion modeq/main.rml
Expand Up @@ -455,7 +455,7 @@ relation translate_file : string list => () =
(* & fix_modelica_output (dimpl') => dimpl
*)
(* & Debug. print "\nJust instantiated" *)
(* & Print.clear_buf() *)
& Print.clear_buf()
& Debug.fprint ("info", "---dumping\n")
& Debug.fcallret ("flatmodelica", DAE.dump_str, d, "") => s
& Debug.fcall ("flatmodelica", Print.print_buf, s)
Expand Down

0 comments on commit d507d2d

Please sign in to comment.