Skip to content

Commit

Permalink
Dunification.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentMazare committed Jan 27, 2019
1 parent b75025d commit 13972a5
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,9 +1,12 @@
_build
.merlin
.depend
*.cm[aioxt]
*.cmti
*.cmx[as]
*.[ao]
*.so
*.swp
*~
*.inc
/generate
Expand Down
43 changes: 43 additions & 0 deletions dune
@@ -0,0 +1,43 @@
(library
(name pyml)
(modules numpy py pyml_arch pytypes pywrappers)
(c_names numpy_stubs pyml_stubs)
(wrapped false)
(libraries bigarray stdcompat pyutils))

(executables
(names generate)
(modules generate)
(libraries stdcompat pyutils))

(library
(name pyutils)
(modules pyutils)
(wrapped false)
(libraries stdcompat unix))

(rule
(targets pywrappers.ml pyml.h pyml_dlsyms.inc pyml_wrappers.inc)
(deps (:gen generate.exe))
(action (run %{gen})))

(rule
(targets pyml_arch.ml)
(deps (:pyml_arch pyml_arch_%{ocaml-config:system}.ml))
(action (copy %{pyml_arch} pyml_arch.ml)))

(library
(name pyml_tests_common)
(modules pyml_tests_common)
(wrapped false)
(libraries pyml stdcompat))

(test
(name numpy_tests)
(modules numpy_tests)
(libraries pyml pyml_tests_common stdcompat pyutils))

(test
(name pyml_tests)
(modules pyml_tests)
(libraries pyml pyml_tests_common stdcompat pyutils))
1 change: 1 addition & 0 deletions dune-project
@@ -0,0 +1 @@
(lang dune 1.6)
22 changes: 15 additions & 7 deletions generate.ml
Expand Up @@ -1318,7 +1318,7 @@ let print_pycaml indent prefix channel wrapper =
Value | Deref -> ""
| Fun [] -> " ()"
| Fun [_] -> " arg"
| Fun list ->
| Fun _list ->
Printf.sprintf " (%s)" (String.concat ", " arguments_list) in
let convert i ty =
let arg = Printf.sprintf "arg%d" i in
Expand All @@ -1337,7 +1337,7 @@ let print_pycaml indent prefix channel wrapper =
Value | Deref -> ""
| Fun [] -> " ()"
| Fun [_] -> " arg"
| Fun list ->
| Fun _list ->
Printf.sprintf " %s" (String.concat " " converted_arguments_list) in
Printf.fprintf channel "%slet %s%s = %s%s%s\n"
indent symbol_lowercase arguments_tuple prefix symbol_lowercase
Expand All @@ -1346,6 +1346,8 @@ let print_pycaml indent prefix channel wrapper =
let print_pycamls indent prefix channel wrappers =
List.iter (print_pycaml indent prefix channel) wrappers

module Set_string = Set.Make(String)

let print_all_externals channel =
Printf.fprintf channel "(** Low-level bindings. *)
(** The library has to be initialized via {!Py.initialize} first. *)
Expand All @@ -1356,24 +1358,30 @@ let print_all_externals channel =
(** Python 2 specific bindings. *)
module Python2 = struct\n";
print_externals " " "Python2_" channel wrappers_python2;
Printf.fprintf channel "end
Printf.fprintf channel "end\n
(** UCS2 specific bindings. *)
module UCS2 = struct\n";
print_externals " " "UCS2_" channel wrappers_ucs2;
Printf.fprintf channel "end
Printf.fprintf channel "end\n
(** UCS4 specific bindings. *)
module UCS4 = struct\n";
print_externals " " "UCS4_" channel wrappers_ucs4;
Printf.fprintf channel "end
Printf.fprintf channel "end\n
(** Python 3 specific bindings. *)
module Python3 = struct\n";
print_externals " " "Python3_" channel wrappers_python3;
Printf.fprintf channel "end\n
(** Automatic wrappers for Pycaml_compat. *)
module Pycaml = struct\n";
print_pycamls " " "" channel wrappers;
print_pycamls " " "Python2." channel wrappers_python2;
print_pycamls " " "Python3." channel wrappers_python3;
let wrappers_python2_not_in_python3 =
let python3_symbols =
List.map (fun w -> w.symbol) wrappers_python3 |> Set_string.of_list
in
List.filter (fun w -> not (Set_string.mem w.symbol python3_symbols)) wrappers_python2
in
Printf.printf "%d\n%!" (List.length wrappers_python2_not_in_python3);
Printf.printf "%d\n%!" (List.length wrappers_python2);
Printf.fprintf channel "end\n"

