1995-12-20 02:39:12 -08:00
|
|
|
external mycallback1 : ('a -> 'b) -> 'a -> 'b = "mycallback1"
|
|
|
|
external mycallback2 : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = "mycallback2"
|
|
|
|
external mycallback3 : ('a -> 'b -> 'c -> 'd) -> 'a -> 'b -> 'c -> 'd = "mycallback3"
|
1999-01-15 08:59:06 -08:00
|
|
|
external mycallback4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a -> 'b -> 'c -> 'd -> 'e = "mycallback4"
|
1995-12-20 02:39:12 -08:00
|
|
|
|
2007-10-09 03:29:37 -07:00
|
|
|
let rec tak (x, y, z as _tuple) =
|
1995-12-20 02:39:12 -08:00
|
|
|
if x > y then tak(tak (x-1, y, z), tak (y-1, z, x), tak (z-1, x, y))
|
|
|
|
else z
|
|
|
|
|
|
|
|
let tak2 x (y, z) = tak (x, y, z)
|
|
|
|
|
|
|
|
let tak3 x y z = tak (x, y, z)
|
|
|
|
|
1999-01-15 08:59:06 -08:00
|
|
|
let tak4 x y z u = tak (x, y, z + u)
|
|
|
|
|
1995-12-20 02:39:12 -08:00
|
|
|
let raise_exit () = (raise Exit : unit)
|
|
|
|
|
|
|
|
let trapexit () =
|
|
|
|
begin try
|
|
|
|
mycallback1 raise_exit ()
|
|
|
|
with Exit ->
|
|
|
|
()
|
|
|
|
end;
|
|
|
|
tak (18, 12, 6)
|
|
|
|
|
|
|
|
external mypushroot : 'a -> ('b -> 'c) -> 'b -> 'a = "mypushroot"
|
1999-11-20 07:04:56 -08:00
|
|
|
external mycamlparam : 'a -> ('b -> 'c) -> 'b -> 'a = "mycamlparam"
|
1995-12-20 02:39:12 -08:00
|
|
|
|
1999-11-20 07:04:56 -08:00
|
|
|
let tripwire f =
|
1995-12-20 02:39:12 -08:00
|
|
|
let s = String.make 5 'a' in
|
1999-11-20 07:04:56 -08:00
|
|
|
f s trapexit ()
|
1995-12-20 02:39:12 -08:00
|
|
|
|
1997-11-28 02:35:58 -08:00
|
|
|
(* Test callbacks performed to handle signals *)
|
|
|
|
|
|
|
|
let sighandler signo =
|
1999-03-04 04:42:36 -08:00
|
|
|
(*
|
1997-11-28 02:35:58 -08:00
|
|
|
print_string "Got signal, triggering garbage collection...";
|
|
|
|
print_newline();
|
1999-03-04 04:42:36 -08:00
|
|
|
*)
|
1997-11-28 02:35:58 -08:00
|
|
|
(* Thoroughly wipe the minor heap *)
|
2007-10-09 03:29:37 -07:00
|
|
|
ignore (tak (18, 12, 6))
|
1997-11-28 02:35:58 -08:00
|
|
|
|
|
|
|
external unix_getpid : unit -> int = "unix_getpid" "noalloc"
|
|
|
|
external unix_kill : int -> int -> unit = "unix_kill" "noalloc"
|
|
|
|
|
|
|
|
let callbacksig () =
|
|
|
|
let pid = unix_getpid() in
|
|
|
|
(* Allocate a block in the minor heap *)
|
|
|
|
let s = String.make 5 'b' in
|
|
|
|
(* Send a signal to self. We want s to remain in a register and
|
|
|
|
not be spilled on the stack, hence we declare unix_kill
|
|
|
|
"noalloc". *)
|
|
|
|
unix_kill pid Sys.sigusr1;
|
|
|
|
(* Allocate some more so that the signal will be tested *)
|
|
|
|
let u = (s, s) in
|
|
|
|
fst u
|
|
|
|
|
1995-12-20 02:39:12 -08:00
|
|
|
let _ =
|
|
|
|
print_int(mycallback1 tak (18, 12, 6)); print_newline();
|
|
|
|
print_int(mycallback2 tak2 18 (12, 6)); print_newline();
|
|
|
|
print_int(mycallback3 tak3 18 12 6); print_newline();
|
1999-01-15 08:59:06 -08:00
|
|
|
print_int(mycallback4 tak4 18 12 3 3); print_newline();
|
1995-12-20 02:39:12 -08:00
|
|
|
print_int(trapexit ()); print_newline();
|
1999-11-20 07:04:56 -08:00
|
|
|
print_string(tripwire mypushroot); print_newline();
|
|
|
|
print_string(tripwire mycamlparam); print_newline();
|
2007-10-09 03:29:37 -07:00
|
|
|
Sys.set_signal Sys.sigusr1 (Sys.Signal_handle sighandler);
|
1997-11-28 02:35:58 -08:00
|
|
|
print_string(callbacksig ()); print_newline()
|
1995-12-20 02:39:12 -08:00
|
|
|
|