diff --git a/.gitignore b/.gitignore index bd4a41f..361e8b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,8 @@ -*.annot -*.cmo -*.cma -*.cmi -*.a -*.o -*.so -*.cmx -*.cmxs -*.cmxa README.git _build/ tools/ -Ipython_json_* +.merlin +*.install iocaml.log .*.swp *~ diff --git a/Makefile b/Makefile index 9b95409..c5bbde8 100644 --- a/Makefile +++ b/Makefile @@ -1,77 +1,14 @@ -# new makefile - the build is about to get more complex. +JBUILDER ?= jbuilder -all: top +all: + $(JBUILDER) build -json: - atdgen -t Ipython_json.atd - atdgen -j Ipython_json.atd +tests: + $(JBUILDER) runtest -stub: - ocamlfind c iocaml_zmq_stubs.c - -lib: json stub - # compile log (first so we can use it in the zmq code) - ocamlfind c -c -g log.mli log.ml - # iocaml_zmq (which requires preprocessing) - ocamlfind c -c -g \ - -syntax camlp4o -package lwt.unix,lwt.syntax,ctypes.foreign \ - iocaml_zmq.mli iocaml_zmq.ml - # rest of the library - ocamlfind c -c -g \ - -package yojson,atdgen,compiler-libs \ - Ipython_json_t.mli Ipython_json_j.mli base64.mli \ - Ipython_json_t.ml Ipython_json_j.ml base64.ml - ocamlfind ocamlmklib -o iocaml_lib \ - -l zmq \ - -package ctypes.foreign,lwt.unix,yojson \ - iocaml_zmq_stubs.o \ - log.cmo Ipython_json_t.cmo Ipython_json_j.cmo iocaml_zmq.cmo base64.cmo - -OCP_INDEX_INC=`ocamlfind query ocp-index.lib -predicates byte -format "%d"` -OCP_INDEX_ARCHIVE=`ocamlfind query ocp-index.lib -predicates byte -format "%a"` - -HAS_OCP = $(shell if ocamlfind query ocp-index.lib >/dev/null 2>&1; then echo 1; else echo 0; fi) -ifeq ($(HAS_OCP),1) -TOP_PKG=threads,uuidm,lwt.unix,ctypes.foreign,yojson,atdgen,ocp-indent.lib,compiler-libs -TOP_SRC = \ - message.mli sockets.mli completion.mli exec.mli iocaml.mli \ - message.ml sockets.ml completion.ml exec.ml iocaml.ml -TOP_OBJ = message.cmo sockets.cmo completion.cmo exec.cmo iocaml.cmo -TOP_OCP = -I $(OCP_INDEX_INC) $(OCP_INDEX_INC)/$(OCP_INDEX_ARCHIVE) -else -TOP_PKG=threads,uuidm,lwt.unix,ctypes.foreign,yojson,atdgen,compiler-libs -TOP_SRC = \ - message.mli sockets.mli exec.mli iocaml.mli \ - message.ml sockets.ml exec.ml iocaml.ml -TOP_OBJ = message.cmo sockets.cmo exec.cmo iocaml.cmo -TOP_OCP = -endif - -top: lib - ocamlfind c -c -g -thread \ - -syntax camlp4o -package optcomp -ppopt "-let has_ocp=$(HAS_OCP)" \ - -package $(TOP_PKG) \ - $(TOP_OCP) $(TOP_SRC) - ocamlfind ocamlmktop -g -thread -linkpkg \ - -o iocaml.top \ - -package $(TOP_PKG) $(TOP_OCP) \ - iocaml_lib.cma $(TOP_OBJ) iocaml_main.ml - -BINDIR=`opam config var bin` - -install: top - ocamlfind install iocaml-kernel META *.cmi *.cmo *.cma *.so *.a *.o - cp iocaml.top $(BINDIR)/iocaml.top - -uninstall: - ocamlfind remove iocaml-kernel - rm -f $(BINDIR)/iocaml.top - -reinstall: - -$(MAKE) uninstall - $(MAKE) install +check: tests clean: - rm *.cmi *.cmo *.cma *.so *.a *.o iocaml.top - + $(JBUILDER) clean +.PHONY: all tests clean check diff --git a/_tags b/_tags deleted file mode 100644 index 93f871b..0000000 --- a/_tags +++ /dev/null @@ -1,17 +0,0 @@ -: package(yojson), package(atdgen) - -: syntax(camlp4o), package(ctypes.foreign), package(lwt), package(lwt.syntax), package(lwt.unix) - -: package(uuidm) - -: package(ocp-index.lib) - -: package(compiler-libs) - -: package(threads), package(yojson), package(ocp-index.lib) - -: package(threads), package(uuidm), package(yojson), package(atdgen), package(compiler-libs), package(ocp-index.lib) - -true: bin_annot -true: thread -true: debug diff --git a/exec.ml b/exec.ml index b44e927..9aaab4b 100644 --- a/exec.ml +++ b/exec.ml @@ -1,11 +1,11 @@ type ('a,'b) status = Ok of 'a | Error of 'b let get_error_loc = function -#if ocaml_version > (4,0) +#if OCAML_VERSION > (4, 0, 0) | Syntaxerr.Error(x) -> Some(Syntaxerr.location_of_error x) #endif | Lexer.Error(_, loc) -#if ocaml_version < (4,1) +#if OCAML_VERSION < (4, 1, 0) | Typecore.Error(loc, _) | Typetexp.Error(loc, _) | Typeclass.Error(loc, _) @@ -31,7 +31,7 @@ let run_cell_lb execution_count lb = Errors.report_error formatter exn; (match get_error_loc exn with | Some(loc) -> -#if ocaml_version < (4,2) +#if OCAML_VERSION < (4, 2, 0) ignore (Location.highlight_locations formatter loc Location.none); #else ignore (Location.highlight_locations formatter [loc]); diff --git a/iocaml-kernel.opam b/iocaml-kernel.opam new file mode 100644 index 0000000..33fb8dc --- /dev/null +++ b/iocaml-kernel.opam @@ -0,0 +1,29 @@ +opam-version: "1.2" +maintainer: "Andy Ray " +authors: "Andy Ray " +homepage: "https://github.com/andrewray/iocaml" +dev-repo: "git+https://github.com/andrewray/iocaml.git" +bug-reports: "https://github.com/andrewray/iocaml/issues" +depends: [ + "jbuilder" {build & >= "1.0+beta10"} + "cppo" {build} + "conf-zmq" {build} + "uuidm" + "yojson" + "atdgen" + "ctypes" {>= "0.3"} + "ctypes-foreign" + "base-unix" + "lwt" {>= "2.4"} +] +depopts: ["ocp-index"] +conflicts: [ + "ocp-index" {< "1.0.1"} +] + +build: [ + ["jbuilder" "build" "-p" name "-j" jobs] +] +build-test: [ + ["jbuilder" "runtest" "-p" name "-j" jobs] +] \ No newline at end of file diff --git a/iocaml.ml b/iocaml.ml index 84ca313..57d3f33 100644 --- a/iocaml.ml +++ b/iocaml.ml @@ -335,23 +335,9 @@ module Shell = struct let handle_invalid_message () = raise (Failure "Invalid message on shell socket") - let complete_request index socket msg x = -#if has_ocp=1 - if !completion then - let reply = Completion.complete index x in - send_h socket msg (Complete_reply reply) - else -#endif - () - - let object_info_request index socket msg x = -#if has_ocp=1 - if !object_info then - let reply = Completion.info index x in - send_h socket msg (Object_info_reply reply) - else -#endif - () + let complete_request = Iocaml_complete.complete_request !completion + + let object_info_request = Iocaml_complete.object_info_request !object_info let connect_request socket msg = () let history_request socket msg x = () @@ -452,11 +438,7 @@ let send_flush () = Pervasives.flush stderr; ignore (send_iopub Shell.Iopub_flush) -#if has_ocp=1 -let index = Completion.init () -#else -let index = () -#endif +let index = Iocaml_complete.index let suppress_stdout b = ignore (send_iopub (Shell.Iopub_suppress_stdout b)) let suppress_stderr b = ignore (send_iopub (Shell.Iopub_suppress_stderr b)) diff --git a/iocaml.mli b/iocaml.mli index 19601cb..7756331 100644 --- a/iocaml.mli +++ b/iocaml.mli @@ -53,12 +53,7 @@ val suppress_compiler : bool -> unit (** suppress all output (except mime messages) *) val suppress_all : bool -> unit -(** ocp-index *) -#if has_ocp = 1 -val index : LibIndex.t -#else -val index : unit -#endif +val index : Iocaml_complete.index type cell_context diff --git a/iocaml_no_ocp.ml b/iocaml_no_ocp.ml new file mode 100644 index 0000000..8a9bdb7 --- /dev/null +++ b/iocaml_no_ocp.ml @@ -0,0 +1,7 @@ +type index = unit + +let complete_request _completion _socket _msg _index _x = () + +let object_info_request _object_info _index _socket _msg _x = () + +let index = () diff --git a/iocaml_ocp.ml b/iocaml_ocp.ml new file mode 100644 index 0000000..2f7bab9 --- /dev/null +++ b/iocaml_ocp.ml @@ -0,0 +1,17 @@ +type index = LibIndex.t + +let complete_request completion index socket msg x = + if completion then + let reply = Completion.complete index x in + Message.send_h socket msg (Complete_reply reply) + else + () + +let object_info_request object_info index socket msg x = + if object_info then + let reply = Completion.info index x in + Message.send_h socket msg (Object_info_reply reply) + else + () + +let index = Completion.init () diff --git a/iocaml_zmq.ml b/iocaml_zmq.ml index 639c30b..469e5c1 100644 --- a/iocaml_zmq.ml +++ b/iocaml_zmq.ml @@ -379,17 +379,12 @@ module Lwt_zmq = struct ) in let rec idle_loop () = - try_lwt - Lwt.wrap1 f s.socket - with - | Unix.Unix_error ( Unix.EAGAIN, _, _) -> begin - try_lwt - io_loop () - with - | Break_event_loop -> idle_loop () - end - | Unix.Unix_error (Unix.EINTR, _, _) -> - idle_loop () + Lwt.catch (fun () -> Lwt.wrap1 f s.socket) + (function + | Unix.Unix_error ( Unix.EAGAIN, _, _) -> + Lwt.catch io_loop (function Break_event_loop -> idle_loop()) + | Unix.Unix_error (Unix.EINTR, _, _) -> + idle_loop ()) in idle_loop () diff --git a/jbuild b/jbuild new file mode 100644 index 0000000..e42a0cc --- /dev/null +++ b/jbuild @@ -0,0 +1,29 @@ +(jbuild_version 1) + +(rule + ((targets (Ipython_json_t.ml Ipython_json_t.mli)) + (deps (Ipython_json.atd)) + (action (run atdgen -t ${<})))) + +(rule + ((targets (Ipython_json_j.ml Ipython_json_j.mli)) + (deps (Ipython_json.atd)) + (action (run atdgen -j ${<})))) + +(library + ((name iocaml_kernel) + (public_name iocaml-kernel) + (wrapped false) + + (preprocess + (per_module + ((action (run ${bin:cppo} -V OCAML:${ocaml_version} ${<})) (exec)))) + (libraries + (atdgen + (select iocaml_complete.ml from + (ocp-index.lib -> iocaml_ocp.ml) + (-> iocaml_no_ocp.ml)) + lwt.unix + yojson + ctypes.foreign + uuidm)))) \ No newline at end of file