update cocoa bridge to use c-type words

db4
Joe Groff 2009-10-21 18:17:29 -05:00
parent c5dd8d0b20
commit cc5f9ff98a
7 changed files with 157 additions and 145 deletions

View File

@ -16,11 +16,11 @@ CLASS: {
{ +superclass+ "NSObject" }
}
{ "perform:" "void" { "id" "SEL" "id" }
{ "perform:" void { id SEL id }
[ 2drop callbacks get at try ]
}
{ "dealloc" "void" { "id" "SEL" }
{ "dealloc" void { id SEL }
[
drop
dup callbacks get delete-at

View File

@ -8,8 +8,8 @@ CLASS: {
{ +name+ "Foo" }
} {
"foo:"
"void"
{ "id" "SEL" "NSRect" }
void
{ id SEL NSRect }
[ gc "x" set 2drop ]
} ;
@ -30,8 +30,8 @@ CLASS: {
{ +name+ "Bar" }
} {
"bar"
"NSRect"
{ "id" "SEL" }
NSRect
{ id SEL }
[ 2drop test-foo "x" get ]
} ;
@ -52,13 +52,13 @@ CLASS: {
{ +name+ "Bar" }
} {
"bar"
"NSRect"
{ "id" "SEL" }
NSRect
{ id SEL }
[ 2drop test-foo "x" get ]
} {
"babb"
"int"
{ "id" "SEL" "int" }
int
{ id SEL int }
[ 2nip sq ]
} ;

View File

@ -2,10 +2,12 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.strings arrays assocs
classes.struct continuations combinators compiler compiler.alien
stack-checker kernel math namespaces make quotations sequences
strings words cocoa.runtime io macros memoize io.encodings.utf8
effects libc libc.private lexer init core-foundation fry
generalizations specialized-arrays ;
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
libc.private lexer init core-foundation fry generalizations
specialized-arrays ;
QUALIFIED-WITH: alien.c-types c
IN: cocoa.messages
SPECIALIZED-ARRAY: void*
@ -98,75 +100,84 @@ class-init-hooks [ H{ } clone ] initialize
SYMBOL: objc>alien-types
H{
{ "c" "char" }
{ "i" "int" }
{ "s" "short" }
{ "C" "uchar" }
{ "I" "uint" }
{ "S" "ushort" }
{ "f" "float" }
{ "d" "double" }
{ "B" "bool" }
{ "v" "void" }
{ "*" "char*" }
{ "?" "unknown_type" }
{ "@" "id" }
{ "#" "Class" }
{ ":" "SEL" }
{ "c" c:char }
{ "i" c:int }
{ "s" c:short }
{ "C" c:uchar }
{ "I" c:uint }
{ "S" c:ushort }
{ "f" c:float }
{ "d" c:double }
{ "B" c:bool }
{ "v" c:void }
{ "*" c:char* }
{ "?" unknown_type }
{ "@" id }
{ "#" Class }
{ ":" SEL }
}
"ptrdiff_t" heap-size {
cell {
{ 4 [ H{
{ "l" "long" }
{ "q" "longlong" }
{ "L" "ulong" }
{ "Q" "ulonglong" }
{ "l" c:long }
{ "q" c:longlong }
{ "L" c:ulong }
{ "Q" c:ulonglong }
} ] }
{ 8 [ H{
{ "l" "long32" }
{ "q" "long" }
{ "L" "ulong32" }
{ "Q" "ulong" }
{ "l" long32 }
{ "q" long }
{ "L" ulong32 }
{ "Q" ulong }
} ] }
} case
assoc-union objc>alien-types set-global
SYMBOL: objc>struct-types
H{
{ "_NSPoint" NSPoint }
{ "NSPoint" NSPoint }
{ "CGPoint" NSPoint }
{ "_NSRect" NSRect }
{ "NSRect" NSRect }
{ "CGRect" NSRect }
{ "_NSSize" NSSize }
{ "NSSize" NSSize }
{ "CGSize" NSSize }
{ "_NSRange" NSRange }
{ "NSRange" NSRange }
} objc>struct-types set-global
! The transpose of the above map
SYMBOL: alien>objc-types
objc>alien-types get [ swap ] assoc-map
! A hack...
"ptrdiff_t" heap-size {
cell {
{ 4 [ H{
{ "NSPoint" "{_NSPoint=ff}" }
{ "NSRect" "{_NSRect={_NSPoint=ff}{_NSSize=ff}}" }
{ "NSSize" "{_NSSize=ff}" }
{ "NSRange" "{_NSRange=II}" }
{ "NSInteger" "i" }
{ "NSUInteger" "I" }
{ "CGFloat" "f" }
{ NSPoint "{_NSPoint=ff}" }
{ NSRect "{_NSRect={_NSPoint=ff}{_NSSize=ff}}" }
{ NSSize "{_NSSize=ff}" }
{ NSRange "{_NSRange=II}" }
{ NSInteger "i" }
{ NSUInteger "I" }
{ CGFloat "f" }
} ] }
{ 8 [ H{
{ "NSPoint" "{CGPoint=dd}" }
{ "NSRect" "{CGRect={CGPoint=dd}{CGSize=dd}}" }
{ "NSSize" "{CGSize=dd}" }
{ "NSRange" "{_NSRange=QQ}" }
{ "NSInteger" "q" }
{ "NSUInteger" "Q" }
{ "CGFloat" "d" }
{ NSPoint "{CGPoint=dd}" }
{ NSRect "{CGRect={CGPoint=dd}{CGSize=dd}}" }
{ NSSize "{CGSize=dd}" }
{ NSRange "{_NSRange=QQ}" }
{ NSInteger "q" }
{ NSUInteger "Q" }
{ CGFloat "d" }
} ] }
} case
assoc-union alien>objc-types set-global
: internal-cocoa-type? ( c-type -- ? )
[ "?" = ] [ first CHAR: _ = ] bi or ;
: warn-c-type ( c-type -- )
dup internal-cocoa-type?
[ drop ] [ "Warning: no such C type: " write print ] if ;
: objc-struct-type ( i string -- ctype )
[ CHAR: = ] 2keep index-from swap subseq
dup c-types get key? [ warn-c-type "void*" ] unless ;
objc>struct-types get at* [ drop void* ] unless ;
ERROR: no-objc-type name ;
@ -177,9 +188,9 @@ ERROR: no-objc-type name ;
: (parse-objc-type) ( i string -- ctype )
[ [ 1 + ] dip ] [ nth ] 2bi {
{ [ dup "rnNoORV" member? ] [ drop (parse-objc-type) ] }
{ [ dup CHAR: ^ = ] [ 3drop "void*" ] }
{ [ dup CHAR: ^ = ] [ 3drop void* ] }
{ [ dup CHAR: { = ] [ drop objc-struct-type ] }
{ [ dup CHAR: [ = ] [ 3drop "void*" ] }
{ [ dup CHAR: [ = ] [ 3drop void* ] }
[ 2nip decode-type ]
} cond ;

View File

@ -9,8 +9,8 @@ CLASS: {
{ +name+ "Bar" }
} {
"bar:"
"float"
{ "id" "SEL" "NSRect" }
float
{ id SEL NSRect }
[
[ origin>> [ x>> ] [ y>> ] bi + ]
[ size>> [ w>> ] [ h>> ] bi + ]

View File

@ -218,7 +218,7 @@ CLASS: {
{ +name+ "FactorApplicationDelegate" }
}
{ "applicationDidUpdate:" "void" { "id" "SEL" "id" }
{ "applicationDidUpdate:" void { id SEL id }
[ 3drop reset-run-loop ]
} ;

View File

@ -1,11 +1,12 @@
! Copyright (C) 2006, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax cocoa cocoa.nibs cocoa.application
cocoa.classes cocoa.dialogs cocoa.pasteboard cocoa.subclassing
core-foundation core-foundation.strings help.topics kernel
memory namespaces parser system ui ui.tools.browser
ui.tools.listener ui.backend.cocoa eval locals
vocabs.refresh ;
cocoa.classes cocoa.dialogs cocoa.pasteboard cocoa.runtime
cocoa.subclassing core-foundation core-foundation.strings
help.topics kernel memory namespaces parser system ui
ui.tools.browser ui.tools.listener ui.backend.cocoa eval
locals vocabs.refresh ;
FROM: alien.c-types => int void ;
IN: ui.backend.cocoa.tools
: finder-run-files ( alien -- )
@ -25,43 +26,43 @@ CLASS: {
{ +name+ "FactorWorkspaceApplicationDelegate" }
}
{ "application:openFiles:" "void" { "id" "SEL" "id" "id" }
{ "application:openFiles:" void { id SEL id id }
[ [ 3drop ] dip finder-run-files ]
}
{ "applicationShouldHandleReopen:hasVisibleWindows:" "int" { "id" "SEL" "id" "int" }
{ "applicationShouldHandleReopen:hasVisibleWindows:" int { id SEL id int }
[ [ 3drop ] dip 0 = [ show-listener ] when 1 ]
}
{ "factorListener:" "id" { "id" "SEL" "id" }
{ "factorListener:" id { id SEL id }
[ 3drop show-listener f ]
}
{ "factorBrowser:" "id" { "id" "SEL" "id" }
{ "factorBrowser:" id { id SEL id }
[ 3drop show-browser f ]
}
{ "newFactorListener:" "id" { "id" "SEL" "id" }
{ "newFactorListener:" id { id SEL id }
[ 3drop listener-window f ]
}
{ "newFactorBrowser:" "id" { "id" "SEL" "id" }
{ "newFactorBrowser:" id { id SEL id }
[ 3drop browser-window f ]
}
{ "runFactorFile:" "id" { "id" "SEL" "id" }
{ "runFactorFile:" id { id SEL id }
[ 3drop menu-run-files f ]
}
{ "saveFactorImage:" "id" { "id" "SEL" "id" }
{ "saveFactorImage:" id { id SEL id }
[ 3drop save f ]
}
{ "saveFactorImageAs:" "id" { "id" "SEL" "id" }
{ "saveFactorImageAs:" id { id SEL id }
[ 3drop menu-save-image f ]
}
{ "refreshAll:" "id" { "id" "SEL" "id" }
{ "refreshAll:" id { id SEL id }
[ 3drop [ refresh-all ] \ refresh-all call-listener f ]
} ;
@ -79,13 +80,13 @@ CLASS: {
{ +name+ "FactorServiceProvider" }
} {
"evalInListener:userData:error:"
"void"
{ "id" "SEL" "id" "id" "id" }
void
{ id SEL id id id }
[ nip [ eval-listener f ] do-service 2drop ]
} {
"evalToString:userData:error:"
"void"
{ "id" "SEL" "id" "id" "id" }
void
{ id SEL id id id }
[ nip [ eval>string ] do-service 2drop ]
} ;

View File

@ -3,8 +3,8 @@
USING: accessors alien alien.c-types alien.data alien.strings
arrays assocs cocoa kernel math cocoa.messages cocoa.subclassing
cocoa.classes cocoa.views cocoa.application cocoa.pasteboard
cocoa.types cocoa.windows sequences io.encodings.utf8 ui ui.private
ui.gadgets ui.gadgets.private ui.gadgets.worlds ui.gestures
cocoa.runtime cocoa.types cocoa.windows sequences io.encodings.utf8
ui ui.private ui.gadgets ui.gadgets.private ui.gadgets.worlds ui.gestures
core-foundation.strings core-graphics core-graphics.types threads
combinators math.rectangles ;
IN: ui.backend.cocoa.views
@ -148,76 +148,76 @@ CLASS: {
}
! Rendering
{ "drawRect:" "void" { "id" "SEL" "NSRect" }
{ "drawRect:" void { id SEL NSRect }
[ 2drop window relayout-1 yield ]
}
! Events
{ "acceptsFirstMouse:" "char" { "id" "SEL" "id" }
{ "acceptsFirstMouse:" char { id SEL id }
[ 3drop 1 ]
}
{ "mouseEntered:" "void" { "id" "SEL" "id" }
{ "mouseEntered:" void { id SEL id }
[ nip send-mouse-moved ]
}
{ "mouseExited:" "void" { "id" "SEL" "id" }
{ "mouseExited:" void { id SEL id }
[ 3drop forget-rollover ]
}
{ "mouseMoved:" "void" { "id" "SEL" "id" }
{ "mouseMoved:" void { id SEL id }
[ nip send-mouse-moved ]
}
{ "mouseDragged:" "void" { "id" "SEL" "id" }
{ "mouseDragged:" void { id SEL id }
[ nip send-mouse-moved ]
}
{ "rightMouseDragged:" "void" { "id" "SEL" "id" }
{ "rightMouseDragged:" void { id SEL id }
[ nip send-mouse-moved ]
}
{ "otherMouseDragged:" "void" { "id" "SEL" "id" }
{ "otherMouseDragged:" void { id SEL id }
[ nip send-mouse-moved ]
}
{ "mouseDown:" "void" { "id" "SEL" "id" }
{ "mouseDown:" void { id SEL id }
[ nip send-button-down$ ]
}
{ "mouseUp:" "void" { "id" "SEL" "id" }
{ "mouseUp:" void { id SEL id }
[ nip send-button-up$ ]
}
{ "rightMouseDown:" "void" { "id" "SEL" "id" }
{ "rightMouseDown:" void { id SEL id }
[ nip send-button-down$ ]
}
{ "rightMouseUp:" "void" { "id" "SEL" "id" }
{ "rightMouseUp:" void { id SEL id }
[ nip send-button-up$ ]
}
{ "otherMouseDown:" "void" { "id" "SEL" "id" }
{ "otherMouseDown:" void { id SEL id }
[ nip send-button-down$ ]
}
{ "otherMouseUp:" "void" { "id" "SEL" "id" }
{ "otherMouseUp:" void { id SEL id }
[ nip send-button-up$ ]
}
{ "scrollWheel:" "void" { "id" "SEL" "id" }
{ "scrollWheel:" void { id SEL id }
[ nip send-wheel$ ]
}
{ "keyDown:" "void" { "id" "SEL" "id" }
{ "keyDown:" void { id SEL id }
[ nip send-key-down-event ]
}
{ "keyUp:" "void" { "id" "SEL" "id" }
{ "keyUp:" void { id SEL id }
[ nip send-key-up-event ]
}
{ "validateUserInterfaceItem:" "char" { "id" "SEL" "id" }
{ "validateUserInterfaceItem:" char { id SEL id }
[
nip -> action
2dup [ window ] [ utf8 alien>string ] bi* validate-action
@ -225,57 +225,57 @@ CLASS: {
]
}
{ "undo:" "id" { "id" "SEL" "id" }
{ "undo:" id { id SEL id }
[ nip undo-action send-action$ ]
}
{ "redo:" "id" { "id" "SEL" "id" }
{ "redo:" id { id SEL id }
[ nip redo-action send-action$ ]
}
{ "cut:" "id" { "id" "SEL" "id" }
{ "cut:" id { id SEL id }
[ nip cut-action send-action$ ]
}
{ "copy:" "id" { "id" "SEL" "id" }
{ "copy:" id { id SEL id }
[ nip copy-action send-action$ ]
}
{ "paste:" "id" { "id" "SEL" "id" }
{ "paste:" id { id SEL id }
[ nip paste-action send-action$ ]
}
{ "delete:" "id" { "id" "SEL" "id" }
{ "delete:" id { id SEL id }
[ nip delete-action send-action$ ]
}
{ "selectAll:" "id" { "id" "SEL" "id" }
{ "selectAll:" id { id SEL id }
[ nip select-all-action send-action$ ]
}
{ "newDocument:" "id" { "id" "SEL" "id" }
{ "newDocument:" id { id SEL id }
[ nip new-action send-action$ ]
}
{ "openDocument:" "id" { "id" "SEL" "id" }
{ "openDocument:" id { id SEL id }
[ nip open-action send-action$ ]
}
{ "saveDocument:" "id" { "id" "SEL" "id" }
{ "saveDocument:" id { id SEL id }
[ nip save-action send-action$ ]
}
{ "saveDocumentAs:" "id" { "id" "SEL" "id" }
{ "saveDocumentAs:" id { id SEL id }
[ nip save-as-action send-action$ ]
}
{ "revertDocumentToSaved:" "id" { "id" "SEL" "id" }
{ "revertDocumentToSaved:" id { id SEL id }
[ nip revert-action send-action$ ]
}
! Multi-touch gestures: this is undocumented.
! http://cocoadex.com/2008/02/nsevent-modifications-swipe-ro.html
{ "magnifyWithEvent:" "void" { "id" "SEL" "id" }
{ "magnifyWithEvent:" void { id SEL id }
[
nip
dup -> deltaZ sgn {
@ -286,7 +286,7 @@ CLASS: {
]
}
{ "swipeWithEvent:" "void" { "id" "SEL" "id" }
{ "swipeWithEvent:" void { id SEL id }
[
nip
dup -> deltaX sgn {
@ -305,14 +305,14 @@ CLASS: {
]
}
! "rotateWithEvent:" "void" { "id" "SEL" "id" }}
! "rotateWithEvent:" void { id SEL id }}
{ "acceptsFirstResponder" "char" { "id" "SEL" }
{ "acceptsFirstResponder" char { id SEL }
[ 2drop 1 ]
}
! Services
{ "validRequestorForSendType:returnType:" "id" { "id" "SEL" "id" "id" }
{ "validRequestorForSendType:returnType:" id { id SEL id id }
[
! We return either self or nil
[ over window-focus ] 2dip
@ -320,7 +320,7 @@ CLASS: {
]
}
{ "writeSelectionToPasteboard:types:" "char" { "id" "SEL" "id" "id" }
{ "writeSelectionToPasteboard:types:" char { id SEL id id }
[
CF>string-array NSStringPboardType swap member? [
[ drop window-focus gadget-selection ] dip over
@ -329,7 +329,7 @@ CLASS: {
]
}
{ "readSelectionFromPasteboard:" "char" { "id" "SEL" "id" }
{ "readSelectionFromPasteboard:" char { id SEL id }
[
pasteboard-string dup [
[ drop window ] dip swap user-input 1
@ -338,60 +338,60 @@ CLASS: {
}
! Text input
{ "insertText:" "void" { "id" "SEL" "id" }
{ "insertText:" void { id SEL id }
[ nip CF>string swap window user-input ]
}
{ "hasMarkedText" "char" { "id" "SEL" }
{ "hasMarkedText" char { id SEL }
[ 2drop 0 ]
}
{ "markedRange" "NSRange" { "id" "SEL" }
{ "markedRange" NSRange { id SEL }
[ 2drop 0 0 <NSRange> ]
}
{ "selectedRange" "NSRange" { "id" "SEL" }
{ "selectedRange" NSRange { id SEL }
[ 2drop 0 0 <NSRange> ]
}
{ "setMarkedText:selectedRange:" "void" { "id" "SEL" "id" "NSRange" }
{ "setMarkedText:selectedRange:" void { id SEL id NSRange }
[ 2drop 2drop ]
}
{ "unmarkText" "void" { "id" "SEL" }
{ "unmarkText" void { id SEL }
[ 2drop ]
}
{ "validAttributesForMarkedText" "id" { "id" "SEL" }
{ "validAttributesForMarkedText" id { id SEL }
[ 2drop NSArray -> array ]
}
{ "attributedSubstringFromRange:" "id" { "id" "SEL" "NSRange" }
{ "attributedSubstringFromRange:" id { id SEL NSRange }
[ 3drop f ]
}
{ "characterIndexForPoint:" "NSUInteger" { "id" "SEL" "NSPoint" }
{ "characterIndexForPoint:" NSUInteger { id SEL NSPoint }
[ 3drop 0 ]
}
{ "firstRectForCharacterRange:" "NSRect" { "id" "SEL" "NSRange" }
{ "firstRectForCharacterRange:" NSRect { id SEL NSRange }
[ 3drop 0 0 0 0 <CGRect> ]
}
{ "conversationIdentifier" "NSInteger" { "id" "SEL" }
{ "conversationIdentifier" NSInteger { id SEL }
[ drop alien-address ]
}
! Initialization
{ "updateFactorGadgetSize:" "void" { "id" "SEL" "id" }
{ "updateFactorGadgetSize:" void { id SEL id }
[ 2drop [ window ] [ view-dim ] bi >>dim drop yield ]
}
{ "doCommandBySelector:" "void" { "id" "SEL" "SEL" }
{ "doCommandBySelector:" void { id SEL SEL }
[ 3drop ]
}
{ "initWithFrame:pixelFormat:" "id" { "id" "SEL" "NSRect" "id" }
{ "initWithFrame:pixelFormat:" id { id SEL NSRect id }
[
[ drop ] 2dip
SUPER-> initWithFrame:pixelFormat:
@ -399,13 +399,13 @@ CLASS: {
]
}
{ "isOpaque" "char" { "id" "SEL" }
{ "isOpaque" char { id SEL }
[
2drop 0
]
}
{ "dealloc" "void" { "id" "SEL" }
{ "dealloc" void { id SEL }
[
drop
[ unregister-window ]
@ -430,19 +430,19 @@ CLASS: {
{ +name+ "FactorWindowDelegate" }
}
{ "windowDidMove:" "void" { "id" "SEL" "id" }
{ "windowDidMove:" void { id SEL id }
[
2nip -> object [ -> contentView window ] keep save-position
]
}
{ "windowDidBecomeKey:" "void" { "id" "SEL" "id" }
{ "windowDidBecomeKey:" void { id SEL id }
[
2nip -> object -> contentView window focus-world
]
}
{ "windowDidResignKey:" "void" { "id" "SEL" "id" }
{ "windowDidResignKey:" void { id SEL id }
[
forget-rollover
2nip -> object -> contentView
@ -452,13 +452,13 @@ CLASS: {
]
}
{ "windowShouldClose:" "char" { "id" "SEL" "id" }
{ "windowShouldClose:" char { id SEL id }
[
3drop 1
]
}
{ "windowWillClose:" "void" { "id" "SEL" "id" }
{ "windowWillClose:" void { id SEL id }
[
2nip -> object -> contentView window ungraft
]