Merge branch 'master' of git://factorcode.org/git/factor
commit
001c916cad
|
@ -113,12 +113,6 @@ the command prompt using the console application:
|
||||||
|
|
||||||
factor.com -i=boot.<cpu>.image
|
factor.com -i=boot.<cpu>.image
|
||||||
|
|
||||||
Before bootstrapping, you will need to download the DLLs for the Pango
|
|
||||||
text rendering library. The required DLLs are listed in
|
|
||||||
build-support/dlls.txt and are available from the following location:
|
|
||||||
|
|
||||||
<http://factorcode.org/dlls>
|
|
||||||
|
|
||||||
Once bootstrapped, double-clicking factor.exe or factor.com starts
|
Once bootstrapped, double-clicking factor.exe or factor.com starts
|
||||||
the Factor UI.
|
the Factor UI.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
! 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: functors destructors accessors kernel parser words ;
|
USING: functors destructors accessors kernel parser words
|
||||||
|
effects generalizations sequences ;
|
||||||
IN: alien.destructors
|
IN: alien.destructors
|
||||||
|
|
||||||
SLOT: alien
|
SLOT: alien
|
||||||
|
@ -11,6 +12,7 @@ F-destructor DEFINES-CLASS ${F}-destructor
|
||||||
<F-destructor> DEFINES <${F}-destructor>
|
<F-destructor> DEFINES <${F}-destructor>
|
||||||
&F DEFINES &${F}
|
&F DEFINES &${F}
|
||||||
|F DEFINES |${F}
|
|F DEFINES |${F}
|
||||||
|
N [ F stack-effect out>> length ]
|
||||||
|
|
||||||
WHERE
|
WHERE
|
||||||
|
|
||||||
|
@ -18,7 +20,7 @@ TUPLE: F-destructor alien disposed ;
|
||||||
|
|
||||||
: <F-destructor> ( alien -- destructor ) f F-destructor boa ; inline
|
: <F-destructor> ( alien -- destructor ) f F-destructor boa ; inline
|
||||||
|
|
||||||
M: F-destructor dispose* alien>> F ;
|
M: F-destructor dispose* alien>> F N ndrop ;
|
||||||
|
|
||||||
: &F ( alien -- alien ) dup <F-destructor> &dispose drop ; inline
|
: &F ( alien -- alien ) dup <F-destructor> &dispose drop ; inline
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,10 @@ IN: alien.fortran
|
||||||
ARTICLE: "alien.fortran-abis" "Fortran ABIs"
|
ARTICLE: "alien.fortran-abis" "Fortran ABIs"
|
||||||
"Fortran does not have a standard ABI like C does. Factor supports the following Fortran ABIs:"
|
"Fortran does not have a standard ABI like C does. Factor supports the following Fortran ABIs:"
|
||||||
{ $list
|
{ $list
|
||||||
{ { $subsection gfortran-abi } " is used by gfortran, the Fortran compiler included with GCC 4." }
|
{ { $link gfortran-abi } " is used by gfortran, the Fortran compiler included with GCC 4." }
|
||||||
{ { $subsection f2c-abi } " is used by the F2C Fortran-to-C translator and G77, the Fortran compiler included with GCC 3.x and earlier. It is also used by gfortran when compiling with the -ff2c flag." }
|
{ { $link f2c-abi } " is used by the F2C Fortran-to-C translator and G77, the Fortran compiler included with GCC 3.x and earlier. It is also used by gfortran when compiling with the -ff2c flag." }
|
||||||
{ { $subsection intel-unix-abi } " is used by the Intel Fortran Compiler on Linux and Mac OS X." }
|
{ { $link intel-unix-abi } " is used by the Intel Fortran Compiler on Linux and Mac OS X." }
|
||||||
{ { $subsection intel-windows-abi } " is used by the Intel Fortran Compiler on Windows." }
|
{ { $link intel-windows-abi } " is used by the Intel Fortran Compiler on Windows." }
|
||||||
}
|
}
|
||||||
"A library's ABI is specified when that library is opened by the " { $link add-fortran-library } " word." ;
|
"A library's ABI is specified when that library is opened by the " { $link add-fortran-library } " word." ;
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,4 @@ IN: bootstrap.ui
|
||||||
{ [ os unix? ] [ "x11" ] }
|
{ [ os unix? ] [ "x11" ] }
|
||||||
} cond
|
} cond
|
||||||
] unless* "ui.backend." prepend require
|
] unless* "ui.backend." prepend require
|
||||||
|
|
||||||
"ui-text-backend" get [
|
|
||||||
{
|
|
||||||
{ [ os macosx? ] [ "core-text" ] }
|
|
||||||
{ [ os windows? ] [ "pango" ] }
|
|
||||||
{ [ os unix? ] [ "pango" ] }
|
|
||||||
} cond
|
|
||||||
] unless* "ui.text." prepend require
|
|
||||||
] when
|
] when
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2007 Doug Coleman.
|
! Copyright (C) 2007 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays kernel math math.functions namespaces sequences
|
USING: accessors arrays classes.tuple combinators combinators.short-circuit
|
||||||
strings system vocabs.loader threads accessors combinators
|
kernel locals math math.functions math.order namespaces sequences strings
|
||||||
locals classes.tuple math.order summary combinators.short-circuit ;
|
summary system threads vocabs.loader ;
|
||||||
IN: calendar
|
IN: calendar
|
||||||
|
|
||||||
HOOK: gmt-offset os ( -- hours minutes seconds )
|
HOOK: gmt-offset os ( -- hours minutes seconds )
|
||||||
|
@ -136,7 +136,7 @@ CONSTANT: day-abbreviations3
|
||||||
GENERIC: leap-year? ( obj -- ? )
|
GENERIC: leap-year? ( obj -- ? )
|
||||||
|
|
||||||
M: integer leap-year? ( year -- ? )
|
M: integer leap-year? ( year -- ? )
|
||||||
dup 100 mod zero? 400 4 ? mod zero? ;
|
dup 100 divisor? 400 4 ? divisor? ;
|
||||||
|
|
||||||
M: timestamp leap-year? ( timestamp -- ? )
|
M: timestamp leap-year? ( timestamp -- ? )
|
||||||
year>> leap-year? ;
|
year>> leap-year? ;
|
||||||
|
@ -348,7 +348,7 @@ M: duration time-
|
||||||
#! good for any date since October 15, 1582
|
#! good for any date since October 15, 1582
|
||||||
[
|
[
|
||||||
dup 2 <= [ [ 1- ] [ 12 + ] bi* ] when
|
dup 2 <= [ [ 1- ] [ 12 + ] bi* ] when
|
||||||
[ dup [ 4 /i + ] keep [ 100 /i - ] keep 400 /i + ] dip
|
[ dup [ 4 /i + ] [ 100 /i - ] [ 400 /i + ] tri ] dip
|
||||||
[ 1+ 3 * 5 /i + ] keep 2 * +
|
[ 1+ 3 * 5 /i + ] keep 2 * +
|
||||||
] dip 1+ + 7 mod ;
|
] dip 1+ + 7 mod ;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.syntax io kernel namespaces core-foundation
|
USING: alien alien.syntax io kernel namespaces core-foundation
|
||||||
core-foundation.strings cocoa.messages cocoa cocoa.classes
|
core-foundation.strings cocoa.messages cocoa cocoa.classes
|
||||||
cocoa.runtime sequences threads init summary kernel.private
|
cocoa.runtime sequences init summary kernel.private
|
||||||
assocs ;
|
assocs ;
|
||||||
IN: cocoa.application
|
IN: cocoa.application
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@ USING: accessors fry generalizations kernel macros math.order
|
||||||
stack-checker math ;
|
stack-checker math ;
|
||||||
IN: combinators.smart
|
IN: combinators.smart
|
||||||
|
|
||||||
|
MACRO: drop-outputs ( quot -- quot' )
|
||||||
|
dup infer out>> '[ @ _ ndrop ] ;
|
||||||
|
|
||||||
MACRO: output>sequence ( quot exemplar -- newquot )
|
MACRO: output>sequence ( quot exemplar -- newquot )
|
||||||
[ dup infer out>> ] dip
|
[ dup infer out>> ] dip
|
||||||
'[ @ _ _ nsequence ] ;
|
'[ @ _ _ nsequence ] ;
|
||||||
|
|
|
@ -53,7 +53,7 @@ SYMBOL: labels
|
||||||
V{ } clone literal-table set
|
V{ } clone literal-table set
|
||||||
V{ } clone calls set
|
V{ } clone calls set
|
||||||
compiling-word set
|
compiling-word set
|
||||||
compiled-stack-traces? compiling-word get f ? add-literal ;
|
compiled-stack-traces? [ compiling-word get add-literal ] when ;
|
||||||
|
|
||||||
: generate ( mr -- asm )
|
: generate ( mr -- asm )
|
||||||
[
|
[
|
||||||
|
|
|
@ -312,7 +312,7 @@ generic-comparison-ops [
|
||||||
\ clone [
|
\ clone [
|
||||||
in-d>> first value-info literal>> {
|
in-d>> first value-info literal>> {
|
||||||
{ V{ } [ [ drop { } 0 vector boa ] ] }
|
{ V{ } [ [ drop { } 0 vector boa ] ] }
|
||||||
{ H{ } [ [ drop hashtable new ] ] }
|
{ H{ } [ [ drop 0 <hashtable> ] ] }
|
||||||
[ drop f ]
|
[ drop f ]
|
||||||
} case
|
} case
|
||||||
] "custom-inlining" set-word-prop
|
] "custom-inlining" set-word-prop
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.syntax alien.strings io.encodings.string kernel
|
USING: alien.syntax alien.strings io.encodings.string kernel
|
||||||
sequences byte-arrays io.encodings.utf8 math core-foundation
|
sequences byte-arrays io.encodings.utf8 math core-foundation
|
||||||
core-foundation.arrays destructors unicode.data ;
|
core-foundation.arrays destructors ;
|
||||||
IN: core-foundation.strings
|
IN: core-foundation.strings
|
||||||
|
|
||||||
TYPEDEF: void* CFStringRef
|
TYPEDEF: void* CFStringRef
|
||||||
|
@ -62,7 +62,7 @@ FUNCTION: CFStringRef CFStringCreateWithCString (
|
||||||
: prepare-CFString ( string -- byte-array )
|
: prepare-CFString ( string -- byte-array )
|
||||||
[
|
[
|
||||||
dup HEX: 10ffff >
|
dup HEX: 10ffff >
|
||||||
[ drop CHAR: replacement-character ] when
|
[ drop HEX: fffd ] when
|
||||||
] map utf8 encode ;
|
] map utf8 encode ;
|
||||||
|
|
||||||
: <CFString> ( string -- alien )
|
: <CFString> ( string -- alien )
|
||||||
|
|
|
@ -659,13 +659,40 @@ M: ppc %callback-value ( ctype -- )
|
||||||
|
|
||||||
M: ppc small-enough? ( n -- ? ) -32768 32767 between? ;
|
M: ppc small-enough? ( n -- ? ) -32768 32767 between? ;
|
||||||
|
|
||||||
M: ppc return-struct-in-registers? ( c-type -- ? ) drop f ;
|
M: ppc return-struct-in-registers? ( c-type -- ? )
|
||||||
|
c-type return-in-registers?>> ;
|
||||||
|
|
||||||
M: ppc %box-small-struct
|
M: ppc %box-small-struct ( c-type -- )
|
||||||
drop "No small structs" throw ;
|
#! Box a <= 16-byte struct returned in r3:r4:r5:r6
|
||||||
|
heap-size 7 LI
|
||||||
|
"box_medium_struct" f %alien-invoke ;
|
||||||
|
|
||||||
M: ppc %unbox-small-struct
|
: %unbox-struct-1 ( -- )
|
||||||
drop "No small structs" throw ;
|
! Alien must be in r3.
|
||||||
|
"alien_offset" f %alien-invoke
|
||||||
|
3 3 0 LWZ ;
|
||||||
|
|
||||||
|
: %unbox-struct-2 ( -- )
|
||||||
|
! Alien must be in r3.
|
||||||
|
"alien_offset" f %alien-invoke
|
||||||
|
4 3 4 LWZ
|
||||||
|
3 3 0 LWZ ;
|
||||||
|
|
||||||
|
: %unbox-struct-4 ( -- )
|
||||||
|
! Alien must be in r3.
|
||||||
|
"alien_offset" f %alien-invoke
|
||||||
|
6 3 12 LWZ
|
||||||
|
5 3 8 LWZ
|
||||||
|
4 3 4 LWZ
|
||||||
|
3 3 0 LWZ ;
|
||||||
|
|
||||||
|
M: ppc %unbox-small-struct ( size -- )
|
||||||
|
#! Alien must be in EAX.
|
||||||
|
heap-size cell align cell /i {
|
||||||
|
{ 1 [ %unbox-struct-1 ] }
|
||||||
|
{ 2 [ %unbox-struct-2 ] }
|
||||||
|
{ 4 [ %unbox-struct-4 ] }
|
||||||
|
} case ;
|
||||||
|
|
||||||
USE: vocabs.loader
|
USE: vocabs.loader
|
||||||
|
|
||||||
|
@ -673,3 +700,5 @@ USE: vocabs.loader
|
||||||
{ [ os macosx? ] [ "cpu.ppc.macosx" require ] }
|
{ [ os macosx? ] [ "cpu.ppc.macosx" require ] }
|
||||||
{ [ os linux? ] [ "cpu.ppc.linux" require ] }
|
{ [ os linux? ] [ "cpu.ppc.linux" require ] }
|
||||||
} cond
|
} cond
|
||||||
|
|
||||||
|
"complex-double" c-type t >>return-in-registers? drop
|
||||||
|
|
|
@ -3,68 +3,72 @@
|
||||||
USING: tools.test namespaces documents documents.elements multiline ;
|
USING: tools.test namespaces documents documents.elements multiline ;
|
||||||
IN: document.elements.tests
|
IN: document.elements.tests
|
||||||
|
|
||||||
<document> "doc" set
|
SYMBOL: doc
|
||||||
"123\nabc" "doc" get set-doc-string
|
<document> doc set
|
||||||
|
"123\nabcé" doc get set-doc-string
|
||||||
|
|
||||||
! char-elt
|
! char-elt
|
||||||
[ { 0 0 } ] [ { 0 0 } "doc" get char-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 0 } doc get char-elt prev-elt ] unit-test
|
||||||
[ { 0 0 } ] [ { 0 1 } "doc" get char-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 1 } doc get char-elt prev-elt ] unit-test
|
||||||
[ { 0 3 } ] [ { 1 0 } "doc" get char-elt prev-elt ] unit-test
|
[ { 0 3 } ] [ { 1 0 } doc get char-elt prev-elt ] unit-test
|
||||||
|
[ { 1 3 } ] [ { 1 5 } doc get char-elt prev-elt ] unit-test
|
||||||
|
|
||||||
[ { 1 3 } ] [ { 1 3 } "doc" get char-elt next-elt ] unit-test
|
[ { 1 5 } ] [ { 1 5 } doc get char-elt next-elt ] unit-test
|
||||||
[ { 0 2 } ] [ { 0 1 } "doc" get char-elt next-elt ] unit-test
|
[ { 0 2 } ] [ { 0 1 } doc get char-elt next-elt ] unit-test
|
||||||
[ { 1 0 } ] [ { 0 3 } "doc" get char-elt next-elt ] unit-test
|
[ { 1 0 } ] [ { 0 3 } doc get char-elt next-elt ] unit-test
|
||||||
|
[ { 1 5 } ] [ { 1 3 } doc get char-elt next-elt ] unit-test
|
||||||
|
|
||||||
! word-elt
|
! word-elt
|
||||||
<document> "doc" set
|
<document> doc set
|
||||||
"Hello world\nanother line" "doc" get set-doc-string
|
"Hello world\nanother line" doc get set-doc-string
|
||||||
|
|
||||||
[ { 0 0 } ] [ { 0 0 } "doc" get word-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 0 } doc get word-elt prev-elt ] unit-test
|
||||||
[ { 0 0 } ] [ { 0 2 } "doc" get word-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 2 } doc get word-elt prev-elt ] unit-test
|
||||||
[ { 0 0 } ] [ { 0 5 } "doc" get word-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 5 } doc get word-elt prev-elt ] unit-test
|
||||||
[ { 0 5 } ] [ { 0 6 } "doc" get word-elt prev-elt ] unit-test
|
[ { 0 5 } ] [ { 0 6 } doc get word-elt prev-elt ] unit-test
|
||||||
[ { 0 6 } ] [ { 0 8 } "doc" get word-elt prev-elt ] unit-test
|
[ { 0 6 } ] [ { 0 8 } doc get word-elt prev-elt ] unit-test
|
||||||
[ { 0 11 } ] [ { 1 0 } "doc" get word-elt prev-elt ] unit-test
|
[ { 0 11 } ] [ { 1 0 } doc get word-elt prev-elt ] unit-test
|
||||||
|
|
||||||
|
[ { 0 5 } ] [ { 0 0 } doc get word-elt next-elt ] unit-test
|
||||||
|
[ { 0 6 } ] [ { 0 5 } doc get word-elt next-elt ] unit-test
|
||||||
|
[ { 0 11 } ] [ { 0 6 } doc get word-elt next-elt ] unit-test
|
||||||
|
[ { 1 0 } ] [ { 0 11 } doc get word-elt next-elt ] unit-test
|
||||||
|
|
||||||
[ { 0 5 } ] [ { 0 0 } "doc" get word-elt next-elt ] unit-test
|
|
||||||
[ { 0 6 } ] [ { 0 5 } "doc" get word-elt next-elt ] unit-test
|
|
||||||
[ { 0 11 } ] [ { 0 6 } "doc" get word-elt next-elt ] unit-test
|
|
||||||
[ { 1 0 } ] [ { 0 11 } "doc" get word-elt next-elt ] unit-test
|
|
||||||
|
|
||||||
! one-word-elt
|
! one-word-elt
|
||||||
[ { 0 0 } ] [ { 0 0 } "doc" get one-word-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 0 } doc get one-word-elt prev-elt ] unit-test
|
||||||
[ { 0 0 } ] [ { 0 2 } "doc" get one-word-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 2 } doc get one-word-elt prev-elt ] unit-test
|
||||||
[ { 0 0 } ] [ { 0 5 } "doc" get one-word-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 5 } doc get one-word-elt prev-elt ] unit-test
|
||||||
[ { 0 5 } ] [ { 0 2 } "doc" get one-word-elt next-elt ] unit-test
|
[ { 0 5 } ] [ { 0 2 } doc get one-word-elt next-elt ] unit-test
|
||||||
[ { 0 5 } ] [ { 0 5 } "doc" get one-word-elt next-elt ] unit-test
|
[ { 0 5 } ] [ { 0 5 } doc get one-word-elt next-elt ] unit-test
|
||||||
|
|
||||||
! line-elt
|
! line-elt
|
||||||
<document> "doc" set
|
<document> doc set
|
||||||
"Hello\nworld, how are\nyou?" "doc" get set-doc-string
|
"Hello\nworld, how are\nyou?" doc get set-doc-string
|
||||||
|
|
||||||
[ { 0 0 } ] [ { 0 3 } "doc" get line-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 0 3 } doc get line-elt prev-elt ] unit-test
|
||||||
[ { 0 3 } ] [ { 1 3 } "doc" get line-elt prev-elt ] unit-test
|
[ { 0 3 } ] [ { 1 3 } doc get line-elt prev-elt ] unit-test
|
||||||
[ { 2 4 } ] [ { 2 1 } "doc" get line-elt next-elt ] unit-test
|
[ { 2 4 } ] [ { 2 1 } doc get line-elt next-elt ] unit-test
|
||||||
|
|
||||||
! one-line-elt
|
! one-line-elt
|
||||||
[ { 1 0 } ] [ { 1 3 } "doc" get one-line-elt prev-elt ] unit-test
|
[ { 1 0 } ] [ { 1 3 } doc get one-line-elt prev-elt ] unit-test
|
||||||
[ { 1 14 } ] [ { 1 3 } "doc" get one-line-elt next-elt ] unit-test
|
[ { 1 14 } ] [ { 1 3 } doc get one-line-elt next-elt ] unit-test
|
||||||
|
|
||||||
! page-elt
|
! page-elt
|
||||||
<document> "doc" set
|
<document> doc set
|
||||||
<" First line
|
<" First line
|
||||||
Second line
|
Second line
|
||||||
Third line
|
Third line
|
||||||
Fourth line
|
Fourth line
|
||||||
Fifth line
|
Fifth line
|
||||||
Sixth line"> "doc" get set-doc-string
|
Sixth line"> doc get set-doc-string
|
||||||
|
|
||||||
[ { 0 0 } ] [ { 3 3 } "doc" get 4 <page-elt> prev-elt ] unit-test
|
[ { 0 0 } ] [ { 3 3 } doc get 4 <page-elt> prev-elt ] unit-test
|
||||||
[ { 1 2 } ] [ { 5 2 } "doc" get 4 <page-elt> prev-elt ] unit-test
|
[ { 1 2 } ] [ { 5 2 } doc get 4 <page-elt> prev-elt ] unit-test
|
||||||
|
|
||||||
[ { 4 3 } ] [ { 0 3 } "doc" get 4 <page-elt> next-elt ] unit-test
|
[ { 4 3 } ] [ { 0 3 } doc get 4 <page-elt> next-elt ] unit-test
|
||||||
[ { 5 10 } ] [ { 4 2 } "doc" get 4 <page-elt> next-elt ] unit-test
|
[ { 5 10 } ] [ { 4 2 } doc get 4 <page-elt> next-elt ] unit-test
|
||||||
|
|
||||||
! doc-elt
|
! doc-elt
|
||||||
[ { 0 0 } ] [ { 3 4 } "doc" get doc-elt prev-elt ] unit-test
|
[ { 0 0 } ] [ { 3 4 } doc get doc-elt prev-elt ] unit-test
|
||||||
[ { 5 10 } ] [ { 3 4 } "doc" get doc-elt next-elt ] unit-test
|
[ { 5 10 } ] [ { 3 4 } doc get doc-elt next-elt ] unit-test
|
||||||
|
|
|
@ -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: arrays combinators documents fry kernel math sequences
|
USING: arrays combinators documents fry kernel math sequences
|
||||||
unicode.categories accessors ;
|
accessors unicode.categories unicode.breaks combinators.short-circuit ;
|
||||||
IN: documents.elements
|
IN: documents.elements
|
||||||
|
|
||||||
GENERIC: prev-elt ( loc document elt -- newloc )
|
GENERIC: prev-elt ( loc document elt -- newloc )
|
||||||
|
@ -20,27 +20,32 @@ SINGLETON: char-elt
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: (prev-char) ( loc document quot -- loc )
|
: prev ( loc document quot: ( loc document -- loc ) -- loc )
|
||||||
{
|
{
|
||||||
{ [ pick { 0 0 } = ] [ 2drop ] }
|
{ [ pick { 0 0 } = ] [ 2drop ] }
|
||||||
{ [ pick second zero? ] [ drop [ first 1- ] dip line-end ] }
|
{ [ pick second zero? ] [ drop [ first 1- ] dip line-end ] }
|
||||||
[ call ]
|
[ call ]
|
||||||
} cond ; inline
|
} cond ; inline
|
||||||
|
|
||||||
: (next-char) ( loc document quot -- loc )
|
: next ( loc document quot: ( loc document -- loc ) -- loc )
|
||||||
{
|
{
|
||||||
{ [ 2over doc-end = ] [ 2drop ] }
|
{ [ 2over doc-end = ] [ 2drop ] }
|
||||||
{ [ 2over line-end? ] [ 2drop first 1+ 0 2array ] }
|
{ [ 2over line-end? ] [ 2drop first 1+ 0 2array ] }
|
||||||
[ call ]
|
[ call ]
|
||||||
} cond ; inline
|
} cond ; inline
|
||||||
|
|
||||||
|
: modify-col ( loc document quot: ( col str -- col' ) -- loc )
|
||||||
|
pick [
|
||||||
|
[ [ first2 swap ] dip doc-line ] dip call
|
||||||
|
] dip =col ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
M: char-elt prev-elt
|
M: char-elt prev-elt
|
||||||
drop [ drop -1 +col ] (prev-char) ;
|
drop [ [ last-grapheme-from ] modify-col ] prev ;
|
||||||
|
|
||||||
M: char-elt next-elt
|
M: char-elt next-elt
|
||||||
drop [ drop 1 +col ] (next-char) ;
|
drop [ [ first-grapheme-from ] modify-col ] next ;
|
||||||
|
|
||||||
SINGLETON: one-char-elt
|
SINGLETON: one-char-elt
|
||||||
|
|
||||||
|
@ -50,21 +55,16 @@ M: one-char-elt next-elt 2drop ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: (word-elt) ( loc document quot -- loc )
|
: blank-at? ( n seq -- n seq ? )
|
||||||
pick [
|
|
||||||
[ [ first2 swap ] dip doc-line ] dip call
|
|
||||||
] dip =col ; inline
|
|
||||||
|
|
||||||
: ((word-elt)) ( n seq -- n seq ? )
|
|
||||||
2dup ?nth blank? ;
|
2dup ?nth blank? ;
|
||||||
|
|
||||||
: break-detector ( ? -- quot )
|
: break-detector ( ? -- quot )
|
||||||
'[ blank? _ xor ] ; inline
|
'[ blank? _ xor ] ; inline
|
||||||
|
|
||||||
: (prev-word) ( col str ? -- col )
|
: prev-word ( col str ? -- col )
|
||||||
break-detector find-last-from drop ?1+ ;
|
break-detector find-last-from drop ?1+ ;
|
||||||
|
|
||||||
: (next-word) ( col str ? -- col )
|
: next-word ( col str ? -- col )
|
||||||
[ break-detector find-from drop ] [ drop length ] 2bi or ;
|
[ break-detector find-from drop ] [ drop length ] 2bi or ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
@ -73,23 +73,23 @@ SINGLETON: one-word-elt
|
||||||
|
|
||||||
M: one-word-elt prev-elt
|
M: one-word-elt prev-elt
|
||||||
drop
|
drop
|
||||||
[ [ 1- ] dip f (prev-word) ] (word-elt) ;
|
[ [ 1- ] dip f prev-word ] modify-col ;
|
||||||
|
|
||||||
M: one-word-elt next-elt
|
M: one-word-elt next-elt
|
||||||
drop
|
drop
|
||||||
[ f (next-word) ] (word-elt) ;
|
[ f next-word ] modify-col ;
|
||||||
|
|
||||||
SINGLETON: word-elt
|
SINGLETON: word-elt
|
||||||
|
|
||||||
M: word-elt prev-elt
|
M: word-elt prev-elt
|
||||||
drop
|
drop
|
||||||
[ [ [ 1- ] dip ((word-elt)) (prev-word) ] (word-elt) ]
|
[ [ [ 1- ] dip blank-at? prev-word ] modify-col ]
|
||||||
(prev-char) ;
|
prev ;
|
||||||
|
|
||||||
M: word-elt next-elt
|
M: word-elt next-elt
|
||||||
drop
|
drop
|
||||||
[ [ ((word-elt)) (next-word) ] (word-elt) ]
|
[ [ blank-at? next-word ] modify-col ]
|
||||||
(next-char) ;
|
next ;
|
||||||
|
|
||||||
SINGLETON: one-line-elt
|
SINGLETON: one-line-elt
|
||||||
|
|
||||||
|
@ -118,4 +118,4 @@ SINGLETON: doc-elt
|
||||||
|
|
||||||
M: doc-elt prev-elt 3drop { 0 0 } ;
|
M: doc-elt prev-elt 3drop { 0 0 } ;
|
||||||
|
|
||||||
M: doc-elt next-elt drop nip doc-end ;
|
M: doc-elt next-elt drop nip doc-end ;
|
||||||
|
|
|
@ -182,7 +182,7 @@ link-no-follow? off
|
||||||
[ "<table><tr><td>foo|bar</td></tr></table>" ] [ "|foo\\|bar|" convert-farkup ] unit-test
|
[ "<table><tr><td>foo|bar</td></tr></table>" ] [ "|foo\\|bar|" convert-farkup ] unit-test
|
||||||
[ "<p></p>" ] [ "\\" convert-farkup ] unit-test
|
[ "<p></p>" ] [ "\\" convert-farkup ] unit-test
|
||||||
|
|
||||||
! [ "<p>[abc]</p>" ] [ "[abc]" convert-farkup ] unit-test
|
[ "<p>[abc]</p>" ] [ "[abc]" convert-farkup ] unit-test
|
||||||
|
|
||||||
: random-markup ( -- string )
|
: random-markup ( -- string )
|
||||||
10 [
|
10 [
|
||||||
|
|
|
@ -121,7 +121,7 @@ DEFER: (parse-paragraph)
|
||||||
] if
|
] if
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: take-until ( state delimiter -- string/f state' )
|
: take-until ( state delimiter -- string state'/f )
|
||||||
V{ } clone (take-until) ;
|
V{ } clone (take-until) ;
|
||||||
|
|
||||||
: count= ( string -- n )
|
: count= ( string -- n )
|
||||||
|
@ -186,11 +186,12 @@ DEFER: (parse-paragraph)
|
||||||
|
|
||||||
: parse-code ( state -- state' item )
|
: parse-code ( state -- state' item )
|
||||||
dup 1 look CHAR: [ =
|
dup 1 look CHAR: [ =
|
||||||
[ unclip-slice make-paragraph ] [
|
[ take-line make-paragraph ] [
|
||||||
"{" take-until
|
dup "{" take-until [
|
||||||
[ rest ] dip
|
[ nip rest ] dip
|
||||||
"}]" take-until
|
"}]" take-until
|
||||||
[ code boa ] dip swap
|
[ code boa ] dip swap
|
||||||
|
] [ drop take-line make-paragraph ] if*
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: parse-item ( state -- state' item )
|
: parse-item ( state -- state' item )
|
||||||
|
|
|
@ -60,7 +60,7 @@ M: topic url-of topic>filename ;
|
||||||
: help>html ( topic -- xml )
|
: help>html ( topic -- xml )
|
||||||
[ article-title ]
|
[ article-title ]
|
||||||
[ drop help-stylesheet ]
|
[ drop help-stylesheet ]
|
||||||
[ [ help ] with-html-writer ]
|
[ [ print-topic ] with-html-writer ]
|
||||||
tri simple-page ;
|
tri simple-page ;
|
||||||
|
|
||||||
: generate-help-file ( topic -- )
|
: generate-help-file ( topic -- )
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
IN: help.tips
|
IN: help.tips
|
||||||
USING: help.markup help.syntax debugger prettyprint see help help.vocabs
|
USING: help.markup help.syntax debugger prettyprint see help help.vocabs
|
||||||
help.apropos tools.time stack-checker editors ;
|
help.apropos tools.time stack-checker editors memory ;
|
||||||
|
|
||||||
TIP: "To look at the most recent error, run " { $link :error } ". To look at the most recent error's callstack, run " { $link :c } "." ;
|
TIP: "To look at the most recent error, run " { $link :error } ". To look at the most recent error's callstack, run " { $link :c } "." ;
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@ TIP: "Power tools: " { $links see edit help about apropos time infer. } ;
|
||||||
|
|
||||||
TIP: "Tips of the day implement the " { $link "definition-protocol" } " and new tips of the day can be defined using the " { $link POSTPONE: TIP: } " parsing word." ;
|
TIP: "Tips of the day implement the " { $link "definition-protocol" } " and new tips of the day can be defined using the " { $link POSTPONE: TIP: } " parsing word." ;
|
||||||
|
|
||||||
|
TIP: "Try some simple demo applications, then look at the source code in " { $snippet "extra/" } ": " { $snippet "\"demos\" run" } ;
|
||||||
|
|
||||||
|
TIP: "To save time on reloading big libraries such as the " { $vocab-link "furnace" } " web framework, save the image after loading them using the " { $link save } " word." ;
|
||||||
|
|
||||||
HELP: TIP:
|
HELP: TIP:
|
||||||
{ $syntax "TIP: content ;" }
|
{ $syntax "TIP: content ;" }
|
||||||
{ $values { "content" "a markup element" } }
|
{ $values { "content" "a markup element" } }
|
||||||
|
|
|
@ -119,6 +119,6 @@ SYNTAX: HINTS:
|
||||||
|
|
||||||
\ >be { { bignum fixnum } { fixnum fixnum } } "specializer" set-word-prop
|
\ >be { { bignum fixnum } { fixnum fixnum } } "specializer" set-word-prop
|
||||||
|
|
||||||
\ hashtable \ at* method { { fixnum hashtable } { word hashtable } } "specializer" set-word-prop
|
\ hashtable \ at* method { { fixnum object } { word object } } "specializer" set-word-prop
|
||||||
|
|
||||||
\ hashtable \ set-at method { { object fixnum object } { object word object } } "specializer" set-word-prop
|
\ hashtable \ set-at method { { object fixnum object } { object word object } } "specializer" set-word-prop
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: combinators kernel ;
|
USING: combinators kernel accessors ;
|
||||||
IN: images
|
IN: images
|
||||||
|
|
||||||
SINGLETONS: L BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
|
SINGLETONS: L BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
|
||||||
R16G16B16 R32G32B32 R16G16B16A16 R32G32B32A32 ;
|
R16G16B16 R32G32B32 R16G16B16A16 R32G32B32A32 ;
|
||||||
|
|
||||||
|
UNION: alpha-channel BGRA RGBA ABGR ARGB R16G16B16A16 R32G32B32A32 ;
|
||||||
|
|
||||||
: bytes-per-pixel ( component-order -- n )
|
: bytes-per-pixel ( component-order -- n )
|
||||||
{
|
{
|
||||||
{ L [ 1 ] }
|
{ L [ 1 ] }
|
||||||
|
@ -29,4 +31,6 @@ TUPLE: image dim component-order upside-down? bitmap ;
|
||||||
|
|
||||||
: <image> ( -- image ) image new ; inline
|
: <image> ( -- image ) image new ; inline
|
||||||
|
|
||||||
|
: has-alpha? ( image -- ? ) component-order>> alpha-channel? ;
|
||||||
|
|
||||||
GENERIC: load-image* ( path tuple -- image )
|
GENERIC: load-image* ( path tuple -- image )
|
|
@ -61,6 +61,18 @@ M: ARGB normalize-component-order*
|
||||||
M: ABGR normalize-component-order*
|
M: ABGR normalize-component-order*
|
||||||
drop ARGB>RGBA BGRA>RGBA ;
|
drop ARGB>RGBA BGRA>RGBA ;
|
||||||
|
|
||||||
|
: fix-XBGR ( bitmap -- bitmap' )
|
||||||
|
dup 4 <sliced-groups> [ [ 255 0 ] dip set-nth ] each ;
|
||||||
|
|
||||||
|
M: XBGR normalize-component-order*
|
||||||
|
drop fix-XBGR ABGR normalize-component-order* ;
|
||||||
|
|
||||||
|
: fix-BGRX ( bitmap -- bitmap' )
|
||||||
|
dup 4 <sliced-groups> [ [ 255 3 ] dip set-nth ] each ;
|
||||||
|
|
||||||
|
M: BGRX normalize-component-order*
|
||||||
|
drop fix-BGRX BGRA normalize-component-order* ;
|
||||||
|
|
||||||
: normalize-scan-line-order ( image -- image )
|
: normalize-scan-line-order ( image -- image )
|
||||||
dup upside-down?>> [
|
dup upside-down?>> [
|
||||||
dup dim>> first 4 * '[
|
dup dim>> first 4 * '[
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2008 Daniel Ehrenberg.
|
! Copyright (C) 2008 Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: io io.encodings kernel math io.encodings.private io.encodings.iana ;
|
USING: io io.encodings kernel math io.encodings.private ;
|
||||||
IN: io.encodings.ascii
|
IN: io.encodings.ascii
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -19,6 +19,4 @@ M: ascii encode-char
|
||||||
128 encode-if< ;
|
128 encode-if< ;
|
||||||
|
|
||||||
M: ascii decode-char
|
M: ascii decode-char
|
||||||
128 decode-if< ;
|
128 decode-if< ;
|
||||||
|
|
||||||
ascii "ANSI_X3.4-1968" register-encoding
|
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2008 Daniel Ehrenberg
|
! Copyright (C) 2008 Daniel Ehrenberg
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel strings values io.files assocs
|
USING: kernel strings values io.files assocs
|
||||||
splitting sequences io namespaces sets io.encodings.utf8 ;
|
splitting sequences io namespaces sets
|
||||||
|
io.encodings.ascii io.encodings.utf8 ;
|
||||||
IN: io.encodings.iana
|
IN: io.encodings.iana
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -52,3 +53,5 @@ e>n-table [ initial-e>n ] initialize
|
||||||
[ n>e-table get-global set-at ] with each
|
[ n>e-table get-global set-at ] with each
|
||||||
] [ "Bad encoding registration" throw ] if*
|
] [ "Bad encoding registration" throw ] if*
|
||||||
] [ swap e>n-table get-global set-at ] 2bi ;
|
] [ swap e>n-table get-global set-at ] 2bi ;
|
||||||
|
|
||||||
|
ascii "ANSI_X3.4-1968" register-encoding
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
USING: alien.fortran help.markup help.syntax math.blas.config multiline ;
|
||||||
|
IN: math.blas.config
|
||||||
|
|
||||||
|
ARTICLE: "math.blas.config" "Configuring the BLAS interface"
|
||||||
|
"The " { $link "math.blas-summary" } " chooses the underlying BLAS interface to use based on the values of the following global variables:"
|
||||||
|
{ $subsection blas-library }
|
||||||
|
{ $subsection blas-fortran-abi }
|
||||||
|
"The interface attempts to set default values based on the ones encountered on the Factor project's build machines. If these settings don't work with your system's BLAS, or you wish to use a commercial BLAS, you may change the global values of those variables in your " { $link "factor-rc" } ". For example, to use AMD's ACML library on Windows with " { $snippet "math.blas" } ", your " { $snippet "factor-rc" } " would look like this:"
|
||||||
|
{ $code <"
|
||||||
|
USING: math.blas.config namespaces ;
|
||||||
|
"X:\\path\\to\\acml.dll" blas-library set-global
|
||||||
|
intel-windows-abi blas-fortran-abi set-global
|
||||||
|
"> }
|
||||||
|
"To take effect, the " { $snippet "blas-library" } " and " { $snippet "blas-fortran-abi" } " variables must be set before any other " { $snippet "math.blas" } " vocabularies are loaded."
|
||||||
|
;
|
||||||
|
|
||||||
|
HELP: blas-library
|
||||||
|
{ $description "The name of the shared library containing the BLAS interface to load. The value of this variable must be a valid shared library name that can be passed to " { $link add-fortran-library } ". To take effect, this variable must be set before any other " { $snippet "math.blas" } " vocabularies are loaded. See " { $link "math.blas.config" } " for details and examples." } ;
|
||||||
|
|
||||||
|
HELP: blas-fortran-abi
|
||||||
|
{ $description "The Fortran ABI used by the BLAS interface specified in the " { $link blas-library } " variable. The value of " { $snippet "blas-fortran-abi" } " must be one of the " { $link "alien.fortran-abis" } " that can be passed to " { $link add-fortran-library } ". To take effect, this variable must be set before any other " { $snippet "math.blas" } " vocabularies are loaded. See " { $link "math.blas.config" } " for details and examples." } ;
|
||||||
|
|
||||||
|
ABOUT: "math.blas.config"
|
|
@ -0,0 +1,23 @@
|
||||||
|
USING: alien.fortran combinators kernel namespaces system ;
|
||||||
|
IN: math.blas.config
|
||||||
|
|
||||||
|
SYMBOLS: blas-library blas-fortran-abi ;
|
||||||
|
|
||||||
|
blas-library [
|
||||||
|
{
|
||||||
|
{ [ os macosx? ] [ "libblas.dylib" ] }
|
||||||
|
{ [ os windows? ] [ "blas.dll" ] }
|
||||||
|
[ "libblas.so" ]
|
||||||
|
} cond
|
||||||
|
] initialize
|
||||||
|
|
||||||
|
blas-fortran-abi [
|
||||||
|
{
|
||||||
|
{ [ os macosx? ] [ intel-unix-abi ] }
|
||||||
|
{ [ os windows? cpu x86.32? and ] [ f2c-abi ] }
|
||||||
|
{ [ os windows? cpu x86.64? and ] [ gfortran-abi ] }
|
||||||
|
{ [ os freebsd? ] [ gfortran-abi ] }
|
||||||
|
{ [ os linux? cpu x86.32? and ] [ gfortran-abi ] }
|
||||||
|
[ f2c-abi ]
|
||||||
|
} cond
|
||||||
|
] initialize
|
|
@ -1,19 +1,9 @@
|
||||||
USING: alien alien.fortran kernel system combinators
|
USING: alien.fortran kernel math.blas.config namespaces ;
|
||||||
alien.libraries ;
|
|
||||||
IN: math.blas.ffi
|
IN: math.blas.ffi
|
||||||
|
|
||||||
<<
|
<<
|
||||||
"blas" {
|
"blas" blas-library blas-fortran-abi [ get ] bi@
|
||||||
{ [ os macosx? ] [ "libblas.dylib" intel-unix-abi add-fortran-library ] }
|
add-fortran-library
|
||||||
{ [ os windows? cpu x86.32? and ] [ "blas.dll" f2c-abi add-fortran-library ] }
|
|
||||||
{ [ os windows? cpu x86.64? and ] [ "blas.dll" gfortran-abi add-fortran-library ] }
|
|
||||||
{
|
|
||||||
[ os [ freebsd? ] [ linux? cpu x86.32? and ] bi or ]
|
|
||||||
[ "libblas.so" gfortran-abi add-fortran-library ]
|
|
||||||
}
|
|
||||||
{ [ os [ freebsd? ] [ linux? ] bi or ] [ "libblas.so" gfortran-abi add-fortran-library ] }
|
|
||||||
[ "libblas.so" f2c-abi add-fortran-library ]
|
|
||||||
} cond
|
|
||||||
>>
|
>>
|
||||||
|
|
||||||
LIBRARY: blas
|
LIBRARY: blas
|
||||||
|
|
|
@ -2,13 +2,14 @@ USING: alien byte-arrays help.markup help.syntax math math.blas.vectors sequence
|
||||||
IN: math.blas.matrices
|
IN: math.blas.matrices
|
||||||
|
|
||||||
ARTICLE: "math.blas-summary" "Basic Linear Algebra Subroutines (BLAS) interface"
|
ARTICLE: "math.blas-summary" "Basic Linear Algebra Subroutines (BLAS) interface"
|
||||||
"Factor provides an interface to high-performance vector and matrix math routines available in the system's BLAS library. A set of specialized types are provided for handling packed, unboxed vector data:"
|
"Factor provides an interface to high-performance vector and matrix math routines available in implementations of the BLAS math library. A set of specialized types are provided for handling packed, unboxed vector data:"
|
||||||
{ $subsection "math.blas-types" }
|
{ $subsection "math.blas-types" }
|
||||||
"Scalar-vector and vector-vector operations are available in the " { $vocab-link "math.blas.vectors" } " vocabulary:"
|
"Scalar-vector and vector-vector operations are available in the " { $vocab-link "math.blas.vectors" } " vocabulary:"
|
||||||
{ $subsection "math.blas.vectors" }
|
{ $subsection "math.blas.vectors" }
|
||||||
"Vector-matrix and matrix-matrix operations are available in the " { $vocab-link "math.blas.matrices" } " vocabulary:"
|
"Vector-matrix and matrix-matrix operations are available in the " { $vocab-link "math.blas.matrices" } " vocabulary:"
|
||||||
{ $subsection "math.blas.matrices" }
|
{ $subsection "math.blas.matrices" }
|
||||||
"The low-level BLAS Fortran interface can be accessed directly through the " { $vocab-link "math.blas.ffi" } " vocabulary." ;
|
"The low-level BLAS Fortran interface can be accessed directly through the " { $vocab-link "math.blas.ffi" } " vocabulary. The BLAS interface can be configured to use different underlying BLAS implementations:"
|
||||||
|
{ $subsection "math.blas.config" } ;
|
||||||
|
|
||||||
ARTICLE: "math.blas-types" "BLAS interface types"
|
ARTICLE: "math.blas-types" "BLAS interface types"
|
||||||
"BLAS vectors come in single- and double-precision, real and complex flavors:"
|
"BLAS vectors come in single- and double-precision, real and complex flavors:"
|
||||||
|
|
|
@ -13,7 +13,8 @@ ARTICLE: "integer-functions" "Integer functions"
|
||||||
"Tests:"
|
"Tests:"
|
||||||
{ $subsection power-of-2? }
|
{ $subsection power-of-2? }
|
||||||
{ $subsection even? }
|
{ $subsection even? }
|
||||||
{ $subsection odd? } ;
|
{ $subsection odd? }
|
||||||
|
{ $subsection divisor? } ;
|
||||||
|
|
||||||
ARTICLE: "arithmetic-functions" "Arithmetic functions"
|
ARTICLE: "arithmetic-functions" "Arithmetic functions"
|
||||||
"Computing additive and multiplicative inverses:"
|
"Computing additive and multiplicative inverses:"
|
||||||
|
@ -269,6 +270,11 @@ HELP: gcd
|
||||||
{ $description "Computes the positive greatest common divisor " { $snippet "d" } " of " { $snippet "x" } " and " { $snippet "y" } ", and another value " { $snippet "a" } " satisfying:" { $code "a*y = d mod x" } }
|
{ $description "Computes the positive greatest common divisor " { $snippet "d" } " of " { $snippet "x" } " and " { $snippet "y" } ", and another value " { $snippet "a" } " satisfying:" { $code "a*y = d mod x" } }
|
||||||
{ $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
|
{ $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
|
||||||
|
|
||||||
|
HELP: divisor?
|
||||||
|
{ $values { "m" integer } { "n" integer } { "?" "a boolean" } }
|
||||||
|
{ $description "Tests if " { $snippet "n" } " is a divisor of " { $snippet "m" } ". This is the same thing as asking if " { $snippet "m" } " is divisible by " { $snippet "n" } "." }
|
||||||
|
{ $notes "Returns t for both negative and positive divisors, as well as for trivial and non-trivial divisors." } ;
|
||||||
|
|
||||||
HELP: mod-inv
|
HELP: mod-inv
|
||||||
{ $values { "x" integer } { "n" integer } { "y" integer } }
|
{ $values { "x" integer } { "n" integer } { "y" integer } }
|
||||||
{ $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
|
{ $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
|
||||||
|
|
|
@ -32,13 +32,13 @@ IN: math.functions.tests
|
||||||
|
|
||||||
[ 1.0 ] [ 0 cosh ] unit-test
|
[ 1.0 ] [ 0 cosh ] unit-test
|
||||||
[ 0.0 ] [ 1 acosh ] unit-test
|
[ 0.0 ] [ 1 acosh ] unit-test
|
||||||
|
|
||||||
[ 1.0 ] [ 0 cos ] unit-test
|
[ 1.0 ] [ 0 cos ] unit-test
|
||||||
[ 0.0 ] [ 1 acos ] unit-test
|
[ 0.0 ] [ 1 acos ] unit-test
|
||||||
|
|
||||||
[ 0.0 ] [ 0 sinh ] unit-test
|
[ 0.0 ] [ 0 sinh ] unit-test
|
||||||
[ 0.0 ] [ 0 asinh ] unit-test
|
[ 0.0 ] [ 0 asinh ] unit-test
|
||||||
|
|
||||||
[ 0.0 ] [ 0 sin ] unit-test
|
[ 0.0 ] [ 0 sin ] unit-test
|
||||||
[ 0.0 ] [ 0 asin ] unit-test
|
[ 0.0 ] [ 0 asin ] unit-test
|
||||||
|
|
||||||
|
@ -97,11 +97,17 @@ IN: math.functions.tests
|
||||||
|
|
||||||
: verify-gcd ( a b -- ? )
|
: verify-gcd ( a b -- ? )
|
||||||
2dup gcd
|
2dup gcd
|
||||||
[ rot * swap rem ] dip = ;
|
[ rot * swap rem ] dip = ;
|
||||||
|
|
||||||
[ t ] [ 123 124 verify-gcd ] unit-test
|
[ t ] [ 123 124 verify-gcd ] unit-test
|
||||||
[ t ] [ 50 120 verify-gcd ] unit-test
|
[ t ] [ 50 120 verify-gcd ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ 0 42 divisor? ] unit-test
|
||||||
|
[ t ] [ 42 7 divisor? ] unit-test
|
||||||
|
[ t ] [ 42 -7 divisor? ] unit-test
|
||||||
|
[ t ] [ 42 42 divisor? ] unit-test
|
||||||
|
[ f ] [ 42 16 divisor? ] unit-test
|
||||||
|
|
||||||
[ 3 ] [ 5 7 mod-inv ] unit-test
|
[ 3 ] [ 5 7 mod-inv ] unit-test
|
||||||
[ 78572682077 ] [ 234829342 342389423843 mod-inv ] unit-test
|
[ 78572682077 ] [ 234829342 342389423843 mod-inv ] unit-test
|
||||||
|
|
||||||
|
@ -150,4 +156,4 @@ IN: math.functions.tests
|
||||||
1067811677921310779
|
1067811677921310779
|
||||||
2135623355842621559
|
2135623355842621559
|
||||||
[ >bignum ] tri@ ^mod
|
[ >bignum ] tri@ ^mod
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -111,6 +111,9 @@ PRIVATE>
|
||||||
: lcm ( a b -- c )
|
: lcm ( a b -- c )
|
||||||
[ * ] 2keep gcd nip /i ; foldable
|
[ * ] 2keep gcd nip /i ; foldable
|
||||||
|
|
||||||
|
: divisor? ( m n -- ? )
|
||||||
|
mod 0 = ;
|
||||||
|
|
||||||
: mod-inv ( x n -- y )
|
: mod-inv ( x n -- y )
|
||||||
[ nip ] [ gcd 1 = ] 2bi
|
[ nip ] [ gcd 1 = ] 2bi
|
||||||
[ dup 0 < [ + ] [ nip ] if ]
|
[ dup 0 < [ + ] [ nip ] if ]
|
||||||
|
@ -198,7 +201,7 @@ M: real sin fsin ;
|
||||||
|
|
||||||
GENERIC: sinh ( x -- y ) foldable
|
GENERIC: sinh ( x -- y ) foldable
|
||||||
|
|
||||||
M: complex sinh
|
M: complex sinh
|
||||||
>float-rect
|
>float-rect
|
||||||
[ [ fsinh ] [ fcos ] bi* * ]
|
[ [ fsinh ] [ fcos ] bi* * ]
|
||||||
[ [ fcosh ] [ fsin ] bi* * ] 2bi rect> ;
|
[ [ fcosh ] [ fsin ] bi* * ] 2bi rect> ;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2007-2009 Samuel Tardieu.
|
! Copyright (C) 2007-2009 Samuel Tardieu.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays combinators kernel make math math.primes sequences ;
|
USING: arrays combinators kernel make math math.functions math.primes sequences ;
|
||||||
IN: math.primes.factors
|
IN: math.primes.factors
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -11,7 +11,7 @@ IN: math.primes.factors
|
||||||
swap ;
|
swap ;
|
||||||
|
|
||||||
: write-factor ( n d -- n' d' )
|
: write-factor ( n d -- n' d' )
|
||||||
2dup mod zero? [
|
2dup divisor? [
|
||||||
[ [ count-factor ] keep swap 2array , ] keep
|
[ [ count-factor ] keep swap 2array , ] keep
|
||||||
! If the remainder is a prime number, increase d so that
|
! If the remainder is a prime number, increase d so that
|
||||||
! the caller stops looking for factors.
|
! the caller stops looking for factors.
|
||||||
|
|
|
@ -5,12 +5,13 @@ IN: models
|
||||||
HELP: model
|
HELP: model
|
||||||
{ $class-description "A mutable cell holding a single value. When the value is changed, a sequence of connected objects are notified. Models have the following slots:"
|
{ $class-description "A mutable cell holding a single value. When the value is changed, a sequence of connected objects are notified. Models have the following slots:"
|
||||||
{ $list
|
{ $list
|
||||||
{ { $snippet "value" } " - the value of the model. Use " { $link set-model } " to change the value." }
|
{ { $slot "value" } " - the value of the model. Use " { $link set-model } " to change the value." }
|
||||||
{ { $snippet "connections" } " - a sequence of objects implementing the " { $link model-changed } " generic word, to be notified when the model's value changes." }
|
{ { $slot "connections" } " - a sequence of objects implementing the " { $link model-changed } " generic word, to be notified when the model's value changes." }
|
||||||
{ { $snippet "dependencies" } " - a sequence of models which should have this model added to their sequence of connections when activated." }
|
{ { $slot "dependencies" } " - a sequence of models which should have this model added to their sequence of connections when activated." }
|
||||||
{ { $snippet "ref" } " - a reference count tracking the number of models which depend on this one." }
|
{ { $slot "ref" } " - a reference count tracking the number of models which depend on this one." }
|
||||||
|
{ { $slot "locked?" } " - a slot set by " { $link with-locked-model } " to ensure that the model doesn't get changed recursively" }
|
||||||
}
|
}
|
||||||
"Other classes may delegate to " { $link model } "."
|
"Other classes may inherit from " { $link model } "."
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: <model>
|
HELP: <model>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: accessors assocs cache colors.constants destructors fry kernel
|
USING: accessors assocs cache colors.constants destructors fry kernel
|
||||||
opengl opengl.gl combinators images images.tesselation grouping
|
opengl opengl.gl combinators images images.tesselation grouping
|
||||||
specialized-arrays.float locals sequences math math.vectors
|
specialized-arrays.float locals sequences math math.vectors
|
||||||
math.matrices generalizations fry columns ;
|
math.matrices generalizations fry columns arrays ;
|
||||||
IN: opengl.textures
|
IN: opengl.textures
|
||||||
|
|
||||||
: gen-texture ( -- id ) [ glGenTextures ] (gen-gl-object) ;
|
: gen-texture ( -- id ) [ glGenTextures ] (gen-gl-object) ;
|
||||||
|
@ -17,6 +17,7 @@ M: BGR component-order>format drop GL_BGR GL_UNSIGNED_BYTE ;
|
||||||
M: RGBA component-order>format drop GL_RGBA GL_UNSIGNED_BYTE ;
|
M: RGBA component-order>format drop GL_RGBA GL_UNSIGNED_BYTE ;
|
||||||
M: ARGB component-order>format drop GL_BGRA_EXT GL_UNSIGNED_INT_8_8_8_8_REV ;
|
M: ARGB component-order>format drop GL_BGRA_EXT GL_UNSIGNED_INT_8_8_8_8_REV ;
|
||||||
M: BGRA component-order>format drop GL_BGRA_EXT GL_UNSIGNED_BYTE ;
|
M: BGRA component-order>format drop GL_BGRA_EXT GL_UNSIGNED_BYTE ;
|
||||||
|
M: BGRX component-order>format drop GL_BGRA_EXT GL_UNSIGNED_BYTE ;
|
||||||
|
|
||||||
GENERIC: draw-texture ( texture -- )
|
GENERIC: draw-texture ( texture -- )
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ GENERIC: draw-scaled-texture ( dim texture -- )
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
TUPLE: single-texture loc dim texture-coords texture display-list disposed ;
|
TUPLE: single-texture image loc dim texture-coords texture display-list disposed ;
|
||||||
|
|
||||||
: repeat-last ( seq n -- seq' )
|
: repeat-last ( seq n -- seq' )
|
||||||
over peek pad-tail concat ;
|
over peek pad-tail concat ;
|
||||||
|
@ -44,7 +45,7 @@ TUPLE: single-texture loc dim texture-coords texture display-list disposed ;
|
||||||
tri * group ; inline
|
tri * group ; inline
|
||||||
|
|
||||||
: power-of-2-image ( image -- image )
|
: power-of-2-image ( image -- image )
|
||||||
dup dim>> [ 0 = ] all? [
|
dup dim>> [ [ 0 = ] [ power-of-2? ] bi or ] all? [
|
||||||
clone dup
|
clone dup
|
||||||
[ image-rows ]
|
[ image-rows ]
|
||||||
[ dim>> [ next-power-of-2 ] map ]
|
[ dim>> [ next-power-of-2 ] map ]
|
||||||
|
@ -92,26 +93,30 @@ TUPLE: single-texture loc dim texture-coords texture display-list disposed ;
|
||||||
|
|
||||||
: draw-textured-rect ( dim texture -- )
|
: draw-textured-rect ( dim texture -- )
|
||||||
[
|
[
|
||||||
(draw-textured-rect)
|
[ image>> has-alpha? [ GL_BLEND glDisable ] unless ]
|
||||||
GL_TEXTURE_2D 0 glBindTexture
|
[ (draw-textured-rect) GL_TEXTURE_2D 0 glBindTexture ]
|
||||||
|
[ image>> has-alpha? [ GL_BLEND glEnable ] unless ]
|
||||||
|
tri
|
||||||
] with-texturing ;
|
] with-texturing ;
|
||||||
|
|
||||||
: texture-coords ( dim -- coords )
|
: texture-coords ( texture -- coords )
|
||||||
[ dup next-power-of-2 /f ] map
|
[
|
||||||
{ { 0 0 } { 1 0 } { 1 1 } { 0 1 } } [ v* ] with map
|
[ dim>> ] [ image>> dim>> ] bi v/
|
||||||
|
{ { 0 0 } { 1 0 } { 1 1 } { 0 1 } }
|
||||||
|
[ v* ] with map
|
||||||
|
] keep
|
||||||
|
image>> upside-down?>> [ [ first2 1 swap - 2array ] map ] when
|
||||||
float-array{ } join ;
|
float-array{ } join ;
|
||||||
|
|
||||||
: make-texture-display-list ( texture -- dlist )
|
: make-texture-display-list ( texture -- dlist )
|
||||||
GL_COMPILE [ [ dim>> ] keep draw-textured-rect ] make-dlist ;
|
GL_COMPILE [ [ dim>> ] keep draw-textured-rect ] make-dlist ;
|
||||||
|
|
||||||
: <single-texture> ( image loc -- texture )
|
: <single-texture> ( image loc dim -- texture )
|
||||||
single-texture new swap >>loc
|
[ power-of-2-image ] 2dip
|
||||||
swap
|
single-texture new swap >>dim swap >>loc swap >>image
|
||||||
[ dim>> >>dim ] keep
|
dup image>> dim>> product 0 = [
|
||||||
[ dim>> product 0 = ] keep '[
|
dup texture-coords >>texture-coords
|
||||||
_
|
dup image>> make-texture >>texture
|
||||||
[ dim>> texture-coords >>texture-coords ]
|
|
||||||
[ power-of-2-image make-texture >>texture ] bi
|
|
||||||
dup make-texture-display-list >>display-list
|
dup make-texture-display-list >>display-list
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
||||||
|
@ -133,19 +138,20 @@ TUPLE: multi-texture grid display-list loc disposed ;
|
||||||
|
|
||||||
: <texture-grid> ( image-grid loc -- grid )
|
: <texture-grid> ( image-grid loc -- grid )
|
||||||
[ dup image-locs ] dip
|
[ dup image-locs ] dip
|
||||||
'[ [ _ v+ <single-texture> |dispose ] 2map ] 2map ;
|
'[ [ _ v+ over dim>> <single-texture> |dispose ] 2map ] 2map ;
|
||||||
|
|
||||||
: draw-textured-grid ( grid -- )
|
: draw-textured-grid ( grid -- )
|
||||||
[ [ [ dim>> ] keep (draw-textured-rect) ] each ] each ;
|
[ [ [ dim>> ] keep (draw-textured-rect) ] each ] each ;
|
||||||
|
|
||||||
|
: grid-has-alpha? ( grid -- ? )
|
||||||
|
first first image>> has-alpha? ;
|
||||||
|
|
||||||
: make-textured-grid-display-list ( grid -- dlist )
|
: make-textured-grid-display-list ( grid -- dlist )
|
||||||
GL_COMPILE [
|
GL_COMPILE [
|
||||||
[
|
[
|
||||||
[
|
[ grid-has-alpha? [ GL_BLEND glDisable ] unless ]
|
||||||
[
|
[ [ [ [ dim>> ] keep (draw-textured-rect) ] each ] each ]
|
||||||
[ dim>> ] keep (draw-textured-rect)
|
[ grid-has-alpha? [ GL_BLEND glEnable ] unless ] tri
|
||||||
] each
|
|
||||||
] each
|
|
||||||
GL_TEXTURE_2D 0 glBindTexture
|
GL_TEXTURE_2D 0 glBindTexture
|
||||||
] with-texturing
|
] with-texturing
|
||||||
] make-dlist ;
|
] make-dlist ;
|
||||||
|
@ -163,11 +169,14 @@ M: multi-texture draw-texture display-list>> [ glCallList ] when* ;
|
||||||
|
|
||||||
M: multi-texture dispose* grid>> [ [ dispose ] each ] each ;
|
M: multi-texture dispose* grid>> [ [ dispose ] each ] each ;
|
||||||
|
|
||||||
CONSTANT: max-texture-size { 256 256 }
|
CONSTANT: max-texture-size { 512 512 }
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: <texture> ( image loc -- texture )
|
: small-texture? ( dim -- ? )
|
||||||
over dim>> max-texture-size [ <= ] 2all?
|
max-texture-size [ <= ] 2all? ;
|
||||||
|
|
||||||
|
: <texture> ( image loc dim -- texture )
|
||||||
|
pick dim>> small-texture?
|
||||||
[ <single-texture> ]
|
[ <single-texture> ]
|
||||||
[ [ max-texture-size tesselate ] dip <multi-texture> ] if ;
|
[ drop [ max-texture-size tesselate ] dip <multi-texture> ] if ;
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.c-types arrays assocs byte-arrays io
|
USING: alien alien.c-types arrays assocs byte-arrays io
|
||||||
io.binary io.streams.string kernel math math.parser namespaces
|
io.binary io.streams.string kernel math math.parser namespaces
|
||||||
make parser prettyprint quotations sequences strings vectors
|
make parser quotations sequences strings vectors
|
||||||
words macros math.functions math.bitwise fry generalizations
|
words macros math.functions math.bitwise fry generalizations
|
||||||
combinators.smart io.streams.byte-array io.encodings.binary
|
combinators.smart io.streams.byte-array io.encodings.binary
|
||||||
math.vectors combinators multiline endian ;
|
math.vectors combinators multiline endian ;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
!
|
!
|
||||||
USING: kernel tools.test peg peg.ebnf words math math.parser
|
USING: kernel tools.test peg peg.ebnf words math math.parser
|
||||||
sequences accessors peg.parsers parser namespaces arrays
|
sequences accessors peg.parsers parser namespaces arrays
|
||||||
strings eval ;
|
strings eval unicode.data multiline ;
|
||||||
IN: peg.ebnf.tests
|
IN: peg.ebnf.tests
|
||||||
|
|
||||||
{ T{ ebnf-non-terminal f "abc" } } [
|
{ T{ ebnf-non-terminal f "abc" } } [
|
||||||
|
@ -520,3 +520,13 @@ Tok = Spaces (Number | Special )
|
||||||
{ "\\" } [
|
{ "\\" } [
|
||||||
"\\" [EBNF foo="\\" EBNF]
|
"\\" [EBNF foo="\\" EBNF]
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ "USE: peg.ebnf [EBNF EBNF]" eval ] must-fail
|
||||||
|
|
||||||
|
[ <" USE: peg.ebnf [EBNF
|
||||||
|
lol = a
|
||||||
|
lol = b
|
||||||
|
EBNF] "> eval
|
||||||
|
] [
|
||||||
|
error>> [ redefined-rule? ] [ name>> "lol" = ] bi and
|
||||||
|
] must-fail-with
|
||||||
|
|
|
@ -5,13 +5,18 @@ sequences quotations vectors namespaces make math assocs
|
||||||
continuations peg peg.parsers unicode.categories multiline
|
continuations peg peg.parsers unicode.categories multiline
|
||||||
splitting accessors effects sequences.deep peg.search
|
splitting accessors effects sequences.deep peg.search
|
||||||
combinators.short-circuit lexer io.streams.string stack-checker
|
combinators.short-circuit lexer io.streams.string stack-checker
|
||||||
io combinators parser ;
|
io combinators parser summary ;
|
||||||
IN: peg.ebnf
|
IN: peg.ebnf
|
||||||
|
|
||||||
: rule ( name word -- parser )
|
: rule ( name word -- parser )
|
||||||
#! Given an EBNF word produced from EBNF: return the EBNF rule
|
#! Given an EBNF word produced from EBNF: return the EBNF rule
|
||||||
"ebnf-parser" word-prop at ;
|
"ebnf-parser" word-prop at ;
|
||||||
|
|
||||||
|
ERROR: no-rule rule parser ;
|
||||||
|
|
||||||
|
: lookup-rule ( rule parser -- rule' )
|
||||||
|
2dup rule [ 2nip ] [ no-rule ] if* ;
|
||||||
|
|
||||||
TUPLE: tokenizer any one many ;
|
TUPLE: tokenizer any one many ;
|
||||||
|
|
||||||
: default-tokenizer ( -- tokenizer )
|
: default-tokenizer ( -- tokenizer )
|
||||||
|
@ -34,8 +39,13 @@ TUPLE: tokenizer any one many ;
|
||||||
: reset-tokenizer ( -- )
|
: reset-tokenizer ( -- )
|
||||||
default-tokenizer \ tokenizer set-global ;
|
default-tokenizer \ tokenizer set-global ;
|
||||||
|
|
||||||
|
ERROR: no-tokenizer name ;
|
||||||
|
|
||||||
|
M: no-tokenizer summary
|
||||||
|
drop "Tokenizer not found" ;
|
||||||
|
|
||||||
SYNTAX: TOKENIZER:
|
SYNTAX: TOKENIZER:
|
||||||
scan search [ "Tokenizer not found" throw ] unless*
|
scan dup search [ nip ] [ no-tokenizer ] if*
|
||||||
execute( -- tokenizer ) \ tokenizer set-global ;
|
execute( -- tokenizer ) \ tokenizer set-global ;
|
||||||
|
|
||||||
TUPLE: ebnf-non-terminal symbol ;
|
TUPLE: ebnf-non-terminal symbol ;
|
||||||
|
@ -258,7 +268,7 @@ DEFER: 'choice'
|
||||||
"]]" token ensure-not ,
|
"]]" token ensure-not ,
|
||||||
"]?" token ensure-not ,
|
"]?" token ensure-not ,
|
||||||
[ drop t ] satisfy ,
|
[ drop t ] satisfy ,
|
||||||
] seq* [ first ] action repeat0 [ >string ] action ;
|
] seq* repeat0 [ concat >string ] action ;
|
||||||
|
|
||||||
: 'ensure-not' ( -- parser )
|
: 'ensure-not' ( -- parser )
|
||||||
#! Parses the '!' syntax to ensure that
|
#! Parses the '!' syntax to ensure that
|
||||||
|
@ -367,15 +377,16 @@ M: ebnf-tokenizer (transform) ( ast -- parser )
|
||||||
(transform)
|
(transform)
|
||||||
dup parser-tokenizer \ tokenizer set-global
|
dup parser-tokenizer \ tokenizer set-global
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
ERROR: redefined-rule name ;
|
||||||
|
|
||||||
|
M: redefined-rule summary
|
||||||
|
name>> "Rule '" "' defined more than once" surround ;
|
||||||
|
|
||||||
M: ebnf-rule (transform) ( ast -- parser )
|
M: ebnf-rule (transform) ( ast -- parser )
|
||||||
dup elements>>
|
dup elements>>
|
||||||
(transform) [
|
(transform) [
|
||||||
swap symbol>> dup get parser? [
|
swap symbol>> dup get parser? [ redefined-rule ] [ set ] if
|
||||||
"Rule '" over append "' defined more than once" append throw
|
|
||||||
] [
|
|
||||||
set
|
|
||||||
] if
|
|
||||||
] keep ;
|
] keep ;
|
||||||
|
|
||||||
M: ebnf-sequence (transform) ( ast -- parser )
|
M: ebnf-sequence (transform) ( ast -- parser )
|
||||||
|
@ -466,14 +477,18 @@ ERROR: bad-effect quot effect ;
|
||||||
{ [ dup (( -- b )) effect<= ] [ drop [ drop ] prepose ] }
|
{ [ dup (( -- b )) effect<= ] [ drop [ drop ] prepose ] }
|
||||||
[ bad-effect ]
|
[ bad-effect ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
: ebnf-transform ( ast -- parser quot )
|
||||||
|
[ parser>> (transform) ]
|
||||||
|
[ code>> insert-escapes ]
|
||||||
|
[ parser>> ] tri build-locals
|
||||||
|
[ string-lines parse-lines ] call( string -- quot ) ;
|
||||||
|
|
||||||
M: ebnf-action (transform) ( ast -- parser )
|
M: ebnf-action (transform) ( ast -- parser )
|
||||||
[ parser>> (transform) ] [ code>> insert-escapes ] [ parser>> ] tri build-locals
|
ebnf-transform check-action-effect action ;
|
||||||
[ string-lines parse-lines ] call( string -- quot ) check-action-effect action ;
|
|
||||||
|
|
||||||
M: ebnf-semantic (transform) ( ast -- parser )
|
M: ebnf-semantic (transform) ( ast -- parser )
|
||||||
[ parser>> (transform) ] [ code>> insert-escapes ] [ parser>> ] tri build-locals
|
ebnf-transform semantic ;
|
||||||
[ string-lines parse-lines ] call( string -- quot ) semantic ;
|
|
||||||
|
|
||||||
M: ebnf-var (transform) ( ast -- parser )
|
M: ebnf-var (transform) ( ast -- parser )
|
||||||
parser>> (transform) ;
|
parser>> (transform) ;
|
||||||
|
@ -481,19 +496,20 @@ M: ebnf-var (transform) ( ast -- parser )
|
||||||
M: ebnf-terminal (transform) ( ast -- parser )
|
M: ebnf-terminal (transform) ( ast -- parser )
|
||||||
symbol>> tokenizer one>> call( symbol -- parser ) ;
|
symbol>> tokenizer one>> call( symbol -- parser ) ;
|
||||||
|
|
||||||
|
ERROR: ebnf-foreign-not-found name ;
|
||||||
|
|
||||||
|
M: ebnf-foreign-not-found summary
|
||||||
|
name>> "Foreign word '" "' not found" surround ;
|
||||||
|
|
||||||
M: ebnf-foreign (transform) ( ast -- parser )
|
M: ebnf-foreign (transform) ( ast -- parser )
|
||||||
dup word>> search
|
dup word>> search [ word>> ebnf-foreign-not-found ] unless*
|
||||||
[ "Foreign word '" swap word>> append "' not found" append throw ] unless*
|
|
||||||
swap rule>> [ main ] unless* over rule [
|
swap rule>> [ main ] unless* over rule [
|
||||||
nip
|
nip
|
||||||
] [
|
] [
|
||||||
execute( -- parser )
|
execute( -- parser )
|
||||||
] if* ;
|
] if* ;
|
||||||
|
|
||||||
: parser-not-found ( name -- * )
|
ERROR: parser-not-found name ;
|
||||||
[
|
|
||||||
"Parser '" % % "' not found." %
|
|
||||||
] "" make throw ;
|
|
||||||
|
|
||||||
M: ebnf-non-terminal (transform) ( ast -- parser )
|
M: ebnf-non-terminal (transform) ( ast -- parser )
|
||||||
symbol>> [
|
symbol>> [
|
||||||
|
@ -504,16 +520,16 @@ M: ebnf-non-terminal (transform) ( ast -- parser )
|
||||||
'ebnf' parse transform ;
|
'ebnf' parse transform ;
|
||||||
|
|
||||||
: check-parse-result ( result -- result )
|
: check-parse-result ( result -- result )
|
||||||
dup [
|
[
|
||||||
dup remaining>> [ blank? ] trim empty? [
|
dup remaining>> [ blank? ] trim [
|
||||||
[
|
[
|
||||||
"Unable to fully parse EBNF. Left to parse was: " %
|
"Unable to fully parse EBNF. Left to parse was: " %
|
||||||
remaining>> %
|
remaining>> %
|
||||||
] "" make throw
|
] "" make throw
|
||||||
] unless
|
] unless-empty
|
||||||
] [
|
] [
|
||||||
"Could not parse EBNF" throw
|
"Could not parse EBNF" throw
|
||||||
] if ;
|
] if* ;
|
||||||
|
|
||||||
: parse-ebnf ( string -- hashtable )
|
: parse-ebnf ( string -- hashtable )
|
||||||
'ebnf' (parse) check-parse-result ast>> transform ;
|
'ebnf' (parse) check-parse-result ast>> transform ;
|
||||||
|
@ -522,14 +538,18 @@ M: ebnf-non-terminal (transform) ( ast -- parser )
|
||||||
parse-ebnf dup dup parser [ main swap at compile ] with-variable
|
parse-ebnf dup dup parser [ main swap at compile ] with-variable
|
||||||
[ compiled-parse ] curry [ with-scope ast>> ] curry ;
|
[ compiled-parse ] curry [ with-scope ast>> ] curry ;
|
||||||
|
|
||||||
SYNTAX: <EBNF "EBNF>" reset-tokenizer parse-multiline-string parse-ebnf main swap at
|
SYNTAX: <EBNF
|
||||||
|
"EBNF>"
|
||||||
|
reset-tokenizer parse-multiline-string parse-ebnf main swap at
|
||||||
parsed reset-tokenizer ;
|
parsed reset-tokenizer ;
|
||||||
|
|
||||||
SYNTAX: [EBNF "EBNF]" reset-tokenizer parse-multiline-string ebnf>quot nip
|
SYNTAX: [EBNF
|
||||||
|
"EBNF]"
|
||||||
|
reset-tokenizer parse-multiline-string ebnf>quot nip
|
||||||
parsed \ call parsed reset-tokenizer ;
|
parsed \ call parsed reset-tokenizer ;
|
||||||
|
|
||||||
SYNTAX: EBNF:
|
SYNTAX: EBNF:
|
||||||
reset-tokenizer CREATE-WORD dup ";EBNF" parse-multiline-string
|
reset-tokenizer CREATE-WORD dup ";EBNF" parse-multiline-string
|
||||||
ebnf>quot swapd (( input -- ast )) define-declared "ebnf-parser" set-word-prop
|
ebnf>quot swapd
|
||||||
|
(( input -- ast )) define-declared "ebnf-parser" set-word-prop
|
||||||
reset-tokenizer ;
|
reset-tokenizer ;
|
||||||
|
|
||||||
|
|
|
@ -155,18 +155,21 @@ TUPLE: peg-head rule-id involved-set eval-set ;
|
||||||
dup pos>> pos set ans>>
|
dup pos>> pos set ans>>
|
||||||
; inline
|
; inline
|
||||||
|
|
||||||
:: (setup-lr) ( r l s -- )
|
:: (setup-lr) ( l s -- )
|
||||||
s head>> l head>> eq? [
|
s [
|
||||||
l head>> s (>>head)
|
s left-recursion? [ s throw ] unless
|
||||||
l head>> [ s rule-id>> suffix ] change-involved-set drop
|
s head>> l head>> eq? [
|
||||||
r l s next>> (setup-lr)
|
l head>> s (>>head)
|
||||||
] unless ;
|
l head>> [ s rule-id>> suffix ] change-involved-set drop
|
||||||
|
l s next>> (setup-lr)
|
||||||
|
] unless
|
||||||
|
] when ;
|
||||||
|
|
||||||
:: setup-lr ( r l -- )
|
:: setup-lr ( r l -- )
|
||||||
l head>> [
|
l head>> [
|
||||||
r rule-id V{ } clone V{ } clone peg-head boa l (>>head)
|
r rule-id V{ } clone V{ } clone peg-head boa l (>>head)
|
||||||
] unless
|
] unless
|
||||||
r l lrstack get (setup-lr) ;
|
l lrstack get (setup-lr) ;
|
||||||
|
|
||||||
:: lr-answer ( r p m -- ast )
|
:: lr-answer ( r p m -- ast )
|
||||||
[let* |
|
[let* |
|
||||||
|
@ -216,8 +219,10 @@ TUPLE: peg-head rule-id involved-set eval-set ;
|
||||||
lrstack get next>> lrstack set
|
lrstack get next>> lrstack set
|
||||||
pos get m (>>pos)
|
pos get m (>>pos)
|
||||||
lr head>> [
|
lr head>> [
|
||||||
ans lr (>>seed)
|
m ans>> left-recursion? [
|
||||||
r p m lr-answer
|
ans lr (>>seed)
|
||||||
|
r p m lr-answer
|
||||||
|
] [ ans ] if
|
||||||
] [
|
] [
|
||||||
ans m (>>ans)
|
ans m (>>ans)
|
||||||
ans
|
ans
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: tools.test quoting ;
|
||||||
|
IN: quoting.tests
|
||||||
|
|
||||||
|
[ f ] [ "" quoted? ] unit-test
|
||||||
|
[ t ] [ "''" quoted? ] unit-test
|
||||||
|
[ t ] [ "\"\"" quoted? ] unit-test
|
||||||
|
[ t ] [ "\"Circus Maximus\"" quoted? ] unit-test
|
||||||
|
[ t ] [ "'Circus Maximus'" quoted? ] unit-test
|
||||||
|
[ f ] [ "Circus Maximus" quoted? ] unit-test
|
|
@ -84,21 +84,24 @@ C: <box> box
|
||||||
{ } assoc-like [ first integer? ] partition
|
{ } assoc-like [ first integer? ] partition
|
||||||
[ [ literals>cases ] keep ] dip non-literals>dispatch ;
|
[ [ literals>cases ] keep ] dip non-literals>dispatch ;
|
||||||
|
|
||||||
:: step ( last-match index str quot final? direction -- last-index/f )
|
: advance ( index backwards? -- index+/-1 )
|
||||||
|
-1 1 ? + >fixnum ; inline
|
||||||
|
|
||||||
|
: check ( index string backwards? -- in-bounds? )
|
||||||
|
[ drop -1 eq? not ] [ length < ] if ; inline
|
||||||
|
|
||||||
|
:: step ( last-match index str quot final? backwards? -- last-index/f )
|
||||||
final? index last-match ?
|
final? index last-match ?
|
||||||
index str bounds-check? [
|
index str backwards? check [
|
||||||
index direction + str
|
index backwards? advance str
|
||||||
index str nth-unsafe
|
index str nth-unsafe
|
||||||
quot call
|
quot call
|
||||||
] when ; inline
|
] when ; inline
|
||||||
|
|
||||||
: direction ( -- n )
|
|
||||||
backwards? get -1 1 ? ;
|
|
||||||
|
|
||||||
: transitions>quot ( transitions final-state? -- quot )
|
: transitions>quot ( transitions final-state? -- quot )
|
||||||
dup shortest? get and [ 2drop [ drop nip ] ] [
|
dup shortest? get and [ 2drop [ drop nip ] ] [
|
||||||
[ split-literals swap case>quot ] dip direction
|
[ split-literals swap case>quot ] dip backwards? get
|
||||||
'[ { array-capacity string } declare _ _ _ step ]
|
'[ { fixnum string } declare _ _ _ step ]
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: word>quot ( word dfa -- quot )
|
: word>quot ( word dfa -- quot )
|
||||||
|
@ -122,10 +125,13 @@ C: <box> box
|
||||||
: dfa>main-word ( dfa -- word )
|
: dfa>main-word ( dfa -- word )
|
||||||
states>words [ states>code ] keep start-state>> ;
|
states>words [ states>code ] keep start-state>> ;
|
||||||
|
|
||||||
|
: word-template ( quot -- quot' )
|
||||||
|
'[ drop [ f ] 2dip over array-capacity? _ [ 2drop ] if ] ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: dfa>word ( dfa -- quot )
|
: dfa>word ( dfa -- quot )
|
||||||
dfa>main-word execution-quot '[ drop [ f ] 2dip @ ]
|
dfa>main-word execution-quot word-template
|
||||||
(( start-index string regexp -- i/f )) define-temp ;
|
(( start-index string regexp -- i/f )) define-temp ;
|
||||||
|
|
||||||
: dfa>shortest-word ( dfa -- word )
|
: dfa>shortest-word ( dfa -- word )
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: functors kernel math.order sequences sorting ;
|
||||||
|
IN: sorting.functor
|
||||||
|
|
||||||
|
FUNCTOR: define-sorting ( NAME QUOT -- )
|
||||||
|
|
||||||
|
NAME<=> DEFINES ${NAME}<=>
|
||||||
|
NAME>=< DEFINES ${NAME}>=<
|
||||||
|
|
||||||
|
WHERE
|
||||||
|
|
||||||
|
: NAME<=> ( obj1 obj2 -- <=> ) QUOT bi@ <=> ;
|
||||||
|
: NAME>=< ( obj1 obj2 -- >=< ) NAME<=> invert-comparison ;
|
||||||
|
|
||||||
|
;FUNCTOR
|
|
@ -25,46 +25,11 @@ HELP: human>=<
|
||||||
}
|
}
|
||||||
{ $description "Compares two objects using the " { $link human<=> } " word and inverts the result." } ;
|
{ $description "Compares two objects using the " { $link human<=> } " word and inverts the result." } ;
|
||||||
|
|
||||||
HELP: human-compare
|
|
||||||
{ $values
|
|
||||||
{ "obj1" object } { "obj2" object } { "quot" quotation }
|
|
||||||
{ "<=>" "an ordering specifier" }
|
|
||||||
}
|
|
||||||
{ $description "Compares the results of applying the quotation to both objects via <=>." } ;
|
|
||||||
|
|
||||||
HELP: human-sort
|
|
||||||
{ $values
|
|
||||||
{ "seq" sequence }
|
|
||||||
{ "seq'" sequence }
|
|
||||||
}
|
|
||||||
{ $description "Sorts a sequence of objects by comparing the magnitude of any integers in the input string using the <=> word." } ;
|
|
||||||
|
|
||||||
HELP: human-sort-keys
|
|
||||||
{ $values
|
|
||||||
{ "seq" "an alist" }
|
|
||||||
{ "sortedseq" "a new sorted sequence" }
|
|
||||||
}
|
|
||||||
{ $description "Sorts the elements comparing first elements of pairs using the " { $link human<=> } " word." } ;
|
|
||||||
|
|
||||||
HELP: human-sort-values
|
|
||||||
{ $values
|
|
||||||
{ "seq" "an alist" }
|
|
||||||
{ "sortedseq" "a new sorted sequence" }
|
|
||||||
}
|
|
||||||
{ $description "Sorts the elements comparing second elements of pairs using the " { $link human<=> } " word." } ;
|
|
||||||
|
|
||||||
{ <=> >=< human-compare human-sort human-sort-keys human-sort-values } related-words
|
|
||||||
|
|
||||||
ARTICLE: "sorting.human" "Human-friendly sorting"
|
ARTICLE: "sorting.human" "Human-friendly sorting"
|
||||||
"The " { $vocab-link "sorting.human" } " vocabulary sorts by numbers as a human would -- by comparing their magnitudes -- rather than in a lexicographic way. For example, sorting a1, a10, a03, a2 with human sort returns a1, a2, a03, a10, while sorting with natural sort returns a03, a1, a10, a2." $nl
|
"The " { $vocab-link "sorting.human" } " vocabulary sorts by numbers as a human would -- by comparing their magnitudes -- rather than in a lexicographic way. For example, sorting a1, a10, a03, a2 with human sort returns a1, a2, a03, a10, while sorting with natural sort returns a03, a1, a10, a2." $nl
|
||||||
"Comparing two objects:"
|
"Comparing two objects:"
|
||||||
{ $subsection human<=> }
|
{ $subsection human<=> }
|
||||||
{ $subsection human>=< }
|
{ $subsection human>=< }
|
||||||
{ $subsection human-compare }
|
|
||||||
"Sort a sequence:"
|
|
||||||
{ $subsection human-sort }
|
|
||||||
{ $subsection human-sort-keys }
|
|
||||||
{ $subsection human-sort-values }
|
|
||||||
"Splitting a string into substrings and integers:"
|
"Splitting a string into substrings and integers:"
|
||||||
{ $subsection find-numbers } ;
|
{ $subsection find-numbers } ;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
USING: sorting.human tools.test ;
|
USING: sorting.human tools.test sorting.slots ;
|
||||||
IN: sorting.human.tests
|
IN: sorting.human.tests
|
||||||
|
|
||||||
\ human-sort must-infer
|
[ { "x1y" "x2" "x10y" } ] [ { "x1y" "x10y" "x2" } { human<=> } sort-by ] unit-test
|
||||||
|
|
||||||
[ { "x1y" "x2" "x10y" } ] [ { "x1y" "x10y" "x2" } human-sort ] unit-test
|
|
||||||
|
|
|
@ -1,22 +1,9 @@
|
||||||
! Copyright (C) 2008 Doug Coleman, Slava Pestov.
|
! Copyright (C) 2008 Doug Coleman, Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: peg.ebnf math.parser kernel assocs sorting fry
|
USING: math.parser peg.ebnf sorting.functor ;
|
||||||
math.order sequences ascii splitting.monotonic ;
|
|
||||||
IN: sorting.human
|
IN: sorting.human
|
||||||
|
|
||||||
: find-numbers ( string -- seq )
|
: find-numbers ( string -- seq )
|
||||||
[EBNF Result = ([0-9]+ => [[ string>number ]] | (!([0-9]) .)+)* EBNF] ;
|
[EBNF Result = ([0-9]+ => [[ string>number ]] | (!([0-9]) .)+)* EBNF] ;
|
||||||
|
|
||||||
: human<=> ( obj1 obj2 -- <=> ) [ find-numbers ] bi@ <=> ;
|
<< "human" [ find-numbers ] define-sorting >>
|
||||||
|
|
||||||
: human>=< ( obj1 obj2 -- >=< ) human<=> invert-comparison ; inline
|
|
||||||
|
|
||||||
: human-compare ( obj1 obj2 quot -- <=> ) bi@ human<=> ;
|
|
||||||
|
|
||||||
: human-sort ( seq -- seq' ) [ human<=> ] sort ;
|
|
||||||
|
|
||||||
: human-sort-keys ( seq -- sortedseq )
|
|
||||||
[ [ first ] human-compare ] sort ;
|
|
||||||
|
|
||||||
: human-sort-values ( seq -- sortedseq )
|
|
||||||
[ [ second ] human-compare ] sort ;
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ HELP: compare-slots
|
||||||
HELP: sort-by-slots
|
HELP: sort-by-slots
|
||||||
{ $values
|
{ $values
|
||||||
{ "seq" sequence } { "sort-specs" "a sequence of accessors ending with a comparator" }
|
{ "seq" sequence } { "sort-specs" "a sequence of accessors ending with a comparator" }
|
||||||
{ "seq'" sequence }
|
{ "sortedseq" sequence }
|
||||||
}
|
}
|
||||||
{ $description "Sorts a sequence of tuples by the sort-specs in " { $snippet "sort-spec" } ". A sort-spec is a sequence of slot accessors ending in a comparator." }
|
{ $description "Sorts a sequence of tuples by the sort-specs in " { $snippet "sort-spec" } ". A sort-spec is a sequence of slot accessors ending in a comparator." }
|
||||||
{ $examples
|
{ $examples
|
||||||
|
@ -39,11 +39,20 @@ HELP: split-by-slots
|
||||||
}
|
}
|
||||||
{ $description "Splits a sequence of tuples into a sequence of slices of tuples that have the same values in all slots in the accessor sequence. This word is only useful for splitting a sorted sequence, but is more efficient than partitioning in such a case." } ;
|
{ $description "Splits a sequence of tuples into a sequence of slices of tuples that have the same values in all slots in the accessor sequence. This word is only useful for splitting a sorted sequence, but is more efficient than partitioning in such a case." } ;
|
||||||
|
|
||||||
|
HELP: sort-by
|
||||||
|
{ $values
|
||||||
|
{ "seq" sequence } { "sort-seq" "a sequence of comparators" }
|
||||||
|
{ "sortedseq" sequence }
|
||||||
|
}
|
||||||
|
{ $description "Sorts a sequence by comparing elements by comparators, using subsequent comparators when there is a tie." } ;
|
||||||
|
|
||||||
ARTICLE: "sorting.slots" "Sorting by slots"
|
ARTICLE: "sorting.slots" "Sorting by slots"
|
||||||
"The " { $vocab-link "sorting.slots" } " vocabulary can sort tuples by slot in ascending or descending order, using subsequent slots as tie-breakers." $nl
|
"The " { $vocab-link "sorting.slots" } " vocabulary can sort tuples by slot in ascending or descending order, using subsequent slots as tie-breakers." $nl
|
||||||
"Comparing two objects by a sequence of slots:"
|
"Comparing two objects by a sequence of slots:"
|
||||||
{ $subsection compare-slots }
|
{ $subsection compare-slots }
|
||||||
"Sorting a sequence by a sequence of slots:"
|
"Sorting a sequence of tuples by a slot/comparator pairs:"
|
||||||
{ $subsection sort-by-slots } ;
|
{ $subsection sort-by-slots }
|
||||||
|
"Sorting a sequence by a sequence of comparators:"
|
||||||
|
{ $subsection sort-by } ;
|
||||||
|
|
||||||
ABOUT: "sorting.slots"
|
ABOUT: "sorting.slots"
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors math.order sorting.slots tools.test
|
USING: accessors math.order sorting.slots tools.test
|
||||||
sorting.human arrays sequences kernel assocs multiline ;
|
sorting.human arrays sequences kernel assocs multiline
|
||||||
|
sorting.functor ;
|
||||||
IN: sorting.literals.tests
|
IN: sorting.literals.tests
|
||||||
|
|
||||||
TUPLE: sort-test a b c tuple2 ;
|
TUPLE: sort-test a b c tuple2 ;
|
||||||
|
@ -76,6 +77,9 @@ TUPLE: tuple2 d ;
|
||||||
[ { } ]
|
[ { } ]
|
||||||
[ { } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by-slots ] unit-test
|
[ { } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by-slots ] unit-test
|
||||||
|
|
||||||
|
[ { } ]
|
||||||
|
[ { } { } sort-by-slots ] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 1 } } } }
|
T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 1 } } } }
|
||||||
|
@ -143,3 +147,15 @@ TUPLE: tuple2 d ;
|
||||||
T{ sort-test { a 5 } { tuple2 T{ tuple2 { d 4 } } } }
|
T{ sort-test { a 5 } { tuple2 T{ tuple2 { d 4 } } } }
|
||||||
} { { tuple2>> d>> } { a>> } } split-by-slots [ >array ] map
|
} { { tuple2>> d>> } { a>> } } split-by-slots [ >array ] map
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
||||||
|
[ { "a" "b" "c" } ] [ { "b" "c" "a" } { <=> <=> } sort-by ] unit-test
|
||||||
|
[ { "b" "c" "a" } ] [ { "b" "c" "a" } { } sort-by ] unit-test
|
||||||
|
|
||||||
|
<< "length-test" [ length ] define-sorting >>
|
||||||
|
|
||||||
|
[ { { 1 } { 1 2 3 } { 1 3 2 } { 3 2 1 } } ]
|
||||||
|
[
|
||||||
|
{ { 3 2 1 } { 1 2 3 } { 1 3 2 } { 1 } }
|
||||||
|
{ length-test<=> <=> } sort-by
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -7,13 +7,16 @@ IN: sorting.slots
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
: short-circuit-comparator ( obj1 obj2 word -- comparator/? )
|
||||||
|
execute dup +eq+ eq? [ drop f ] when ; inline
|
||||||
|
|
||||||
: slot-comparator ( seq -- quot )
|
: slot-comparator ( seq -- quot )
|
||||||
[
|
[
|
||||||
but-last-slice
|
but-last-slice
|
||||||
[ '[ [ _ execute ] bi@ ] ] map concat
|
[ '[ [ _ execute ] bi@ ] ] map concat
|
||||||
] [
|
] [
|
||||||
peek
|
peek
|
||||||
'[ @ _ execute dup +eq+ eq? [ drop f ] when ]
|
'[ @ _ short-circuit-comparator ]
|
||||||
] bi ;
|
] bi ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
@ -22,8 +25,20 @@ MACRO: compare-slots ( sort-specs -- <=> )
|
||||||
#! sort-spec: { accessors comparator }
|
#! sort-spec: { accessors comparator }
|
||||||
[ slot-comparator ] map '[ _ 2|| +eq+ or ] ;
|
[ slot-comparator ] map '[ _ 2|| +eq+ or ] ;
|
||||||
|
|
||||||
: sort-by-slots ( seq sort-specs -- seq' )
|
MACRO: sort-by-slots ( sort-specs -- quot )
|
||||||
'[ _ compare-slots ] sort ;
|
'[ [ _ compare-slots ] sort ] ;
|
||||||
|
|
||||||
|
MACRO: compare-seq ( seq -- quot )
|
||||||
|
[ '[ _ short-circuit-comparator ] ] map '[ _ 2|| +eq+ or ] ;
|
||||||
|
|
||||||
|
MACRO: sort-by ( sort-seq -- quot )
|
||||||
|
'[ [ _ compare-seq ] sort ] ;
|
||||||
|
|
||||||
|
MACRO: sort-keys-by ( sort-seq -- quot )
|
||||||
|
'[ [ first ] bi@ _ compare-seq ] sort ;
|
||||||
|
|
||||||
|
MACRO: sort-values-by ( sort-seq -- quot )
|
||||||
|
'[ [ second ] bi@ _ compare-seq ] sort ;
|
||||||
|
|
||||||
MACRO: split-by-slots ( accessor-seqs -- quot )
|
MACRO: split-by-slots ( accessor-seqs -- quot )
|
||||||
[ [ '[ [ _ execute ] bi@ ] ] map concat [ = ] compose ] map
|
[ [ '[ [ _ execute ] bi@ ] ] map concat [ = ] compose ] map
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -0,0 +1,40 @@
|
||||||
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: tools.test sorting.title sorting.slots ;
|
||||||
|
IN: sorting.title.tests
|
||||||
|
|
||||||
|
: sort-me ( -- seq )
|
||||||
|
{
|
||||||
|
"The Beatles"
|
||||||
|
"A river runs through it"
|
||||||
|
"Another"
|
||||||
|
"la vida loca"
|
||||||
|
"Basketball"
|
||||||
|
"racquetball"
|
||||||
|
"Los Fujis"
|
||||||
|
"los Fujis"
|
||||||
|
"La cucaracha"
|
||||||
|
"a day to remember"
|
||||||
|
"of mice and men"
|
||||||
|
"on belay"
|
||||||
|
"for the horde"
|
||||||
|
} ;
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"Another"
|
||||||
|
"Basketball"
|
||||||
|
"The Beatles"
|
||||||
|
"La cucaracha"
|
||||||
|
"a day to remember"
|
||||||
|
"for the horde"
|
||||||
|
"Los Fujis"
|
||||||
|
"los Fujis"
|
||||||
|
"of mice and men"
|
||||||
|
"on belay"
|
||||||
|
"racquetball"
|
||||||
|
"A river runs through it"
|
||||||
|
"la vida loca"
|
||||||
|
}
|
||||||
|
] [
|
||||||
|
sort-me { title<=> } sort-by
|
||||||
|
] unit-test
|
|
@ -0,0 +1,7 @@
|
||||||
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: sorting.functor regexp kernel accessors sequences
|
||||||
|
unicode.case ;
|
||||||
|
IN: sorting.title
|
||||||
|
|
||||||
|
<< "title" [ >lower dup R/ ^(the|a|an|el|la|los|las|il) / first-match [ to>> tail-slice ] when* ] define-sorting >>
|
|
@ -605,6 +605,8 @@ M: object infer-call*
|
||||||
|
|
||||||
\ fflush { alien } { } define-primitive
|
\ fflush { alien } { } define-primitive
|
||||||
|
|
||||||
|
\ fseek { alien integer integer } { } define-primitive
|
||||||
|
|
||||||
\ fclose { alien } { } define-primitive
|
\ fclose { alien } { } define-primitive
|
||||||
|
|
||||||
\ <wrapper> { object } { wrapper } define-primitive
|
\ <wrapper> { object } { wrapper } define-primitive
|
||||||
|
|
|
@ -35,9 +35,9 @@ HELP: download-feed
|
||||||
{ $values { "url" url } { "feed" feed } }
|
{ $values { "url" url } { "feed" feed } }
|
||||||
{ $description "Downloads a feed from a URL using the " { $link "http.client" } "." } ;
|
{ $description "Downloads a feed from a URL using the " { $link "http.client" } "." } ;
|
||||||
|
|
||||||
HELP: string>feed
|
HELP: parse-feed
|
||||||
{ $values { "string" string } { "feed" feed } }
|
{ $values { "seq" "a string or a byte array" } { "feed" feed } }
|
||||||
{ $description "Parses a feed in string form." } ;
|
{ $description "Parses a feed." } ;
|
||||||
|
|
||||||
HELP: xml>feed
|
HELP: xml>feed
|
||||||
{ $values { "xml" xml } { "feed" feed } }
|
{ $values { "xml" xml } { "feed" feed } }
|
||||||
|
@ -58,7 +58,7 @@ $nl
|
||||||
{ $subsection <entry> }
|
{ $subsection <entry> }
|
||||||
"Reading feeds:"
|
"Reading feeds:"
|
||||||
{ $subsection download-feed }
|
{ $subsection download-feed }
|
||||||
{ $subsection string>feed }
|
{ $subsection parse-feed }
|
||||||
{ $subsection xml>feed }
|
{ $subsection xml>feed }
|
||||||
"Writing feeds:"
|
"Writing feeds:"
|
||||||
{ $subsection feed>xml }
|
{ $subsection feed>xml }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: syndication io kernel io.files tools.test io.encodings.utf8
|
USING: syndication io kernel io.files tools.test io.encodings.binary
|
||||||
calendar urls xml.writer ;
|
calendar urls xml.writer ;
|
||||||
IN: syndication.tests
|
IN: syndication.tests
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ IN: syndication.tests
|
||||||
: load-news-file ( filename -- feed )
|
: load-news-file ( filename -- feed )
|
||||||
#! Load an news syndication file and process it, returning
|
#! Load an news syndication file and process it, returning
|
||||||
#! it as an feed tuple.
|
#! it as an feed tuple.
|
||||||
utf8 file-contents string>feed ;
|
binary file-contents parse-feed ;
|
||||||
|
|
||||||
[ T{
|
[ T{
|
||||||
feed
|
feed
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
! Copyright (C) 2006 Chris Double, Daniel Ehrenberg.
|
! Copyright (C) 2006 Chris Double, Daniel Ehrenberg.
|
||||||
! Portions copyright (C) 2008 Slava Pestov.
|
! Portions copyright (C) 2008, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: xml.traversal kernel assocs math.order
|
USING: xml.traversal kernel assocs math.order strings sequences
|
||||||
strings sequences xml.data xml.writer
|
xml.data xml.writer io.streams.string combinators xml
|
||||||
io.streams.string combinators xml xml.entities.html io.files io
|
xml.entities.html io.files io http.client namespaces make
|
||||||
http.client namespaces make xml.syntax hashtables
|
xml.syntax hashtables calendar.format accessors continuations
|
||||||
calendar.format accessors continuations urls present ;
|
urls present byte-arrays ;
|
||||||
IN: syndication
|
IN: syndication
|
||||||
|
|
||||||
: any-tag-named ( tag names -- tag-inside )
|
: any-tag-named ( tag names -- tag-inside )
|
||||||
|
@ -106,12 +106,15 @@ TUPLE: entry title url description date ;
|
||||||
{ "feed" [ atom1.0 ] }
|
{ "feed" [ atom1.0 ] }
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
: string>feed ( string -- feed )
|
GENERIC: parse-feed ( seq -- feed )
|
||||||
[ string>xml xml>feed ] with-html-entities ;
|
|
||||||
|
M: string parse-feed [ string>xml xml>feed ] with-html-entities ;
|
||||||
|
|
||||||
|
M: byte-array parse-feed [ bytes>xml xml>feed ] with-html-entities ;
|
||||||
|
|
||||||
: download-feed ( url -- feed )
|
: download-feed ( url -- feed )
|
||||||
#! Retrieve an news syndication file, return as a feed tuple.
|
#! Retrieve an news syndication file, return as a feed tuple.
|
||||||
http-get nip string>feed ;
|
http-get nip parse-feed ;
|
||||||
|
|
||||||
! Atom generation
|
! Atom generation
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,12 @@ IN: tools.deploy.macosx
|
||||||
|
|
||||||
: create-app-dir ( vocab bundle-name -- vm )
|
: create-app-dir ( vocab bundle-name -- vm )
|
||||||
[
|
[
|
||||||
nip
|
nip {
|
||||||
[ copy-dll ]
|
[ copy-dll ]
|
||||||
[ copy-nib ]
|
[ copy-nib ]
|
||||||
[ "Contents/Resources" append-path make-directories ]
|
[ "Contents/Resources" append-path make-directories ]
|
||||||
tri
|
[ "Contents/Resources" copy-theme ]
|
||||||
|
} cleave
|
||||||
]
|
]
|
||||||
[ create-app-plist ]
|
[ create-app-plist ]
|
||||||
[ "Contents/MacOS/" append-path copy-vm ] 2tri
|
[ "Contents/MacOS/" append-path copy-vm ] 2tri
|
||||||
|
|
|
@ -157,6 +157,8 @@ IN: tools.deploy.shaker
|
||||||
"specializer"
|
"specializer"
|
||||||
"step-into"
|
"step-into"
|
||||||
"step-into?"
|
"step-into?"
|
||||||
|
! UI needs this
|
||||||
|
! "superclass"
|
||||||
"transform-n"
|
"transform-n"
|
||||||
"transform-quot"
|
"transform-quot"
|
||||||
"tuple-dispatch-generic"
|
"tuple-dispatch-generic"
|
||||||
|
@ -275,7 +277,6 @@ IN: tools.deploy.shaker
|
||||||
lexer-factory
|
lexer-factory
|
||||||
print-use-hook
|
print-use-hook
|
||||||
root-cache
|
root-cache
|
||||||
vocab-roots
|
|
||||||
vocabs:dictionary
|
vocabs:dictionary
|
||||||
vocabs:load-vocab-hook
|
vocabs:load-vocab-hook
|
||||||
word
|
word
|
||||||
|
|
|
@ -9,11 +9,6 @@ IN: tools.deploy.windows
|
||||||
: copy-dll ( bundle-name -- )
|
: copy-dll ( bundle-name -- )
|
||||||
"resource:factor.dll" swap copy-file-into ;
|
"resource:factor.dll" swap copy-file-into ;
|
||||||
|
|
||||||
: copy-pango ( bundle-name -- )
|
|
||||||
"resource:build-support/dlls.txt" ascii file-lines
|
|
||||||
[ "resource:" prepend-path ] map
|
|
||||||
swap copy-files-into ;
|
|
||||||
|
|
||||||
:: copy-vm ( executable bundle-name extension -- vm )
|
:: copy-vm ( executable bundle-name extension -- vm )
|
||||||
vm "." split1-last drop extension append
|
vm "." split1-last drop extension append
|
||||||
bundle-name executable ".exe" append append-path
|
bundle-name executable ".exe" append append-path
|
||||||
|
@ -22,9 +17,7 @@ IN: tools.deploy.windows
|
||||||
: create-exe-dir ( vocab bundle-name -- vm )
|
: create-exe-dir ( vocab bundle-name -- vm )
|
||||||
dup copy-dll
|
dup copy-dll
|
||||||
deploy-ui? get [
|
deploy-ui? get [
|
||||||
[ copy-pango ]
|
[ "" copy-theme ] [ ".exe" copy-vm ] bi
|
||||||
[ "" copy-theme ]
|
|
||||||
[ ".exe" copy-vm ] tri
|
|
||||||
] [ ".com" copy-vm ] if ;
|
] [ ".com" copy-vm ] if ;
|
||||||
|
|
||||||
M: winnt deploy*
|
M: winnt deploy*
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
! Copyright (C) 2005, 2006 Doug Coleman.
|
! Copyright (C) 2005, 2006 Doug Coleman.
|
||||||
! Portions copyright (C) 2007, 2009 Slava Pestov.
|
! Portions copyright (C) 2007, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.c-types alien.strings arrays assocs ui
|
USING: alien alien.c-types alien.strings arrays assocs ui ui.private
|
||||||
ui.private ui.gadgets ui.gadgets.private ui.backend
|
ui.gadgets ui.gadgets.private ui.backend ui.clipboards
|
||||||
ui.clipboards ui.gadgets.worlds ui.gestures ui.event-loop io
|
ui.gadgets.worlds ui.gestures ui.event-loop io kernel math
|
||||||
kernel math math.vectors namespaces make sequences strings
|
math.vectors namespaces make sequences strings vectors words
|
||||||
vectors words windows.kernel32 windows.gdi32 windows.user32
|
windows.kernel32 windows.gdi32 windows.user32 windows.opengl32
|
||||||
windows.opengl32 windows.messages windows.types windows.nt
|
windows.messages windows.types windows.offscreen windows.nt windows
|
||||||
windows threads libc combinators fry combinators.short-circuit
|
threads libc combinators fry combinators.short-circuit continuations
|
||||||
continuations command-line shuffle opengl ui.render ascii
|
command-line shuffle opengl ui.render ascii math.bitwise locals
|
||||||
math.bitwise locals accessors math.rectangles math.order ascii
|
accessors math.rectangles math.order ascii calendar
|
||||||
calendar io.encodings.utf16n ;
|
io.encodings.utf16n ;
|
||||||
IN: ui.backend.windows
|
IN: ui.backend.windows
|
||||||
|
|
||||||
SINGLETON: windows-ui-backend
|
SINGLETON: windows-ui-backend
|
||||||
|
@ -433,12 +433,7 @@ M: windows-ui-backend do-events
|
||||||
style 0 ex-style AdjustWindowRectEx win32-error=0/f ;
|
style 0 ex-style AdjustWindowRectEx win32-error=0/f ;
|
||||||
|
|
||||||
: make-RECT ( world -- RECT )
|
: make-RECT ( world -- RECT )
|
||||||
[ window-loc>> dup ] [ dim>> ] bi v+
|
[ window-loc>> ] [ dim>> ] bi <RECT> ;
|
||||||
"RECT" <c-object>
|
|
||||||
over first over set-RECT-right
|
|
||||||
swap second over set-RECT-bottom
|
|
||||||
over first over set-RECT-left
|
|
||||||
swap second over set-RECT-top ;
|
|
||||||
|
|
||||||
: default-position-RECT ( RECT -- )
|
: default-position-RECT ( RECT -- )
|
||||||
dup get-RECT-dimensions [ 2drop ] 2dip
|
dup get-RECT-dimensions [ 2drop ] 2dip
|
||||||
|
@ -501,35 +496,12 @@ M: windows-ui-backend (open-window) ( world -- )
|
||||||
hWnd>> show-window ;
|
hWnd>> show-window ;
|
||||||
|
|
||||||
M: win-base select-gl-context ( handle -- )
|
M: win-base select-gl-context ( handle -- )
|
||||||
[ hDC>> ] keep hRC>> wglMakeCurrent win32-error=0/f
|
[ hDC>> ] [ hRC>> ] bi wglMakeCurrent win32-error=0/f
|
||||||
GdiFlush drop ;
|
GdiFlush drop ;
|
||||||
|
|
||||||
M: win-base flush-gl-context ( handle -- )
|
M: win-base flush-gl-context ( handle -- )
|
||||||
hDC>> SwapBuffers win32-error=0/f ;
|
hDC>> SwapBuffers win32-error=0/f ;
|
||||||
|
|
||||||
: (bitmap-info) ( dim -- BITMAPINFO )
|
|
||||||
"BITMAPINFO" <c-object> [
|
|
||||||
BITMAPINFO-bmiHeader {
|
|
||||||
[ nip "BITMAPINFOHEADER" heap-size swap set-BITMAPINFOHEADER-biSize ]
|
|
||||||
[ [ first ] dip set-BITMAPINFOHEADER-biWidth ]
|
|
||||||
[ [ second ] dip set-BITMAPINFOHEADER-biHeight ]
|
|
||||||
[ nip 1 swap set-BITMAPINFOHEADER-biPlanes ]
|
|
||||||
[ nip 32 swap set-BITMAPINFOHEADER-biBitCount ]
|
|
||||||
[ nip BI_RGB swap set-BITMAPINFOHEADER-biCompression ]
|
|
||||||
[ [ first2 * 4 * ] dip set-BITMAPINFOHEADER-biSizeImage ]
|
|
||||||
[ nip 72 swap set-BITMAPINFOHEADER-biXPelsPerMeter ]
|
|
||||||
[ nip 72 swap set-BITMAPINFOHEADER-biYPelsPerMeter ]
|
|
||||||
[ nip 0 swap set-BITMAPINFOHEADER-biClrUsed ]
|
|
||||||
[ nip 0 swap set-BITMAPINFOHEADER-biClrImportant ]
|
|
||||||
} 2cleave
|
|
||||||
] keep ;
|
|
||||||
|
|
||||||
: make-offscreen-dc-and-bitmap ( dim -- hDC hBitmap bits )
|
|
||||||
f CreateCompatibleDC
|
|
||||||
dup rot (bitmap-info) DIB_RGB_COLORS f <void*>
|
|
||||||
[ f 0 CreateDIBSection ] keep *void*
|
|
||||||
[ 2dup SelectObject drop ] dip ;
|
|
||||||
|
|
||||||
: setup-offscreen-gl ( dim -- hDC hRC hBitmap bits )
|
: setup-offscreen-gl ( dim -- hDC hRC hBitmap bits )
|
||||||
make-offscreen-dc-and-bitmap [
|
make-offscreen-dc-and-bitmap [
|
||||||
[ dup offscreen-pfd-dwFlags setup-pixel-format ]
|
[ dup offscreen-pfd-dwFlags setup-pixel-format ]
|
||||||
|
@ -548,13 +520,12 @@ M: windows-ui-backend (close-offscreen-buffer) ( handle -- )
|
||||||
! each pixel; it's left as zero
|
! each pixel; it's left as zero
|
||||||
|
|
||||||
: (make-opaque) ( byte-array -- byte-array' )
|
: (make-opaque) ( byte-array -- byte-array' )
|
||||||
[ length 4 / ]
|
[ length 4 /i ]
|
||||||
[ '[ 255 swap 4 * 3 + _ set-nth ] each ]
|
[ '[ 255 swap 4 * 3 + _ set-nth ] each ]
|
||||||
[ ] tri ;
|
[ ] tri ;
|
||||||
|
|
||||||
: (opaque-pixels) ( world -- pixels )
|
: (opaque-pixels) ( world -- pixels )
|
||||||
[ handle>> bits>> ] [ dim>> first2 * 4 * ] bi
|
[ handle>> bits>> ] [ dim>> ] bi bitmap>byte-array (make-opaque) ;
|
||||||
memory>byte-array (make-opaque) ;
|
|
||||||
|
|
||||||
M: windows-ui-backend offscreen-pixels ( world -- alien w h )
|
M: windows-ui-backend offscreen-pixels ( world -- alien w h )
|
||||||
[ (opaque-pixels) ] [ dim>> first2 ] bi ;
|
[ (opaque-pixels) ] [ dim>> first2 ] bi ;
|
||||||
|
|
|
@ -141,7 +141,7 @@ M: editor ungraft*
|
||||||
: scroll>caret ( editor -- )
|
: scroll>caret ( editor -- )
|
||||||
dup graft-state>> second [
|
dup graft-state>> second [
|
||||||
[
|
[
|
||||||
[ caret-loc ] [ caret-dim { 1 0 } v+ ] bi <rect>
|
[ caret-loc ] [ caret-dim { 2 1 } v+ ] bi <rect>
|
||||||
] keep scroll>rect
|
] keep scroll>rect
|
||||||
] [ drop ] if ;
|
] [ drop ] if ;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ CONSTANT: horizontal { 1 0 }
|
||||||
CONSTANT: vertical { 0 1 }
|
CONSTANT: vertical { 0 1 }
|
||||||
|
|
||||||
TUPLE: gadget < rect
|
TUPLE: gadget < rect
|
||||||
|
id
|
||||||
pref-dim
|
pref-dim
|
||||||
parent
|
parent
|
||||||
children
|
children
|
||||||
|
@ -28,7 +29,7 @@ model ;
|
||||||
|
|
||||||
M: gadget equal? 2drop f ;
|
M: gadget equal? 2drop f ;
|
||||||
|
|
||||||
M: gadget hashcode* drop gadget hashcode* ;
|
M: gadget hashcode* nip [ [ \ gadget counter ] unless* ] change-id id>> ;
|
||||||
|
|
||||||
M: gadget model-changed 2drop ;
|
M: gadget model-changed 2drop ;
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ M: line-gadget line-height font>> font-metrics height>> ceiling ;
|
||||||
: validate-line ( m gadget -- n )
|
: validate-line ( m gadget -- n )
|
||||||
control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
|
control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
|
||||||
|
|
||||||
|
: valid-line? ( n gadget -- ? )
|
||||||
|
control-value length 1- 0 swap between? ;
|
||||||
|
|
||||||
: visible-line ( gadget quot -- n )
|
: visible-line ( gadget quot -- n )
|
||||||
'[
|
'[
|
||||||
[ clip get @ origin get [ second ] bi@ - ] dip
|
[ clip get @ origin get [ second ] bi@ - ] dip
|
||||||
|
|
|
@ -49,13 +49,13 @@ M: pane-stream stream-element-type drop +character+ ;
|
||||||
: pane-caret&mark ( pane -- caret mark )
|
: pane-caret&mark ( pane -- caret mark )
|
||||||
[ caret>> ] [ mark>> ] bi ; inline
|
[ caret>> ] [ mark>> ] bi ; inline
|
||||||
|
|
||||||
: selected-children ( pane -- seq )
|
: selected-subtree ( pane -- seq )
|
||||||
[ pane-caret&mark sort-pair ] keep gadget-subtree ;
|
[ pane-caret&mark sort-pair ] keep gadget-subtree ;
|
||||||
|
|
||||||
M: pane gadget-selection? pane-caret&mark and ;
|
M: pane gadget-selection? pane-caret&mark and ;
|
||||||
|
|
||||||
M: pane gadget-selection ( pane -- string/f )
|
M: pane gadget-selection ( pane -- string/f )
|
||||||
selected-children gadget-text ;
|
selected-subtree gadget-text ;
|
||||||
|
|
||||||
: init-prototype ( pane -- pane )
|
: init-prototype ( pane -- pane )
|
||||||
<shelf> +baseline+ >>align >>prototype ; inline
|
<shelf> +baseline+ >>align >>prototype ; inline
|
||||||
|
@ -72,31 +72,12 @@ M: pane gadget-selection ( pane -- string/f )
|
||||||
[ >>last-line ] [ 1 track-add ] bi
|
[ >>last-line ] [ 1 track-add ] bi
|
||||||
dup prepare-last-line ; inline
|
dup prepare-last-line ; inline
|
||||||
|
|
||||||
GENERIC: draw-selection ( loc obj -- )
|
M: pane selected-children
|
||||||
|
|
||||||
: if-fits ( rect quot -- )
|
|
||||||
[ clip get over contains-rect? ] dip [ drop ] if ; inline
|
|
||||||
|
|
||||||
M: gadget draw-selection ( loc gadget -- )
|
|
||||||
swap offset-rect [
|
|
||||||
rect-bounds gl-fill-rect
|
|
||||||
] if-fits ;
|
|
||||||
|
|
||||||
M: node draw-selection ( loc node -- )
|
|
||||||
2dup value>> swap offset-rect [
|
|
||||||
drop 2dup
|
|
||||||
[ value>> loc>> v+ ] keep
|
|
||||||
children>> [ draw-selection ] with each
|
|
||||||
] if-fits 2drop ;
|
|
||||||
|
|
||||||
M: pane draw-gadget*
|
|
||||||
dup gadget-selection? [
|
dup gadget-selection? [
|
||||||
[ selection-color>> gl-color ]
|
[ selected-subtree leaves ]
|
||||||
[
|
[ selection-color>> ]
|
||||||
[ loc>> vneg ] keep selected-children
|
bi
|
||||||
[ draw-selection ] with each
|
] [ drop f f ] if ;
|
||||||
] bi
|
|
||||||
] [ drop ] if ;
|
|
||||||
|
|
||||||
: scroll-pane ( pane -- )
|
: scroll-pane ( pane -- )
|
||||||
dup scrolls?>> [ scroll>bottom ] [ drop ] if ;
|
dup scrolls?>> [ scroll>bottom ] [ drop ] if ;
|
||||||
|
|
|
@ -54,10 +54,10 @@ M: viewport pref-dim* gadget-child pref-viewport-dim ;
|
||||||
2dup control-value = [ 2drop ] [ set-control-value ] if ;
|
2dup control-value = [ 2drop ] [ set-control-value ] if ;
|
||||||
|
|
||||||
: (scroll>rect) ( rect scroller -- )
|
: (scroll>rect) ( rect scroller -- )
|
||||||
[ [ loc>> ] [ dim>> { 1 1 } v+ ] bi <rect> ] dip
|
|
||||||
{
|
{
|
||||||
[ scroller-value vneg offset-rect ]
|
[ scroller-value vneg offset-rect ]
|
||||||
[ viewport>> dim>> rect-min ]
|
[ viewport>> dim>> rect-min ]
|
||||||
|
[ viewport>> loc>> offset-rect ]
|
||||||
[ viewport>> [ v- { 0 0 } vmin ] [ v- { 0 0 } vmax ] with-rect-extents v+ ]
|
[ viewport>> [ v- { 0 0 } vmin ] [ v- { 0 0 } vmax ] with-rect-extents v+ ]
|
||||||
[ scroller-value v+ ]
|
[ scroller-value v+ ]
|
||||||
[ scroll ]
|
[ scroll ]
|
||||||
|
|
|
@ -268,12 +268,13 @@ M: table model-changed
|
||||||
: mouse-row ( table -- n )
|
: mouse-row ( table -- n )
|
||||||
[ hand-rel second ] keep y>line ;
|
[ hand-rel second ] keep y>line ;
|
||||||
|
|
||||||
|
: if-mouse-row ( table true: ( table mouse-index -- ) false: ( table -- ) -- )
|
||||||
|
[ [ mouse-row ] keep 2dup valid-line? ]
|
||||||
|
[ ] [ '[ nip @ ] ] tri* if ; inline
|
||||||
|
|
||||||
: table-button-down ( table -- )
|
: table-button-down ( table -- )
|
||||||
dup takes-focus?>> [ dup request-focus ] when
|
dup takes-focus?>> [ dup request-focus ] when
|
||||||
dup control-value empty? [ drop ] [
|
[ swap [ >>mouse-index ] [ (select-row) ] bi ] [ drop ] if-mouse-row ;
|
||||||
dup [ mouse-row ] keep validate-line
|
|
||||||
[ >>mouse-index ] [ (select-row) ] bi
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
@ -283,11 +284,14 @@ PRIVATE>
|
||||||
[ 2drop ]
|
[ 2drop ]
|
||||||
if ;
|
if ;
|
||||||
|
|
||||||
|
: row-action? ( table -- ? )
|
||||||
|
[ [ mouse-row ] keep valid-line? ]
|
||||||
|
[ single-click?>> hand-click# get 2 = or ] bi and ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: table-button-up ( table -- )
|
: table-button-up ( table -- )
|
||||||
dup single-click?>> hand-click# get 2 = or
|
dup row-action? [ row-action ] [ update-selected-value ] if ;
|
||||||
[ row-action ] [ update-selected-value ] if ;
|
|
||||||
|
|
||||||
: select-row ( table n -- )
|
: select-row ( table n -- )
|
||||||
over validate-line
|
over validate-line
|
||||||
|
@ -320,13 +324,6 @@ PRIVATE>
|
||||||
: next-page ( table -- )
|
: next-page ( table -- )
|
||||||
1 prev/next-page ;
|
1 prev/next-page ;
|
||||||
|
|
||||||
: valid-row? ( row table -- ? )
|
|
||||||
control-value length 1- 0 swap between? ;
|
|
||||||
|
|
||||||
: if-mouse-row ( table true false -- )
|
|
||||||
[ [ mouse-row ] keep 2dup valid-row? ]
|
|
||||||
[ ] [ '[ nip @ ] ] tri* if ; inline
|
|
||||||
|
|
||||||
: show-mouse-help ( table -- )
|
: show-mouse-help ( table -- )
|
||||||
[
|
[
|
||||||
swap
|
swap
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
USING: accessors arrays assocs continuations kernel math models
|
USING: accessors arrays assocs continuations kernel math models
|
||||||
namespaces opengl sequences io combinators combinators.short-circuit
|
namespaces opengl sequences io combinators combinators.short-circuit
|
||||||
fry math.vectors math.rectangles cache ui.gadgets ui.gestures
|
fry math.vectors math.rectangles cache ui.gadgets ui.gestures
|
||||||
ui.render ui.text ui.text.private ui.backend ui.gadgets.tracks
|
ui.render ui.backend ui.gadgets.tracks ui.commands ;
|
||||||
ui.commands ;
|
|
||||||
IN: ui.gadgets.worlds
|
IN: ui.gadgets.worlds
|
||||||
|
|
||||||
TUPLE: world < track
|
TUPLE: world < track
|
||||||
|
@ -53,7 +52,6 @@ M: world request-focus-on ( child gadget -- )
|
||||||
swap >>status
|
swap >>status
|
||||||
swap >>title
|
swap >>title
|
||||||
swap 1 track-add
|
swap 1 track-add
|
||||||
dup init-text-rendering
|
|
||||||
dup request-focus ;
|
dup request-focus ;
|
||||||
|
|
||||||
: <world> ( gadget title status -- world )
|
: <world> ( gadget title status -- world )
|
||||||
|
@ -74,15 +72,20 @@ M: world remove-gadget
|
||||||
2dup layers>> memq?
|
2dup layers>> memq?
|
||||||
[ layers>> delq ] [ call-next-method ] if ;
|
[ layers>> delq ] [ call-next-method ] if ;
|
||||||
|
|
||||||
|
SYMBOL: flush-layout-cache-hook
|
||||||
|
|
||||||
|
flush-layout-cache-hook [ [ ] ] initialize
|
||||||
|
|
||||||
: (draw-world) ( world -- )
|
: (draw-world) ( world -- )
|
||||||
dup handle>> [
|
dup handle>> [
|
||||||
{
|
{
|
||||||
[ init-gl ]
|
[ init-gl ]
|
||||||
[ draw-gadget ]
|
[ draw-gadget ]
|
||||||
[ finish-text-rendering ]
|
[ text-handle>> [ purge-cache ] when* ]
|
||||||
[ images>> [ purge-cache ] when* ]
|
[ images>> [ purge-cache ] when* ]
|
||||||
} cleave
|
} cleave
|
||||||
] with-gl-context ;
|
] with-gl-context
|
||||||
|
flush-layout-cache-hook get call( -- ) ;
|
||||||
|
|
||||||
: draw-world? ( world -- ? )
|
: draw-world? ( world -- ? )
|
||||||
#! We don't draw deactivated worlds, or those with 0 size.
|
#! We don't draw deactivated worlds, or those with 0 size.
|
||||||
|
|
|
@ -20,7 +20,7 @@ PRIVATE>
|
||||||
|
|
||||||
: rendered-image ( path -- texture )
|
: rendered-image ( path -- texture )
|
||||||
world get image-texture-cache
|
world get image-texture-cache
|
||||||
[ cached-image { 0 0 } <texture> ] cache ;
|
[ cached-image [ { 0 0 } ] keep dim>> <texture> ] cache ;
|
||||||
|
|
||||||
: draw-image ( image-name -- )
|
: draw-image ( image-name -- )
|
||||||
rendered-image draw-texture ;
|
rendered-image draw-texture ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2005, 2009 Slava Pestov.
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: math.rectangles math.vectors namespaces kernel accessors
|
USING: math.rectangles math.vectors namespaces kernel accessors
|
||||||
combinators sequences opengl opengl.gl opengl.glu colors
|
assocs combinators sequences opengl opengl.gl opengl.glu colors
|
||||||
colors.constants ui.gadgets ui.pens ;
|
colors.constants ui.gadgets ui.pens ;
|
||||||
IN: ui.render
|
IN: ui.render
|
||||||
|
|
||||||
|
@ -55,21 +55,57 @@ SYMBOL: origin
|
||||||
|
|
||||||
GENERIC: draw-children ( gadget -- )
|
GENERIC: draw-children ( gadget -- )
|
||||||
|
|
||||||
|
! For gadget selection
|
||||||
|
SYMBOL: selected-gadgets
|
||||||
|
|
||||||
|
SYMBOL: selection-background
|
||||||
|
|
||||||
|
GENERIC: selected-children ( gadget -- assoc/f selection-background )
|
||||||
|
|
||||||
|
M: gadget selected-children drop f f ;
|
||||||
|
|
||||||
|
! For text rendering
|
||||||
|
SYMBOL: background
|
||||||
|
|
||||||
|
SYMBOL: foreground
|
||||||
|
|
||||||
|
GENERIC: gadget-background ( gadget -- color )
|
||||||
|
|
||||||
|
M: gadget gadget-background dup interior>> pen-background ;
|
||||||
|
|
||||||
|
GENERIC: gadget-foreground ( gadget -- color )
|
||||||
|
|
||||||
|
M: gadget gadget-foreground dup interior>> pen-foreground ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: draw-selection-background ( gadget -- )
|
||||||
|
selection-background get background set
|
||||||
|
selection-background get gl-color
|
||||||
|
[ { 0 0 } ] dip dim>> gl-fill-rect ;
|
||||||
|
|
||||||
|
: draw-standard-background ( object -- )
|
||||||
|
dup interior>> dup [ draw-interior ] [ 2drop ] if ;
|
||||||
|
|
||||||
|
: draw-background ( gadget -- )
|
||||||
|
origin get [
|
||||||
|
[
|
||||||
|
dup selected-gadgets get key?
|
||||||
|
[ draw-selection-background ]
|
||||||
|
[ draw-standard-background ] if
|
||||||
|
] [ draw-gadget* ] bi
|
||||||
|
] with-translation ;
|
||||||
|
|
||||||
|
: draw-border ( object -- )
|
||||||
|
dup boundary>> dup [
|
||||||
|
origin get [ draw-boundary ] with-translation
|
||||||
|
] [ 2drop ] if ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: (draw-gadget) ( gadget -- )
|
: (draw-gadget) ( gadget -- )
|
||||||
dup loc>> origin get v+ origin [
|
dup loc>> origin get v+ origin [
|
||||||
[
|
[ draw-background ] [ draw-children ] [ draw-border ] tri
|
||||||
origin get [
|
|
||||||
[ dup interior>> dup [ draw-interior ] [ 2drop ] if ]
|
|
||||||
[ draw-gadget* ]
|
|
||||||
bi
|
|
||||||
] with-translation
|
|
||||||
]
|
|
||||||
[ draw-children ]
|
|
||||||
[
|
|
||||||
dup boundary>> dup [
|
|
||||||
origin get [ draw-boundary ] with-translation
|
|
||||||
] [ 2drop ] if
|
|
||||||
] tri
|
|
||||||
] with-variable ;
|
] with-variable ;
|
||||||
|
|
||||||
: >absolute ( rect -- rect )
|
: >absolute ( rect -- rect )
|
||||||
|
@ -88,27 +124,24 @@ GENERIC: draw-children ( gadget -- )
|
||||||
[ [ (draw-gadget) ] with-clipping ]
|
[ [ (draw-gadget) ] with-clipping ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
! For text rendering
|
|
||||||
SYMBOL: background
|
|
||||||
|
|
||||||
SYMBOL: foreground
|
|
||||||
|
|
||||||
GENERIC: gadget-background ( gadget -- color )
|
|
||||||
|
|
||||||
M: gadget gadget-background dup interior>> pen-background ;
|
|
||||||
|
|
||||||
GENERIC: gadget-foreground ( gadget -- color )
|
|
||||||
|
|
||||||
M: gadget gadget-foreground dup interior>> pen-foreground ;
|
|
||||||
|
|
||||||
M: gadget draw-children
|
M: gadget draw-children
|
||||||
[ visible-children ]
|
dup children>> [
|
||||||
[ gadget-background ]
|
{
|
||||||
[ gadget-foreground ] tri [
|
[ visible-children ]
|
||||||
[ foreground set ] when*
|
[ selected-children ]
|
||||||
[ background set ] when*
|
[ gadget-background ]
|
||||||
[ draw-gadget ] each
|
[ gadget-foreground ]
|
||||||
] with-scope ;
|
} cleave [
|
||||||
|
|
||||||
|
{
|
||||||
|
[ [ selected-gadgets set ] when* ]
|
||||||
|
[ [ selection-background set ] when* ]
|
||||||
|
[ [ background set ] when* ]
|
||||||
|
[ [ foreground set ] when* ]
|
||||||
|
} spread
|
||||||
|
[ draw-gadget ] each
|
||||||
|
] with-scope
|
||||||
|
] [ drop ] if ;
|
||||||
|
|
||||||
CONSTANT: selection-color T{ rgba f 0.8 0.8 1.0 1.0 }
|
CONSTANT: selection-color T{ rgba f 0.8 0.8 1.0 1.0 }
|
||||||
|
|
||||||
|
|
|
@ -10,22 +10,20 @@ IN: ui.text.core-text
|
||||||
|
|
||||||
SINGLETON: core-text-renderer
|
SINGLETON: core-text-renderer
|
||||||
|
|
||||||
M: core-text-renderer init-text-rendering
|
|
||||||
<cache-assoc> >>text-handle drop ;
|
|
||||||
|
|
||||||
M: core-text-renderer string-dim
|
M: core-text-renderer string-dim
|
||||||
[ " " string-dim { 0 1 } v* ]
|
[ " " string-dim { 0 1 } v* ]
|
||||||
[ cached-line dim>> ]
|
[ cached-line dim>> ]
|
||||||
if-empty ;
|
if-empty ;
|
||||||
|
|
||||||
M: core-text-renderer finish-text-rendering
|
M: core-text-renderer flush-layout-cache
|
||||||
text-handle>> purge-cache
|
|
||||||
cached-lines get purge-cache ;
|
cached-lines get purge-cache ;
|
||||||
|
|
||||||
: rendered-line ( font string -- texture )
|
: rendered-line ( font string -- texture )
|
||||||
world get text-handle>>
|
world get world-text-handle [
|
||||||
[ cached-line [ image>> ] [ loc>> ] bi <texture> ]
|
cached-line
|
||||||
2cache ;
|
[ image>> ] [ loc>> ] [ image>> dim>> ] tri
|
||||||
|
<texture>
|
||||||
|
] 2cache ;
|
||||||
|
|
||||||
M: core-text-renderer draw-string ( font string -- )
|
M: core-text-renderer draw-string ( font string -- )
|
||||||
rendered-line draw-texture ;
|
rendered-line draw-texture ;
|
||||||
|
|
|
@ -7,21 +7,19 @@ IN: ui.text.pango
|
||||||
|
|
||||||
SINGLETON: pango-renderer
|
SINGLETON: pango-renderer
|
||||||
|
|
||||||
M: pango-renderer init-text-rendering
|
|
||||||
<cache-assoc> >>text-handle drop ;
|
|
||||||
|
|
||||||
M: pango-renderer string-dim
|
M: pango-renderer string-dim
|
||||||
[ " " string-dim { 0 1 } v* ]
|
[ " " string-dim { 0 1 } v* ]
|
||||||
[ cached-layout logical-rect>> dim>> [ >integer ] map ] if-empty ;
|
[ cached-layout logical-rect>> dim>> [ >integer ] map ] if-empty ;
|
||||||
|
|
||||||
M: pango-renderer finish-text-rendering
|
M: pango-renderer flush-layout-cache
|
||||||
text-handle>> purge-cache
|
|
||||||
cached-layouts get purge-cache ;
|
cached-layouts get purge-cache ;
|
||||||
|
|
||||||
: rendered-layout ( font string -- texture )
|
: rendered-layout ( font string -- texture )
|
||||||
world get text-handle>>
|
world get world-text-handle [
|
||||||
[ cached-layout [ image>> ] [ text-position vneg ] bi <texture> ]
|
cached-layout
|
||||||
2cache ;
|
[ image>> ] [ text-position vneg ] [ image>> dim>> ] tri
|
||||||
|
<texture>
|
||||||
|
] 2cache ;
|
||||||
|
|
||||||
M: pango-renderer draw-string ( font string -- )
|
M: pango-renderer draw-string ( font string -- )
|
||||||
rendered-layout draw-texture ;
|
rendered-layout draw-texture ;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
UI text rendering implementation using cross-platform Pango library
|
|
@ -1,6 +1,22 @@
|
||||||
! 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: tools.test ui.text fonts ;
|
USING: tools.test ui.text fonts math accessors kernel sequences ;
|
||||||
IN: ui.text.tests
|
IN: ui.text.tests
|
||||||
|
|
||||||
[ 0.0 ] [ 0 sans-serif-font "aaa" offset>x ] unit-test
|
[ t ] [ 0 sans-serif-font "aaa" offset>x zero? ] unit-test
|
||||||
|
[ t ] [ 1 sans-serif-font "aaa" offset>x 0.0 > ] unit-test
|
||||||
|
[ t ] [ 3 sans-serif-font "aaa" offset>x 0.0 > ] unit-test
|
||||||
|
[ t ] [ 1 monospace-font "a" offset>x 0.0 > ] unit-test
|
||||||
|
[ 0 ] [ 0 sans-serif-font "aaa" x>offset ] unit-test
|
||||||
|
[ 3 ] [ 100 sans-serif-font "aaa" x>offset ] unit-test
|
||||||
|
[ 0 ] [ 0 sans-serif-font "" x>offset ] unit-test
|
||||||
|
|
||||||
|
[ t ] [
|
||||||
|
sans-serif-font "aaa" line-metrics
|
||||||
|
[ [ ascent>> ] [ descent>> ] bi + ] [ height>> ] bi =
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ f ] [ sans-serif-font "\0a" text-dim first zero? ] unit-test
|
||||||
|
[ t ] [ sans-serif-font "" text-dim first zero? ] unit-test
|
||||||
|
|
||||||
|
[ f ] [ sans-serif-font font-metrics height>> zero? ] unit-test
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
! 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: kernel arrays sequences math math.order opengl opengl.gl
|
USING: kernel arrays sequences math math.order cache opengl
|
||||||
strings fonts colors accessors ;
|
opengl.gl strings fonts colors accessors namespaces
|
||||||
|
ui.gadgets.worlds ;
|
||||||
IN: ui.text
|
IN: ui.text
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
SYMBOL: font-renderer
|
SYMBOL: font-renderer
|
||||||
|
|
||||||
HOOK: init-text-rendering font-renderer ( world -- )
|
: world-text-handle ( world -- handle )
|
||||||
|
dup text-handle>> [ <cache-assoc> >>text-handle ] unless
|
||||||
|
text-handle>> ;
|
||||||
|
|
||||||
HOOK: finish-text-rendering font-renderer ( world -- )
|
HOOK: flush-layout-cache font-renderer ( -- )
|
||||||
|
|
||||||
M: object finish-text-rendering drop ;
|
[ flush-layout-cache ] flush-layout-cache-hook set-global
|
||||||
|
|
||||||
HOOK: string-dim font-renderer ( font string -- dim )
|
HOOK: string-dim font-renderer ( font string -- dim )
|
||||||
|
|
||||||
|
@ -68,4 +71,14 @@ M: array draw-text
|
||||||
[ draw-string ]
|
[ draw-string ]
|
||||||
[ [ 0.0 ] 2dip string-height 0.0 glTranslated ] 2bi
|
[ [ 0.0 ] 2dip string-height 0.0 glTranslated ] 2bi
|
||||||
] with each
|
] with each
|
||||||
] do-matrix ;
|
] do-matrix ;
|
||||||
|
|
||||||
|
USING: vocabs.loader namespaces system combinators ;
|
||||||
|
|
||||||
|
"ui-backend" get [
|
||||||
|
{
|
||||||
|
{ [ os macosx? ] [ "core-text" ] }
|
||||||
|
{ [ os windows? ] [ "uniscribe" ] }
|
||||||
|
{ [ os unix? ] [ "pango" ] }
|
||||||
|
} cond
|
||||||
|
] unless* "ui.text." prepend require
|
|
@ -0,0 +1 @@
|
||||||
|
Slava Pestov
|
|
@ -0,0 +1 @@
|
||||||
|
UI text rendering implementation using the MS Windows Uniscribe library
|
|
@ -0,0 +1 @@
|
||||||
|
unportable
|
|
@ -0,0 +1,42 @@
|
||||||
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: accessors assocs cache kernel math math.vectors sequences fonts
|
||||||
|
namespaces opengl.textures ui.text ui.text.private ui.gadgets.worlds
|
||||||
|
windows.uniscribe ;
|
||||||
|
IN: ui.text.uniscribe
|
||||||
|
|
||||||
|
SINGLETON: uniscribe-renderer
|
||||||
|
|
||||||
|
M: uniscribe-renderer string-dim
|
||||||
|
[ " " string-dim { 0 1 } v* ]
|
||||||
|
[ cached-script-string size>> ] if-empty ;
|
||||||
|
|
||||||
|
M: uniscribe-renderer flush-layout-cache
|
||||||
|
cached-script-strings get purge-cache ;
|
||||||
|
|
||||||
|
: rendered-script-string ( font string -- texture )
|
||||||
|
world get world-text-handle
|
||||||
|
[ cached-script-string [ image>> { 0 0 } ] [ size>> ] bi <texture> ]
|
||||||
|
2cache ;
|
||||||
|
|
||||||
|
M: uniscribe-renderer draw-string ( font string -- )
|
||||||
|
dup dup selection? [ string>> ] when empty?
|
||||||
|
[ 2drop ] [ rendered-script-string draw-texture ] if ;
|
||||||
|
|
||||||
|
M: uniscribe-renderer x>offset ( x font string -- n )
|
||||||
|
[ 2drop 0 ] [
|
||||||
|
cached-script-string x>line-offset 0 = [ 1+ ] unless
|
||||||
|
] if-empty ;
|
||||||
|
|
||||||
|
M: uniscribe-renderer offset>x ( n font string -- x )
|
||||||
|
[ 2drop 0 ] [ cached-script-string line-offset>x ] if-empty ;
|
||||||
|
|
||||||
|
M: uniscribe-renderer font-metrics ( font -- metrics )
|
||||||
|
" " cached-script-string metrics>> clone f >>width ;
|
||||||
|
|
||||||
|
M: uniscribe-renderer line-metrics ( font string -- metrics )
|
||||||
|
[ " " line-metrics clone 0 >>width ]
|
||||||
|
[ cached-script-string metrics>> 50 >>width 10 >>cap-height 10 >>x-height ]
|
||||||
|
if-empty ;
|
||||||
|
|
||||||
|
uniscribe-renderer font-renderer set-global
|
|
@ -2,7 +2,7 @@ USING: help.markup help.syntax ui.commands ;
|
||||||
IN: ui.tools.browser
|
IN: ui.tools.browser
|
||||||
|
|
||||||
ARTICLE: "ui-browser" "UI browser"
|
ARTICLE: "ui-browser" "UI browser"
|
||||||
"The browser is used to display Factor code, documentation, and vocabularies. The browser is opened when a word or articlelink presentation is clicked. It can also be opened using words:"
|
"The browser is used to display Factor code, documentation, and vocabularies. The browser is opened when a word or article link presentation is clicked. It can also be opened using words:"
|
||||||
{ $subsection com-browse }
|
{ $subsection com-browse }
|
||||||
{ $subsection browser-window }
|
{ $subsection browser-window }
|
||||||
{ $command-map browser-gadget "toolbar" }
|
{ $command-map browser-gadget "toolbar" }
|
||||||
|
|
|
@ -141,6 +141,7 @@ GENERIC# accept-completion-hook 1 ( item popup -- )
|
||||||
t >>selection-required?
|
t >>selection-required?
|
||||||
t >>single-click?
|
t >>single-click?
|
||||||
30 >>min-cols
|
30 >>min-cols
|
||||||
|
10 >>min-rows
|
||||||
10 >>max-rows
|
10 >>max-rows
|
||||||
dup '[ _ accept-completion ] >>action ;
|
dup '[ _ accept-completion ] >>action ;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2007, 2008 Slava Pestov.
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors namespaces make sequences kernel math arrays io
|
USING: accessors namespaces make sequences kernel math arrays io
|
||||||
ui.gadgets generic combinators ;
|
ui.gadgets generic combinators fry sets ;
|
||||||
IN: ui.traverse
|
IN: ui.traverse
|
||||||
|
|
||||||
TUPLE: node value children ;
|
TUPLE: node value children ;
|
||||||
|
@ -85,3 +85,13 @@ M: node gadget-text*
|
||||||
|
|
||||||
: gadget-at-path ( parent path -- gadget )
|
: gadget-at-path ( parent path -- gadget )
|
||||||
[ swap nth-gadget ] each ;
|
[ swap nth-gadget ] each ;
|
||||||
|
|
||||||
|
GENERIC# leaves* 1 ( tree assoc -- )
|
||||||
|
|
||||||
|
M: node leaves* [ children>> ] dip leaves* ;
|
||||||
|
|
||||||
|
M: array leaves* '[ _ leaves* ] each ;
|
||||||
|
|
||||||
|
M: gadget leaves* conjoin ;
|
||||||
|
|
||||||
|
: leaves ( tree -- assoc ) H{ } clone [ leaves* ] keep ;
|
|
@ -4,8 +4,7 @@ USING: arrays assocs io kernel math models namespaces make dlists
|
||||||
deques sequences threads sequences words continuations init
|
deques sequences threads sequences words continuations init
|
||||||
combinators hashtables concurrency.flags sets accessors calendar fry
|
combinators hashtables concurrency.flags sets accessors calendar fry
|
||||||
destructors ui.gadgets ui.gadgets.private ui.gadgets.worlds
|
destructors ui.gadgets ui.gadgets.private ui.gadgets.worlds
|
||||||
ui.gadgets.tracks ui.gestures ui.backend ui.render ui.text
|
ui.gadgets.tracks ui.gestures ui.backend ui.render ;
|
||||||
ui.text.private ;
|
|
||||||
IN: ui
|
IN: ui
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -63,7 +62,7 @@ M: world graft*
|
||||||
: (ungraft-world) ( world -- )
|
: (ungraft-world) ( world -- )
|
||||||
{
|
{
|
||||||
[ handle>> select-gl-context ]
|
[ handle>> select-gl-context ]
|
||||||
[ text-handle>> dispose ]
|
[ text-handle>> [ dispose ] when* ]
|
||||||
[ images>> [ dispose ] when* ]
|
[ images>> [ dispose ] when* ]
|
||||||
[ hand-clicked close-global ]
|
[ hand-clicked close-global ]
|
||||||
[ hand-gadget close-global ]
|
[ hand-gadget close-global ]
|
||||||
|
@ -95,8 +94,7 @@ M: world ungraft*
|
||||||
: restore-world ( world -- )
|
: restore-world ( world -- )
|
||||||
{
|
{
|
||||||
[ reset-world ]
|
[ reset-world ]
|
||||||
[ init-text-rendering ]
|
[ f >>text-handle f >>images drop ]
|
||||||
[ f >>images drop ]
|
|
||||||
[ restore-gadget ]
|
[ restore-gadget ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@ IN: unicode.breaks.tests
|
||||||
[ 3 ] [ "\u001112\u001161\u0011abA\u000300a"
|
[ 3 ] [ "\u001112\u001161\u0011abA\u000300a"
|
||||||
dup last-grapheme head last-grapheme ] unit-test
|
dup last-grapheme head last-grapheme ] unit-test
|
||||||
|
|
||||||
|
[ 3 ] [ 2 "hello" first-grapheme-from ] unit-test
|
||||||
|
[ 1 ] [ 2 "hello" last-grapheme-from ] unit-test
|
||||||
|
|
||||||
: grapheme-break-test ( -- filename )
|
: grapheme-break-test ( -- filename )
|
||||||
"vocab:unicode/breaks/GraphemeBreakTest.txt" ;
|
"vocab:unicode/breaks/GraphemeBreakTest.txt" ;
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,16 @@ PRIVATE>
|
||||||
[ grapheme-class [ nip ] [ grapheme-break? ] 2bi ] find drop
|
[ grapheme-class [ nip ] [ grapheme-break? ] 2bi ] find drop
|
||||||
nip swap length or 1+ ;
|
nip swap length or 1+ ;
|
||||||
|
|
||||||
|
: first-grapheme-from ( start str -- i )
|
||||||
|
over tail-slice first-grapheme + ;
|
||||||
|
|
||||||
|
: last-grapheme ( str -- i )
|
||||||
|
unclip-last-slice grapheme-class swap
|
||||||
|
[ grapheme-class dup rot grapheme-break? ] find-last drop ?1+ nip ;
|
||||||
|
|
||||||
|
: last-grapheme-from ( end str -- i )
|
||||||
|
swap head-slice last-grapheme ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: >pieces ( str quot: ( str -- i ) -- graphemes )
|
: >pieces ( str quot: ( str -- i ) -- graphemes )
|
||||||
|
@ -114,10 +124,6 @@ PRIVATE>
|
||||||
: string-reverse ( str -- rts )
|
: string-reverse ( str -- rts )
|
||||||
>graphemes reverse concat ;
|
>graphemes reverse concat ;
|
||||||
|
|
||||||
: last-grapheme ( str -- i )
|
|
||||||
unclip-last-slice grapheme-class swap
|
|
||||||
[ grapheme-class dup rot grapheme-break? ] find-last drop ?1+ nip ;
|
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
graphemes init-table table
|
graphemes init-table table
|
||||||
|
|
|
@ -12,3 +12,8 @@ IN: unicode.categories.tests
|
||||||
[ "Lo" ] [ HEX: 3450 category ] unit-test
|
[ "Lo" ] [ HEX: 3450 category ] unit-test
|
||||||
[ "Lo" ] [ HEX: 4DB5 category ] unit-test
|
[ "Lo" ] [ HEX: 4DB5 category ] unit-test
|
||||||
[ "Cs" ] [ HEX: DD00 category ] unit-test
|
[ "Cs" ] [ HEX: DD00 category ] unit-test
|
||||||
|
[ t ] [ CHAR: \t blank? ] unit-test
|
||||||
|
[ t ] [ CHAR: \s blank? ] unit-test
|
||||||
|
[ t ] [ CHAR: \r blank? ] unit-test
|
||||||
|
[ t ] [ CHAR: \n blank? ] unit-test
|
||||||
|
[ f ] [ CHAR: a blank? ] unit-test
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: unicode.categories.syntax sequences unicode.data ;
|
USING: unicode.categories.syntax sequences unicode.data ;
|
||||||
IN: unicode.categories
|
IN: unicode.categories
|
||||||
|
|
||||||
CATEGORY: blank Zs Zl Zp | "\r\n" member? ;
|
CATEGORY: blank Zs Zl Zp | "\r\n\t" member? ;
|
||||||
CATEGORY: letter Ll | "Other_Lowercase" property? ;
|
CATEGORY: letter Ll | "Other_Lowercase" property? ;
|
||||||
CATEGORY: LETTER Lu | "Other_Uppercase" property? ;
|
CATEGORY: LETTER Lu | "Other_Uppercase" property? ;
|
||||||
CATEGORY: Letter Lu Ll Lt Lm Lo Nl ;
|
CATEGORY: Letter Lu Ll Lt Lm Lo Nl ;
|
||||||
|
|
|
@ -65,9 +65,8 @@ HELP: derive-url
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: ensure-port
|
HELP: ensure-port
|
||||||
{ $values { "url" url } }
|
{ $values { "url" url } { "url'" url } }
|
||||||
{ $description "If the URL does not specify a port number, fill in the default for the URL's protocol. If the protocol is unknown, the port number is not changed." }
|
{ $description "If the URL does not specify a port number, create a new URL which is equal except the port number is set to the default for the URL's protocol. If the protocol is unknown, outputs an exact copy of the input URL." }
|
||||||
{ $side-effects "url" }
|
|
||||||
{ $examples
|
{ $examples
|
||||||
{ $example
|
{ $example
|
||||||
"USING: accessors prettyprint urls ;"
|
"USING: accessors prettyprint urls ;"
|
||||||
|
|
|
@ -175,8 +175,8 @@ PRIVATE>
|
||||||
] [ protocol>> ] bi
|
] [ protocol>> ] bi
|
||||||
secure-protocol? [ >secure-addr ] when ;
|
secure-protocol? [ >secure-addr ] when ;
|
||||||
|
|
||||||
: ensure-port ( url -- url )
|
: ensure-port ( url -- url' )
|
||||||
dup protocol>> '[ _ protocol-port or ] change-port ;
|
clone dup protocol>> '[ _ protocol-port or ] change-port ;
|
||||||
|
|
||||||
! Literal syntax
|
! Literal syntax
|
||||||
SYNTAX: URL" lexer get skip-blank parse-string >url parsed ;
|
SYNTAX: URL" lexer get skip-blank parse-string >url parsed ;
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
USING: assocs memoize locals kernel accessors init fonts math
|
||||||
|
combinators windows windows.types windows.gdi32 ;
|
||||||
|
IN: windows.fonts
|
||||||
|
|
||||||
|
: windows-font-name ( string -- string' )
|
||||||
|
H{
|
||||||
|
{ "sans-serif" "Tahoma" }
|
||||||
|
{ "serif" "Times New Roman" }
|
||||||
|
{ "monospace" "Courier New" }
|
||||||
|
} at-default ;
|
||||||
|
|
||||||
|
MEMO:: (cache-font) ( font -- HFONT )
|
||||||
|
font size>> neg ! nHeight
|
||||||
|
0 0 0 ! nWidth, nEscapement, nOrientation
|
||||||
|
font bold?>> FW_BOLD FW_NORMAL ? ! fnWeight
|
||||||
|
font italic?>> TRUE FALSE ? ! fdwItalic
|
||||||
|
FALSE ! fdwUnderline
|
||||||
|
FALSE ! fdWStrikeOut
|
||||||
|
DEFAULT_CHARSET ! fdwCharSet
|
||||||
|
OUT_OUTLINE_PRECIS ! fdwOutputPrecision
|
||||||
|
CLIP_DEFAULT_PRECIS ! fdwClipPrecision
|
||||||
|
DEFAULT_QUALITY ! fdwQuality
|
||||||
|
DEFAULT_PITCH ! fdwPitchAndFamily
|
||||||
|
font name>> windows-font-name
|
||||||
|
CreateFont
|
||||||
|
dup win32-error=0/f ;
|
||||||
|
|
||||||
|
: cache-font ( font -- HFONT ) strip-font-colors (cache-font) ;
|
||||||
|
|
||||||
|
[ \ (cache-font) reset-memoized ] "windows.fonts" add-init-hook
|
||||||
|
|
||||||
|
: TEXTMETRIC>metrics ( TEXTMETRIC -- metrics )
|
||||||
|
[ metrics new 0 >>width ] dip {
|
||||||
|
[ TEXTMETRICW-tmHeight >>height ]
|
||||||
|
[ TEXTMETRICW-tmAscent >>ascent ]
|
||||||
|
[ TEXTMETRICW-tmDescent >>descent ]
|
||||||
|
} cleave ;
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
||||||
|
Slava Pestov
|
|
@ -0,0 +1,5 @@
|
||||||
|
IN: windows.offscreen.tests
|
||||||
|
USING: windows.offscreen effects tools.test kernel images ;
|
||||||
|
|
||||||
|
{ 1 1 } [ [ [ ] make-bitmap-image ] with-memory-dc ] must-infer-as
|
||||||
|
[ t ] [ [ { 10 10 } swap [ ] make-bitmap-image ] with-memory-dc image? ] unit-test
|
|
@ -0,0 +1,53 @@
|
||||||
|
! Copyright (C) 2009 Joe Groff, Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: alien.c-types kernel combinators sequences
|
||||||
|
math windows.gdi32 windows.types images destructors
|
||||||
|
accessors fry locals ;
|
||||||
|
IN: windows.offscreen
|
||||||
|
|
||||||
|
: (bitmap-info) ( dim -- BITMAPINFO )
|
||||||
|
"BITMAPINFO" <c-object> [
|
||||||
|
BITMAPINFO-bmiHeader {
|
||||||
|
[ nip "BITMAPINFOHEADER" heap-size swap set-BITMAPINFOHEADER-biSize ]
|
||||||
|
[ [ first ] dip set-BITMAPINFOHEADER-biWidth ]
|
||||||
|
[ [ second ] dip set-BITMAPINFOHEADER-biHeight ]
|
||||||
|
[ nip 1 swap set-BITMAPINFOHEADER-biPlanes ]
|
||||||
|
[ nip 32 swap set-BITMAPINFOHEADER-biBitCount ]
|
||||||
|
[ nip BI_RGB swap set-BITMAPINFOHEADER-biCompression ]
|
||||||
|
[ [ first2 * 4 * ] dip set-BITMAPINFOHEADER-biSizeImage ]
|
||||||
|
[ nip 72 swap set-BITMAPINFOHEADER-biXPelsPerMeter ]
|
||||||
|
[ nip 72 swap set-BITMAPINFOHEADER-biYPelsPerMeter ]
|
||||||
|
[ nip 0 swap set-BITMAPINFOHEADER-biClrUsed ]
|
||||||
|
[ nip 0 swap set-BITMAPINFOHEADER-biClrImportant ]
|
||||||
|
} 2cleave
|
||||||
|
] keep ;
|
||||||
|
|
||||||
|
: make-bitmap ( dim dc -- hBitmap bits )
|
||||||
|
[ nip ]
|
||||||
|
[
|
||||||
|
swap (bitmap-info) DIB_RGB_COLORS f <void*>
|
||||||
|
[ f 0 CreateDIBSection ] keep *void*
|
||||||
|
] 2bi
|
||||||
|
[ [ SelectObject drop ] keep ] dip ;
|
||||||
|
|
||||||
|
: make-offscreen-dc-and-bitmap ( dim -- dc hBitmap bits )
|
||||||
|
[ f CreateCompatibleDC ] dip over make-bitmap ;
|
||||||
|
|
||||||
|
: bitmap>byte-array ( bits dim -- byte-array )
|
||||||
|
product 4 * memory>byte-array ;
|
||||||
|
|
||||||
|
: bitmap>image ( bits dim -- image )
|
||||||
|
[ bitmap>byte-array ] keep
|
||||||
|
<image>
|
||||||
|
swap >>dim
|
||||||
|
swap >>bitmap
|
||||||
|
BGRX >>component-order
|
||||||
|
t >>upside-down? ;
|
||||||
|
|
||||||
|
: with-memory-dc ( quot: ( hDC -- ) -- )
|
||||||
|
[ [ f CreateCompatibleDC &DeleteDC ] dip call ] with-destructors ; inline
|
||||||
|
|
||||||
|
:: make-bitmap-image ( dim dc quot -- image )
|
||||||
|
dim dc make-bitmap [ &DeleteObject drop ] dip
|
||||||
|
quot dip
|
||||||
|
dim bitmap>image ; inline
|
|
@ -0,0 +1 @@
|
||||||
|
Utility words for memory DCs and bitmaps
|
|
@ -0,0 +1 @@
|
||||||
|
unportable
|
|
@ -1,6 +1,7 @@
|
||||||
! Copyright (C) 2005, 2006 Doug Coleman.
|
! Copyright (C) 2005, 2006 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.syntax namespaces kernel words ;
|
USING: alien alien.c-types alien.syntax namespaces kernel words
|
||||||
|
sequences math math.bitwise math.vectors colors ;
|
||||||
IN: windows.types
|
IN: windows.types
|
||||||
|
|
||||||
TYPEDEF: char CHAR
|
TYPEDEF: char CHAR
|
||||||
|
@ -244,14 +245,14 @@ C-STRUCT: RECT
|
||||||
{ "LONG" "right" }
|
{ "LONG" "right" }
|
||||||
{ "LONG" "bottom" } ;
|
{ "LONG" "bottom" } ;
|
||||||
|
|
||||||
! C-STRUCT: PAINTSTRUCT
|
C-STRUCT: PAINTSTRUCT
|
||||||
! { "HDC" " hdc" }
|
{ "HDC" " hdc" }
|
||||||
! { "BOOL" "fErase" }
|
{ "BOOL" "fErase" }
|
||||||
! { "RECT" "rcPaint" }
|
{ "RECT" "rcPaint" }
|
||||||
! { "BOOL" "fRestore" }
|
{ "BOOL" "fRestore" }
|
||||||
! { "BOOL" "fIncUpdate" }
|
{ "BOOL" "fIncUpdate" }
|
||||||
! { "BYTE[32]" "rgbReserved" }
|
{ "BYTE[32]" "rgbReserved" }
|
||||||
! ;
|
;
|
||||||
|
|
||||||
C-STRUCT: BITMAPINFOHEADER
|
C-STRUCT: BITMAPINFOHEADER
|
||||||
{ "DWORD" "biSize" }
|
{ "DWORD" "biSize" }
|
||||||
|
@ -283,6 +284,10 @@ C-STRUCT: POINT
|
||||||
{ "LONG" "x" }
|
{ "LONG" "x" }
|
||||||
{ "LONG" "y" } ;
|
{ "LONG" "y" } ;
|
||||||
|
|
||||||
|
C-STRUCT: SIZE
|
||||||
|
{ "LONG" "cx" }
|
||||||
|
{ "LONG" "cy" } ;
|
||||||
|
|
||||||
C-STRUCT: MSG
|
C-STRUCT: MSG
|
||||||
{ "HWND" "hWnd" }
|
{ "HWND" "hWnd" }
|
||||||
{ "UINT" "message" }
|
{ "UINT" "message" }
|
||||||
|
@ -327,6 +332,14 @@ C-STRUCT: RECT
|
||||||
{ "LONG" "right" }
|
{ "LONG" "right" }
|
||||||
{ "LONG" "bottom" } ;
|
{ "LONG" "bottom" } ;
|
||||||
|
|
||||||
|
: <RECT> ( loc dim -- RECT )
|
||||||
|
over v+
|
||||||
|
"RECT" <c-object>
|
||||||
|
over first over set-RECT-right
|
||||||
|
swap second over set-RECT-bottom
|
||||||
|
over first over set-RECT-left
|
||||||
|
swap second over set-RECT-top ;
|
||||||
|
|
||||||
TYPEDEF: RECT* PRECT
|
TYPEDEF: RECT* PRECT
|
||||||
TYPEDEF: RECT* LPRECT
|
TYPEDEF: RECT* LPRECT
|
||||||
TYPEDEF: PIXELFORMATDESCRIPTOR PFD
|
TYPEDEF: PIXELFORMATDESCRIPTOR PFD
|
||||||
|
@ -363,3 +376,36 @@ C-STRUCT: ACCEL
|
||||||
{ "WORD" "key" }
|
{ "WORD" "key" }
|
||||||
{ "WORD" "cmd" } ;
|
{ "WORD" "cmd" } ;
|
||||||
TYPEDEF: ACCEL* LPACCEL
|
TYPEDEF: ACCEL* LPACCEL
|
||||||
|
|
||||||
|
TYPEDEF: DWORD COLORREF
|
||||||
|
TYPEDEF: DWORD* LPCOLORREF
|
||||||
|
|
||||||
|
: RGB ( r g b -- COLORREF )
|
||||||
|
{ 16 8 0 } bitfield ; inline
|
||||||
|
|
||||||
|
: color>RGB ( color -- COLORREF )
|
||||||
|
>rgba-components drop [ 255 * >integer ] tri@ RGB ;
|
||||||
|
|
||||||
|
C-STRUCT: TEXTMETRICW
|
||||||
|
{ "LONG" "tmHeight" }
|
||||||
|
{ "LONG" "tmAscent" }
|
||||||
|
{ "LONG" "tmDescent" }
|
||||||
|
{ "LONG" "tmInternalLeading" }
|
||||||
|
{ "LONG" "tmExternalLeading" }
|
||||||
|
{ "LONG" "tmAveCharWidth" }
|
||||||
|
{ "LONG" "tmMaxCharWidth" }
|
||||||
|
{ "LONG" "tmWeight" }
|
||||||
|
{ "LONG" "tmOverhang" }
|
||||||
|
{ "LONG" "tmDigitizedAspectX" }
|
||||||
|
{ "LONG" "tmDigitizedAspectY" }
|
||||||
|
{ "WCHAR" "tmFirstChar" }
|
||||||
|
{ "WCHAR" "tmLastChar" }
|
||||||
|
{ "WCHAR" "tmDefaultChar" }
|
||||||
|
{ "WCHAR" "tmBreakChar" }
|
||||||
|
{ "BYTE" "tmItalic" }
|
||||||
|
{ "BYTE" "tmUnderlined" }
|
||||||
|
{ "BYTE" "tmStruckOut" }
|
||||||
|
{ "BYTE" "tmPitchAndFamily" }
|
||||||
|
{ "BYTE" "tmCharSet" } ;
|
||||||
|
|
||||||
|
TYPEDEF: TEXTMETRICW* LPTEXTMETRIC
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Slava Pestov
|
|
@ -0,0 +1 @@
|
||||||
|
High-level wrapper around Uniscribe binding
|
|
@ -0,0 +1 @@
|
||||||
|
unportable
|
|
@ -0,0 +1,118 @@
|
||||||
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: kernel assocs math sequences fry io.encodings.string
|
||||||
|
io.encodings.utf16n accessors arrays combinators destructors locals
|
||||||
|
cache namespaces init images.normalization fonts alien.c-types
|
||||||
|
windows windows.usp10 windows.offscreen windows.gdi32
|
||||||
|
windows.ole32 windows.types windows.fonts opengl.textures ;
|
||||||
|
IN: windows.uniscribe
|
||||||
|
|
||||||
|
TUPLE: script-string font string metrics ssa size image disposed ;
|
||||||
|
|
||||||
|
: line-offset>x ( n script-string -- x )
|
||||||
|
2dup string>> length = [
|
||||||
|
ssa>> ! ssa
|
||||||
|
swap 1- ! icp
|
||||||
|
TRUE ! fTrailing
|
||||||
|
] [
|
||||||
|
ssa>>
|
||||||
|
swap ! icp
|
||||||
|
FALSE ! fTrailing
|
||||||
|
] if
|
||||||
|
0 <int> [ ScriptStringCPtoX ole32-error ] keep *int ;
|
||||||
|
|
||||||
|
: x>line-offset ( x script-string -- n trailing )
|
||||||
|
ssa>> ! ssa
|
||||||
|
swap ! iX
|
||||||
|
0 <int> ! pCh
|
||||||
|
0 <int> ! piTrailing
|
||||||
|
[ ScriptStringXtoCP ole32-error ] 2keep [ *int ] bi@ ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: make-script-string ( dc string -- script-string )
|
||||||
|
dup selection? [ string>> ] when
|
||||||
|
[ utf16n encode ] ! pString
|
||||||
|
[ length ] bi ! cString
|
||||||
|
dup 1.5 * 16 + >integer ! cGlyphs -- MSDN says this is "recommended size"
|
||||||
|
-1 ! iCharset -- Unicode
|
||||||
|
SSA_GLYPHS ! dwFlags
|
||||||
|
0 ! iReqWidth
|
||||||
|
f ! psControl
|
||||||
|
f ! psState
|
||||||
|
f ! piDx
|
||||||
|
f ! pTabdef
|
||||||
|
f ! pbInClass
|
||||||
|
f <void*> ! pssa
|
||||||
|
[ ScriptStringAnalyse ] keep
|
||||||
|
[ ole32-error ] [ |ScriptStringFree *void* ] bi* ;
|
||||||
|
|
||||||
|
: set-dc-colors ( dc font -- )
|
||||||
|
[ background>> color>RGB SetBkColor drop ]
|
||||||
|
[ foreground>> color>RGB SetTextColor drop ] 2bi ;
|
||||||
|
|
||||||
|
: selection-start/end ( script-string -- iMinSel iMaxSel )
|
||||||
|
string>> dup selection? [ [ start>> ] [ end>> ] bi ] [ drop 0 0 ] if ;
|
||||||
|
|
||||||
|
: (draw-script-string) ( script-string -- )
|
||||||
|
[
|
||||||
|
ssa>> ! ssa
|
||||||
|
0 ! iX
|
||||||
|
0 ! iY
|
||||||
|
0 ! uOptions
|
||||||
|
f ! prc
|
||||||
|
]
|
||||||
|
[ selection-start/end ] bi
|
||||||
|
! iMinSel
|
||||||
|
! iMaxSel
|
||||||
|
FALSE ! fDisabled
|
||||||
|
ScriptStringOut ole32-error ;
|
||||||
|
|
||||||
|
: draw-script-string ( dc script-string -- )
|
||||||
|
[ font>> set-dc-colors ] keep (draw-script-string) ;
|
||||||
|
|
||||||
|
: script-string-bitmap-size ( script-string -- dim )
|
||||||
|
size>> dup small-texture? [ [ next-power-of-2 ] map ] when ;
|
||||||
|
|
||||||
|
:: make-script-string-image ( dc script-string -- image )
|
||||||
|
script-string script-string-bitmap-size dc
|
||||||
|
[ dc script-string draw-script-string ] make-bitmap-image ;
|
||||||
|
|
||||||
|
: set-dc-font ( dc font -- )
|
||||||
|
cache-font SelectObject win32-error=0/f ;
|
||||||
|
|
||||||
|
: script-string-size ( script-string -- dim )
|
||||||
|
ssa>> ScriptString_pSize
|
||||||
|
dup win32-error=0/f
|
||||||
|
[ SIZE-cx ] [ SIZE-cy ] bi 2array ;
|
||||||
|
|
||||||
|
: dc-metrics ( dc -- metrics )
|
||||||
|
"TEXTMETRICW" <c-object>
|
||||||
|
[ GetTextMetrics drop ] keep
|
||||||
|
TEXTMETRIC>metrics ;
|
||||||
|
|
||||||
|
: <script-string> ( font string -- script-string )
|
||||||
|
[ script-string new ] 2dip
|
||||||
|
[ >>font ] [ >>string ] bi*
|
||||||
|
[
|
||||||
|
{
|
||||||
|
[ over font>> set-dc-font ]
|
||||||
|
[ dc-metrics >>metrics ]
|
||||||
|
[ over string>> make-script-string >>ssa ]
|
||||||
|
[ drop dup script-string-size >>size ]
|
||||||
|
[ over make-script-string-image >>image ]
|
||||||
|
} cleave
|
||||||
|
] with-memory-dc ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
M: script-string dispose*
|
||||||
|
ssa>> <void*> ScriptStringFree ole32-error ;
|
||||||
|
|
||||||
|
SYMBOL: cached-script-strings
|
||||||
|
|
||||||
|
: cached-script-string ( string font -- script-string )
|
||||||
|
cached-script-strings get-global [ <script-string> ] 2cache ;
|
||||||
|
|
||||||
|
[ <cache-assoc> cached-script-strings set-global ]
|
||||||
|
"windows.uniscribe" add-init-hook
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.syntax ;
|
USING: alien.syntax alien.destructors ;
|
||||||
IN: windows.usp10
|
IN: windows.usp10
|
||||||
|
|
||||||
LIBRARY: usp10
|
LIBRARY: usp10
|
||||||
|
@ -262,6 +262,8 @@ FUNCTION: HRESULT ScriptStringFree (
|
||||||
SCRIPT_STRING_ANALYSIS* pssa
|
SCRIPT_STRING_ANALYSIS* pssa
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
|
DESTRUCTOR: ScriptStringFree
|
||||||
|
|
||||||
FUNCTION: SIZE* ScriptString_pSize ( SCRIPT_STRING_ANALYSIS ssa ) ;
|
FUNCTION: SIZE* ScriptString_pSize ( SCRIPT_STRING_ANALYSIS ssa ) ;
|
||||||
|
|
||||||
FUNCTION: int* ScriptString_pcOutChars ( SCRIPT_STRING_ANALYSIS ssa ) ;
|
FUNCTION: int* ScriptString_pcOutChars ( SCRIPT_STRING_ANALYSIS ssa ) ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2005, 2006 Doug Coleman.
|
! Copyright (C) 2005, 2006 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.syntax alien.c-types alien.strings arrays
|
USING: alien alien.syntax alien.c-types alien.strings arrays
|
||||||
combinators kernel math namespaces parser prettyprint sequences
|
combinators kernel math namespaces parser sequences
|
||||||
windows.errors windows.types windows.kernel32 words
|
windows.errors windows.types windows.kernel32 words
|
||||||
io.encodings.utf16n ;
|
io.encodings.utf16n ;
|
||||||
IN: windows
|
IN: windows
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue