-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from ddeclerck/ctypes_skeleton
Add Ctypes skeleton
- Loading branch information
Showing
38 changed files
with
766 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
; generated by drom from package skeleton '!{skeleton}' | ||
|
||
(executable | ||
(name main) | ||
(public_name !{name}) | ||
(package !{name}) | ||
(libraries !{dune-libraries} !(package-dune-libraries)) | ||
!{dune-stanzas} | ||
!(package-dune-stanzas) | ||
) | ||
|
||
!{package-dune-files} | ||
(documentation | ||
(package !{package-name})) | ||
!{package-dune-installs} | ||
!(package-dune-trailer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{1 Program !{name}} | ||
|
||
!{description} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
!{header-ml} | ||
|
||
module Gsl = !(lib-name:alpha:cap) | ||
|
||
let () = | ||
let order = 10 in | ||
let f x = if x < 0.5 then 0. else 1. in | ||
let cs = Gsl.Functions.Gsl_cheb.make ~a:0. ~b:1. f order in | ||
let x = 0.3 in | ||
let y = Gsl.Functions.Gsl_cheb.eval cs x in | ||
Printf.printf | ||
"Evaluation of Chebishev series at order %d for x = %.1f -> %.4f\n" | ||
order x y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name = "!{name}" | ||
dir = "!{dir}" | ||
skeleton = "ctypes_drv" | ||
kind = "program" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[skeleton] | ||
name = "ctypes_drv" | ||
inherits = "virtual" | ||
|
||
[file] | ||
dune_ = { file = "dune", skips = [ "dune" ] } | ||
"index.mld" = { skips = [ "docs" ] } | ||
"main.ml" = { skips = [ "code" ] } |
19 changes: 19 additions & 0 deletions
19
share/drom/skeletons/packages/ctypes_lib_foreign/discover/discover.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
!{header-ml} | ||
|
||
module C = Configurator.V1 | ||
|
||
let () = | ||
C.main ~name:"gsl" (fun c -> | ||
let default : C.Pkg_config.package_conf = | ||
{ libs = [ "-lgsl"; "-lgslcblas"; "-lm" ]; cflags = [] } | ||
in | ||
let conf = | ||
match C.Pkg_config.get c with | ||
| None -> default | ||
| Some pc -> | ||
match C.Pkg_config.query pc ~package:"gsl" with | ||
| None -> default | ||
| Some deps -> deps | ||
in | ||
C.Flags.write_sexp "ccopt.sexp" conf.cflags; | ||
C.Flags.write_sexp "cclib.sexp" conf.libs) |
4 changes: 4 additions & 0 deletions
4
share/drom/skeletons/packages/ctypes_lib_foreign/discover/dune_
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
(executable | ||
(name discover) | ||
(libraries dune-configurator)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; generated by drom from package skeleton '!{skeleton}' | ||
|
||
(rule | ||
(targets ccopt.sexp cclib.sexp) | ||
(deps discover/discover.exe) | ||
(action (run %{deps}))) | ||
|
||
(library | ||
(name !{library-name}) | ||
(public_name !{name}) | ||
(wrapped !{pack-modules}) | ||
(libraries !{dune-libraries} !(package-dune-libraries)) | ||
(c_library_flags (:standard (:include cclib.sexp))) | ||
!{dune-stanzas} | ||
!(package-dune-stanzas) | ||
) | ||
|
||
!{package-dune-files} | ||
(documentation | ||
(package !{package-name})) | ||
!{package-dune-installs} | ||
!(package-dune-trailer) |
10 changes: 10 additions & 0 deletions
10
share/drom/skeletons/packages/ctypes_lib_foreign/index.mld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{1 Library !{name}} | ||
|
||
!{description} | ||
|
||
!{escape:true}![if:pack] | ||
The entry point of this library is the module: {\!!{pack}}. | ||
![else] | ||
This library exposes the following toplevel modules: | ||
{\!modules:!{modules}} | ||
![fi]!{escape:false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
!{header-ml} | ||
|
||
(* If you delete or rename this file, you should add | ||
'src/!{dir}/!{name}.ml' to the 'skip' field in "drom.toml" *) | ||
|
||
open Ctypes | ||
open Foreign | ||
|
||
(* To force the external library to be linked *) | ||
external _dummy : unit -> unit = "gsl_cheb_eval" | ||
|
||
module Types = struct | ||
|
||
module Gsl_function = struct | ||
|
||
type gsl_function | ||
type t = gsl_function structure | ||
|
||
let t : t typ = | ||
typedef (structure "gsl_function_struct") "gsl_function" | ||
|
||
let function_ = | ||
field t "function" (funptr (double @-> ptr void @-> returning double)) | ||
|
||
let params = | ||
field t "params" (ptr void) | ||
|
||
let () = | ||
seal t | ||
|
||
let make f = | ||
let gf = Ctypes.make t in | ||
Ctypes.setf gf function_ (fun x (_p : unit ptr) -> f x); | ||
Ctypes.setf gf params Ctypes.null; | ||
gf | ||
|
||
end | ||
|
||
end | ||
|
||
module Functions = struct | ||
|
||
open Types | ||
|
||
module Gsl_cheb = struct | ||
|
||
type gsl_cheb_series | ||
type t = gsl_cheb_series structure | ||
|
||
let t : t typ = | ||
typedef (structure "gsl_cheb_series_struct") "gsl_cheb_series" | ||
|
||
let alloc = | ||
foreign "gsl_cheb_alloc" (size_t @-> returning (ptr t)) | ||
|
||
let free = | ||
foreign "gsl_cheb_free" (ptr t @-> returning void) | ||
|
||
let init = | ||
foreign "gsl_cheb_init" | ||
(ptr t @-> ptr Gsl_function.t @-> double @-> double @-> returning int) | ||
|
||
let eval = | ||
foreign "gsl_cheb_eval" (ptr t @-> double @-> returning double) | ||
|
||
let make ~a ~b (f : float -> float) (n : int) = | ||
let cs = alloc (Unsigned.Size_t.of_int n) in | ||
Gc.finalise free cs; | ||
let _ = init cs (Ctypes.addr (Gsl_function.make f)) a b in | ||
cs | ||
|
||
end | ||
|
||
end |
14 changes: 14 additions & 0 deletions
14
share/drom/skeletons/packages/ctypes_lib_foreign/package.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name = "!{name}" | ||
dir = "!{dir}" | ||
skeleton = "ctypes_lib_foreign" | ||
kind = "library" | ||
gen-version = "version.ml" | ||
pack-modules = false | ||
|
||
[dependencies] | ||
ctypes = "" | ||
ctypes-foreign = { libname = "ctypes.foreign" } | ||
|
||
[tools] | ||
dune-configurator = "" | ||
conf-gsl = "" |
10 changes: 10 additions & 0 deletions
10
share/drom/skeletons/packages/ctypes_lib_foreign/skeleton.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[skeleton] | ||
name = "ctypes_lib_foreign" | ||
inherits = "virtual" | ||
|
||
[file] | ||
"dune_" = { file = "dune", skips = [ "dune" ] } | ||
"index.mld" = { skips = [ "docs" ] } | ||
"lib.ml" = { file = "!{name}.ml", skips = [ "code" ] } | ||
"discover/dune_" = { file = "discover/dune", skips = [ "dune" ] } | ||
"discover/discover.ml" = { skips = [ "code" ] } |
27 changes: 27 additions & 0 deletions
27
share/drom/skeletons/packages/ctypes_lib_stubs/bindings/ctypes_stubgen/ctypes_stubgen.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
let fmt = | ||
Format.std_formatter | ||
|
||
let print_headers fmt = | ||
List.iter (Format.fprintf fmt "#include <%s>@\n") | ||
|
||
let make_types_stubs | ||
(c_headers : string list) | ||
(types_functor : (module Cstubs.Types.BINDINGS)) = | ||
print_headers fmt c_headers; | ||
Cstubs_structs.write_c fmt types_functor; | ||
Format.pp_print_flush fmt () | ||
|
||
let make_functions_stubs | ||
(c_headers : string list) | ||
(functions_functor : (module Cstubs.BINDINGS)) = | ||
begin | ||
match Sys.argv.(1) with | ||
| "c" -> | ||
print_headers fmt c_headers; | ||
Cstubs.write_c ~prefix:"gsl_stub" fmt functions_functor | ||
| "ml" -> | ||
Cstubs.write_ml ~prefix:"gsl_stub" fmt functions_functor | ||
| s -> failwith ("unknown functions " ^ s) | ||
end; | ||
Format.pp_print_flush fmt () |
4 changes: 4 additions & 0 deletions
4
share/drom/skeletons/packages/ctypes_lib_stubs/bindings/ctypes_stubgen/ctypes_stubgen.mli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
val make_types_stubs : string list -> (module Cstubs.Types.BINDINGS) -> unit | ||
|
||
val make_functions_stubs : string list -> (module Cstubs.BINDINGS) -> unit |
6 changes: 6 additions & 0 deletions
6
share/drom/skeletons/packages/ctypes_lib_stubs/bindings/ctypes_stubgen/dune_
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
(library | ||
(name ctypes_stubgen) | ||
(modules ctypes_stubgen) | ||
(libraries ctypes ctypes.stubs) | ||
(wrapped false)) |
Oops, something went wrong.