Skip to content
This repository
tag: v947
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 119 lines (99 sloc) 3.028 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
/*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Defining API on external continuation.
*
* This file provides the definition of a continuation, and define
* an API to manipulate them.
*
* @category general
* @author Mathieu Barbin, 2010
* @destination public
* @stability wip, unstable
*/


/**
* {1 About this module}
*
* With the apparition of {[ @callcc : ( continuation('a) -> void ) : void }
* there is a need for the user to apply a continuation to a value of type ['a]
*
* Since the continuation will also be the native support of transactions,
* there is a need for an API.
*
* {1 Where should I start?}
*
* {1 What if I need more?}
**/

/**
* {1 Types defined in this module}
**/

type bycps__unit = external

/**
* The abstract type of a continuation
*/
@opacapi
type continuation('a) = external

/**
* {1 Interface}
*/

Continuation = {{

  /**
* Return a value using a continuation : apply the continuation to the value.
* This is the standard function to use when you use @callcc
*
* {[
* f(x) =
* call(k) = Continuation.return(k, x)
* @callcc(call)
* }
*
* Do not use {!Continuation.execute} in standard cases.
**/
  return = %%bslcps.user_return%% : continuation('a), 'a -> void

  /**
* Like {!Continuation.return} but can't be scheduled before to return the value
* Hack for synchronous situations.
* Not for casual user.
**/
  execute = %%bslcps.execute%% : continuation('a), 'a -> void

  make = @may_cps(%%bslcps.user_cont%%) : ('a -> void) -> continuation('a)

  /**
* This bypass is defined on both sides, but the client implementation is dummy.
* This is done so that the code may not be sliced differently if we add some debug
* print of the stack trace in the middle of a client-side code.
**/
  print_trace_of = %% bslcps.print_trace %% : continuation('a) -> void

  /**
* see {!Continuation.print_trace_of}
* applied on the current continuation.
**/
  print_trace() : void =
    @sliced_expr({
      server =
        @callcc(k ->
          do print_trace_of(k)
          return(k,void)
      )
     client =
       error("Continuation.print_trace was called on the client side")
   })
}}


/**
* The type of a future.
* Currently, used by generated code only.
* May become used by the user, if we export the
* concurrency primitives spawn, wait.
**/
@opacapi
type Cps.future('a) = external
Something went wrong with that request. Please try again.