diff --git a/bindgen/caml.ml b/bindgen/caml.ml index 6f8ca97..50353aa 100644 --- a/bindgen/caml.ml +++ b/bindgen/caml.ml @@ -32,13 +32,20 @@ let rec core_type_from_ir typ = | Ir.Prim Char -> Typ.constr (lid "char") [] | Ir.Prim Void -> Typ.constr (lid "unit") [] | Ir.Ptr t -> core_type_from_ir t - | Ir.Func { fn_ret; fn_params } -> - List.fold_left - (fun acc (name, typ) -> - let label = Asttypes.Labelled name in - let typ = core_type_from_ir typ in - Typ.arrow label typ acc) - (core_type_from_ir fn_ret) fn_params + | Ir.Func { fn_ret; fn_params } -> ( + match fn_params with + | [] -> + (* If the C function declaration has no parameters we must introduce a `unit` param *) + Typ.arrow Asttypes.Nolabel + (core_type_from_ir (Ir.Prim Void)) + (core_type_from_ir fn_ret) + | params -> + List.fold_left + (fun acc (name, typ) -> + let label = Asttypes.Labelled name in + let typ = core_type_from_ir typ in + Typ.arrow label typ acc) + (core_type_from_ir fn_ret) params) let type_from_ir typ = match typ with diff --git a/examples/caml_doggo.c b/examples/caml_doggo.c index 73f3e38..35536cb 100644 --- a/examples/caml_doggo.c +++ b/examples/caml_doggo.c @@ -31,4 +31,10 @@ void caml_eleven_out_of_ten_majestic_af(value caml_pupper) { CAMLreturn0; } +void caml_no_input_no_output() { + CAMLparam0(); + no_input_no_output(); + CAMLreturn0; +} + diff --git a/examples/doggo.c b/examples/doggo.c index 60a4784..bbf5c9d 100644 --- a/examples/doggo.c +++ b/examples/doggo.c @@ -13,3 +13,6 @@ void eleven_out_of_ten_majestic_af(Doggo* pupper) { printf("doggo is a %s\n", BreedToString[pupper->breed]); } +void no_input_no_output(void) { + printf("We are doing nothing (of importance)\n"); +} \ No newline at end of file diff --git a/examples/doggo.h b/examples/doggo.h index ea8d8dd..cc65fe9 100644 --- a/examples/doggo.h +++ b/examples/doggo.h @@ -12,3 +12,5 @@ typedef struct Doggo { } Doggo; void eleven_out_of_ten_majestic_af(Doggo* pupper); + +void no_input_no_output(void); \ No newline at end of file diff --git a/examples/doggo.ml b/examples/doggo.ml index 9b9bbe2..ca1434a 100644 --- a/examples/doggo.ml +++ b/examples/doggo.ml @@ -10,3 +10,4 @@ type nonrec doggo = { wow: char } external eleven_out_of_ten_majestic_af : pupper:doggo -> unit = "caml_eleven_out_of_ten_majestic_af" +external no_input_no_output : unit -> unit = "caml_no_input_no_output"