Skip to content

Commit

Permalink
Upgrade throw_continuation to be an escape function (return any).
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Dec 30, 2022
1 parent afce9c6 commit f3b6a43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions src/compiler/flx_cpp_backend/flx_gen_exe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ print_endline ("gen_exe: " ^ string_of_bexe bsym_table 0 exe);
in
let name = cpp_instance_name syms bsym_table index ts in
if mem `Cfun props then begin
(* this code should work for an ESCAPE function too *)
(if with_comments
then " //call cproc " ^ src_str ^ "\n"
else "") ^
Expand All @@ -191,6 +192,16 @@ print_endline ("gen_exe: " ^ string_of_bexe bsym_table 0 exe);
(*
print_endline ("[handle_closure] GENERATING STACK CALL for " ^ id);
*)
if is_ehandler then begin
let _,argt = a in
" // stack call ESCAPE FUNCTION\n" ^
" {\n" ^
subs ^
" " ^ name ^ Flx_gen_display.strd the_display props ^
"\n .apply (" ^ args ^ ");\n" ^
" }\n"
end else

(if with_comments
then " //run procedure " ^ src_str ^ "\n"
else "") ^
Expand All @@ -203,6 +214,15 @@ print_endline ("gen_exe: " ^ string_of_bexe bsym_table 0 exe);
else
let ptrmap = name ^ "_ptr_map" in
begin
if is_ehandler then begin
let _,argt = a in
" // heap call ESCAPE FUNCTION\n" ^
" {\n" ^
subs ^
" (FLX_NEWP(" ^ name ^ ")" ^ Flx_gen_display.strd the_display props ^ ")" ^
"\n ->apply (" ^ args ^ ");\n" ^
" }\n"
end else
match kind with
| Function ->
(*
Expand Down Expand Up @@ -233,14 +253,6 @@ print_endline ("gen_exe: " ^ string_of_bexe bsym_table 0 exe);
" }\n"

| Procedure ->
if is_ehandler then begin
let _,argt = a in
" {\n" ^
subs ^
" (FLX_NEWP(" ^ name ^ ")" ^ Flx_gen_display.strd the_display props ^ ")" ^
"\n ->apply (" ^ args ^ ");\n" ^
" }\n"
end else
let call_string =
" return (FLX_NEWP(" ^ name ^ ")" ^ Flx_gen_display.strd the_display props ^ ")" ^
"\n ->call(" ^ args ^ ");\n"
Expand Down
2 changes: 1 addition & 1 deletion src/packages/control.fdoc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ open class Control
//$ use a non-local goto, and they cannot pass across
//$ a function boundary.

proc throw_continuation(x: unit->void) { _throw (C_hack::cast[cont] x); }
fun throw_continuation(x: unit->void) : any { _throw (C_hack::cast[cont] x); }
private proc _throw: cont = "throw $1;";

}
Expand Down

0 comments on commit f3b6a43

Please sign in to comment.