Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Native delimited continuations for bytecode OCaml

14 views
Skip to first unread message

Jacques Carette

unread,
Feb 27, 2006, 8:37:14 PM2/27/06
to caml...@inria.fr, ol...@pobox.com
[Posted for ol...@pobox.com]

This message announces the native implementation of delimited
continuation framework for byte-code OCaml. The framework supports
`static' (shift/reset) and `dynamic' (prompt/control, shift0,
control0) delimited continuation operators with multiple, arbitrarily
typed prompts. The test file testd0.ml is a good example of using
shift/reset in OCaml programs.

The implementation is native: it copies a relevant fragment of the
OCaml interpreter stack (The stack or its fragments are never
inspected however). The implementation is efficient: only the
necessary prefix of the stack is copied. The implementation is
fully integrated with OCaml exceptions: exception handlers may be
captured in delimited continuation (and re-instated when the captured
continuation is installed); exceptions remove the prompts along the
way. The implementation has no typing problems, no bizarre 'a cont
types, and no use for magic. The implementation does no patching to
the OCaml system and is a regular library. If you compile the
top-level (see `make top'), you can use delimited continuation
operators in interactive OCaml sessions.

The library has been tested for OCaml 3.08, 3.09.0, and 3.09.1, on
ia32 Linux and FreeBSD platforms. The current version is 1.6, Feb 7,
2006.

The library is distributed under the MIT license.

http://pobox.com/~oleg/ftp/packages/caml-shift.tar.gz


_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Till Varoquaux

unread,
Mar 1, 2006, 4:16:26 AM3/1/06
to Jacques Carette, ol...@pobox.com, caml...@inria.fr
Can your code be used for undelimited continuation? I am currently
using code that looks somewhat like this:


open Netchannels
open Marshal

let suspend ()=
let oo=open_out "state"
and save_state k=
to_string k [Closures])
(* Skips a warning because this function does not return (it is an exit
point)*)
ignore(exit 0)
in
callcc save_state
(*
Saves the "state" the application is in as an base64 encoded marshalled
continuation.
*)
let _ =
if (Sys.file_exists "state") then
let res =

Sys.remove("state");
let k=Marshal.from_string res 0 in
throw k ()

Till Varoquaux

unread,
Mar 1, 2006, 4:29:03 AM3/1/06
to Jacques Carette, ol...@pobox.com, caml...@inria.fr
Oups, sorry the mail was sent while I was typing (someone accidentally
pressed enter...).

Can your code be used for unlimited continuation? I am currently


using code that looks somewhat like this:

let suspend ()=
and save_state k=
let oc=open_out_bin "state" in
Marshal.to_channel oc k [Marshal.Closures]);
close_out oc;


(* Skips a warning because this function does not return (it is an exi
t
point)*)
ignore(exit 0)
in
callcc save_state

(* If there is a resume point skip to it


*)
let _ =
if (Sys.file_exists "state") then

( let oi = open_in_bin "state" in
let k=Marshal.from_channel oi in
Sys.remove("state");
close_in oi;
throw k ());

[note]This code was simplified for sake of clarity and might have small err
ors.

I was wondering if something similar is possible with your library?

Regards,
Till Varoquaux

ol...@pobox.com

unread,
Mar 1, 2006, 6:43:22 AM3/1/06
to till.va...@gmail.com, car...@mcmaster.ca, caml...@inria.fr

Hello!

[I'm not sure if this messages makes it to the caml-list. Sorry]

Till Varoquaux wrote:
> Can your code be used for unlimited continuation? I am currently
> using code that looks somewhat like this:
>

> [capture continuation and Marshall it out]
> [Upon startup of the application, resume from the saved state]


Hmm, I have written code to test this interesting application. Alas,
when I run it and was writing the captured continuation, I got a
problem:

Fatal error: exception Invalid_argument("output_value: abstract value
(Custom)")

I guess the marshalling function isn't happy about abstract values. I
really don't know which particular value it is complaining about: the
values used by the low-level C code are actually tuples and
integers. But there are a lot of abstract values in the delimcc OCaml
code, introduced to hide the representation.

Jacques Garrigue

unread,
Mar 1, 2006, 6:53:46 PM3/1/06
to ol...@pobox.com, caml...@inria.fr
From: ol...@pobox.com

> Hmm, I have written code to test this interesting application. Alas,
> when I run it and was writing the captured continuation, I got a
> problem:
>
> Fatal error: exception Invalid_argument("output_value: abstract value
> (Custom)")
>
> I guess the marshalling function isn't happy about abstract values. I
> really don't know which particular value it is complaining about: the
> values used by the low-level C code are actually tuples and
> integers. But there are a lot of abstract values in the delimcc OCaml
> code, introduced to hide the representation.

The above message is a bit confusing. "abstract" here is unrelated to
typing and representation hiding, it just says that the marshaller
encountered a custom C value. Note that, as it is custom, it might be
possible to define a custom marshaller for it.

Jacques Garrigue

ol...@pobox.com

unread,
Mar 2, 2006, 8:27:16 PM3/2/06
to garr...@math.nagoya-u.ac.jp, caml...@inria.fr

Jacques Garrigue wrote:
>> Fatal error: exception Invalid_argument("output_value: abstract value
>> (Custom)")

> it just says that the marshaller encountered a custom C value.

But there are no such values in my code: C functions return either
Val_long, Val_unit, or a tuple with the tag 0 rather than
Custom_tag. The custom value must be referenced in the custom stack
fragement...

Till Varoquaux

unread,
Mar 2, 2006, 8:38:20 PM3/2/06
to ol...@pobox.com, garr...@math.nagoya-u.ac.jp, caml...@inria.fr
On 3/3/06, ol...@pobox.com <ol...@pobox.com> wrote:
>
> Jacques Garrigue wrote:
> >> Fatal error: exception Invalid_argument("output_value: abstract value
> >> (Custom)")
>
> > it just says that the marshaller encountered a custom C value.
>
> But there are no such values in my code: C functions return either
> Val_long, Val_unit, or a tuple with the tag 0 rather than
> Custom_tag. The custom value must be referenced in the custom stack
> fragement...
>
It can also come from an open io handle or threads (I doubt you are using a
ny).

Regards,
Till

0 new messages