Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

configure, lwt-fiber and example

  • Loading branch information...
commit 9826a4a18324a5eb659ff6fbf2b9f17ce6093f85 1 parent 5933b8e
Jake Donham authored
View
2  Makefile
@@ -1,4 +1,4 @@
-PKGLIST=lwt-equeue lwt-stuff cohttpserver-netplex
+-include ../Makefile.conf
all:
mkdir -p stage
View
149 configure
@@ -0,0 +1,149 @@
+#! /bin/sh
+
+# adapted from ocamlnet's configure
+
+#######################################################################
+# Helpers:
+
+# Split $PATH into words:
+oldifs="$IFS"
+IFS=" :"
+spacepath=`echo $PATH`
+IFS="$oldifs"
+
+get_path () {
+ for d in $spacepath; do
+ if test -x "$d/$1"; then
+ echo "$d/$1"
+ return
+ fi
+ done
+}
+
+ocamlc=`get_path ocamlc`
+
+version="0.3"
+exec_suffix=""
+
+check_library () {
+ # $1: the name of the library (findlib)
+ ocamlfind query "$1" >/dev/null 2>/dev/null
+ return
+ return 1 # not found
+}
+
+echo "Welcome to lwt-equeue version $version" >&2
+
+######################################################################
+# Check ocamlfind
+
+printf "%s" "Checking for findlib... "
+if check_library stdlib; then
+ echo "found"
+else
+ echo "not found"
+ echo "Download findlib from http://projects.camlcity.org/projects/findlib.html"
+ exit 1
+fi
+
+######################################################################
+# Check that Lwt is available:
+
+printf "%s" "Checking for Lwt... "
+if check_library lwt; then
+ echo "found"
+else
+ echo "not found"
+ echo "Download Lwt from http://ocsigen.org/lwt/"
+ exit 1
+fi
+
+######################################################################
+# Check that equeue is available:
+
+printf "%s" "Checking for equeue... "
+if check_library equeue; then
+ echo "found"
+else
+ echo "not found"
+ echo "Download equeue from http://projects.camlcity.org/projects/ocamlnet.html"
+ exit 1
+fi
+
+######################################################################
+# Check that cohttpserver is available:
+
+printf "%s" "Checking for cohttpserver... "
+has_cohttpserver=0
+if check_library cohttpserver; then
+ echo "found"
+ has_cohttpserver=1
+else
+ echo "not found, continuing"
+ echo "Download cohttpserver from http://github.com/jaked/ocaml-cohttpserver/"
+fi
+
+######################################################################
+# Check that netplex is available:
+
+printf "%s" "Checking for netplex... "
+has_netplex=0
+if check_library netplex; then
+ echo "found"
+ has_netplex=1
+else
+ has_cohttpserver=0
+ echo "not found"
+ echo "Download netplex from http://projects.camlcity.org/projects/ocamlnet.html"
+fi
+
+######################################################################
+# Check that delimcc is available:
+
+printf "%s" "Checking for delimcc... "
+has_delimcc=0
+if check_library delimcc; then
+ echo "found"
+ has_delimcc=1
+else
+ echo "not found, continuing"
+ echo "Download delimcc from http://okmij.org/ftp/continuations/"
+fi
+
+######################################################################
+# Summary
+
+pkglist="lwt-equeue lwt-stuff"
+
+if [ $has_cohttpserver -gt 0 ]; then
+ pkglist="$pkglist cohttpserver-netplex"
+fi
+if [ $has_delimcc -gt 0 ]; then
+ pkglist="$pkglist lwt-fiber"
+fi
+
+######################################################################
+# Write Makefile.conf
+
+echo "Writing Makefile.conf"
+cat <<_EOF_ >Makefile.conf
+# Makefike.conf written by configure
+# The lwt-equeue version
+VERSION = $version
+
+# The packages to build in the right order:
+PKGLIST = $pkglist
+
+HAS_COHTTPSERVER = $has_cohttpserver
+HAS_DELIMCC = $has_delimcc
+_EOF_
+
+######################################################################
+# Finish
+
+echo
+echo "You can now compile lwt-equeue by invoking"
+echo " make all"
+echo "Finally, a"
+echo " make install"
+echo "will install the package(s)."
View
10 examples/Makefile
@@ -1,5 +1,15 @@
+-include ../Makefile.conf
+
DIRS=relay
+ifeq ($(HAS_COHTTPSERVER),1)
+DIRS += cohttpserver
+endif
+
+ifeq ($(HAS_DELIMCC),1)
+DIRS += fiber
+endif
+
all:
for dir in $(DIRS); do \
$(MAKE) -C $$dir all || exit; \
View
9 examples/fiber/Makefile
@@ -0,0 +1,9 @@
+all: myocamlbuild.ml
+ ocamlbuild fiber.byte fiber.native
+
+clean:
+ ocamlbuild -clean
+ rm -f myocamlbuild.ml
+
+myocamlbuild.ml:
+ ln -s ../../tools/myocamlbuild.ml .
View
3  examples/fiber/_tags
@@ -0,0 +1,3 @@
+<*.ml*> : syntax_camlp4o,pkg_lwt.syntax,pkg_lwt-fiber,pkg_lwt.unix
+<*.byte> or <*.native> : pkg_lwt-fiber,pkg_lwt.unix
+
View
33 examples/fiber/fiber.ml
@@ -0,0 +1,33 @@
+open Lwt
+
+let t1 =
+ let rec loop n =
+ match n with
+ | 0 -> Lwt.return ()
+ | _ ->
+ prerr_endline "tick";
+ lwt () = Lwt_unix.sleep 1. in
+ loop (n - 1) in
+ loop 15
+
+let t2 =
+ Lwt_fiber.start begin fun () ->
+ let rec loop n =
+ match n with
+ | 0 -> ()
+ | _ ->
+ prerr_endline "tock";
+ begin
+ try Lwt_fiber.await (lwt () = Lwt_unix.sleep 2. in Lwt.fail (Failure "failed"))
+ with Failure "failed" -> ()
+ end;
+ loop (n - 1) in
+ loop 5
+ end
+
+let t2 =
+ lwt () = t2 in
+ prerr_endline "t2 finished";
+ Lwt.return ()
+
+let _ = Lwt_main.run (t1 <&> t2)
View
5 src/lwt-fiber/META
@@ -0,0 +1,5 @@
+name="Lwt-fiber"
+requires="lwt,delimcc"
+version="0.3"
+archive(byte) = "lwt-fiber.cma"
+archive(native) = "lwt-fiber.cmxa"
View
24 src/lwt-fiber/Makefile
@@ -0,0 +1,24 @@
+FILES=\
+lwt-fiber.cma lwt-fiber.cmxa lwt-fiber.a \
+lwt_fiber.cmi lwt_fiber.mli \
+
+BFILES=$(addprefix _build/,$(FILES))
+
+all: myocamlbuild.ml
+ ocamlbuild lwt-fiber.cma lwt-fiber.cmxa
+
+doc:
+ ocamlbuild -no-links doc.docdir/index.html
+
+install:
+ ocamlfind install lwt-fiber META $(BFILES)
+
+uninstall:
+ ocamlfind remove lwt-fiber
+
+clean:
+ ocamlbuild -clean
+ rm -f myocamlbuild.ml
+
+myocamlbuild.ml:
+ ln -s ../../tools/myocamlbuild.ml .
View
1  src/lwt-fiber/_tags
@@ -0,0 +1 @@
+<*.ml*> : pkg_lwt,pkg_delimcc
View
1  src/lwt-fiber/lwt-fiber.mllib
@@ -0,0 +1 @@
+Lwt_fiber
View
40 src/lwt-fiber/lwt_fiber.ml
@@ -0,0 +1,40 @@
+let active_prompt = ref None
+
+let start f =
+ let t, u = Lwt.wait () in
+ let p = Delimcc.new_prompt () in
+ active_prompt := Some p;
+
+ Delimcc.push_prompt p begin fun () ->
+ let r =
+ try Lwt.Return (f ())
+ with e -> Lwt.Fail e in
+ active_prompt := None;
+ match r with
+ | Lwt.Return v -> Lwt.wakeup u v
+ | Lwt.Fail e -> Lwt.wakeup_exn u e
+ | Lwt.Sleep -> assert false
+ end;
+ t
+
+let await t =
+ let p =
+ match !active_prompt with
+ | None -> failwith "await called outside start"
+ | Some p -> p in
+ active_prompt := None;
+
+ match Lwt.poll t with
+ | Some v -> v
+ | None ->
+ Delimcc.take_subcont p begin fun sk () ->
+ let ready _ =
+ active_prompt := Some p;
+ Delimcc.push_delim_subcont sk begin fun () ->
+ match Lwt.poll t with
+ | Some v -> v
+ | None -> assert false
+ end;
+ Lwt.return () in
+ ignore (Lwt.try_bind (fun () -> t) ready ready)
+ end
View
2  src/lwt-fiber/lwt_fiber.mli
@@ -0,0 +1,2 @@
+val start : (unit -> 'a) -> 'a Lwt.t
+val await : 'a Lwt.t -> 'a
Please sign in to comment.
Something went wrong with that request. Please try again.