module Cell = struct type t external global : unit -> t = "caml_global_cell" external create : int -> t = "caml_cell_create" external set : t -> int -> unit = "caml_cell_set" external get : t -> int = "caml_cell_get" external throw : unit -> string = "caml_cell_throw" external call : string -> string = "caml_cell_call" end let test_cell c = Printf.printf "c=%d\n" (Cell.get c); flush stdout; Printf.printf "set 42... "; flush stdout; Cell.set c 42; Printf.printf "c=%d\n" (Cell.get c); flush stdout; begin try Printf.printf "set -1... "; flush stdout; Cell.set c (-1); with e -> print_endline (Printexc.to_string e); flush stdout end let _ = print_endline "start"; flush stdout; test_cell (Cell.create 271828); Gc.full_major (); print_newline (); test_cell (Cell.global ()); print_newline () let _ = Callback.register "caml-throw" Cell.throw; print_endline ("callback: "^Cell.call "caml-throw"); flush stdout