update cocoa and core-foundation stuff to use classes.struct and boxed malloc-arrays

db4
Joe Groff 2009-08-29 12:22:55 -05:00
parent 8a9d0e13bb
commit 2eff554273
9 changed files with 83 additions and 96 deletions

View File

@ -1,27 +1,28 @@
! Copyright (C) 2008 Joe Groff. ! Copyright (C) 2008 Joe Groff.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel cocoa cocoa.types alien.c-types locals math USING: accessors kernel classes.struct cocoa cocoa.types alien.c-types
sequences vectors fry libc destructors locals math sequences vectors fry libc destructors ;
specialized-arrays.direct.alien ;
IN: cocoa.enumeration IN: cocoa.enumeration
<< "id" require-c-type-arrays >>
CONSTANT: NS-EACH-BUFFER-SIZE 16 CONSTANT: NS-EACH-BUFFER-SIZE 16
: with-enumeration-buffers ( quot -- ) : with-enumeration-buffers ( quot -- )
'[ '[
"NSFastEnumerationState" malloc-object &free NSFastEnumerationState malloc-struct &free
NS-EACH-BUFFER-SIZE "id" malloc-array &free NS-EACH-BUFFER-SIZE "id" malloc-array &free
NS-EACH-BUFFER-SIZE NS-EACH-BUFFER-SIZE
@ @
] with-destructors ; inline ] with-destructors ; inline
:: (NSFastEnumeration-each) ( object quot: ( elt -- ) state stackbuf count -- ) :: (NSFastEnumeration-each) ( object quot: ( elt -- ) state stackbuf count -- )
object state stackbuf count -> countByEnumeratingWithState:objects:count: object state stackbuf count -> countByEnumeratingWithState:objects:count: :> items-count
dup 0 = [ drop ] [ items-count 0 = [
state NSFastEnumerationState-itemsPtr [ stackbuf ] unless* state itemsPtr>> [ items-count "id" <c-type-direct-array> ] [ stackbuf ] if* :> items
swap <direct-void*-array> quot each items-count iota [ items nth quot call ] each
object quot state stackbuf count (NSFastEnumeration-each) object quot state stackbuf count (NSFastEnumeration-each)
] if ; inline recursive ] unless ; inline recursive
: NSFastEnumeration-each ( object quot -- ) : NSFastEnumeration-each ( object quot -- )
[ (NSFastEnumeration-each) ] with-enumeration-buffers ; inline [ (NSFastEnumeration-each) ] with-enumeration-buffers ; inline

View File

@ -1,11 +1,11 @@
! Copyright (C) 2006, 2009 Slava Pestov. ! Copyright (C) 2006, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.strings arrays assocs USING: accessors alien alien.c-types alien.strings arrays assocs
continuations combinators compiler compiler.alien stack-checker kernel classes.struct continuations combinators compiler compiler.alien
math namespaces make quotations sequences strings words stack-checker kernel math namespaces make quotations sequences
cocoa.runtime io macros memoize io.encodings.utf8 effects libc strings words cocoa.runtime io macros memoize io.encodings.utf8
libc.private lexer init core-foundation fry generalizations effects libc libc.private lexer init core-foundation fry
specialized-arrays.direct.alien ; generalizations specialized-arrays.direct.alien ;
IN: cocoa.messages IN: cocoa.messages
: make-sender ( method function -- quot ) : make-sender ( method function -- quot )
@ -31,11 +31,8 @@ super-message-senders [ H{ } clone ] initialize
bi ; bi ;
: <super> ( receiver -- super ) : <super> ( receiver -- super )
"objc-super" <c-object> [ [ ] [ object_getClass class_getSuperclass ] bi
[ dup object_getClass class_getSuperclass ] dip objc-super <struct-boa> ;
set-objc-super-class
] keep
[ set-objc-super-receiver ] keep ;
TUPLE: selector name object ; TUPLE: selector name object ;

View File

