 core-graphics.types stack-checker kernel math namespaces make
 quotations sequences strings words cocoa.runtime cocoa.types io
 macros memoize io.encodings.utf8 effects layouts libc lexer init
-core-foundation fry generalizations specialized-arrays ;
+core-foundation fry generalizations specialized-arrays locals ;
 QUALIFIED-WITH: alien.c-types c
 IN: cocoa.messages
 
 SPECIALIZED-ARRAY: void*
 
-: make-sender ( method function -- quot )
+: make-sender ( signature function -- quot )
     [ over first , f , , second , \ alien-invoke , ] [ ] make ;
 
-: sender-stub ( method function -- word )
-    [ "( sender-stub )" f <word> dup ] 2dip
+: sender-stub ( name signature function -- word )
+    [ "( sender-stub:" ")" surround f <word> dup ] 2dip
     over first large-struct? [ "_stret" append ] when
     make-sender dup infer define-declared ;
 

message-senders [ H{ } clone ] initialize
super-message-senders [ H{ } clone ] initialize

: cache-stub ( method assoc function -- )
    '[ _ sender-stub ] cache drop ;

: cache-stubs ( method -- )
    [ super-message-senders get "objc_msgSendSuper" cache-stub ]
    [ message-senders get "objc_msgSend" cache-stub ]
    bi ;

: <super> ( receiver -- super )
    [ ] [ object_getClass class_getSuperclass ] bi

    [ utf8 alien>string parse-objc-type ] keep
    (free) ;

: method-name ( method -- name )
    method_getName sel_getName ;

: register-objc-method ( method -- )
    [ method-name ]
    [ [ method-return-type ] [ method-arg-types ] bi 2array ] bi
    [ cache-stubs ] [ swap objc-methods get set-at ] 2bi ;

: each-method-in-class ( class quot -- )
    [ { uint } [ class_copyMethodList ] with-out-parameters ] dip
