From 1f18d54a8420e511faef85f856e62bb5de317180 Mon Sep 17 00:00:00 2001 From: "Boris D." Date: Thu, 16 May 2024 09:24:37 -0700 Subject: [PATCH] Refactor. --- runtime/objc_t.ml | 5 +++++ runtime/runtime.ml | 6 +++++- test/test_objc.ml | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/runtime/objc_t.ml b/runtime/objc_t.ml index 80d8a066..42daff3e 100644 --- a/runtime/objc_t.ml +++ b/runtime/objc_t.ml @@ -13,6 +13,7 @@ type _ t = | Short : int t | Long : Signed.long t | LLong : Signed.llong t +| ULLong : Unsigned.ullong t | Float : float t | Double : float t | Unknown : unit ptr t @@ -44,6 +45,7 @@ let int = Int let short = Short let long = Long let llong = LLong +let ullong = ULLong let float = Float let double = Double let unknown = Unknown @@ -69,6 +71,7 @@ let rec ctype_of_t | Short -> short | Long -> long | LLong -> llong + | ULLong -> ullong | Float -> float | Double -> double | Unknown -> ptr void @@ -98,6 +101,7 @@ module Encode = struct | Short -> sizeof (ctype_of_t Short) | Long -> sizeof (ctype_of_t Long) | LLong -> sizeof (ctype_of_t LLong) + | ULLong -> sizeof (ctype_of_t ULLong) | Float -> sizeof (ctype_of_t Float) | Double -> sizeof (ctype_of_t Double) | Unknown -> sizeof (ctype_of_t Unknown) @@ -124,6 +128,7 @@ module Encode = struct | Short -> "s" | Long -> "l" | LLong -> "q" + | ULLong -> "Q" | Float -> "f" | Double -> "d" | Unknown -> "?" diff --git a/runtime/runtime.ml b/runtime/runtime.ml index 00e964ea..8b8f89f7 100644 --- a/runtime/runtime.ml +++ b/runtime/runtime.ml @@ -275,13 +275,17 @@ module Block = struct let block_is_global = Int.(shift_left one 28) let _class_ = Objc.get_class "__NSGlobalBlock" - let make f ~typ = + let make' f ~typ = let b = make t in setf b isa _class_; setf b descriptor desc_ptr; setf b invoke (coerce (Foreign.funptr typ) (ptr void) f); setf b flags block_is_global; allocate t b |> coerce (ptr t) (ptr void) + + let make f ~args ~return = + let typ = Objc_t.method_typ ~args: (Objc_t.id :: args) return in + make' f ~typ end module Def = diff --git a/test/test_objc.ml b/test/test_objc.ml index b0a02174..5a7458b4 100644 --- a/test/test_objc.ml +++ b/test/test_objc.ml @@ -193,8 +193,10 @@ let test_block () = ar |> NSMutableArray.addObject (new_string "World"); let block = Block.make - ~typ: (id @-> id @-> ullong @-> bool @-> returning void) - (fun _blk obj idx _stop -> + (* ~typ: (id @-> id @-> ullong @-> bool @-> returning void) *) + ~args: Objc_t.[id; ullong; bool] + ~return: Objc_t.void + (fun _self obj idx _stop -> actual := Printf.sprintf "%d: %s" (ULLong.to_int idx)