let print_dlsym indent prefix channel wrapper =
Expand Down
2 changes: 1 addition & 1 deletion numpy.ml
@@ -1,4 +1,4 @@
external get_pyarray_type: Py.Object.t -> Py.Object.t = "get_pyarray_type"
external _get_pyarray_type: Py.Object.t -> Py.Object.t = "get_pyarray_type"

external pyarray_of_bigarray: Py.Object.t -> Py.Object.t
-> ('a, 'b, 'c) Bigarray.Genarray.t
Expand Down
20 changes: 10 additions & 10 deletions py.ml
Expand Up @@ -45,6 +45,8 @@ external pycapsule_isvalid: Pytypes.pyobject -> string -> int
= "Python27_PyCapsule_IsValid_wrapper"

external ucs: unit -> ucs = "py_get_UCS"
(* Avoid warning 32. *)
let () = ignore (UCSNone, UCS2, UCS4)

let initialized = ref false

Expand Down Expand Up @@ -1014,10 +1016,10 @@ let string_length = String.length
module String__ = struct
include String_

let check_bytes s =
let _check_bytes s =
Type.get s = Type.Bytes

let check_unicode s =
let _check_unicode s =
Type.get s = Type.Unicode

let check s =
Expand Down Expand Up @@ -1399,7 +1401,7 @@ module Object = struct
try
try
repr_or_string repr v
with E (ty, value) ->
with E (_ty, _value) ->
repr_or_string (Pervasives.not repr) v
with E (ty, value) ->
Printf.sprintf "[ERROR] %s: %s" (to_string ty) (to_string value)
Expand Down Expand Up @@ -1494,7 +1496,7 @@ module Number = struct

let number_and v0 v1 = check_not_null (Pywrappers.pynumber_and v0 v1)

let check v = Pywrappers.pynumber_check v <> 0
let _check v = Pywrappers.pynumber_check v <> 0

let divmod v0 v1 = check_not_null (Pywrappers.pynumber_divmod v0 v1)

Expand Down Expand Up @@ -1607,8 +1609,6 @@ module Number = struct

let ( lxor ) = number_xor

let ( lnot ) = invert

let ( lsl ) = lshift

let ( lsr ) = rshift
Expand Down Expand Up @@ -1968,7 +1968,7 @@ module Import = struct
let import_module_opt name =
try
Some (check_not_null (Pywrappers.pyimport_importmodule name))
with E (e, msg)
with E (e, _msg)
when
let ty = Object.to_string e in
ty = "<class 'ModuleNotFoundError'>" ||
Expand Down Expand Up @@ -2182,13 +2182,13 @@ module Array = struct
["__len__",
Callable.of_function_as_tuple (fun _tuple -> Int.of_int length);
"__getitem__", Callable.of_function_as_tuple (fun tuple ->
let (self, key) = Tuple.to_tuple2 tuple in
let (_self, key) = Tuple.to_tuple2 tuple in
getter (Long.to_int key));
"__setitem__", Callable.of_function_as_tuple (fun tuple ->
let (self, key, value) = Tuple.to_tuple3 tuple in
let (_self, key, value) = Tuple.to_tuple3 tuple in
setter (Long.to_int key) value;
none);
"__iter__", Callable.of_function_as_tuple (fun tuple ->
"__iter__", Callable.of_function_as_tuple (fun _tuple ->
let cursor = ref 0 in
let next () =
let index = !cursor in
Expand Down
4 changes: 0 additions & 4 deletions py.mli
Expand Up @@ -1169,10 +1169,6 @@ module Number: sig
(** Wrapper for
{{:https://docs.python.org/3/c-api/number.html#c.PyNumber_And} PyNumber_And} *)

val check: Object.t -> bool
(** Wrapper for
{{:https://docs.python.org/3/c-api/number.html#c.PyNumber_Check} PyNumber_Check} *)

val divmod: Object.t -> Object.t -> Object.t
(** Wrapper for
{{:https://docs.python.org/3/c-api/number.html#c.PyNumber_Divmod} PyNumber_Divmod} *)
Expand Down

0 comments on commit 13972a5

Please sign in to comment.