caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Native delimited continuations for bytecode OCaml
@ 2006-02-28  1:34 Jacques Carette
  2006-03-01  9:13 ` [Caml-list] " Till Varoquaux
  0 siblings, 1 reply; 7+ messages in thread
From: Jacques Carette @ 2006-02-28  1:34 UTC (permalink / raw)
  To: caml-list; +Cc: oleg

[Posted for oleg@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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Native delimited continuations for bytecode OCaml
  2006-02-28  1:34 Native delimited continuations for bytecode OCaml Jacques Carette
@ 2006-03-01  9:13 ` Till Varoquaux
  2006-03-01  9:26   ` Till Varoquaux
  0 siblings, 1 reply; 7+ messages in thread
From: Till Varoquaux @ 2006-03-01  9:13 UTC (permalink / raw)
  To: Jacques Carette; +Cc: caml-list, oleg

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 ()


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Native delimited continuations for bytecode OCaml
  2006-03-01  9:13 ` [Caml-list] " Till Varoquaux
@ 2006-03-01  9:26   ` Till Varoquaux
  2006-03-01 11:37     ` oleg
  0 siblings, 1 reply; 7+ messages in thread
From: Till Varoquaux @ 2006-03-01  9:26 UTC (permalink / raw)
  To: Jacques Carette; +Cc: caml-list, oleg

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 exit
        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 errors.

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

Regards,
Till Varoquaux


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Native delimited continuations for bytecode OCaml
  2006-03-01  9:26   ` Till Varoquaux
@ 2006-03-01 11:37     ` oleg
  2006-03-01 23:51       ` Jacques Garrigue
  0 siblings, 1 reply; 7+ messages in thread
From: oleg @ 2006-03-01 11:37 UTC (permalink / raw)
  To: till.varoquaux; +Cc: carette, caml-list


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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Native delimited continuations for bytecode OCaml
  2006-03-01 11:37     ` oleg
@ 2006-03-01 23:51       ` Jacques Garrigue
  2006-03-03  1:20         ` oleg
  0 siblings, 1 reply; 7+ messages in thread
From: Jacques Garrigue @ 2006-03-01 23:51 UTC (permalink / raw)
  To: oleg; +Cc: caml-list

From: oleg@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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Native delimited continuations for bytecode OCaml
  2006-03-01 23:51       ` Jacques Garrigue
@ 2006-03-03  1:20         ` oleg
  2006-03-03  1:36           ` Till Varoquaux
  0 siblings, 1 reply; 7+ messages in thread
From: oleg @ 2006-03-03  1:20 UTC (permalink / raw)
  To: garrigue; +Cc: caml-list


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...


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Native delimited continuations for bytecode OCaml
  2006-03-03  1:20         ` oleg
@ 2006-03-03  1:36           ` Till Varoquaux
  0 siblings, 0 replies; 7+ messages in thread
From: Till Varoquaux @ 2006-03-03  1:36 UTC (permalink / raw)
  To: oleg; +Cc: garrigue, caml-list

On 3/3/06, oleg@pobox.com <oleg@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 any).

Regards,
Till


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-03-03  1:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-28  1:34 Native delimited continuations for bytecode OCaml Jacques Carette
2006-03-01  9:13 ` [Caml-list] " Till Varoquaux
2006-03-01  9:26   ` Till Varoquaux
2006-03-01 11:37     ` oleg
2006-03-01 23:51       ` Jacques Garrigue
2006-03-03  1:20         ` oleg
2006-03-03  1:36           ` Till Varoquaux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).