 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 ;
 

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

: register-objc-method ( method -- )
    dup method-return-type over method-arg-types 2array
    dup cache-stubs
    swap method_getName sel_getName
    objc-methods get set-at ;

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

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

:: cache-stub ( name signature function assoc -- )
    signature assoc [ [ name ] dip function sender-stub ] cache drop ;

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

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