Merge branch 'master' of git://factorcode.org/git/factor
commit
693e7fefb1
|
@ -26,6 +26,10 @@ HELP: with-cocoa
|
|||
{ $values { "quot" quotation } }
|
||||
{ $description "Sets up an autorelease pool, initializes the " { $snippet "NSApplication" } " singleton, and calls the quotation." } ;
|
||||
|
||||
HELP: cocoa-app
|
||||
{ $values { "quot" quotation } }
|
||||
{ $description "Initializes Cocoa, calls the quotation, and starts the Cocoa event loop." } ;
|
||||
|
||||
HELP: do-event
|
||||
{ $values { "app" "an " { $snippet "NSApplication" } } { "?" "a boolean" } }
|
||||
{ $description "Processes a pending event in the queue, if any, returning a boolean indicating if there was one. Does not block." } ;
|
||||
|
@ -46,13 +50,16 @@ HELP: objc-error
|
|||
{ $error-description "Thrown by the Objective C runtime when an error occurs, for example, sending a message to an object with an unrecognized selector." } ;
|
||||
|
||||
ARTICLE: "cocoa-application-utils" "Cocoa application utilities"
|
||||
"Utilities:"
|
||||
{ $subsection NSApp }
|
||||
{ $subsection with-autorelease-pool }
|
||||
{ $subsection with-cocoa }
|
||||
{ $subsection do-event }
|
||||
{ $subsection add-observer }
|
||||
{ $subsection remove-observer }
|
||||
{ $subsection install-delegate } ;
|
||||
{ $subsection install-delegate }
|
||||
"Combinators:"
|
||||
{ $subsection cocoa-app }
|
||||
{ $subsection with-autorelease-pool }
|
||||
{ $subsection with-cocoa } ;
|
||||
|
||||
IN: cocoa.application
|
||||
ABOUT: "cocoa-application-utils"
|
||||
|
|
|
@ -30,7 +30,7 @@ IN: cocoa.application
|
|||
FUNCTION: void NSBeep ( ) ;
|
||||
|
||||
: with-cocoa ( quot -- )
|
||||
[ NSApp drop call ] with-autorelease-pool ;
|
||||
[ NSApp drop call ] with-autorelease-pool ; inline
|
||||
|
||||
: next-event ( app -- event )
|
||||
0 f CFRunLoopDefaultMode 1
|
||||
|
@ -50,6 +50,13 @@ FUNCTION: void NSBeep ( ) ;
|
|||
|
||||
: finish-launching ( -- ) NSApp -> finishLaunching ;
|
||||
|
||||
: cocoa-app ( quot -- )
|
||||
[
|
||||
call
|
||||
finish-launching
|
||||
NSApp -> run
|
||||
] with-cocoa ; inline
|
||||
|
||||
: install-delegate ( receiver delegate -- )
|
||||
-> alloc -> init -> setDelegate: ;
|
||||
|
||||
|
|
|
@ -16,9 +16,16 @@ HELP: SUPER->
|
|||
|
||||
{ send super-send POSTPONE: -> POSTPONE: SUPER-> } related-words
|
||||
|
||||
HELP: IMPORT:
|
||||
{ $syntax "IMPORT: name" }
|
||||
{ $description "Makes an Objective C class available for use." }
|
||||
{ $examples
|
||||
{ $code "IMPORT: QTMovie" "QTMovie \"My Movie.mov\" <NSString> f -> movieWithFile:error:" }
|
||||
} ;
|
||||
|
||||
ARTICLE: "objc-calling" "Calling Objective C code"
|
||||
"Before an Objective C class can be used, it must be imported; by default, a small set of common classes are imported automatically, but additional classes can be imported as needed."
|
||||
{ $subsection import-objc-class }
|
||||
{ $subsection POSTPONE: IMPORT: }
|
||||
"Every imported Objective C class has as corresponding class word in the " { $vocab-link "cocoa.classes" } " vocabulary. Class words push the class object in the stack, allowing class methods to be invoked."
|
||||
$nl
|
||||
"Messages can be sent to classes and instances using a pair of parsing words:"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
USING: compiler io kernel cocoa.runtime cocoa.subclassing
|
||||
cocoa.messages cocoa.types sequences words vocabs parser
|
||||
core-foundation namespaces assocs hashtables compiler.units
|
||||
lexer ;
|
||||
lexer init ;
|
||||
IN: cocoa
|
||||
|
||||
: (remember-send) ( selector variable -- )
|
||||
|
@ -27,6 +27,16 @@ SYMBOL: super-sent-messages
|
|||
scan dup remember-super-send parsed \ super-send parsed ;
|
||||
parsing
|
||||
|
||||
SYMBOL: frameworks
|
||||
|
||||
frameworks global [ V{ } clone or ] change-at
|
||||
|
||||
[ frameworks get [ load-framework ] each ] "cocoa.messages" add-init-hook
|
||||
|
||||
: FRAMEWORK: scan [ load-framework ] [ frameworks get push ] bi ; parsing
|
||||
|
||||
: IMPORT: scan [ ] import-objc-class ; parsing
|
||||
|
||||
"Compiling Objective C bridge..." print
|
||||
|
||||
"cocoa.classes" create-vocab drop
|
||||
|
|
|
@ -32,11 +32,7 @@ HELP: alien>objc-types
|
|||
|
||||
HELP: import-objc-class
|
||||
{ $values { "name" string } { "quot" "a quotation with stack effect " { $snippet "( -- )" } } }
|
||||
{ $description "If a class named " { $snippet "name" } " is already known to the Objective C interface, does nothing. Otherwise, first calls the quotation. The quotation should make the class available to the Objective C runtime if necessary, either by loading a framework or defining it directly. After the quotation returns, this word makes the class available to Factor programs by importing methods and creating a class word the class object in the " { $vocab-link "cocoa.classes" } " vocabulary." }
|
||||
{ $notes "In most cases, the quotation should be " { $link f } "." }
|
||||
{ $examples
|
||||
{ $code "\"QTMovie\" f import-objc-class" "QTMovie \"My Movie.mov\" <NSString> f -> movieWithFile:error:" }
|
||||
} ;
|
||||
{ $description "If a class named " { $snippet "name" } " is already known to the Objective C interface, does nothing. Otherwise, first calls the quotation. The quotation should make the class available to the Objective C runtime if necessary, either by loading a framework or defining it directly. After the quotation returns, this word makes the class available to Factor programs by importing methods and creating a class word the class object in the " { $vocab-link "cocoa.classes" } " vocabulary." } ;
|
||||
|
||||
HELP: root-class
|
||||
{ $values { "class" alien } { "root" alien } }
|
||||
|
|
|
@ -4,7 +4,8 @@ USING: accessors alien alien.c-types alien.strings arrays assocs
|
|||
combinators compiler kernel math namespaces make parser
|
||||
prettyprint prettyprint.sections quotations sequences strings
|
||||
words cocoa.runtime io macros memoize debugger
|
||||
io.encodings.ascii effects compiler.generator libc libc.private ;
|
||||
io.encodings.ascii effects compiler.generator libc libc.private
|
||||
parser lexer init core-foundation ;
|
||||
IN: cocoa.messages
|
||||
|
||||
: make-sender ( method function -- quot )
|
||||
|
|
|
@ -1,48 +1,33 @@
|
|||
! Copyright (C) 2003, 2007, 2008 Slava Pestov.
|
||||
! Copyright (C) 2003, 2008 Slava Pestov.
|
||||
! Copyright (C) 2008 Eduardo Cavazos.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
USING: kernel combinators sequences arrays classes.tuple accessors colors.hsv ;
|
||||
|
||||
USING: kernel accessors ;
|
||||
IN: colors
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
TUPLE: color ;
|
||||
|
||||
TUPLE: rgba < color red green blue alpha ;
|
||||
|
||||
TUPLE: hsva < color hue saturation value alpha ;
|
||||
|
||||
TUPLE: gray < color gray alpha ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
C: <rgba> rgba
|
||||
|
||||
GENERIC: >rgba ( object -- rgba )
|
||||
|
||||
M: rgba >rgba ( rgba -- rgba ) ;
|
||||
|
||||
M: hsva >rgba ( hsva -- rgba )
|
||||
{ [ hue>> ] [ saturation>> ] [ value>> ] [ alpha>> ] } cleave 4array
|
||||
[ hsv>rgb ] [ peek ] bi suffix first4 rgba boa ;
|
||||
|
||||
M: gray >rgba ( gray -- rgba ) [ gray>> dup dup ] [ alpha>> ] bi rgba boa ;
|
||||
|
||||
M: color red>> ( color -- red ) >rgba red>> ;
|
||||
M: color green>> ( color -- green ) >rgba green>> ;
|
||||
M: color blue>> ( color -- blue ) >rgba blue>> ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: black T{ rgba f 0.0 0.0 0.0 1.0 } ;
|
||||
: blue T{ rgba f 0.0 0.0 1.0 1.0 } ;
|
||||
: cyan T{ rgba f 0 0.941 0.941 1 } ;
|
||||
: gray T{ rgba f 0.6 0.6 0.6 1.0 } ;
|
||||
: green T{ rgba f 0.0 1.0 0.0 1.0 } ;
|
||||
: light-gray T{ rgba f 0.95 0.95 0.95 0.95 } ;
|
||||
: light-purple T{ rgba f 0.8 0.8 1.0 1.0 } ;
|
||||
: magenta T{ rgba f 0.941 0 0.941 1 } ;
|
||||
: orange T{ rgba f 0.941 0.627 0 1 } ;
|
||||
: purple T{ rgba f 0.627 0 0.941 1 } ;
|
||||
: red T{ rgba f 1.0 0.0 0.0 1.0 } ;
|
||||
: white T{ rgba f 1.0 1.0 1.0 1.0 } ;
|
||||
: yellow T{ rgba f 1.0 1.0 0.0 1.0 } ;
|
||||
: black T{ rgba f 0.0 0.0 0.0 1.0 } ; inline
|
||||
: blue T{ rgba f 0.0 0.0 1.0 1.0 } ; inline
|
||||
: cyan T{ rgba f 0 0.941 0.941 1 } ; inline
|
||||
: gray T{ rgba f 0.6 0.6 0.6 1.0 } ; inline
|
||||
: green T{ rgba f 0.0 1.0 0.0 1.0 } ; inline
|
||||
: light-gray T{ rgba f 0.95 0.95 0.95 0.95 } ; inline
|
||||
: light-purple T{ rgba f 0.8 0.8 1.0 1.0 } ; inline
|
||||
: magenta T{ rgba f 0.941 0 0.941 1 } ; inline
|
||||
: orange T{ rgba f 0.941 0.627 0 1 } ; inline
|
||||
: purple T{ rgba f 0.627 0 0.941 1 } ; inline
|
||||
: red T{ rgba f 1.0 0.0 0.0 1.0 } ; inline
|
||||
: white T{ rgba f 1.0 1.0 1.0 1.0 } ; inline
|
||||
: yellow T{ rgba f 1.0 1.0 0.0 1.0 } ; inline
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
! Copyright (C) 2008 Eduardo Cavazos.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: colors kernel accessors ;
|
||||
IN: colors.gray
|
||||
|
||||
TUPLE: gray < color gray alpha ;
|
||||
|
||||
C: <gray> gray
|
||||
|
||||
M: gray >rgba ( gray -- rgba )
|
||||
[ gray>> dup dup ] [ alpha>> ] bi <rgba> ;
|
|
@ -0,0 +1,26 @@
|
|||
IN: colors.hsv.tests
|
||||
USING: accessors kernel colors colors.hsv tools.test math ;
|
||||
|
||||
: hsv>rgb ( h s v -- r g b )
|
||||
[ 360 * ] 2dip
|
||||
1 <hsva> >rgba [ red>> ] [ green>> ] [ blue>> ] tri ;
|
||||
|
||||
[ 1/2 1/2 1/2 ] [ 0 0 1/2 hsv>rgb ] unit-test
|
||||
|
||||
[ 1/2 1/4 1/4 ] [ 0 1/2 1/2 hsv>rgb ] unit-test
|
||||
[ 1/3 2/9 2/9 ] [ 0 1/3 1/3 hsv>rgb ] unit-test
|
||||
|
||||
[ 24/125 1/5 4/25 ] [ 1/5 1/5 1/5 hsv>rgb ] unit-test
|
||||
[ 29/180 1/6 5/36 ] [ 1/5 1/6 1/6 hsv>rgb ] unit-test
|
||||
|
||||
[ 6/25 2/5 38/125 ] [ 2/5 2/5 2/5 hsv>rgb ] unit-test
|
||||
[ 8/25 4/5 64/125 ] [ 2/5 3/5 4/5 hsv>rgb ] unit-test
|
||||
|
||||
[ 6/25 48/125 3/5 ] [ 3/5 3/5 3/5 hsv>rgb ] unit-test
|
||||
[ 0 0 0 ] [ 3/5 1/5 0 hsv>rgb ] unit-test
|
||||
|
||||
[ 84/125 4/25 4/5 ] [ 4/5 4/5 4/5 hsv>rgb ] unit-test
|
||||
[ 7/15 1/3 1/2 ] [ 4/5 1/3 1/2 hsv>rgb ] unit-test
|
||||
|
||||
[ 5/6 5/36 5/6 ] [ 5/6 5/6 5/6 hsv>rgb ] unit-test
|
||||
[ 1/6 0 1/6 ] [ 5/6 1 1/6 hsv>rgb ] unit-test
|
|
@ -1,41 +1,38 @@
|
|||
! Copyright (C) 2007 Eduardo Cavazos
|
||||
! Copyright (C) 2008 Eduardo Cavazos.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
USING: kernel combinators arrays sequences math math.functions ;
|
||||
|
||||
USING: colors kernel combinators math math.functions accessors ;
|
||||
IN: colors.hsv
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: H ( hsv -- H ) first ;
|
||||
|
||||
: S ( hsv -- S ) second ;
|
||||
|
||||
: V ( hsv -- V ) third ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: Hi ( hsv -- Hi ) H 60 / floor 6 mod ;
|
||||
|
||||
: f ( hsv -- f ) [ H 60 / ] [ Hi ] bi - ;
|
||||
|
||||
: p ( hsv -- p ) [ S 1 swap - ] [ V ] bi * ;
|
||||
|
||||
: q ( hsv -- q ) [ [ f ] [ S ] bi * 1 swap - ] [ V ] bi * ;
|
||||
|
||||
: t ( hsv -- t ) [ [ f 1 swap - ] [ S ] bi * 1 swap - ] [ V ] bi * ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
! h [0,360)
|
||||
! s [0,1]
|
||||
! v [0,1]
|
||||
TUPLE: hsva < color hue saturation value alpha ;
|
||||
|
||||
: hsv>rgb ( hsv -- rgb )
|
||||
dup Hi
|
||||
{ { 0 [ [ V ] [ t ] [ p ] tri ] }
|
||||
{ 1 [ [ q ] [ V ] [ p ] tri ] }
|
||||
{ 2 [ [ p ] [ V ] [ t ] tri ] }
|
||||
{ 3 [ [ p ] [ q ] [ V ] tri ] }
|
||||
{ 4 [ [ t ] [ p ] [ V ] tri ] }
|
||||
{ 5 [ [ V ] [ p ] [ q ] tri ] } } case 3array ;
|
||||
C: <hsva> hsva
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: Hi ( hsv -- Hi ) hue>> 60 / floor 6 mod ; inline
|
||||
|
||||
: f ( hsv -- f ) [ hue>> 60 / ] [ Hi ] bi - ; inline
|
||||
|
||||
: p ( hsv -- p ) [ saturation>> 1 swap - ] [ value>> ] bi * ; inline
|
||||
|
||||
: q ( hsv -- q ) [ [ f ] [ saturation>> ] bi * 1 swap - ] [ value>> ] bi * ; inline
|
||||
|
||||
: t ( hsv -- t ) [ [ f 1 swap - ] [ saturation>> ] bi * 1 swap - ] [ value>> ] bi * ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
||||
M: hsva >rgba ( hsva -- rgba )
|
||||
[
|
||||
dup Hi
|
||||
{
|
||||
{ 0 [ [ value>> ] [ t ] [ p ] tri ] }
|
||||
{ 1 [ [ q ] [ value>> ] [ p ] tri ] }
|
||||
{ 2 [ [ p ] [ value>> ] [ t ] tri ] }
|
||||
{ 3 [ [ p ] [ q ] [ value>> ] tri ] }
|
||||
{ 4 [ [ t ] [ p ] [ value>> ] tri ] }
|
||||
{ 5 [ [ value>> ] [ p ] [ q ] tri ] }
|
||||
} case
|
||||
] [ alpha>> ] bi <rgba> ;
|
||||
|
|
|
@ -8,7 +8,7 @@ math.functions math.private strings layouts
|
|||
compiler.tree.propagation.info compiler.tree.def-use
|
||||
compiler.tree.debugger compiler.tree.checker
|
||||
slots.private words hashtables classes assocs locals
|
||||
float-arrays ;
|
||||
float-arrays system ;
|
||||
IN: compiler.tree.propagation.tests
|
||||
|
||||
\ propagate must-infer
|
||||
|
@ -590,6 +590,8 @@ MIXIN: empty-mixin
|
|||
|
||||
[ V{ float-array } ] [ [| | F{ } ] final-classes ] unit-test
|
||||
|
||||
[ V{ t } ] [ [ netbsd unix? ] final-literals ] unit-test
|
||||
|
||||
! [ V{ string } ] [
|
||||
! [ dup string? t xor [ "A" throw ] [ ] if ] final-classes
|
||||
! ] unit-test
|
||||
|
|
|
@ -76,13 +76,25 @@ M: #declare propagate-before
|
|||
: fold-call ( #call word -- )
|
||||
[ (fold-call) ] [ drop out-d>> ] 2bi set-value-infos ;
|
||||
|
||||
: predicate-output-infos ( info class -- info )
|
||||
: predicate-output-infos/literal ( info class -- info )
|
||||
[ literal>> ] dip
|
||||
'[ _ _ instance? <literal-info> ]
|
||||
[ drop object-info ]
|
||||
recover ;
|
||||
|
||||
: predicate-output-infos/class ( info class -- info )
|
||||
[ class>> ] dip {
|
||||
{ [ 2dup class<= ] [ t <literal-info> ] }
|
||||
{ [ 2dup classes-intersect? not ] [ f <literal-info> ] }
|
||||
[ object-info ]
|
||||
} cond 2nip ;
|
||||
|
||||
: predicate-output-infos ( info class -- info )
|
||||
over literal?>>
|
||||
[ predicate-output-infos/literal ]
|
||||
[ predicate-output-infos/class ]
|
||||
if ;
|
||||
|
||||
: propagate-predicate ( #call word -- infos )
|
||||
#! We need to force the caller word to recompile when the class
|
||||
#! is redefined, since now we're making assumptions but the
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue