Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboris committed May 16, 2024
1 parent d040fcc commit 1f18d54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions runtime/objc_t.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -69,6 +71,7 @@ let rec ctype_of_t
| Short -> short
| Long -> long
| LLong -> llong
| ULLong -> ullong
| Float -> float
| Double -> double
| Unknown -> ptr void
Expand Down Expand Up @@ -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)
Expand All @@ -124,6 +128,7 @@ module Encode = struct
| Short -> "s"
| Long -> "l"
| LLong -> "q"
| ULLong -> "Q"
| Float -> "f"
| Double -> "d"
| Unknown -> "?"
Expand Down
6 changes: 5 additions & 1 deletion runtime/runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 4 additions & 2 deletions test/test_objc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1f18d54

Please sign in to comment.