@ -1,6 +1,6 @@
! Copyright (C) 2006, 2007 Slava Pestov ! Copyright (C) 2006, 2007 Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax ; USING: alien.syntax classes.struct ;
IN: cocoa.runtime IN: cocoa.runtime
TYPEDEF: void* SEL TYPEDEF: void* SEL
@ -17,9 +17,9 @@ TYPEDEF: void* Class
TYPEDEF: void* Method TYPEDEF: void* Method
TYPEDEF: void* Protocol TYPEDEF: void* Protocol
C-STRUCT: objc-super STRUCT: objc-super
{ "id" "receiver" } { receiver id }
{ "Class" "class" } ; { class Class } ;
CONSTANT: CLS_CLASS HEX: 1 CONSTANT: CLS_CLASS HEX: 1
CONSTANT: CLS_META HEX: 2 CONSTANT: CLS_META HEX: 2

View File

@ -1,7 +1,7 @@
! Copyright (C) 2006, 2009 Slava Pestov ! Copyright (C) 2006, 2009 Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.syntax combinators kernel layouts USING: alien.c-types alien.syntax combinators kernel layouts
core-graphics.types ; classes.struct core-graphics.types ;
IN: cocoa.types IN: cocoa.types
TYPEDEF: long NSInteger TYPEDEF: long NSInteger
@ -16,9 +16,9 @@ TYPEDEF: NSSize _NSSize
TYPEDEF: CGRect NSRect TYPEDEF: CGRect NSRect
TYPEDEF: NSRect _NSRect TYPEDEF: NSRect _NSRect
C-STRUCT: NSRange STRUCT: NSRange
{ "NSUInteger" "location" } { location NSUInteger }
{ "NSUInteger" "length" } ; { length NSUInteger } ;
TYPEDEF: NSRange _NSRange TYPEDEF: NSRange _NSRange
@ -27,13 +27,11 @@ TYPEDEF: int long32
TYPEDEF: uint ulong32 TYPEDEF: uint ulong32
TYPEDEF: void* unknown_type TYPEDEF: void* unknown_type
: <NSRange> ( length location -- size ) : <NSRange> ( location length -- size )
"NSRange" <c-object> NSRange <struct-boa> ;
[ set-NSRange-length ] keep
[ set-NSRange-location ] keep ;
C-STRUCT: NSFastEnumerationState STRUCT: NSFastEnumerationState
{ "ulong" "state" } { state ulong }
{ "id*" "itemsPtr" } { itemsPtr id* }
{ "ulong*" "mutationsPtr" } { mutationsPtr ulong* }
{ "ulong[5]" "extra" } ; { extra ulong[5] } ;

View File

@ -58,6 +58,6 @@ CONSTANT: NSOpenGLCPSwapInterval 222
: mouse-location ( view event -- loc ) : mouse-location ( view event -- loc )
[ [
-> locationInWindow f -> convertPoint:fromView: -> locationInWindow f -> convertPoint:fromView:
[ CGPoint-x ] [ CGPoint-y ] bi [ x>> ] [ y>> ] bi
] [ drop -> frame CGRect-h ] 2bi ] [ drop -> frame CGRect-h ] 2bi
swap - [ >integer ] bi@ 2array ; swap - [ >integer ] bi@ 2array ;

View File

@ -1,6 +1,6 @@
! Copyright (C) 2006, 2008 Slava Pestov ! Copyright (C) 2006, 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax alien.c-types alien.destructors accessors kernel ; USING: alien.syntax alien.c-types alien.destructors accessors classes.struct kernel ;
IN: core-foundation IN: core-foundation
TYPEDEF: void* CFTypeRef TYPEDEF: void* CFTypeRef
@ -20,14 +20,12 @@ TYPEDEF: void* CFUUIDRef
ALIAS: <CFIndex> <long> ALIAS: <CFIndex> <long>
ALIAS: *CFIndex *long ALIAS: *CFIndex *long
C-STRUCT: CFRange STRUCT: CFRange
{ "CFIndex" "location" } { location CFIndex }
{ "CFIndex" "length" } ; { length CFIndex } ;
: <CFRange> ( location length -- range ) : <CFRange> ( location length -- range )
"CFRange" <c-object> CFRange <struct-boa> ;
[ set-CFRange-length ] keep
[ set-CFRange-location ] keep ;
FUNCTION: CFTypeRef CFRetain ( CFTypeRef cf ) ; FUNCTION: CFTypeRef CFRetain ( CFTypeRef cf ) ;

View File

@ -3,7 +3,7 @@
USING: alien alien.c-types alien.strings alien.syntax kernel USING: alien alien.c-types alien.strings alien.syntax kernel
math sequences namespaces make assocs init accessors math sequences namespaces make assocs init accessors
continuations combinators io.encodings.utf8 destructors locals continuations combinators io.encodings.utf8 destructors locals
arrays specialized-arrays.direct.alien arrays specialized-arrays.direct.alien classes.struct
specialized-arrays.direct.int specialized-arrays.direct.longlong specialized-arrays.direct.int specialized-arrays.direct.longlong
core-foundation core-foundation.run-loop core-foundation.strings core-foundation core-foundation.run-loop core-foundation.strings
core-foundation.time ; core-foundation.time ;
@ -26,12 +26,12 @@ TYPEDEF: int FSEventStreamEventFlags
TYPEDEF: longlong FSEventStreamEventId TYPEDEF: longlong FSEventStreamEventId
TYPEDEF: void* FSEventStreamRef TYPEDEF: void* FSEventStreamRef
C-STRUCT: FSEventStreamContext STRUCT: FSEventStreamContext
{ "CFIndex" "version" } { version CFIndex }
{ "void*" "info" } { info void* }
{ "void*" "retain" } { retain void* }
{ "void*" "release" } { release void* }
{ "void*" "copyDescription" } ; { copyDescription void* } ;
! callback(FSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]); ! callback(FSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]);
TYPEDEF: void* FSEventStreamCallback TYPEDEF: void* FSEventStreamCallback
@ -104,8 +104,8 @@ FUNCTION: void FSEventStreamShow ( FSEventStreamRef streamRef ) ;
FUNCTION: CFStringRef FSEventStreamCopyDescription ( FSEventStreamRef streamRef ) ; FUNCTION: CFStringRef FSEventStreamCopyDescription ( FSEventStreamRef streamRef ) ;
: make-FSEventStreamContext ( info -- alien ) : make-FSEventStreamContext ( info -- alien )
"FSEventStreamContext" <c-object> FSEventStreamContext <struct>
[ set-FSEventStreamContext-info ] keep ; swap >>info ;
:: <FSEventStream> ( callback info paths latency flags -- event-stream ) :: <FSEventStream> ( callback info paths latency flags -- event-stream )
f ! allocator f ! allocator

View File

@ -1,6 +1,6 @@
! Copyright (C) 2009 Slava Pestov. ! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.syntax kernel layouts USING: accessors alien.c-types alien.syntax classes.struct kernel layouts
math math.rectangles arrays ; math math.rectangles arrays ;
IN: core-graphics.types IN: core-graphics.types
@ -12,63 +12,56 @@ IN: core-graphics.types
: *CGFloat ( alien -- x ) : *CGFloat ( alien -- x )
cell 4 = [ *float ] [ *double ] if ; inline cell 4 = [ *float ] [ *double ] if ; inline
C-STRUCT: CGPoint STRUCT: CGPoint
{ "CGFloat" "x" } { x CGFloat }
{ "CGFloat" "y" } ; { y CGFloat } ;
: <CGPoint> ( x y -- point ) : <CGPoint> ( x y -- point )
"CGPoint" <c-object> CGPoint <struct-boa> ;
[ set-CGPoint-y ] keep
[ set-CGPoint-x ] keep ;
C-STRUCT: CGSize STRUCT: CGSize
{ "CGFloat" "w" } { w CGFloat }
{ "CGFloat" "h" } ; { h CGFloat } ;
: <CGSize> ( w h -- size ) : <CGSize> ( w h -- size )
"CGSize" <c-object> CGSize <struct-boa> ;
[ set-CGSize-h ] keep
[ set-CGSize-w ] keep ;
C-STRUCT: CGRect STRUCT: CGRect
{ "CGPoint" "origin" } { origin CGPoint }
{ "CGSize" "size" } ; { size CGSize } ;
: CGPoint>loc ( CGPoint -- loc ) : CGPoint>loc ( CGPoint -- loc )
[ CGPoint-x ] [ CGPoint-y ] bi 2array ; [ x>> ] [ y>> ] bi 2array ;
: CGSize>dim ( CGSize -- dim ) : CGSize>dim ( CGSize -- dim )
[ CGSize-w ] [ CGSize-h ] bi 2array ; [ w>> ] [ h>> ] bi 2array ;
: CGRect>rect ( CGRect -- rect ) : CGRect>rect ( CGRect -- rect )
[ CGRect-origin CGPoint>loc ] [ origin>> CGPoint>loc ]
[ CGRect-size CGSize>dim ] [ size>> CGSize>dim ]
bi <rect> ; inline bi <rect> ; inline
: CGRect-x ( CGRect -- x ) : CGRect-x ( CGRect -- x )
CGRect-origin CGPoint-x ; inline origin>> x>> ; inline
: CGRect-y ( CGRect -- y ) : CGRect-y ( CGRect -- y )
CGRect-origin CGPoint-y ; inline origin>> y>> ; inline
: CGRect-w ( CGRect -- w ) : CGRect-w ( CGRect -- w )
CGRect-size CGSize-w ; inline size>> w>> ; inline
: CGRect-h ( CGRect -- h ) : CGRect-h ( CGRect -- h )
CGRect-size CGSize-h ; inline size>> h>> ; inline
: set-CGRect-x ( x CGRect -- ) : set-CGRect-x ( x CGRect -- )
CGRect-origin set-CGPoint-x ; inline origin>> (>>x) ; inline
: set-CGRect-y ( y CGRect -- ) : set-CGRect-y ( y CGRect -- )
CGRect-origin set-CGPoint-y ; inline origin>> (>>y) ; inline
: set-CGRect-w ( w CGRect -- ) : set-CGRect-w ( w CGRect -- )
CGRect-size set-CGSize-w ; inline size>> (>>w) ; inline
: set-CGRect-h ( h CGRect -- ) : set-CGRect-h ( h CGRect -- )
CGRect-size set-CGSize-h ; inline size>> (>>h) ; inline
: <CGRect> ( x y w h -- rect ) : <CGRect> ( x y w h -- rect )
"CGRect" <c-object> [ CGPoint <struct-boa> ] [ CGSize <struct-boa> ] 2bi*
[ set-CGRect-h ] keep CGRect <struct-boa> ;
[ set-CGRect-w ] keep
[ set-CGRect-y ] keep
[ set-CGRect-x ] keep ;
: CGRect-x-y ( alien -- origin-x origin-y ) : CGRect-x-y ( alien -- origin-x origin-y )
[ CGRect-x ] [ CGRect-y ] bi ; [ CGRect-x ] [ CGRect-y ] bi ;
@ -76,13 +69,13 @@ C-STRUCT: CGRect
: CGRect-top-left ( alien -- x y ) : CGRect-top-left ( alien -- x y )
[ CGRect-x ] [ [ CGRect-y ] [ CGRect-h ] bi + ] bi ; [ CGRect-x ] [ [ CGRect-y ] [ CGRect-h ] bi + ] bi ;
C-STRUCT: CGAffineTransform STRUCT: CGAffineTransform
{ "CGFloat" "a" } { a CGFloat }
{ "CGFloat" "b" } { b CGFloat }
{ "CGFloat" "c" } { c CGFloat }
{ "CGFloat" "d" } { d CGFloat }
{ "CGFloat" "tx" } { tx CGFloat }
{ "CGFloat" "ty" } ; { ty CGFloat } ;
TYPEDEF: void* CGColorRef TYPEDEF: void* CGColorRef
TYPEDEF: void* CGColorSpaceRef TYPEDEF: void* CGColorSpaceRef

View File

@ -116,8 +116,8 @@ TUPLE: line < disposable line metrics image loc dim ;
line [ string open-font font foreground>> <CTLine> |CFRelease ] line [ string open-font font foreground>> <CTLine> |CFRelease ]
rect [ line line-rect ] rect [ line line-rect ]
(loc) [ rect CGRect-origin CGPoint>loc ] (loc) [ rect origin>> CGPoint>loc ]
(dim) [ rect CGRect-size CGSize>dim ] (dim) [ rect size>> CGSize>dim ]
(ext) [ (loc) (dim) v+ ] (ext) [ (loc) (dim) v+ ]
loc [ (loc) [ floor ] map ] loc [ (loc) [ floor ] map ]
ext [ (loc) (dim) [ + ceiling ] 2map ] ext [ (loc) (dim) [ + ceiling ] 2map ]