Last active
December 1, 2019 11:26
-
-
Save toots/0c9a1256fd9f0182a6fde9bba954e60c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
include Ctypes | |
let lift x = x | |
open Ctypes_static | |
let rec field : type t a. t typ -> string -> a typ -> (a, t) field = | |
fun s fname ftype -> match s, fname with | |
| View { ty }, _ -> | |
let { ftype; foffset; fname } = field ty fname ftype in | |
{ ftype; foffset; fname } | |
| _ -> failwith ("Unexpected field "^ fname) | |
let rec seal : type a. a typ -> unit = function | |
| Struct { tag; spec = Complete _ } -> | |
raise (ModifyingSealedType tag) | |
| Union { utag; uspec = Some _ } -> | |
raise (ModifyingSealedType utag) | |
| View { ty } -> seal ty | |
| _ -> | |
raise (Unsupported "Sealing a non-structured type") | |
type 'a const = 'a | |
let constant (type t) name (t : t typ) : t = match t, name with | |
| Ctypes_static.Primitive Cstubs_internals.Int, "NI_NUMERICSERV" -> | |
8 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "NI_NUMERICHOST" -> | |
2 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "NI_MAXHOST" -> | |
1025 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "NI_MAXSERV" -> | |
32 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "SOCKLEN_T_LEN" -> | |
4 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "SOCK_STREAM" -> | |
1 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "SOCK_STREAM" -> | |
1 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "SOCK_DGRAM" -> | |
2 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "SA_FAMILY_LEN" -> | |
1 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "SA_DATA_LEN" -> | |
14 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "AF_UNSPEC" -> | |
0 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "AF_UNIX" -> | |
1 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "AF_INET6" -> | |
30 | |
| Ctypes_static.Primitive Cstubs_internals.Int, "AF_INET" -> | |
2 | |
| _, s -> failwith ("unmatched constant: "^ s) | |
let enum (type a) name ?typedef ?unexpected (alist : (a * int64) list) = | |
match name with | |
| s -> | |
failwith ("unmatched enum: "^ s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment