Merge branch 'master' of git://factorcode.org/git/factor

db4
Aaron Schaefer 2009-04-19 13:01:40 -04:00
commit 5006f11342
227 changed files with 2692 additions and 1078 deletions

2
.gitignore vendored
View File

@ -25,3 +25,5 @@ build-support/wordsize
.#* .#*
*.swo *.swo
checksums.txt checksums.txt
*.so
a.out

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Slava Pestov. ! 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: alien alien.c-types arrays assocs effects grouping kernel USING: alien alien.c-types arrays assocs effects grouping kernel
parser sequences splitting words fry locals ; parser sequences splitting words fry locals lexer namespaces ;
IN: alien.parser IN: alien.parser
: parse-arglist ( parameters return -- types effect ) : parse-arglist ( parameters return -- types effect )
@ -12,8 +12,15 @@ IN: alien.parser
: function-quot ( return library function types -- quot ) : function-quot ( return library function types -- quot )
'[ _ _ _ _ alien-invoke ] ; '[ _ _ _ _ alien-invoke ] ;
:: define-function ( return library function parameters -- ) :: make-function ( return library function parameters -- word quot effect )
function create-in dup reset-generic function create-in dup reset-generic
return library function return library function
parameters return parse-arglist [ function-quot ] dip parameters return parse-arglist [ function-quot ] dip ;
define-declared ;
: (FUNCTION:) ( -- word quot effect )
scan "c-library" get scan ";" parse-tokens
[ "()" subseq? not ] filter
make-function ;
: define-function ( return library function parameters -- )
make-function define-declared ;

View File

@ -16,9 +16,7 @@ SYNTAX: BAD-ALIEN <bad-alien> parsed ;
SYNTAX: LIBRARY: scan "c-library" set ; SYNTAX: LIBRARY: scan "c-library" set ;
SYNTAX: FUNCTION: SYNTAX: FUNCTION:
scan "c-library" get scan ";" parse-tokens (FUNCTION:) define-declared ;
[ "()" subseq? not ] filter
define-function ;
SYNTAX: TYPEDEF: SYNTAX: TYPEDEF:
scan scan typedef ; scan scan typedef ;

View File

@ -8,7 +8,7 @@ namespaces eval kernel vocabs.loader io ;
(command-line) parse-command-line (command-line) parse-command-line
load-vocab-roots load-vocab-roots
run-user-init run-user-init
"e" get [ eval ] when* "e" get [ eval( -- ) ] when*
ignore-cli-args? not script get and ignore-cli-args? not script get and
[ run-script ] [ "run" get run ] if* [ run-script ] [ "run" get run ] if*
output-stream get [ stream-flush ] when* output-stream get [ stream-flush ] when*

View File

@ -2,33 +2,4 @@ IN: compiler.errors
USING: help.markup help.syntax vocabs.loader words io USING: help.markup help.syntax vocabs.loader words io
quotations words.symbol ; quotations words.symbol ;
ARTICLE: "compiler-errors" "Compiler warnings and errors"
"After loading a vocabulary, you might see messages like:"
{ $code
":errors - print 2 compiler errors"
":warnings - print 50 compiler warnings"
}
"These messages arise from the compiler's stack effect checker. Production code should not have any warnings and errors in it. Warning and error conditions are documented in " { $link "inference-errors" } "."
$nl
"Words to view warnings and errors:"
{ $subsection :warnings }
{ $subsection :errors }
{ $subsection :linkage }
"Compiler warnings and errors are reported using the " { $link "tools.errors" } " mechanism and are shown in the " { $link "ui.tools.error-list" } "." ;
HELP: compiler-error
{ $values { "error" "an error" } { "word" word } }
{ $description "Saves the error for future persual via " { $link :errors } ", " { $link :warnings } " and " { $link :linkage } "." } ;
HELP: :errors
{ $description "Prints all serious compiler errors from the most recent compile to " { $link output-stream } "." } ;
HELP: :warnings
{ $description "Prints all ignorable compiler warnings from the most recent compile to " { $link output-stream } "." } ;
HELP: :linkage
{ $description "Prints all C library interface linkage errors from the most recent compile to " { $link output-stream } "." } ;
{ :errors :warnings } related-words
ABOUT: "compiler-errors" ABOUT: "compiler-errors"

View File

@ -1,7 +1,6 @@
! Copyright (C) 2007, 2009 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 source-files.errors kernel namespaces assocs USING: accessors source-files.errors kernel namespaces assocs ;
tools.errors ;
IN: compiler.errors IN: compiler.errors
TUPLE: compiler-error < source-file-error ; TUPLE: compiler-error < source-file-error ;
@ -44,6 +43,7 @@ T{ error-type
{ icon "vocab:ui/tools/error-list/icons/linkage-error.tiff" } { icon "vocab:ui/tools/error-list/icons/linkage-error.tiff" }
{ quot [ +linkage-error+ errors-of-type values ] } { quot [ +linkage-error+ errors-of-type values ] }
{ forget-quot [ compiler-errors get delete-at ] } { forget-quot [ compiler-errors get delete-at ] }
{ fatal? f }
} define-error-type } define-error-type
: <compiler-error> ( error word -- compiler-error ) : <compiler-error> ( error word -- compiler-error )
@ -52,12 +52,3 @@ T{ error-type
: compiler-error ( error word -- ) : compiler-error ( error word -- )
compiler-errors get-global pick compiler-errors get-global pick
[ [ [ <compiler-error> ] keep ] dip set-at ] [ delete-at drop ] if ; [ [ [ <compiler-error> ] keep ] dip set-at ] [ delete-at drop ] if ;
: compiler-errors. ( type -- )
errors-of-type values errors. ;
: :errors ( -- ) +compiler-error+ compiler-errors. ;
: :warnings ( -- ) +compiler-warning+ compiler-errors. ;
: :linkage ( -- ) +linkage-error+ compiler-errors. ;

View File

@ -12,7 +12,7 @@ IN: compiler.tests
IN: compiler.tests.folding IN: compiler.tests.folding
GENERIC: foldable-generic ( a -- b ) foldable GENERIC: foldable-generic ( a -- b ) foldable
M: integer foldable-generic f <array> ; M: integer foldable-generic f <array> ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [
@ -20,7 +20,7 @@ IN: compiler.tests
USING: math arrays ; USING: math arrays ;
IN: compiler.tests.folding IN: compiler.tests.folding
: fold-test ( -- x ) 10 foldable-generic ; : fold-test ( -- x ) 10 foldable-generic ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ t ] [ [ t ] [

View File

@ -11,7 +11,7 @@ M: integer method-redefine-generic-1 3 + ;
[ 6 ] [ method-redefine-test-1 ] unit-test [ 6 ] [ method-redefine-test-1 ] unit-test
[ ] [ "IN: compiler.tests USE: math M: fixnum method-redefine-generic-1 4 + ;" (( -- )) eval ] unit-test [ ] [ "IN: compiler.tests USE: math M: fixnum method-redefine-generic-1 4 + ;" eval( -- ) ] unit-test
[ 7 ] [ method-redefine-test-1 ] unit-test [ 7 ] [ method-redefine-test-1 ] unit-test
@ -27,7 +27,7 @@ M: integer method-redefine-generic-2 3 + ;
[ 6 ] [ method-redefine-test-2 ] unit-test [ 6 ] [ method-redefine-test-2 ] unit-test
[ ] [ "IN: compiler.tests USE: kernel USE: math M: fixnum method-redefine-generic-2 4 + ; USE: strings M: string method-redefine-generic-2 drop f ;" (( -- )) eval ] unit-test [ ] [ "IN: compiler.tests USE: kernel USE: math M: fixnum method-redefine-generic-2 4 + ; USE: strings M: string method-redefine-generic-2 drop f ;" eval( -- ) ] unit-test
[ 7 ] [ method-redefine-test-2 ] unit-test [ 7 ] [ method-redefine-test-2 ] unit-test
@ -43,10 +43,10 @@ M: integer method-redefine-generic-2 3 + ;
[ t ] [ \ hey optimized>> ] unit-test [ t ] [ \ hey optimized>> ] unit-test
[ t ] [ \ there optimized>> ] unit-test [ t ] [ \ there optimized>> ] unit-test
[ ] [ "IN: compiler.tests : hey ( -- ) 3 ;" (( -- )) eval ] unit-test [ ] [ "IN: compiler.tests : hey ( -- ) 3 ;" eval( -- ) ] unit-test
[ f ] [ \ hey optimized>> ] unit-test [ f ] [ \ hey optimized>> ] unit-test
[ f ] [ \ there optimized>> ] unit-test [ f ] [ \ there optimized>> ] unit-test
[ ] [ "IN: compiler.tests : hey ( -- ) ;" (( -- )) eval ] unit-test [ ] [ "IN: compiler.tests : hey ( -- ) ;" eval( -- ) ] unit-test
[ t ] [ \ there optimized>> ] unit-test [ t ] [ \ there optimized>> ] unit-test
: good ( -- ) ; : good ( -- ) ;
@ -59,7 +59,7 @@ M: integer method-redefine-generic-2 3 + ;
[ f ] [ \ good compiled-usage assoc-empty? ] unit-test [ f ] [ \ good compiled-usage assoc-empty? ] unit-test
[ ] [ "IN: compiler.tests : good ( -- ) 3 ;" (( -- )) eval ] unit-test [ ] [ "IN: compiler.tests : good ( -- ) 3 ;" eval( -- ) ] unit-test
[ f ] [ \ good optimized>> ] unit-test [ f ] [ \ good optimized>> ] unit-test
[ f ] [ \ bad optimized>> ] unit-test [ f ] [ \ bad optimized>> ] unit-test
@ -67,7 +67,7 @@ M: integer method-redefine-generic-2 3 + ;
[ t ] [ \ good compiled-usage assoc-empty? ] unit-test [ t ] [ \ good compiled-usage assoc-empty? ] unit-test
[ ] [ "IN: compiler.tests : good ( -- ) ;" (( -- )) eval ] unit-test [ ] [ "IN: compiler.tests : good ( -- ) ;" eval( -- ) ] unit-test
[ t ] [ \ good optimized>> ] unit-test [ t ] [ \ good optimized>> ] unit-test
[ t ] [ \ bad optimized>> ] unit-test [ t ] [ \ bad optimized>> ] unit-test

View File

@ -13,7 +13,7 @@ IN: compiler.tests
MIXIN: my-mixin MIXIN: my-mixin
INSTANCE: fixnum my-mixin INSTANCE: fixnum my-mixin
: my-inline ( a -- b ) dup my-mixin instance? [ 1 + ] when ; : my-inline ( a -- b ) dup my-mixin instance? [ 1 + ] when ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [
@ -21,7 +21,7 @@ IN: compiler.tests
USE: math USE: math
IN: compiler.tests.redefine10 IN: compiler.tests.redefine10
INSTANCE: float my-mixin INSTANCE: float my-mixin
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ 2.0 ] [ [ 2.0 ] [

View File

@ -17,7 +17,7 @@ IN: compiler.tests
M: my-mixin my-generic drop 0 ; M: my-mixin my-generic drop 0 ;
M: object my-generic drop 1 ; M: object my-generic drop 1 ;
: my-inline ( -- b ) { } my-generic ; : my-inline ( -- b ) { } my-generic ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [

View File

@ -15,6 +15,6 @@ M: object g drop t ;
TUPLE: jeah ; TUPLE: jeah ;
[ ] [ "USE: kernel IN: compiler.tests.redefine12 M: jeah g drop f ;" (( -- )) eval ] unit-test [ ] [ "USE: kernel IN: compiler.tests.redefine12 M: jeah g drop f ;" eval( -- ) ] unit-test
[ f ] [ T{ jeah } h ] unit-test [ f ] [ T{ jeah } h ] unit-test

View File

@ -5,7 +5,7 @@ arrays words assocs eval words.symbol ;
DEFER: redefine2-test DEFER: redefine2-test
[ ] [ "USE: sequences USE: kernel IN: compiler.tests TUPLE: redefine2-test ; M: redefine2-test nth 2drop 3 ; INSTANCE: redefine2-test sequence" (( -- )) eval ] unit-test [ ] [ "USE: sequences USE: kernel IN: compiler.tests TUPLE: redefine2-test ; M: redefine2-test nth 2drop 3 ; INSTANCE: redefine2-test sequence" eval( -- ) ] unit-test
[ t ] [ \ redefine2-test symbol? ] unit-test [ t ] [ \ redefine2-test symbol? ] unit-test

View File

@ -18,7 +18,7 @@ M: empty-mixin sheeple drop "wake up" ;
[ t ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test [ t ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test
[ f ] [ empty-mixin \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test [ f ] [ empty-mixin \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test
[ ] [ "IN: compiler.tests USE: arrays INSTANCE: array empty-mixin" (( -- )) eval ] unit-test [ ] [ "IN: compiler.tests USE: arrays INSTANCE: array empty-mixin" eval( -- ) ] unit-test
[ "wake up" ] [ sheeple-test ] unit-test [ "wake up" ] [ sheeple-test ] unit-test
[ f ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test [ f ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test

View File

@ -7,6 +7,6 @@ USING: io.streams.string kernel tools.test eval ;
[ "" ] [ [ declaration-test ] with-string-writer ] unit-test [ "" ] [ [ declaration-test ] with-string-writer ] unit-test
[ ] [ "IN: compiler.tests USE: io : declaration-test-1 ( -- a ) \"X\" write f ;" (( -- )) eval ] unit-test [ ] [ "IN: compiler.tests USE: io : declaration-test-1 ( -- a ) \"X\" write f ;" eval( -- ) ] unit-test
[ "X" ] [ [ declaration-test ] with-string-writer ] unit-test [ "X" ] [ [ declaration-test ] with-string-writer ] unit-test

View File

@ -14,7 +14,7 @@ IN: compiler.tests
GENERIC: my-generic ( a -- b ) GENERIC: my-generic ( a -- b )
M: object my-generic [ <=> ] sort ; M: object my-generic [ <=> ] sort ;
: my-inline ( a -- b ) my-generic ; : my-inline ( a -- b ) my-generic ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [
@ -23,7 +23,7 @@ IN: compiler.tests
IN: compiler.tests.redefine5 IN: compiler.tests.redefine5
TUPLE: my-tuple ; TUPLE: my-tuple ;
M: my-tuple my-generic drop 0 ; M: my-tuple my-generic drop 0 ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ 0 ] [ [ 0 ] [

View File

@ -14,7 +14,7 @@ IN: compiler.tests
MIXIN: my-mixin MIXIN: my-mixin
M: my-mixin my-generic drop 0 ; M: my-mixin my-generic drop 0 ;
: my-inline ( a -- b ) { my-mixin } declare my-generic ; : my-inline ( a -- b ) { my-mixin } declare my-generic ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [
@ -24,7 +24,7 @@ IN: compiler.tests
TUPLE: my-tuple ; TUPLE: my-tuple ;
M: my-tuple my-generic drop 1 ; M: my-tuple my-generic drop 1 ;
INSTANCE: my-tuple my-mixin INSTANCE: my-tuple my-mixin
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ 1 ] [ [ 1 ] [

View File

@ -13,7 +13,7 @@ IN: compiler.tests
MIXIN: my-mixin MIXIN: my-mixin
INSTANCE: fixnum my-mixin INSTANCE: fixnum my-mixin
: my-inline ( a -- b ) dup my-mixin? [ 1 + ] when ; : my-inline ( a -- b ) dup my-mixin? [ 1 + ] when ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [
@ -21,7 +21,7 @@ IN: compiler.tests
USE: math USE: math
IN: compiler.tests.redefine7 IN: compiler.tests.redefine7
INSTANCE: float my-mixin INSTANCE: float my-mixin
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ 2.0 ] [ [ 2.0 ] [

View File

@ -16,7 +16,7 @@ IN: compiler.tests
! We add the bogus quotation here to hinder inlining ! We add the bogus quotation here to hinder inlining
! since otherwise we cannot trigger this bug. ! since otherwise we cannot trigger this bug.
M: my-mixin my-generic 1 + [ [ <=> ] sort ] drop ; M: my-mixin my-generic 1 + [ [ <=> ] sort ] drop ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [
@ -24,7 +24,7 @@ IN: compiler.tests
USE: math USE: math
IN: compiler.tests.redefine8 IN: compiler.tests.redefine8
INSTANCE: float my-mixin INSTANCE: float my-mixin
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ 2.0 ] [ [ 2.0 ] [

View File

@ -16,7 +16,7 @@ IN: compiler.tests
! We add the bogus quotation here to hinder inlining ! We add the bogus quotation here to hinder inlining
! since otherwise we cannot trigger this bug. ! since otherwise we cannot trigger this bug.
M: my-mixin my-generic 1 + [ [ <=> ] sort ] drop ; M: my-mixin my-generic 1 + [ [ <=> ] sort ] drop ;
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [
@ -25,7 +25,7 @@ IN: compiler.tests
IN: compiler.tests.redefine9 IN: compiler.tests.redefine9
TUPLE: my-tuple ; TUPLE: my-tuple ;
INSTANCE: my-tuple my-mixin INSTANCE: my-tuple my-mixin
"> (( -- )) eval "> eval( -- )
] unit-test ] unit-test
[ [

View File

@ -237,6 +237,6 @@ M: f single-combination-test-2 single-combination-test-4 ;
10 [ 10 [
[ "compiler.tests.foo" forget-vocab ] with-compilation-unit [ "compiler.tests.foo" forget-vocab ] with-compilation-unit
[ t ] [ [ t ] [
"USING: prettyprint words accessors ; IN: compiler.tests.foo : (recursive) ( -- ) (recursive) (recursive) ; inline recursive : recursive ( -- ) (recursive) ; \\ (recursive) optimized>>" (( -- obj )) eval "USING: prettyprint words accessors ; IN: compiler.tests.foo : (recursive) ( -- ) (recursive) (recursive) ; inline recursive : recursive ( -- ) (recursive) ; \\ (recursive) optimized>>" eval( -- obj )
] unit-test ] unit-test
] times ] times

View File

@ -302,7 +302,7 @@ cell-bits 32 = [
] unit-test ] unit-test
[ t ] [ [ t ] [
[ 1000 [ 1+ ] map ] { 1+ fixnum+ } inlined? [ 1000 iota [ 1+ ] map ] { 1+ fixnum+ } inlined?
] unit-test ] unit-test
: rec ( a -- b ) : rec ( a -- b )

View File

@ -17,13 +17,13 @@ sequences accessors tools.test kernel math ;
[ 2 ] [ [ 3 [ drop ] [ 2drop 3 ] if ] build-tree count-introductions ] unit-test [ 2 ] [ [ 3 [ drop ] [ 2drop 3 ] if ] build-tree count-introductions ] unit-test
: foo ( a b -- b a ) swap ; inline recursive : foo ( quot: ( -- ) -- ) call ; inline recursive
: recursive-inputs ( nodes -- n ) : recursive-inputs ( nodes -- n )
[ #recursive? ] find nip child>> first in-d>> length ; [ #recursive? ] find nip child>> first in-d>> length ;
[ 0 2 ] [ [ 1 3 ] [
[ foo ] build-tree [ [ swap ] foo ] build-tree
[ recursive-inputs ] [ recursive-inputs ]
[ analyze-recursive normalize recursive-inputs ] bi [ analyze-recursive normalize recursive-inputs ] bi
] unit-test ] unit-test

View File

@ -310,7 +310,7 @@ CONSTANT: rs-reg 30
4 ds-reg 0 LWZ 4 ds-reg 0 LWZ
5 ds-reg -4 LWZU 5 ds-reg -4 LWZU
5 0 4 CMP 5 0 4 CMP
2 swap execute ! magic number 2 swap execute( offset -- ) ! magic number
\ f tag-number 3 LI \ f tag-number 3 LI
3 ds-reg 0 STW ; 3 ds-reg 0 STW ;
@ -341,7 +341,7 @@ CONSTANT: rs-reg 30
: jit-math ( insn -- ) : jit-math ( insn -- )
3 ds-reg 0 LWZ 3 ds-reg 0 LWZ
4 ds-reg -4 LWZU 4 ds-reg -4 LWZU
[ 5 3 4 ] dip execute [ 5 3 4 ] dip execute( dst src1 src2 -- )
5 ds-reg 0 STW ; 5 ds-reg 0 STW ;
[ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive [ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive

View File

@ -334,7 +334,7 @@ big-endian off
! compare with second value ! compare with second value
ds-reg [] temp0 CMP ds-reg [] temp0 CMP
! move t if true ! move t if true
[ temp1 temp3 ] dip execute [ temp1 temp3 ] dip execute( dst src -- )
! store ! store
ds-reg [] temp1 MOV ; ds-reg [] temp1 MOV ;
@ -355,7 +355,7 @@ big-endian off
! pop stack ! pop stack
ds-reg bootstrap-cell SUB ds-reg bootstrap-cell SUB
! compute result ! compute result
[ ds-reg [] temp0 ] dip execute ; [ ds-reg [] temp0 ] dip execute( dst src -- ) ;
[ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive [ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive

View File

@ -35,7 +35,7 @@ M: hello bing hello-test ;
[ 3 ] [ 1 0 <hello> 2 whoa ] unit-test [ 3 ] [ 1 0 <hello> 2 whoa ] unit-test
[ 3 ] [ 1 0 <hello> f <goodbye> 2 whoa ] unit-test [ 3 ] [ 1 0 <hello> f <goodbye> 2 whoa ] unit-test
[ ] [ 3 [ "USING: accessors delegate ; IN: delegate.tests CONSULT: baz goodbye these>> ;" (( -- )) eval ] times ] unit-test [ ] [ 3 [ "USING: accessors delegate ; IN: delegate.tests CONSULT: baz goodbye these>> ;" eval( -- ) ] times ] unit-test
[ H{ { goodbye T{ consultation f baz goodbye [ these>> ] } } } ] [ baz protocol-consult ] unit-test [ H{ { goodbye T{ consultation f baz goodbye [ these>> ] } } } ] [ baz protocol-consult ] unit-test
[ H{ } ] [ bee protocol-consult ] unit-test [ H{ } ] [ bee protocol-consult ] unit-test
@ -63,22 +63,22 @@ CONSULT: beta hey value>> 1- ;
[ 0 ] [ 1 <hey> three ] unit-test [ 0 ] [ 1 <hey> three ] unit-test
[ { hey } ] [ alpha protocol-users ] unit-test [ { hey } ] [ alpha protocol-users ] unit-test
[ { hey } ] [ beta protocol-users ] unit-test [ { hey } ] [ beta protocol-users ] unit-test
[ ] [ "USE: delegate IN: delegate.tests PROTOCOL: alpha one ;" (( -- )) eval ] unit-test [ ] [ "USE: delegate IN: delegate.tests PROTOCOL: alpha one ;" eval( -- ) ] unit-test
[ f ] [ hey \ two method ] unit-test [ f ] [ hey \ two method ] unit-test
[ f ] [ hey \ four method ] unit-test [ f ] [ hey \ four method ] unit-test
[ ] [ "USE: delegate IN: delegate.tests PROTOCOL: beta two three four ;" (( -- )) eval ] unit-test [ ] [ "USE: delegate IN: delegate.tests PROTOCOL: beta two three four ;" eval( -- ) ] unit-test
[ { hey } ] [ alpha protocol-users ] unit-test [ { hey } ] [ alpha protocol-users ] unit-test
[ { hey } ] [ beta protocol-users ] unit-test [ { hey } ] [ beta protocol-users ] unit-test
[ 2 ] [ 1 <hey> one ] unit-test [ 2 ] [ 1 <hey> one ] unit-test
[ 0 ] [ 1 <hey> two ] unit-test [ 0 ] [ 1 <hey> two ] unit-test
[ 0 ] [ 1 <hey> three ] unit-test [ 0 ] [ 1 <hey> three ] unit-test
[ 0 ] [ 1 <hey> four ] unit-test [ 0 ] [ 1 <hey> four ] unit-test
[ ] [ "USING: math accessors delegate ; IN: delegate.tests CONSULT: beta hey value>> 2 - ;" (( -- )) eval ] unit-test [ ] [ "USING: math accessors delegate ; IN: delegate.tests CONSULT: beta hey value>> 2 - ;" eval( -- ) ] unit-test
[ 2 ] [ 1 <hey> one ] unit-test [ 2 ] [ 1 <hey> one ] unit-test
[ -1 ] [ 1 <hey> two ] unit-test [ -1 ] [ 1 <hey> two ] unit-test
[ -1 ] [ 1 <hey> three ] unit-test [ -1 ] [ 1 <hey> three ] unit-test
[ -1 ] [ 1 <hey> four ] unit-test [ -1 ] [ 1 <hey> four ] unit-test
[ ] [ "IN: delegate.tests FORGET: alpha" (( -- )) eval ] unit-test [ ] [ "IN: delegate.tests FORGET: alpha" eval( -- ) ] unit-test
[ f ] [ hey \ one method ] unit-test [ f ] [ hey \ one method ] unit-test
TUPLE: slot-protocol-test-1 a b ; TUPLE: slot-protocol-test-1 a b ;

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -0,0 +1,17 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: editors io.launcher kernel make math.parser namespaces
sequences ;
IN: editors.gedit
: gedit-path ( -- path )
\ gedit-path get-global [
"gedit"
] unless* ;
: gedit ( file line -- )
[
gedit-path , number>string "+" prepend , ,
] { } make run-detached drop ;
[ gedit ] edit-hook set-global

View File

@ -0,0 +1 @@
gedit integration

View File

@ -1,4 +1,6 @@
IN: eval.tests IN: eval.tests
USING: eval tools.test ; USING: eval tools.test ;
[ 4 ] [ "USE: math 2 2 +" eval( -- result ) ] unit-test
[ "USE: math 2 2 +" eval( -- ) ] must-fail
[ "4\n" ] [ "USING: math prettyprint ; 2 2 + ." eval>string ] unit-test [ "4\n" ] [ "USING: math prettyprint ; 2 2 + ." eval>string ] unit-test

View File

@ -56,7 +56,7 @@ sequences eval accessors ;
3 '[ [ [ _ 1array ] call 1array ] call 1array ] call 3 '[ [ [ _ 1array ] call 1array ] call 1array ] call
] unit-test ] unit-test
[ "USING: fry locals.backend ; f '[ load-local _ ]" (( -- quot )) eval ] [ "USING: fry locals.backend ; f '[ load-local _ ]" eval( -- quot ) ]
[ error>> >r/r>-in-fry-error? ] must-fail-with [ error>> >r/r>-in-fry-error? ] must-fail-with
[ { { "a" 1 } { "b" 2 } { "c" 3 } { "d" 4 } } ] [ [ { { "a" 1 } { "b" 2 } { "c" 3 } { "d" 4 } } ] [

View File

@ -272,8 +272,8 @@ HELP: nweave
HELP: n*quot HELP: n*quot
{ $values { $values
{ "n" integer } { "seq" sequence } { "n" integer } { "quot" quotation }
{ "seq'" sequence } { "quot'" quotation }
} }
{ $examples { $examples
{ $example "USING: generalizations prettyprint math ;" { $example "USING: generalizations prettyprint math ;"

View File

@ -7,7 +7,7 @@ IN: generalizations
<< <<
: n*quot ( n seq -- seq' ) <repetition> concat >quotation ; : n*quot ( n quot -- quot' ) <repetition> concat >quotation ;
: repeat ( n obj quot -- ) swapd times ; inline : repeat ( n obj quot -- ) swapd times ; inline

View File

@ -6,9 +6,9 @@ IN: hash2.tests
: sample-hash ( -- hash ) : sample-hash ( -- hash )
5 <hash2> 5 <hash2>
dup 2 3 "foo" roll set-hash2 [ [ 2 3 "foo" ] dip set-hash2 ] keep
dup 4 2 "bar" roll set-hash2 [ [ 4 2 "bar" ] dip set-hash2 ] keep
dup 4 7 "other" roll set-hash2 ; [ [ 4 7 "other" ] dip set-hash2 ] keep ;
[ "foo" ] [ 2 3 sample-hash hash2 ] unit-test [ "foo" ] [ 2 3 sample-hash hash2 ] unit-test
[ "bar" ] [ 4 2 sample-hash hash2 ] unit-test [ "bar" ] [ 4 2 sample-hash hash2 ] unit-test

View File

@ -1,4 +1,6 @@
USING: kernel sequences arrays math vectors ; ! Copyright (C) 2007 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences arrays math vectors locals ;
IN: hash2 IN: hash2
! Little ad-hoc datastructure used to map two numbers ! Little ad-hoc datastructure used to map two numbers
@ -22,8 +24,8 @@ IN: hash2
: assoc2 ( a b alist -- value ) : assoc2 ( a b alist -- value )
(assoc2) dup [ third ] when ; inline (assoc2) dup [ third ] when ; inline
: set-assoc2 ( value a b alist -- alist ) :: set-assoc2 ( value a b alist -- alist )
[ rot 3array ] dip ?push ; inline { a b value } alist ?push ; inline
: hash2@ ( a b hash2 -- a b bucket hash2 ) : hash2@ ( a b hash2 -- a b bucket hash2 )
[ 2dup hashcode2 ] dip [ length mod ] keep ; inline [ 2dup hashcode2 ] dip [ length mod ] keep ; inline
@ -31,8 +33,8 @@ IN: hash2
: hash2 ( a b hash2 -- value/f ) : hash2 ( a b hash2 -- value/f )
hash2@ nth dup [ assoc2 ] [ 3drop f ] if ; hash2@ nth dup [ assoc2 ] [ 3drop f ] if ;
: set-hash2 ( a b value hash2 -- ) :: set-hash2 ( a b value hash2 -- )
[ -rot ] dip hash2@ [ set-assoc2 ] change-nth ; value a b hash2 hash2@ [ set-assoc2 ] change-nth ;
: alist>hash2 ( alist size -- hash2 ) : alist>hash2 ( alist size -- hash2 )
<hash2> [ over [ first3 ] dip set-hash2 ] reduce ; inline <hash2> [ over [ first3 ] dip set-hash2 ] reduce ; inline

View File

@ -4,7 +4,7 @@ definitions assocs sequences kernel namespaces parser arrays
io.streams.string continuations debugger compiler.units eval ; io.streams.string continuations debugger compiler.units eval ;
[ ] [ [ ] [
"IN: help.crossref.tests USING: help.syntax help.markup ; : foo ( -- ) ; HELP: foo \"foo is great\" ; ARTICLE: \"foo\" \"Foo\" { $subsection foo } ;" (( -- )) eval "IN: help.crossref.tests USING: help.syntax help.markup ; : foo ( -- ) ; HELP: foo \"foo is great\" ; ARTICLE: \"foo\" \"Foo\" { $subsection foo } ;" eval( -- )
] unit-test ] unit-test
[ $subsection ] [ [ $subsection ] [
@ -23,7 +23,7 @@ io.streams.string continuations debugger compiler.units eval ;
] unit-test ] unit-test
[ ] [ [ ] [
"IN: help.crossref.tests USING: help.syntax help.markup ; : bar ( -- ) ; HELP: bar \"bar is great\" ; ARTICLE: \"bar\" \"Bar\" { $subsection bar } ;" (( -- )) eval "IN: help.crossref.tests USING: help.syntax help.markup ; : bar ( -- ) ; HELP: bar \"bar is great\" ; ARTICLE: \"bar\" \"Bar\" { $subsection bar } ;" eval( -- )
] unit-test ] unit-test
[ ] [ [ ] [

View File

@ -32,7 +32,7 @@ IN: help.definitions.tests
"hello" "help.definitions.tests" lookup "help" word-prop "hello" "help.definitions.tests" lookup "help" word-prop
] unit-test ] unit-test
[ ] [ "IN: help.definitions.tests USING: help.syntax ; : xxx ( -- ) ; HELP: xxx ;" (( -- )) eval ] unit-test [ ] [ "IN: help.definitions.tests USING: help.syntax ; : xxx ( -- ) ; HELP: xxx ;" eval( -- ) ] unit-test
[ ] [ "xxx" "help.definitions.tests" lookup print-topic ] unit-test [ ] [ "xxx" "help.definitions.tests" lookup print-topic ] unit-test

View File

@ -4,12 +4,12 @@ IN: help.syntax.tests
[ [
[ "foobar" ] [ [ "foobar" ] [
"IN: help.syntax.tests USE: help.syntax ABOUT: \"foobar\"" (( -- )) eval "IN: help.syntax.tests USE: help.syntax ABOUT: \"foobar\"" eval( -- )
"help.syntax.tests" vocab vocab-help "help.syntax.tests" vocab vocab-help
] unit-test ] unit-test
[ { "foobar" } ] [ [ { "foobar" } ] [
"IN: help.syntax.tests USE: help.syntax ABOUT: { \"foobar\" }" (( -- )) eval "IN: help.syntax.tests USE: help.syntax ABOUT: { \"foobar\" }" eval( -- )
"help.syntax.tests" vocab vocab-help "help.syntax.tests" vocab vocab-help
] unit-test ] unit-test

View File

@ -29,7 +29,7 @@ SYMBOL: foo
} "\n" join } "\n" join
[ [
"testfile" source-file file set "testfile" source-file file set
(( -- )) eval eval( -- )
] with-scope ] with-scope
] unit-test ] unit-test

View File

@ -184,6 +184,12 @@ ERROR: download-failed response ;
: http-put ( post-data url -- response data ) : http-put ( post-data url -- response data )
<put-request> http-request ; <put-request> http-request ;
: <delete-request> ( url -- request )
"DELETE" <client-request> ;
: http-delete ( url -- response data )
<delete-request> http-request ;
USING: vocabs vocabs.loader ; USING: vocabs vocabs.loader ;
"debugger" vocab [ "http.client.debugger" require ] when "debugger" vocab [ "http.client.debugger" require ] when

View File

@ -0,0 +1,8 @@
IN: io.crlf.tests
USING: io.crlf tools.test io.streams.string io ;
[ "Hello, world." ] [ "Hello, world." [ read-crlf ] with-string-reader ] unit-test
[ "Hello, world." ] [ "Hello, world.\r\n" [ read-crlf ] with-string-reader ] unit-test
[ "Hello, world.\r" [ read-crlf ] with-string-reader ] must-fail
[ f ] [ "" [ read-crlf ] with-string-reader ] unit-test
[ "" ] [ "\r\n" [ read-crlf ] with-string-reader ] unit-test

View File

@ -1,6 +1,6 @@
! Copyright (C) 2009 Daniel Ehrenberg, Slava Pestov ! Copyright (C) 2009 Daniel Ehrenberg, Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: io kernel ; USING: io kernel sequences ;
IN: io.crlf IN: io.crlf
: crlf ( -- ) : crlf ( -- )
@ -8,4 +8,4 @@ IN: io.crlf
: read-crlf ( -- seq ) : read-crlf ( -- seq )
"\r" read-until "\r" read-until
[ CHAR: \r assert= read1 CHAR: \n assert= ] when* ; [ CHAR: \r assert= read1 CHAR: \n assert= ] [ f like ] if* ;

View File

@ -10,13 +10,13 @@ USING: io.launcher.unix.parser tools.test ;
[ V{ "abc" "def" } ] [ "abc def" tokenize-command ] unit-test [ V{ "abc" "def" } ] [ "abc def" tokenize-command ] unit-test
[ V{ "abc def" } ] [ "abc\\ def" tokenize-command ] unit-test [ V{ "abc def" } ] [ "abc\\ def" tokenize-command ] unit-test
[ V{ "abc\\" "def" } ] [ "abc\\\\ def" tokenize-command ] unit-test [ V{ "abc\\" "def" } ] [ "abc\\\\ def" tokenize-command ] unit-test
[ V{ "abc\\ def" } ] [ "'abc\\\\ def'" tokenize-command ] unit-test [ V{ "abc\\ def" } ] [ "\"abc\\\\ def\"" tokenize-command ] unit-test
[ V{ "abc\\ def" } ] [ " 'abc\\\\ def'" tokenize-command ] unit-test [ V{ "abc\\ def" } ] [ " \"abc\\\\ def\"" tokenize-command ] unit-test
[ V{ "abc\\ def" "hey" } ] [ "'abc\\\\ def' hey" tokenize-command ] unit-test [ V{ "abc\\ def" "hey" } ] [ "\"abc\\\\ def\" hey" tokenize-command ] unit-test
[ V{ "abc def" "hey" } ] [ "'abc def' \"hey\"" tokenize-command ] unit-test [ V{ "abc def" "hey" } ] [ "\"abc def\" \"hey\"" tokenize-command ] unit-test
[ "'abc def' \"hey" tokenize-command ] must-fail [ "\"abc def\" \"hey" tokenize-command ] must-fail
[ "'abc def" tokenize-command ] must-fail [ "\"abc def" tokenize-command ] must-fail
[ V{ "abc def" "h\"ey" } ] [ "'abc def' \"h\\\"ey\" " tokenize-command ] unit-test [ V{ "abc def" "h\"ey" } ] [ "\"abc def\" \"h\\\"ey\" " tokenize-command ] unit-test
[ [
V{ V{

View File

@ -1,33 +1,17 @@
! Copyright (C) 2008 Slava Pestov ! Copyright (C) 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: peg peg.parsers kernel sequences strings words ; USING: peg peg.ebnf arrays sequences strings kernel ;
IN: io.launcher.unix.parser IN: io.launcher.unix.parser
! Our command line parser. Supported syntax: ! Our command line parser. Supported syntax:
! foo bar baz -- simple tokens ! foo bar baz -- simple tokens
! foo\ bar -- escaping the space ! foo\ bar -- escaping the space
! 'foo bar' -- quotation
! "foo bar" -- quotation ! "foo bar" -- quotation
: 'escaped-char' ( -- parser ) EBNF: tokenize-command
"\\" token any-char 2seq [ second ] action ; space = " "
escaped-char = "\" .:ch => [[ ch ]]
: 'quoted-char' ( delimiter -- parser' ) quoted = '"' (escaped-char | [^"])*:a '"' => [[ a ]]
'escaped-char' unquoted = (escaped-char | [^ "])+
swap [ member? not ] curry satisfy argument = (quoted | unquoted) => [[ >string ]]
2choice ; inline command = space* (argument:a space* => [[ a ]])+:c !(.) => [[ c ]]
;EBNF
: 'quoted' ( delimiter -- parser )
dup 'quoted-char' repeat0 swap dup surrounded-by ;
: 'unquoted' ( -- parser ) " '\"" 'quoted-char' repeat1 ;
: 'argument' ( -- parser )
"\"" 'quoted'
"'" 'quoted'
'unquoted' 3choice
[ >string ] action ;
PEG: tokenize-command ( command -- ast/f )
'argument' " " token repeat1 list-of
" " token repeat0 tuck pack
just ;

View File

@ -98,7 +98,7 @@ IN: io.launcher.windows.nt.tests
<process> <process>
console-vm "-script" "env.factor" 3array >>command console-vm "-script" "env.factor" 3array >>command
ascii <process-reader> contents ascii <process-reader> contents
] with-directory eval ] with-directory eval( -- alist )
os-envs = os-envs =
] unit-test ] unit-test
@ -110,7 +110,7 @@ IN: io.launcher.windows.nt.tests
+replace-environment+ >>environment-mode +replace-environment+ >>environment-mode
os-envs >>environment os-envs >>environment
ascii <process-reader> contents ascii <process-reader> contents
] with-directory eval ] with-directory eval( -- alist )
os-envs = os-envs =
] unit-test ] unit-test
@ -121,7 +121,7 @@ IN: io.launcher.windows.nt.tests
console-vm "-script" "env.factor" 3array >>command console-vm "-script" "env.factor" 3array >>command
{ { "A" "B" } } >>environment { { "A" "B" } } >>environment
ascii <process-reader> contents ascii <process-reader> contents
] with-directory eval ] with-directory eval( -- alist )
"A" swap at "A" swap at
] unit-test ] unit-test
@ -133,7 +133,7 @@ IN: io.launcher.windows.nt.tests
{ { "USERPROFILE" "XXX" } } >>environment { { "USERPROFILE" "XXX" } } >>environment
+prepend-environment+ >>environment-mode +prepend-environment+ >>environment-mode
ascii <process-reader> contents ascii <process-reader> contents
] with-directory eval ] with-directory eval( -- alist )
"USERPROFILE" swap at "XXX" = "USERPROFILE" swap at "XXX" =
] unit-test ] unit-test

View File

@ -192,7 +192,7 @@ M: object (client) ( remote -- client-in client-out local )
] with-destructors ; ] with-destructors ;
: <client> ( remote encoding -- stream local ) : <client> ( remote encoding -- stream local )
[ (client) -rot ] dip <encoder-duplex> swap ; [ (client) ] dip swap [ <encoder-duplex> ] dip ;
SYMBOL: local-address SYMBOL: local-address

View File

@ -25,7 +25,7 @@ SYNTAX: hello "Hi" print ;
"\\ + 1 2 3 4" parse-interactive "\\ + 1 2 3 4" parse-interactive
"cont" get continue-with "cont" get continue-with
] ignore-errors ] ignore-errors
"USE: debugger :1" (( -- quot )) eval "USE: debugger :1" eval( -- quot )
] callcc1 ] callcc1
] unit-test ] unit-test
] with-file-vocabs ] with-file-vocabs

View File

@ -106,7 +106,8 @@ PRIVATE>
: deep-sequence>cons ( sequence -- cons ) : deep-sequence>cons ( sequence -- cons )
[ <reversed> ] keep nil [ <reversed> ] keep nil
[ tuck same? [ deep-sequence>cons ] when swons ] with reduce ; [ [ nip ] [ same? ] 2bi [ deep-sequence>cons ] when swons ]
with reduce ;
<PRIVATE <PRIVATE
:: (lmap>vector) ( acc list quot: ( elt -- elt' ) -- acc ) :: (lmap>vector) ( acc list quot: ( elt -- elt' ) -- acc )

View File

@ -261,7 +261,7 @@ M:: fixnum next-method-test ( a -- b ) a call-next-method 1 + ;
CONSTANT: new-definition "USING: math ;\nIN: locals.tests\n: a-word-with-locals ( -- x ) 2 3 + ;\n" CONSTANT: new-definition "USING: math ;\nIN: locals.tests\n: a-word-with-locals ( -- x ) 2 3 + ;\n"
[ ] [ new-definition (( -- )) eval ] unit-test [ ] [ new-definition eval( -- ) ] unit-test
[ t ] [ [ t ] [
[ \ a-word-with-locals see ] with-string-writer [ \ a-word-with-locals see ] with-string-writer
@ -461,7 +461,7 @@ M:: integer lambda-method-forget-test ( a -- b ) ;
[ [
"USING: locals fry math ; 1 '[ [let | A [ 10 ] | A _ + ] ]" "USING: locals fry math ; 1 '[ [let | A [ 10 ] | A _ + ] ]"
(( -- )) eval call eval( -- ) call
] [ error>> >r/r>-in-fry-error? ] must-fail-with ] [ error>> >r/r>-in-fry-error? ] must-fail-with
:: (funny-macro-test) ( obj quot -- ? ) obj { quot } 1&& ; inline :: (funny-macro-test) ( obj quot -- ? ) obj { quot } 1&& ; inline
@ -473,10 +473,10 @@ M:: integer lambda-method-forget-test ( a -- b ) ;
[ f ] [ 2 funny-macro-test ] unit-test [ f ] [ 2 funny-macro-test ] unit-test
! Some odd parser corner cases ! Some odd parser corner cases
[ "USE: locals [let" (( -- )) eval ] [ error>> unexpected-eof? ] must-fail-with [ "USE: locals [let" eval( -- ) ] [ error>> unexpected-eof? ] must-fail-with
[ "USE: locals [let |" (( -- )) eval ] [ error>> unexpected-eof? ] must-fail-with [ "USE: locals [let |" eval( -- ) ] [ error>> unexpected-eof? ] must-fail-with
[ "USE: locals [let | a" (( -- )) eval ] [ error>> unexpected-eof? ] must-fail-with [ "USE: locals [let | a" eval( -- ) ] [ error>> unexpected-eof? ] must-fail-with
[ "USE: locals [|" (( -- )) eval ] [ error>> unexpected-eof? ] must-fail-with [ "USE: locals [|" eval( -- ) ] [ error>> unexpected-eof? ] must-fail-with
[ 25 ] [ 5 [| a | { [ a sq ] } cond ] call ] unit-test [ 25 ] [ 5 [| a | { [ a sq ] } cond ] call ] unit-test
[ 25 ] [ 5 [| | { [| a | a sq ] } ] call first call ] unit-test [ 25 ] [ 5 [| | { [| a | a sq ] } ] call first call ] unit-test
@ -491,19 +491,19 @@ M:: integer lambda-method-forget-test ( a -- b ) ;
[ 3 ] [ 3 [| a | \ a ] call ] unit-test [ 3 ] [ 3 [| a | \ a ] call ] unit-test
[ "USE: locals [| | { [let | a [ 0 ] | a ] } ]" (( -- )) eval ] must-fail [ "USE: locals [| | { [let | a [ 0 ] | a ] } ]" eval( -- ) ] must-fail
[ "USE: locals [| | { [wlet | a [ 0 ] | a ] } ]" (( -- )) eval ] must-fail [ "USE: locals [| | { [wlet | a [ 0 ] | a ] } ]" eval( -- ) ] must-fail
[ "USE: locals [| | { [let* | a [ 0 ] | a ] } ]" (( -- )) eval ] must-fail [ "USE: locals [| | { [let* | a [ 0 ] | a ] } ]" eval( -- ) ] must-fail
[ "USE: locals [| | [let | a! [ 0 ] | { a! } ] ]" (( -- )) eval ] must-fail [ "USE: locals [| | [let | a! [ 0 ] | { a! } ] ]" eval( -- ) ] must-fail
[ "USE: locals [| | [wlet | a [ 0 ] | { a } ] ]" (( -- )) eval ] must-fail [ "USE: locals [| | [wlet | a [ 0 ] | { a } ] ]" eval( -- ) ] must-fail
[ "USE: locals [| | { :> a } ]" (( -- )) eval ] must-fail [ "USE: locals [| | { :> a } ]" eval( -- ) ] must-fail
[ "USE: locals 3 :> a" (( -- )) eval ] must-fail [ "USE: locals 3 :> a" eval( -- ) ] must-fail
[ 3 ] [ 3 [| | :> a a ] call ] unit-test [ 3 ] [ 3 [| | :> a a ] call ] unit-test

View File

@ -13,11 +13,11 @@ unit-test
[ t ] [ \ see-test macro? ] unit-test [ t ] [ \ see-test macro? ] unit-test
[ t ] [ [ t ] [
"USING: math ;\nIN: macros.tests\n: see-test ( a b -- c ) - ;\n" dup (( -- )) eval "USING: math ;\nIN: macros.tests\n: see-test ( a b -- c ) - ;\n" dup eval( -- )
[ \ see-test see ] with-string-writer = [ \ see-test see ] with-string-writer =
] unit-test ] unit-test
[ f ] [ \ see-test macro? ] unit-test [ f ] [ \ see-test macro? ] unit-test
[ ] [ "USING: macros stack-checker kernel ; IN: hanging-macro MACRO: c ( quot -- ) infer drop [ ] ; : a ( -- ) [ a ] c ;" (( -- )) eval ] unit-test [ ] [ "USING: macros stack-checker kernel ; IN: hanging-macro MACRO: c ( quot -- ) infer drop [ ] ; : a ( -- ) [ a ] c ;" eval( -- ) ] unit-test

View File

@ -62,8 +62,7 @@ MACRO: match-cond ( assoc -- )
} cond ; } cond ;
: match-replace ( object pattern1 pattern2 -- result ) : match-replace ( object pattern1 pattern2 -- result )
-rot [ match [ "Pattern does not match" throw ] unless* ] dip swap
match [ "Pattern does not match" throw ] unless*
[ replace-patterns ] bind ; [ replace-patterns ] bind ;
: ?1-tail ( seq -- tail/f ) : ?1-tail ( seq -- tail/f )

View File

@ -9,7 +9,7 @@ MEMO: fib ( m -- n )
[ 89 ] [ 10 fib ] unit-test [ 89 ] [ 10 fib ] unit-test
[ "USING: kernel math memoize generalizations ; IN: memoize.tests MEMO: x ( a b c d e -- f g h i j ) [ 1+ ] 4 ndip ;" (( -- )) eval ] must-fail [ "USING: kernel math memoize generalizations ; IN: memoize.tests MEMO: x ( a b c d e -- f g h i j ) [ 1+ ] 4 ndip ;" eval( -- ) ] must-fail
MEMO: see-test ( a -- b ) reverse ; MEMO: see-test ( a -- b ) reverse ;
@ -17,7 +17,7 @@ MEMO: see-test ( a -- b ) reverse ;
[ [ \ see-test see ] with-string-writer ] [ [ \ see-test see ] with-string-writer ]
unit-test unit-test
[ ] [ "IN: memoize.tests : fib ( -- ) ;" (( -- )) eval ] unit-test [ ] [ "IN: memoize.tests : fib ( -- ) ;" eval( -- ) ] unit-test
[ "IN: memoize.tests\n: fib ( -- ) ;\n" ] [ [ \ fib see ] with-string-writer ] unit-test [ "IN: memoize.tests\n: fib ( -- ) ;\n" ] [ [ \ fib see ] with-string-writer ] unit-test

View File

@ -56,6 +56,6 @@ TUPLE: color
! Test reshaping with a mirror ! Test reshaping with a mirror
1 2 3 color boa <mirror> "mirror" set 1 2 3 color boa <mirror> "mirror" set
[ ] [ "IN: mirrors.tests USE: math TUPLE: color { green integer } { red integer } { blue integer } ;" (( -- )) eval ] unit-test [ ] [ "IN: mirrors.tests USE: math TUPLE: color { green integer } { red integer } { blue integer } ;" eval( -- ) ] unit-test
[ 1 ] [ "red" "mirror" get at ] unit-test [ 1 ] [ "red" "mirror" get at ] unit-test

View File

@ -45,7 +45,7 @@ TUPLE: single-texture image dim loc texture-coords texture display-list disposed
: adjust-texture-dim ( dim -- dim' ) : adjust-texture-dim ( dim -- dim' )
non-power-of-2-textures? get [ non-power-of-2-textures? get [
[ next-power-of-2 ] map [ dup 1 = [ next-power-of-2 ] unless ] map
] unless ; ] unless ;
: (tex-image) ( image bitmap -- ) : (tex-image) ( image bitmap -- )

View File

@ -445,11 +445,11 @@ foo=<foreign any-char> 'd'
] unit-test ] unit-test
{ } [ { } [
"USING: kernel peg.ebnf ; \"a\\n\" [EBNF foo='a' '\n' => [[ drop \"\n\" ]] EBNF] drop" (( -- )) eval "USING: kernel peg.ebnf ; \"a\\n\" [EBNF foo='a' '\n' => [[ drop \"\n\" ]] EBNF] drop" eval( -- )
] unit-test ] unit-test
[ [
"USING: peg.ebnf ; <EBNF foo='a' foo='b' EBNF>" (( -- )) eval drop "USING: peg.ebnf ; <EBNF foo='a' foo='b' EBNF>" eval( -- ) drop
] must-fail ] must-fail
{ t } [ { t } [
@ -521,12 +521,12 @@ 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 EBNF]" eval( -- ) ] must-fail
[ <" USE: peg.ebnf [EBNF [ <" USE: peg.ebnf [EBNF
lol = a lol = a
lol = b lol = b
EBNF] "> (( -- )) eval EBNF] "> eval( -- )
] [ ] [
error>> [ redefined-rule? ] [ name>> "lol" = ] bi and error>> [ redefined-rule? ] [ name>> "lol" = ] bi and
] must-fail-with ] must-fail-with

View File

@ -2,8 +2,8 @@ USING: arrays definitions io.streams.string io.streams.duplex
kernel math namespaces parser prettyprint prettyprint.config kernel math namespaces parser prettyprint prettyprint.config
prettyprint.sections sequences tools.test vectors words prettyprint.sections sequences tools.test vectors words
effects splitting generic.standard prettyprint.private effects splitting generic.standard prettyprint.private
continuations generic compiler.units tools.walker eval continuations generic compiler.units tools.continuations
accessors make vocabs.parser see ; tools.continuations.private eval accessors make vocabs.parser see ;
IN: prettyprint.tests IN: prettyprint.tests
[ "4" ] [ 4 unparse ] unit-test [ "4" ] [ 4 unparse ] unit-test
@ -254,7 +254,7 @@ M: class-see-layout class-see-layout ;
! Regression ! Regression
[ t ] [ [ t ] [
"IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n" "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
dup (( -- )) eval dup eval( -- )
"generic-decl-test" "prettyprint.tests" lookup "generic-decl-test" "prettyprint.tests" lookup
[ see ] with-string-writer = [ see ] with-string-writer =
] unit-test ] unit-test

View File

@ -1 +1,2 @@
Slava Pestov Slava Pestov
Alex Chapman

View File

@ -1,37 +1,89 @@
! Copyright (C) 2007 Slava Pestov ! Copyright (C) 2007 Slava Pestov, 2009 Alex Chapman
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel ; USING: boxes help.markup help.syntax kernel math namespaces ;
IN: refs IN: refs
ARTICLE: "refs" "References to assoc entries" ARTICLE: "refs" "References"
"A " { $emphasis "reference" } " is an object encapsulating an assoc and a key; the reference then refers to either the key itself, or the value associated to the key. References can be read, written, and deleted. References are defined in the " { $vocab-link "refs" } " vocabulary." "References provide a uniform way of accessing and changing values. Some examples of referenced values are variables, tuple slots, and keys or values of assocs. References can be read, written, and deleted. References are defined in the " { $vocab-link "refs" } " vocabulary, and new reference types can be made by implementing the " { $link "refs-protocol" } "."
{ $subsection get-ref } { $subsection get-ref }
{ $subsection set-ref } { $subsection set-ref }
{ $subsection set-ref* }
{ $subsection delete-ref } { $subsection delete-ref }
"References to keys:" "References to objects:"
{ $subsection obj-ref }
{ $subsection <obj-ref> }
"References to assoc keys:"
{ $subsection key-ref } { $subsection key-ref }
{ $subsection <key-ref> } { $subsection <key-ref> }
"References to values:" "References to assoc values:"
{ $subsection value-ref } { $subsection value-ref }
{ $subsection <value-ref> } { $subsection <value-ref> }
"References to variables:"
{ $subsection var-ref }
{ $subsection <var-ref> }
{ $subsection global-var-ref }
{ $subsection <global-var-ref> }
"References to tuple slots:"
{ $subsection slot-ref }
{ $subsection <slot-ref> }
"Using boxes as references:"
{ $subsection "box-refs" }
"References are used by the UI inspector." ; "References are used by the UI inspector." ;
ABOUT: "refs" ABOUT: "refs"
ARTICLE: "refs-protocol" "Reference Protocol"
"To use a class of objects as references you must implement the reference protocol for that class, and mark your class as an instance of the " { $link ref } " mixin class. All references must implement these two words:"
{ $subsection get-ref }
{ $subsection set-ref }
"References may also implement:"
{ $subsection delete-ref } ;
ARTICLE: "box-refs" "Using Boxes as References"
"Boxes are elements of the " { $link ref } " mixin class, so any box may be used as a reference. Bear in mind that boxes will still throw an error if you call " { $link get-ref } " on an empty box." ;
HELP: ref HELP: ref
{ $class-description "A class whose instances identify a key or value location in an associative structure. Instances of this clas are never used directly; only instances of " { $link key-ref } " and " { $link value-ref } " should be created." } ; { $class-description "A mixin class whose instances encapsulate a value which can be read, written, and deleted. Instantiable members of this class include:" { $link obj-ref } ", " { $link var-ref } ", " { $link global-var-ref } ", " { $link slot-ref } ", " { $link box } ", " { $link key-ref } ", and " { $link value-ref } "." } ;
HELP: delete-ref HELP: delete-ref
{ $values { "ref" ref } } { $values { "ref" ref } }
{ $description "Deletes the association entry pointed at by this reference." } ; { $description "Deletes the value pointed to by this reference. In most references this simply sets the value to f, but in some cases it is more destructive, such as in " { $link value-ref } " and " { $link key-ref } ", where it actually deletes the entry from the underlying assoc." } ;
HELP: get-ref HELP: get-ref
{ $values { "ref" ref } { "obj" object } } { $values { "ref" ref } { "obj" object } }
{ $description "Outputs the key or the value pointed at by this reference." } ; { $description "Outputs the value pointed at by this reference." } ;
HELP: set-ref HELP: set-ref
{ $values { "obj" object } { "ref" ref } } { $values { "obj" object } { "ref" ref } }
{ $description "Stores a new key or value at by this reference." } ; { $description "Stores a new value at this reference." } ;
HELP: obj-ref
{ $class-description "Instances of this class contain a value which can be changed using the " { $link "refs-protocol" } ". New object references are created by calling " { $link <obj-ref> } "." } ;
HELP: <obj-ref>
{ $values { "obj" object } { "obj-ref" obj-ref } }
{ $description "Creates a reference which contains the value it references." } ;
HELP: var-ref
{ $class-description "Instances of this class reference a variable as defined by the " { $vocab-link "namespaces" } " vocabulary. New variable references are created by calling " { $link <var-ref> } "." } ;
HELP: <var-ref>
{ $values { "var" object } { "var-ref" var-ref } }
{ $description "Creates a reference to the given variable. Note that this reference behaves just like any variable when it comes to dynamic scope. For example, if you use " { $link set-ref } " in an inner scope and then leave that scope, then calling " { $link get-ref } " may not return the expected value. If this is not what you want, try using an " { $link obj-ref } " instead." } ;
HELP: global-var-ref
{ $class-description "Instances of this class reference a global variable. New global references are created by calling " { $link <global-var-ref> } "." } ;
HELP: <global-var-ref>
{ $values { "var" object } { "global-var-ref" global-var-ref } }
{ $description "Creates a reference to a global variable." } ;
HELP: slot-ref
{ $class-description "Instances of this class identify a particular slot of a particular instance of a tuple. New slot references are created by calling " { $link <slot-ref> } "." } ;
HELP: <slot-ref>
{ $values { "tuple" tuple } { "slot" integer } { "slot-ref" slot-ref } }
{ $description "Creates a reference to the value in a particular slot of the given tuple. The slot must be given as an integer, where the first user-defined slot is number 2. This is mostly just a proof of concept until we have a way of generating this slot number from a slot name." } ;
HELP: key-ref HELP: key-ref
{ $class-description "Instances of this class identify a key in an associative structure. New key references are created by calling " { $link <key-ref> } "." } ; { $class-description "Instances of this class identify a key in an associative structure. New key references are created by calling " { $link <key-ref> } "." } ;
@ -47,6 +99,37 @@ HELP: <value-ref>
{ $values { "assoc" "an assoc" } { "key" object } { "value-ref" value-ref } } { $values { "assoc" "an assoc" } { "key" object } { "value-ref" value-ref } }
{ $description "Creates a reference to the value associated with " { $snippet "key" } " in " { $snippet "assoc" } "." } ; { $description "Creates a reference to the value associated with " { $snippet "key" } " in " { $snippet "assoc" } "." } ;
{ get-ref set-ref delete-ref } related-words { get-ref set-ref delete-ref set-ref* } related-words
{ <key-ref> <value-ref> } related-words { <obj-ref> <var-ref> <global-var-ref> <slot-ref> <key-ref> <value-ref> } related-words
HELP: set-ref*
{ $values { "ref" ref } { "obj" object } }
{ $description "Just like " { $link set-ref } ", but leave the ref on the stack." } ;
HELP: ref-on
{ $values { "ref" ref } }
{ $description "Sets the value of the ref to t." } ;
HELP: ref-off
{ $values { "ref" ref } }
{ $description "Sets the value of the ref to f." } ;
HELP: ref-inc
{ $values { "ref" ref } }
{ $description "Increment the value of the ref by 1." } ;
HELP: ref-dec
{ $values { "ref" ref } }
{ $description "Decrement the value of the ref by 1." } ;
HELP: take
{ $values { "ref" ref } { "obj" object } }
{ $description "Retrieve the value of the ref and then delete it, returning the value." } ;
{ ref-on ref-off ref-inc ref-dec take } related-words
{ take delete-ref } related-words
{ on ref-on } related-words
{ off ref-off } related-words
{ inc ref-inc } related-words
{ dec ref-dec } related-words

View File

@ -1,5 +1,7 @@
USING: refs tools.test kernel ; USING: boxes kernel namespaces refs tools.test ;
IN: refs.tests
! assoc-refs
[ 3 ] [ [ 3 ] [
H{ { "a" 3 } } "a" <value-ref> get-ref H{ { "a" 3 } } "a" <value-ref> get-ref
] unit-test ] unit-test
@ -20,3 +22,84 @@ USING: refs tools.test kernel ;
set-ref set-ref
] keep ] keep
] unit-test ] unit-test
SYMBOLS: lion giraffe elephant rabbit ;
! obj-refs
[ rabbit ] [ rabbit <obj-ref> get-ref ] unit-test
[ rabbit ] [ f <obj-ref> rabbit set-ref* get-ref ] unit-test
[ rabbit ] [ rabbit <obj-ref> take ] unit-test
[ rabbit f ] [ rabbit <obj-ref> [ take ] keep get-ref ] unit-test
[ lion ] [ rabbit <obj-ref> dup [ drop lion ] change-ref get-ref ] unit-test
! var-refs
[ giraffe ] [ [ giraffe rabbit set rabbit <var-ref> get-ref ] with-scope ] unit-test
[ rabbit ]
[
[
lion rabbit set [
rabbit rabbit set rabbit <var-ref> get-ref
] with-scope
] with-scope
] unit-test
[ rabbit ] [
rabbit <var-ref>
[
lion rabbit set [
rabbit rabbit set get-ref
] with-scope
] with-scope
] unit-test
[ elephant ] [
rabbit <var-ref>
[
elephant rabbit set [
rabbit rabbit set
] with-scope
get-ref
] with-scope
] unit-test
[ rabbit ] [
rabbit <var-ref>
[
elephant set-ref* [
rabbit set-ref* get-ref
] with-scope
] with-scope
] unit-test
[ elephant ] [
rabbit <var-ref>
[
elephant set-ref* [
rabbit set-ref*
] with-scope
get-ref
] with-scope
] unit-test
! Top Hats
[ lion ] [ lion rabbit set-global rabbit <global-var-ref> get-ref ] unit-test
[ giraffe ] [ rabbit <global-var-ref> giraffe set-ref* get-ref ] unit-test
! Tuple refs
TUPLE: foo bar ;
C: <foo> foo
: test-tuple ( -- tuple )
rabbit <foo> ;
: test-slot-ref ( -- slot-ref )
test-tuple 2 <slot-ref> ; ! hack!
[ rabbit ] [ test-slot-ref get-ref ] unit-test
[ lion ] [ test-slot-ref lion set-ref* get-ref ] unit-test
! Boxes as refs
[ rabbit ] [ <box> rabbit set-ref* get-ref ] unit-test
[ <box> rabbit set-ref* lion set-ref* ] must-fail
[ <box> get-ref ] must-fail

View File

@ -1,22 +1,77 @@
! Copyright (C) 2007, 2008 Slava Pestov ! Copyright (C) 2007, 2008 Slava Pestov, 2009 Alex Chapman
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: classes.tuple kernel assocs accessors ; USING: kernel assocs accessors boxes math namespaces ;
IN: refs IN: refs
TUPLE: ref assoc key ; MIXIN: ref
: >ref< ( ref -- key value ) [ key>> ] [ assoc>> ] bi ; inline
: delete-ref ( ref -- ) >ref< delete-at ;
GENERIC: get-ref ( ref -- obj ) GENERIC: get-ref ( ref -- obj )
GENERIC: set-ref ( obj ref -- ) GENERIC: set-ref ( obj ref -- )
GENERIC: delete-ref ( ref -- )
TUPLE: key-ref < ref ; ! works like >>slot words
: set-ref* ( ref obj -- ref ) over set-ref ;
! very similar to change, on, off, +@, inc, and dec from namespaces
: change-ref ( ref quot -- )
[ [ get-ref ] keep ] dip dip set-ref ; inline
: ref-on ( ref -- ) t swap set-ref ;
: ref-off ( ref -- ) f swap set-ref ;
: ref-+@ ( n ref -- ) [ 0 or + ] change-ref ;
: ref-inc ( ref -- ) 1 swap ref-+@ ;
: ref-dec ( ref -- ) -1 swap ref-+@ ;
: take ( ref -- obj )
dup get-ref swap delete-ref ;
! delete-ref defaults to setting ref to f
M: ref delete-ref ref-off ;
TUPLE: obj-ref obj ;
C: <obj-ref> obj-ref
M: obj-ref get-ref obj>> ;
M: obj-ref set-ref (>>obj) ;
INSTANCE: obj-ref ref
TUPLE: var-ref var ;
C: <var-ref> var-ref
M: var-ref get-ref var>> get ;
M: var-ref set-ref var>> set ;
INSTANCE: var-ref ref
TUPLE: global-var-ref var ;
C: <global-var-ref> global-var-ref
M: global-var-ref get-ref var>> get-global ;
M: global-var-ref set-ref var>> set-global ;
INSTANCE: global-var-ref ref
USE: slots.private
TUPLE: slot-ref tuple slot ;
C: <slot-ref> slot-ref
: >slot-ref< ( slot-ref -- tuple slot ) [ tuple>> ] [ slot>> ] bi ; inline
M: slot-ref get-ref >slot-ref< slot ;
M: slot-ref set-ref >slot-ref< set-slot ;
INSTANCE: slot-ref ref
M: box get-ref box> ;
M: box set-ref >box ;
M: box delete-ref box> drop ;
INSTANCE: box ref
TUPLE: assoc-ref assoc key ;
: >assoc-ref< ( assoc-ref -- key value ) [ key>> ] [ assoc>> ] bi ; inline
M: assoc-ref delete-ref ( assoc-ref -- ) >assoc-ref< delete-at ;
TUPLE: key-ref < assoc-ref ;
C: <key-ref> key-ref C: <key-ref> key-ref
M: key-ref get-ref key>> ; M: key-ref get-ref key>> ;
M: key-ref set-ref >ref< rename-at ; M: key-ref set-ref >assoc-ref< rename-at ;
INSTANCE: key-ref ref
TUPLE: value-ref < ref ; TUPLE: value-ref < assoc-ref ;
C: <value-ref> value-ref C: <value-ref> value-ref
M: value-ref get-ref >ref< at ; M: value-ref get-ref >assoc-ref< at ;
M: value-ref set-ref >ref< set-at ; M: value-ref set-ref >assoc-ref< set-at ;
INSTANCE: value-ref ref

View File

@ -262,11 +262,11 @@ IN: regexp-tests
! Comment inside a regular expression ! Comment inside a regular expression
[ t ] [ "ac" "a(?#boo)c" <regexp> matches? ] unit-test [ t ] [ "ac" "a(?#boo)c" <regexp> matches? ] unit-test
[ ] [ "USING: regexp kernel ; R' -{3}[+]{1,6}(?:!!)?\\s' drop" (( -- )) eval ] unit-test [ ] [ "USING: regexp kernel ; R' -{3}[+]{1,6}(?:!!)?\\s' drop" eval( -- ) ] unit-test
[ ] [ "USING: regexp kernel ; R' (ftp|http|https)://(\\w+:?\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?' drop" (( -- )) eval ] unit-test [ ] [ "USING: regexp kernel ; R' (ftp|http|https)://(\\w+:?\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?' drop" eval( -- ) ] unit-test
[ ] [ "USING: regexp kernel ; R' \\*[^\s*][^*]*\\*' drop" (( -- )) eval ] unit-test [ ] [ "USING: regexp kernel ; R' \\*[^\s*][^*]*\\*' drop" eval( -- ) ] unit-test
[ "ab" ] [ "ab" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test [ "ab" ] [ "ab" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
[ "abc" ] [ "abc" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test [ "abc" ] [ "abc" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test

View File

@ -1,3 +1,5 @@
Elie Chaftari Elie Chaftari
Dirk Vleugels Dirk Vleugels
Slava Pestov Slava Pestov
Doug Coleman
Daniel Ehrenberg

View File

@ -36,6 +36,7 @@ SYMBOL: data-mode
: process ( -- ) : process ( -- )
read-crlf { read-crlf {
{ [ dup not ] [ f ] }
{ {
[ dup [ "HELO" head? ] [ "EHLO" head? ] bi or ] [ dup [ "HELO" head? ] [ "EHLO" head? ] bi or ]
[ "220 and..?\r\n" write flush t ] [ "220 and..?\r\n" write flush t ]

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel quotations help.syntax help.markup USING: accessors kernel quotations help.syntax help.markup
io.sockets strings calendar ; io.sockets strings calendar io.encodings.utf8 ;
IN: smtp IN: smtp
HELP: smtp-domain HELP: smtp-domain
@ -42,6 +42,8 @@ HELP: email
{ { $slot "cc" } "Carbon-copy. A sequence of e-mail addresses." } { { $slot "cc" } "Carbon-copy. A sequence of e-mail addresses." }
{ { $slot "bcc" } "Blind carbon-copy. A sequence of e-mail addresses." } { { $slot "bcc" } "Blind carbon-copy. A sequence of e-mail addresses." }
{ { $slot "subject" } "The subject of the e-mail. A string." } { { $slot "subject" } "The subject of the e-mail. A string." }
{ { $slot "content-type" } { "The MIME type of the body. A string, default is " { $snippet "text/plain" } "." } }
{ { $slot "encoding" } { "An encoding to send the body as. Default is " { $link utf8 } "." } }
{ { $slot "body" } " The body of the e-mail. A string." } { { $slot "body" } " The body of the e-mail. A string." }
} }
"The " { $slot "from" } " and " { $slot "to" } " slots are required; the rest are optional." "The " { $slot "from" } " and " { $slot "to" } " slots are required; the rest are optional."

View File

@ -16,7 +16,7 @@ IN: smtp.tests
[ { "hello" "." "world" } validate-message ] must-fail [ { "hello" "." "world" } validate-message ] must-fail
[ "aGVsbG8Kd29ybGQ=\r\n.\r\n" ] [ [ "aGVsbG8Kd29ybGQ=\r\n.\r\n" ] [
"hello\nworld" [ send-body ] with-string-writer T{ email { body "hello\nworld" } } [ send-body ] with-string-writer
] unit-test ] unit-test
[ { "500 syntax error" } <response> check-response ] [ { "500 syntax error" } <response> check-response ]
@ -51,7 +51,7 @@ IN: smtp.tests
[ [
{ {
{ "Content-Transfer-Encoding" "base64" } { "Content-Transfer-Encoding" "base64" }
{ "Content-Type" "Text/plain; charset=utf-8" } { "Content-Type" "text/plain; charset=UTF-8" }
{ "From" "Doug <erg@factorcode.org>" } { "From" "Doug <erg@factorcode.org>" }
{ "MIME-Version" "1.0" } { "MIME-Version" "1.0" }
{ "Subject" "Factor rules" } { "Subject" "Factor rules" }

View File

@ -1,12 +1,12 @@
! Copyright (C) 2007, 2008 Elie CHAFTARI, Dirk Vleugels, ! Copyright (C) 2007, 2008 Elie CHAFTARI, Dirk Vleugels,
! Slava Pestov, Doug Coleman. ! Slava Pestov, Doug Coleman, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: arrays namespaces make io io.encodings.string USING: arrays namespaces make io io.encodings.string io.encodings.utf8
io.encodings.utf8 io.timeouts io.sockets io.sockets.secure io.encodings.iana io.timeouts io.sockets io.sockets.secure
io.encodings.ascii kernel logging sequences combinators io.encodings.ascii kernel logging sequences combinators splitting
splitting assocs strings math.order math.parser random system assocs strings math.order math.parser random system calendar summary
calendar summary calendar.format accessors sets hashtables calendar.format accessors sets hashtables base64 debugger classes
base64 debugger classes prettyprint io.crlf ; prettyprint io.crlf words ;
IN: smtp IN: smtp
SYMBOL: smtp-domain SYMBOL: smtp-domain
@ -44,6 +44,8 @@ TUPLE: email
{ cc array } { cc array }
{ bcc array } { bcc array }
{ subject string } { subject string }
{ content-type string initial: "text/plain" }
{ encoding word initial: utf8 }
{ body string } ; { body string } ;
: <email> ( -- email ) email new ; inline : <email> ( -- email ) email new ; inline
@ -85,8 +87,8 @@ M: message-contains-dot summary ( obj -- string )
"." over member? "." over member?
[ message-contains-dot ] when ; [ message-contains-dot ] when ;
: send-body ( body -- ) : send-body ( email -- )
utf8 encode [ body>> ] [ encoding>> ] bi encode
>base64-lines write crlf >base64-lines write crlf
"." command ; "." command ;
@ -162,9 +164,8 @@ M: plain-auth send-auth
: encode-header ( string -- string' ) : encode-header ( string -- string' )
dup aux>> [ dup aux>> [
"=?utf-8?B?" utf8 encode >base64
swap utf8 encode >base64 "=?utf-8?B?" "?=" surround
"?=" 3append
] when ; ] when ;
ERROR: invalid-header-string string ; ERROR: invalid-header-string string ;
@ -195,24 +196,23 @@ ERROR: invalid-header-string string ;
! This could be much smarter. ! This could be much smarter.
" " split1-last swap or "<" ?head drop ">" ?tail drop ; " " split1-last swap or "<" ?head drop ">" ?tail drop ;
: utf8-mime-header ( -- alist ) : email-content-type ( email -- content-type )
{ [ content-type>> ] [ encoding>> encoding>name ] bi "; charset=" glue ;
{ "MIME-Version" "1.0" }
{ "Content-Transfer-Encoding" "base64" }
{ "Content-Type" "Text/plain; charset=utf-8" }
} ;
: email>headers ( email -- hashtable ) : email>headers ( email -- assoc )
[ [
now timestamp>rfc822 "Date" set
message-id "Message-Id" set
"1.0" "MIME-Version" set
"base64" "Content-Transfer-Encoding" set
{ {
[ from>> "From" set ] [ from>> "From" set ]
[ to>> ", " join "To" set ] [ to>> ", " join "To" set ]
[ cc>> ", " join [ "Cc" set ] unless-empty ] [ cc>> ", " join [ "Cc" set ] unless-empty ]
[ subject>> "Subject" set ] [ subject>> "Subject" set ]
[ email-content-type "Content-Type" set ]
} cleave } cleave
now timestamp>rfc822 "Date" set ] { } make-assoc ;
message-id "Message-Id" set
] { } make-assoc utf8-mime-header append ;
: (send-email) ( headers email -- ) : (send-email) ( headers email -- )
[ [
@ -227,7 +227,7 @@ ERROR: invalid-header-string string ;
data get-ok data get-ok
swap write-headers swap write-headers
crlf crlf
body>> send-body get-ok send-body get-ok
quit get-ok quit get-ok
] with-smtp-connection ; ] with-smtp-connection ;

View File

@ -6,19 +6,21 @@ IN: sorting.slots
HELP: compare-slots HELP: compare-slots
{ $values { $values
{ "obj1" object }
{ "obj2" object }
{ "sort-specs" "a sequence of accessors ending with a comparator" } { "sort-specs" "a sequence of accessors ending with a comparator" }
{ "<=>" { $link +lt+ } " " { $link +eq+ } " or " { $link +gt+ } } { "<=>" { $link +lt+ } " " { $link +eq+ } " or " { $link +gt+ } }
} }
{ $description "Compares two objects using a chain of intrinsic linear orders such that if two objects are " { $link +eq+ } ", then the next comparator is tried. The comparators are slot-name/comparator pairs." } ; { $description "Compares two objects using a chain of intrinsic linear orders such that if two objects are " { $link +eq+ } ", then the next comparator is tried. The comparators are slot-name/comparator pairs." } ;
HELP: sort-by-slots HELP: sort-by
{ $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" }
{ "sortedseq" sequence } { "seq'" 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
"Sort by slot c, then b descending:" "Sort by slot a, then b descending:"
{ $example { $example
"USING: accessors math.order prettyprint sorting.slots ;" "USING: accessors math.order prettyprint sorting.slots ;"
"IN: scratchpad" "IN: scratchpad"
@ -27,32 +29,18 @@ HELP: sort-by-slots
" T{ sort-me f 2 3 } T{ sort-me f 3 2 }" " T{ sort-me f 2 3 } T{ sort-me f 3 2 }"
" T{ sort-me f 4 3 } T{ sort-me f 2 1 }" " T{ sort-me f 4 3 } T{ sort-me f 2 1 }"
"}" "}"
"{ { a>> <=> } { b>> >=< } } sort-by-slots ." "{ { a>> <=> } { b>> >=< } } sort-by ."
"{\n T{ sort-me { a 2 } { b 3 } }\n T{ sort-me { a 2 } { b 1 } }\n T{ sort-me { a 3 } { b 2 } }\n T{ sort-me { a 4 } { b 3 } }\n}" "{\n T{ sort-me { a 2 } { b 3 } }\n T{ sort-me { a 2 } { b 1 } }\n T{ sort-me { a 3 } { b 2 } }\n T{ sort-me { a 4 } { b 3 } }\n}"
} }
} ; } ;
HELP: split-by-slots
{ $values
{ "accessor-seqs" "a sequence of sequences of tuple accessors" }
{ "quot" quotation }
}
{ $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 of tuples by a slot/comparator pairs:" "Sorting a sequence of tuples by a slot/comparator pairs:"
{ $subsection sort-by-slots } { $subsection sort-by }
"Sorting a sequence by a sequence of comparators:" { $subsection sort-keys-by }
{ $subsection sort-by } ; { $subsection sort-values-by } ;
ABOUT: "sorting.slots" ABOUT: "sorting.slots"

View File

@ -24,7 +24,7 @@ TUPLE: tuple2 d ;
T{ sort-test f 1 1 11 } T{ sort-test f 1 1 11 }
T{ sort-test f 2 5 3 } T{ sort-test f 2 5 3 }
T{ sort-test f 2 5 2 } T{ sort-test f 2 5 2 }
} { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by-slots } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by
] unit-test ] unit-test
[ [
@ -42,43 +42,14 @@ TUPLE: tuple2 d ;
T{ sort-test f 1 1 11 } T{ sort-test f 1 1 11 }
T{ sort-test f 2 5 3 } T{ sort-test f 2 5 3 }
T{ sort-test f 2 5 2 } T{ sort-test f 2 5 2 }
} { { a>> human<=> } { b>> human>=< } { c>> <=> } } sort-by-slots } { { a>> human<=> } { b>> human>=< } { c>> <=> } } sort-by
] unit-test ] unit-test
[ [ { } ]
{ [ { } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by ] unit-test
{
T{ sort-test { a 1 } { b 1 } { c 10 } }
T{ sort-test { a 1 } { b 1 } { c 11 } }
}
{ T{ sort-test { a 1 } { b 3 } { c 9 } } }
{
T{ sort-test { a 2 } { b 5 } { c 3 } }
T{ sort-test { a 2 } { b 5 } { c 2 } }
}
}
] [
{
T{ sort-test f 1 3 9 }
T{ sort-test f 1 1 10 }
T{ sort-test f 1 1 11 }
T{ sort-test f 2 5 3 }
T{ sort-test f 2 5 2 }
}
{ { a>> human<=> } { b>> <=> } } [ sort-by-slots ] keep
[ but-last-slice ] map split-by-slots [ >array ] map
] unit-test
: split-test ( seq -- seq' )
{ { a>> } { b>> } } split-by-slots ;
[ split-test ] must-infer
[ { } ] [ { } ]
[ { } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by-slots ] unit-test [ { } { } sort-by ] unit-test
[ { } ]
[ { } { } sort-by-slots ] unit-test
[ [
{ {
@ -97,55 +68,7 @@ TUPLE: tuple2 d ;
T{ sort-test f 6 f f T{ tuple2 f 3 } } T{ sort-test f 6 f f T{ tuple2 f 3 } }
T{ sort-test f 5 f f T{ tuple2 f 3 } } T{ sort-test f 5 f f T{ tuple2 f 3 } }
T{ sort-test f 6 f f T{ tuple2 f 2 } } T{ sort-test f 6 f f T{ tuple2 f 2 } }
} { { tuple2>> d>> <=> } { a>> <=> } } sort-by-slots } { { tuple2>> d>> <=> } { a>> <=> } } sort-by
] unit-test
[
{
{
T{ sort-test
{ a 6 }
{ tuple2 T{ tuple2 { d 1 } } }
}
}
{
T{ sort-test
{ a 6 }
{ tuple2 T{ tuple2 { d 2 } } }
}
}
{
T{ sort-test
{ a 5 }
{ tuple2 T{ tuple2 { d 3 } } }
}
}
{
T{ sort-test
{ a 6 }
{ tuple2 T{ tuple2 { d 3 } } }
}
T{ sort-test
{ a 6 }
{ tuple2 T{ tuple2 { d 3 } } }
}
}
{
T{ sort-test
{ a 5 }
{ tuple2 T{ tuple2 { d 4 } } }
}
}
}
] [
{
T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 1 } } } }
T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 2 } } } }
T{ sort-test { a 5 } { tuple2 T{ tuple2 { d 3 } } } }
T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 3 } } } }
T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 3 } } } }
T{ sort-test { a 5 } { tuple2 T{ tuple2 { d 4 } } } }
} { { tuple2>> d>> } { a>> } } split-by-slots [ >array ] map
] unit-test ] unit-test
@ -159,3 +82,15 @@ TUPLE: tuple2 d ;
{ { 3 2 1 } { 1 2 3 } { 1 3 2 } { 1 } } { { 3 2 1 } { 1 2 3 } { 1 3 2 } { 1 } }
{ length-test<=> <=> } sort-by { length-test<=> <=> } sort-by
] unit-test ] unit-test
[ { { 0 1 } { 1 2 } { 1 1 } { 3 2 } } ]
[
{ { 3 2 } { 1 2 } { 0 1 } { 1 1 } }
{ length-test<=> <=> } sort-keys-by
] unit-test
[ { { 0 1 } { 1 1 } { 3 2 } { 1 2 } } ]
[
{ { 3 2 } { 1 2 } { 0 1 } { 1 1 } }
{ length-test<=> <=> } sort-values-by
] unit-test

View File

@ -1,45 +1,28 @@
! Copyright (C) 2009 Slava Pestov, Doug Coleman. ! Copyright (C) 2009 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: combinators.short-circuit fry kernel macros math.order USING: arrays fry kernel math.order sequences sorting ;
sequences words sorting sequences.deep assocs splitting.monotonic
math ;
IN: sorting.slots IN: sorting.slots
<PRIVATE : execute-comparator ( obj1 obj2 word -- <=>/f )
execute( obj1 obj2 -- <=> ) dup +eq+ eq? [ drop f ] when ;
: short-circuit-comparator ( obj1 obj2 word -- comparator/? ) : execute-accessor ( obj1 obj2 word -- obj1' obj2' )
execute dup +eq+ eq? [ drop f ] when ; inline '[ _ execute( tuple -- value ) ] bi@ ;
: slot-comparator ( seq -- quot ) : compare-slots ( obj1 obj2 sort-specs -- <=> )
[
but-last-slice
[ '[ [ _ execute ] bi@ ] ] map concat
] [
peek
'[ @ _ short-circuit-comparator ]
] bi ;
PRIVATE>
MACRO: compare-slots ( sort-specs -- <=> )
#! sort-spec: { accessors comparator } #! sort-spec: { accessors comparator }
[ slot-comparator ] map '[ _ 2|| +eq+ or ] ; [
dup array? [
unclip-last-slice
[ [ execute-accessor ] each ] dip
] when execute-comparator
] with with map-find drop +eq+ or ;
MACRO: sort-by-slots ( sort-specs -- quot ) : sort-by-with ( seq sort-specs quot -- seq' )
'[ [ _ compare-slots ] sort ] ; swap '[ _ bi@ _ compare-slots ] sort ; inline
MACRO: compare-seq ( seq -- quot ) : sort-by ( seq sort-specs -- seq' ) [ ] sort-by-with ;
[ '[ _ short-circuit-comparator ] ] map '[ _ 2|| +eq+ or ] ;
MACRO: sort-by ( sort-seq -- quot ) : sort-keys-by ( seq sort-seq -- seq' ) [ first ] sort-by-with ;
'[ [ _ compare-seq ] sort ] ;
MACRO: sort-keys-by ( sort-seq -- quot ) : sort-values-by ( seq sort-seq -- seq' ) [ second ] sort-by-with ;
'[ [ first ] bi@ _ compare-seq ] sort ;
MACRO: sort-values-by ( sort-seq -- quot )
'[ [ second ] bi@ _ compare-seq ] sort ;
MACRO: split-by-slots ( accessor-seqs -- quot )
[ [ '[ [ _ execute ] bi@ ] ] map concat [ = ] compose ] map
'[ [ _ 2&& ] slice monotonic-slice ] ;

View File

@ -524,7 +524,7 @@ ERROR: custom-error ;
{ 2 1 } [ [ + ] inference-invalidation-b ] must-infer-as { 2 1 } [ [ + ] inference-invalidation-b ] must-infer-as
[ ] [ "IN: stack-checker.tests : inference-invalidation-a ( -- a b ) 1 2 ;" (( -- )) eval ] unit-test [ ] [ "IN: stack-checker.tests : inference-invalidation-a ( -- a b ) 1 2 ;" eval( -- ) ] unit-test
[ 3 ] [ inference-invalidation-c ] unit-test [ 3 ] [ inference-invalidation-c ] unit-test
@ -536,7 +536,7 @@ M: object inference-invalidation-d inference-invalidation-c 2drop ;
\ inference-invalidation-d must-infer \ inference-invalidation-d must-infer
[ ] [ "IN: stack-checker.tests : inference-invalidation-a ( -- ) ;" (( -- )) eval ] unit-test [ ] [ "IN: stack-checker.tests : inference-invalidation-a ( -- ) ;" eval( -- ) ] unit-test
[ [ inference-invalidation-d ] infer ] must-fail [ [ inference-invalidation-d ] infer ] must-fail

View File

@ -18,7 +18,7 @@ M: integer some-generic 1+ ;
[ 4 ] [ 3 some-generic ] unit-test [ 4 ] [ 3 some-generic ] unit-test
[ ] [ "IN: tools.annotations.tests USE: math M: integer some-generic 1- ;" (( -- )) eval ] unit-test [ ] [ "IN: tools.annotations.tests USE: math M: integer some-generic 1- ;" eval( -- ) ] unit-test
[ 2 ] [ 3 some-generic ] unit-test [ 2 ] [ 3 some-generic ] unit-test
@ -33,7 +33,7 @@ M: object another-generic ;
\ another-generic watch \ another-generic watch
[ ] [ "IN: tools.annotations.tests GENERIC: another-generic ( a -- b )" (( -- )) eval ] unit-test [ ] [ "IN: tools.annotations.tests GENERIC: another-generic ( a -- b )" eval( -- ) ] unit-test
[ ] [ \ another-generic reset ] unit-test [ ] [ \ another-generic reset ] unit-test

View File

@ -3,20 +3,20 @@
USING: accessors kernel arrays sequences math namespaces USING: accessors kernel arrays sequences math namespaces
strings io fry vectors words assocs combinators sorting strings io fry vectors words assocs combinators sorting
unicode.case unicode.categories math.order vocabs unicode.case unicode.categories math.order vocabs
tools.vocabs unicode.data ; tools.vocabs unicode.data locals ;
IN: tools.completion IN: tools.completion
: (fuzzy) ( accum ch i full -- accum i ? ) :: (fuzzy) ( accum i full ch -- accum i full ? )
index-from ch i full index-from [
[ :> i i accum push
[ swap push ] 2keep 1+ t accum i 1+ full t
] [ ] [
drop f -1 f f -1 full f
] if* ; ] if* ;
: fuzzy ( full short -- indices ) : fuzzy ( full short -- indices )
dup length <vector> -rot 0 -rot dup [ length <vector> 0 ] curry 2dip
[ -rot [ (fuzzy) ] keep swap ] all? 3drop ; [ (fuzzy) ] all? 3drop ;
: (runs) ( runs n seq -- runs n ) : (runs) ( runs n seq -- runs n )
[ [

View File

@ -357,7 +357,7 @@ IN: tools.deploy.shaker
V{ } set-namestack V{ } set-namestack
V{ } set-catchstack V{ } set-catchstack
"Saving final image" show "Saving final image" show
[ save-image-and-exit ] call-clear ; save-image-and-exit ;
SYMBOL: deploy-vocab SYMBOL: deploy-vocab
@ -421,10 +421,10 @@ SYMBOL: deploy-vocab
: deploy-error-handler ( quot -- ) : deploy-error-handler ( quot -- )
[ [
strip-debugger? strip-debugger?
[ error-continuation get call>> callstack>array die ] [ error-continuation get call>> callstack>array die 1 exit ]
! Don't reference these words literally, if we're stripping the ! Don't reference these words literally, if we're stripping the
! debugger out we don't want to load the prettyprinter at all ! debugger out we don't want to load the prettyprinter at all
[ [:c] execute nl [print-error] execute flush ] if [ [:c] execute( -- ) nl [print-error] execute( error -- ) flush ] if
1 exit 1 exit
] recover ; inline ] recover ; inline

View File

@ -1,5 +1,35 @@
IN: tools.errors IN: tools.errors
USING: help.markup help.syntax source-files.errors ; USING: help.markup help.syntax source-files.errors words io
compiler.errors ;
ARTICLE: "compiler-errors" "Compiler warnings and errors"
"After loading a vocabulary, you might see messages like:"
{ $code
":errors - print 2 compiler errors"
":warnings - print 50 compiler warnings"
}
"These messages arise from the compiler's stack effect checker. Production code should not have any warnings and errors in it. Warning and error conditions are documented in " { $link "inference-errors" } "."
$nl
"Words to view warnings and errors:"
{ $subsection :warnings }
{ $subsection :errors }
{ $subsection :linkage }
"Compiler warnings and errors are reported using the " { $link "tools.errors" } " mechanism and are shown in the " { $link "ui.tools.error-list" } "." ;
HELP: compiler-error
{ $values { "error" "an error" } { "word" word } }
{ $description "Saves the error for future persual via " { $link :errors } ", " { $link :warnings } " and " { $link :linkage } "." } ;
HELP: :errors
{ $description "Prints all serious compiler errors from the most recent compile to " { $link output-stream } "." } ;
HELP: :warnings
{ $description "Prints all ignorable compiler warnings from the most recent compile to " { $link output-stream } "." } ;
HELP: :linkage
{ $description "Prints all C library interface linkage errors from the most recent compile to " { $link output-stream } "." } ;
{ :errors :warnings :linkage } related-words
HELP: errors. HELP: errors.
{ $values { "errors" "a sequence of " { $link source-file-error } " instances" } } { $values { "errors" "a sequence of " { $link source-file-error } " instances" } }

View File

@ -1,35 +1,28 @@
! 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: assocs debugger io kernel sequences source-files.errors USING: assocs debugger io kernel sequences source-files.errors
summary accessors continuations make math.parser io.styles namespaces ; summary accessors continuations make math.parser io.styles namespaces
compiler.errors ;
IN: tools.errors IN: tools.errors
#! Tools for source-files.errors. Used by tools.tests and others #! Tools for source-files.errors. Used by tools.tests and others
#! for error reporting #! for error reporting
M: source-file-error summary
error>> summary ;
M: source-file-error compute-restarts M: source-file-error compute-restarts
error>> compute-restarts ; error>> compute-restarts ;
M: source-file-error error-help M: source-file-error error-help
error>> error-help ; error>> error-help ;
M: source-file-error error. M: source-file-error summary
[ [
[ [ file>> [ % ": " % ] [ "<Listener input>" % ] if* ]
[ [ line#>> [ # ] when* ] bi
[ file>> [ % ": " % ] when* ]
[ line#>> [ # "\n" % ] when* ] bi
] "" make ] "" make
] [ ;
[
presented set M: source-file-error error.
bold font-style set [ summary print nl ] [ error>> error. ] bi ;
] H{ } make-assoc
] bi format
] [ error>> error. ] bi ;
: errors. ( errors -- ) : errors. ( errors -- )
group-by-source-file sort-errors group-by-source-file sort-errors
@ -38,3 +31,12 @@ M: source-file-error error.
[ [ nl ] [ error. ] interleave ] [ [ nl ] [ error. ] interleave ]
bi* bi*
] assoc-each ; ] assoc-each ;
: compiler-errors. ( type -- )
errors-of-type values errors. ;
: :errors ( -- ) +compiler-error+ compiler-errors. ;
: :warnings ( -- ) +compiler-warning+ compiler-errors. ;
: :linkage ( -- ) +linkage-error+ compiler-errors. ;

View File

@ -75,7 +75,7 @@ M: object file-spec>string ( file-listing spec -- string )
: list-files-slow ( listing-tool -- array ) : list-files-slow ( listing-tool -- array )
[ path>> ] [ sort>> ] [ specs>> ] tri '[ [ path>> ] [ sort>> ] [ specs>> ] tri '[
[ dup name>> file-info file-listing boa ] map [ dup name>> file-info file-listing boa ] map
_ [ sort-by-slots ] when* _ [ sort-by ] when*
[ _ [ file-spec>string ] with map ] map [ _ [ file-spec>string ] with map ] map
] with-directory-entries ; inline ] with-directory-entries ; inline

View File

@ -5,7 +5,8 @@ io.encodings.utf8 hashtables kernel namespaces sequences
vocabs.loader io combinators calendar accessors math.parser vocabs.loader io combinators calendar accessors math.parser
io.streams.string ui.tools.operations quotations strings arrays io.streams.string ui.tools.operations quotations strings arrays
prettyprint words vocabs sorting sets classes math alien urls prettyprint words vocabs sorting sets classes math alien urls
splitting ascii combinators.short-circuit alarms words.symbol ; splitting ascii combinators.short-circuit alarms words.symbol
system ;
IN: tools.scaffold IN: tools.scaffold
SYMBOL: developer-name SYMBOL: developer-name
@ -24,6 +25,9 @@ ERROR: no-vocab vocab ;
: contains-separator? ( string -- ? ) [ path-separator? ] any? ; : contains-separator? ( string -- ? ) [ path-separator? ] any? ;
: ensure-vocab-exists ( string -- string )
dup vocabs member? [ no-vocab ] unless ;
: check-vocab-name ( string -- string ) : check-vocab-name ( string -- string )
[ ] [ ]
[ contains-dot? [ vocab-name-contains-dot ] when ] [ contains-dot? [ vocab-name-contains-dot ] when ]
@ -234,6 +238,7 @@ PRIVATE>
[ (help.) ] [ nl vocabulary>> link-vocab ] bi ; [ (help.) ] [ nl vocabulary>> link-vocab ] bi ;
: scaffold-help ( vocab -- ) : scaffold-help ( vocab -- )
ensure-vocab-exists
[ [
dup "-docs.factor" vocab/suffix>path scaffolding? [ dup "-docs.factor" vocab/suffix>path scaffolding? [
set-scaffold-docs-file set-scaffold-docs-file
@ -268,6 +273,7 @@ PRIVATE>
PRIVATE> PRIVATE>
: scaffold-tests ( vocab -- ) : scaffold-tests ( vocab -- )
ensure-vocab-exists
dup "-tests.factor" vocab/suffix>path dup "-tests.factor" vocab/suffix>path
scaffolding? [ scaffolding? [
set-scaffold-tests-file set-scaffold-tests-file
@ -296,8 +302,10 @@ SYMBOL: examples-flag
[ home ] dip append-path [ home ] dip append-path
[ touch-file ] [ "Click to edit: " write <pathname> . ] bi ; [ touch-file ] [ "Click to edit: " write <pathname> . ] bi ;
: scaffold-factor-boot-rc ( -- ) ".factor-boot-rc" scaffold-rc ; : scaffold-factor-boot-rc ( -- )
os windows? "factor-boot-rc" ".factor-boot-rc" ? scaffold-rc ;
: scaffold-factor-rc ( -- ) ".factor-rc" scaffold-rc ; : scaffold-factor-rc ( -- )
os windows? "factor-rc" ".factor-rc" ? scaffold-rc ;
: scaffold-emacs ( -- ) ".emacs" scaffold-rc ; : scaffold-emacs ( -- ) ".emacs" scaffold-rc ;

View File

@ -129,13 +129,13 @@ TEST: must-infer
TEST: must-fail-with TEST: must-fail-with
TEST: must-fail TEST: must-fail
M: test-failure summary
asset>> [ [ experiment. ] with-string-writer ] [ "Top-level form" ] if* ;
M: test-failure error. ( error -- ) M: test-failure error. ( error -- )
[ call-next-method ] {
[ summary print nl ]
[ asset>> [ experiment. nl ] when* ]
[ error>> error. ]
[ traceback-button. ] [ traceback-button. ]
bi ; } cleave ;
: :test-failures ( -- ) test-failures get errors. ; : :test-failures ( -- ) test-failures get errors. ;

View File

@ -3,11 +3,11 @@
USING: accessors alien alien.c-types arrays ui ui.private ui.gadgets USING: accessors alien alien.c-types arrays ui ui.private ui.gadgets
ui.gadgets.private ui.gestures ui.backend ui.clipboards ui.gadgets.private ui.gestures ui.backend ui.clipboards
ui.gadgets.worlds ui.render ui.event-loop assocs kernel math ui.gadgets.worlds ui.render ui.event-loop assocs kernel math
namespaces opengl sequences strings x11.xlib x11.events x11.xim namespaces opengl sequences strings x11 x11.xlib x11.events x11.xim
x11.glx x11.clipboard x11.constants x11.windows io.encodings.string x11.glx x11.clipboard x11.constants x11.windows x11.io
io.encodings.ascii io.encodings.utf8 combinators command-line io.encodings.string io.encodings.ascii io.encodings.utf8 combinators
math.vectors classes.tuple opengl.gl threads math.rectangles command-line math.vectors classes.tuple opengl.gl threads
environment ascii ; math.rectangles environment ascii ;
IN: ui.backend.x11 IN: ui.backend.x11
SINGLETON: x11-ui-backend SINGLETON: x11-ui-backend
@ -196,7 +196,7 @@ M: world client-event
QueuedAfterFlush events-queued 0 > [ QueuedAfterFlush events-queued 0 > [
next-event dup next-event dup
None XFilterEvent 0 = [ drop wait-event ] unless None XFilterEvent 0 = [ drop wait-event ] unless
] [ ui-wait wait-event ] if ; ] [ wait-for-display wait-event ] if ;
M: x11-ui-backend do-events M: x11-ui-backend do-events
wait-event dup XAnyEvent-window window dup wait-event dup XAnyEvent-window window dup

View File

@ -3,7 +3,7 @@
USING: accessors arrays hashtables kernel models math namespaces USING: accessors arrays hashtables kernel models math namespaces
make sequences quotations math.vectors combinators sorting make sequences quotations math.vectors combinators sorting
binary-search vectors dlists deques models threads binary-search vectors dlists deques models threads
concurrency.flags math.order math.rectangles fry ; concurrency.flags math.order math.rectangles fry locals ;
IN: ui.gadgets IN: ui.gadgets
! Values for orientation slot ! Values for orientation slot
@ -66,8 +66,8 @@ M: gadget children-on nip children>> ;
: ((fast-children-on)) ( gadget dim axis -- <=> ) : ((fast-children-on)) ( gadget dim axis -- <=> )
[ swap loc>> v- ] dip v. 0 <=> ; [ swap loc>> v- ] dip v. 0 <=> ;
: (fast-children-on) ( dim axis children -- i ) :: (fast-children-on) ( dim axis children -- i )
-rot '[ _ _ ((fast-children-on)) ] search drop ; children [ dim axis ((fast-children-on)) ] search drop ;
PRIVATE> PRIVATE>

View File

@ -27,7 +27,7 @@ INSTANCE: fake-break word-break
[ { 0 0 } ] [ "a" get loc>> ] unit-test [ { 0 0 } ] [ "a" get loc>> ] unit-test
[ { 45 15 } ] [ "b" get loc>> ] unit-test [ { 45 7 } ] [ "b" get loc>> ] unit-test
[ { 0 30 } ] [ "c" get loc>> ] unit-test [ { 0 30 } ] [ "c" get loc>> ] unit-test

View File

@ -46,7 +46,7 @@ HELP: offset>x
HELP: line-metrics HELP: line-metrics
{ $values { "font" font } { "string" string } { "metrics" line-metrics } } { $values { "font" font } { "string" string } { "metrics" line-metrics } }
{ $contract "Outputs a " { $link line-metrics } " object with text measurements." } ; { $contract "Outputs a " { $link metrics } " object with text measurements." } ;
ARTICLE: "text-rendering" "Rendering text" ARTICLE: "text-rendering" "Rendering text"
"The " { $vocab-link "ui.text" } " vocabulary provides a cross-platform interface to the operating system's native font rendering engine. Currently, it uses Core Text on Mac OS X and FreeType on Windows and X11." "The " { $vocab-link "ui.text" } " vocabulary provides a cross-platform interface to the operating system's native font rendering engine. Currently, it uses Core Text on Mac OS X and FreeType on Windows and X11."

View File

@ -26,7 +26,7 @@ MEMO: error-icon ( type -- image-name )
: <error-toggle> ( -- model gadget ) : <error-toggle> ( -- model gadget )
#! Linkage errors are not shown by default. #! Linkage errors are not shown by default.
error-types get keys [ dup +linkage-error+ eq? not <model> ] { } map>assoc error-types get [ fatal?>> <model> ] assoc-map
[ [ [ error-icon ] dip ] assoc-map <checkboxes> ] [ [ [ error-icon ] dip ] assoc-map <checkboxes> ]
[ <mapping> ] bi ; [ <mapping> ] bi ;
@ -80,7 +80,7 @@ M: error-renderer row-columns
{ {
[ error-type error-icon ] [ error-type error-icon ]
[ line#>> [ number>string ] [ "" ] if* ] [ line#>> [ number>string ] [ "" ] if* ]
[ asset>> unparse-short ] [ asset>> [ unparse-short ] [ "" ] if* ]
[ error>> summary ] [ error>> summary ]
} cleave } cleave
] output>array ; ] output>array ;

View File

@ -358,9 +358,8 @@ interactor "completion" f {
} define-command-map } define-command-map
: ui-error-summary ( -- ) : ui-error-summary ( -- )
all-errors [ error-counts keys [
[ error-type ] map prune [ icon>> 1array \ $image prefix " " 2array ] { } map-as
[ error-icon-path 1array \ $image prefix " " 2array ] { } map-as
{ "Press " { $command tool "common" show-error-list } " to view errors." } { "Press " { $command tool "common" show-error-list } " to view errors." }
append print-element nl append print-element nl
] unless-empty ; ] unless-empty ;

View File

@ -7,7 +7,11 @@ HELP: url-decode
HELP: url-encode HELP: url-encode
{ $values { "str" string } { "encoded" string } } { $values { "str" string } { "encoded" string } }
{ $description "URL-encodes a string." } ; { $description "URL-encodes a string, excluding certain characters, such as \"/\"." } ;
HELP: url-encode-full
{ $values { "str" string } { "encoded" string } }
{ $description "URL-encodes a string, including all reserved characters, such as \"/\"." } ;
HELP: url-quotable? HELP: url-quotable?
{ $values { "ch" "a character" } { "?" "a boolean" } } { $values { "ch" "a character" } { "?" "a boolean" } }

View File

@ -14,6 +14,25 @@ IN: urls.encoding
[ "/_-.:" member? ] [ "/_-.:" member? ]
} 1|| ; foldable } 1|| ; foldable
! see http://tools.ietf.org/html/rfc3986#section-2.2
: gen-delim? ( ch -- ? )
":/?#[]@" member? ; foldable
: sub-delim? ( ch -- ? )
"!$&'()*+,;=" member? ; foldable
: reserved? ( ch -- ? )
[ gen-delim? ] [ sub-delim? ] bi or ; foldable
! see http://tools.ietf.org/html/rfc3986#section-2.3
: unreserved? ( ch -- ? )
{
[ letter? ]
[ LETTER? ]
[ digit? ]
[ "-._~" member? ]
} 1|| ; foldable
<PRIVATE <PRIVATE
: push-utf8 ( ch -- ) : push-utf8 ( ch -- )
@ -27,6 +46,11 @@ PRIVATE>
[ dup url-quotable? [ , ] [ push-utf8 ] if ] each [ dup url-quotable? [ , ] [ push-utf8 ] if ] each
] "" make ; ] "" make ;
: url-encode-full ( str -- encoded )
[
[ dup unreserved? [ , ] [ push-utf8 ] if ] each
] "" make ;
<PRIVATE <PRIVATE
: url-decode-hex ( index str -- ) : url-decode-hex ( index str -- )

View File

@ -1,5 +1,6 @@
USING: alien.syntax kernel math windows.types math.bitwise ; USING: alien.syntax kernel math windows.types math.bitwise ;
IN: windows.advapi32 IN: windows.advapi32
LIBRARY: advapi32 LIBRARY: advapi32
CONSTANT: PROV_RSA_FULL 1 CONSTANT: PROV_RSA_FULL 1
@ -122,6 +123,34 @@ C-STRUCT: ACCESS_ALLOWED_CALLBACK_ACE
TYPEDEF: ACCESS_ALLOWED_CALLBACK_ACE* PACCESS_ALLOWED_CALLBACK_ACE TYPEDEF: ACCESS_ALLOWED_CALLBACK_ACE* PACCESS_ALLOWED_CALLBACK_ACE
C-STRUCT: SECURITY_DESCRIPTOR
{ "UCHAR" "Revision" }
{ "UCHAR" "Sbz1" }
{ "WORD" "Control" }
{ "PVOID" "Owner" }
{ "PVOID" "Group" }
{ "PACL" "Sacl" }
{ "PACL" "Dacl" } ;
TYPEDEF: SECURITY_DESCRIPTOR* PSECURITY_DESCRIPTOR
CONSTANT: SE_OWNER_DEFAULTED 1
CONSTANT: SE_GROUP_DEFAULTED 2
CONSTANT: SE_DACL_PRESENT 4
CONSTANT: SE_DACL_DEFAULTED 8
CONSTANT: SE_SACL_PRESENT 16
CONSTANT: SE_SACL_DEFAULTED 32
CONSTANT: SE_DACL_AUTO_INHERIT_REQ 256
CONSTANT: SE_SACL_AUTO_INHERIT_REQ 512
CONSTANT: SE_DACL_AUTO_INHERITED 1024
CONSTANT: SE_SACL_AUTO_INHERITED 2048
CONSTANT: SE_DACL_PROTECTED 4096
CONSTANT: SE_SACL_PROTECTED 8192
CONSTANT: SE_SELF_RELATIVE 32768
TYPEDEF: DWORD SECURITY_DESCRIPTOR_CONTROL
TYPEDEF: SECURITY_DESCRIPTOR_CONTROL* PSECURITY_DESCRIPTOR_CONTROL
! typedef enum _TOKEN_INFORMATION_CLASS { ! typedef enum _TOKEN_INFORMATION_CLASS {
CONSTANT: TokenUser 1 CONSTANT: TokenUser 1
@ -141,6 +170,140 @@ CONSTANT: TokenSessionReference 14
CONSTANT: TokenSandBoxInert 15 CONSTANT: TokenSandBoxInert 15
! } TOKEN_INFORMATION_CLASS; ! } TOKEN_INFORMATION_CLASS;
TYPEDEF: DWORD ACCESS_MODE
C-ENUM:
NOT_USED_ACCESS
GRANT_ACCESS
SET_ACCESS
DENY_ACCESS
REVOKE_ACCESS
SET_AUDIT_SUCCESS
SET_AUDIT_FAILURE ;
TYPEDEF: DWORD MULTIPLE_TRUSTEE_OPERATION
C-ENUM:
NO_MULTIPLE_TRUSTEE
TRUSTEE_IS_IMPERSONATE ;
TYPEDEF: DWORD TRUSTEE_FORM
C-ENUM:
TRUSTEE_IS_SID
TRUSTEE_IS_NAME
TRUSTEE_BAD_FORM
TRUSTEE_IS_OBJECTS_AND_SID
TRUSTEE_IS_OBJECTS_AND_NAME ;
TYPEDEF: DWORD TRUSTEE_TYPE
C-ENUM:
TRUSTEE_IS_UNKNOWN
TRUSTEE_IS_USER
TRUSTEE_IS_GROUP
TRUSTEE_IS_DOMAIN
TRUSTEE_IS_ALIAS
TRUSTEE_IS_WELL_KNOWN_GROUP
TRUSTEE_IS_DELETED
TRUSTEE_IS_INVALID
TRUSTEE_IS_COMPUTER ;
TYPEDEF: DWORD SE_OBJECT_TYPE
C-ENUM:
SE_UNKNOWN_OBJECT_TYPE
SE_FILE_OBJECT
SE_SERVICE
SE_PRINTER
SE_REGISTRY_KEY
SE_LMSHARE
SE_KERNEL_OBJECT
SE_WINDOW_OBJECT
SE_DS_OBJECT
SE_DS_OBJECT_ALL
SE_PROVIDER_DEFINED_OBJECT
SE_WMIGUID_OBJECT
SE_REGISTRY_WOW64_32KEY ;
TYPEDEF: TRUSTEE* PTRUSTEE
C-STRUCT: TRUSTEE
{ "PTRUSTEE" "pMultipleTrustee" }
{ "MULTIPLE_TRUSTEE_OPERATION" "MultipleTrusteeOperation" }
{ "TRUSTEE_FORM" "TrusteeForm" }
{ "TRUSTEE_TYPE" "TrusteeType" }
{ "LPTSTR" "ptstrName" } ;
C-STRUCT: EXPLICIT_ACCESS
{ "DWORD" "grfAccessPermissions" }
{ "ACCESS_MODE" "grfAccessMode" }
{ "DWORD" "grfInheritance" }
{ "TRUSTEE" "Trustee" } ;
C-STRUCT: SID_IDENTIFIER_AUTHORITY
{ { "BYTE" 6 } "Value" } ;
TYPEDEF: SID_IDENTIFIER_AUTHORITY* PSID_IDENTIFIER_AUTHORITY
CONSTANT: SECURITY_NULL_SID_AUTHORITY 0
CONSTANT: SECURITY_WORLD_SID_AUTHORITY 1
CONSTANT: SECURITY_LOCAL_SID_AUTHORITY 2
CONSTANT: SECURITY_CREATOR_SID_AUTHORITY 3
CONSTANT: SECURITY_NON_UNIQUE_AUTHORITY 4
CONSTANT: SECURITY_NT_AUTHORITY 5
CONSTANT: SECURITY_RESOURCE_MANAGER_AUTHORITY 6
CONSTANT: SECURITY_NULL_RID 0
CONSTANT: SECURITY_WORLD_RID 0
CONSTANT: SECURITY_LOCAL_RID 0
CONSTANT: SECURITY_CREATOR_OWNER_RID 0
CONSTANT: SECURITY_CREATOR_GROUP_RID 1
CONSTANT: SECURITY_CREATOR_OWNER_SERVER_RID 2
CONSTANT: SECURITY_CREATOR_GROUP_SERVER_RID 3
CONSTANT: SECURITY_DIALUP_RID 1
CONSTANT: SECURITY_NETWORK_RID 2
CONSTANT: SECURITY_BATCH_RID 3
CONSTANT: SECURITY_INTERACTIVE_RID 4
CONSTANT: SECURITY_SERVICE_RID 6
CONSTANT: SECURITY_ANONYMOUS_LOGON_RID 7
CONSTANT: SECURITY_PROXY_RID 8
CONSTANT: SECURITY_SERVER_LOGON_RID 9
CONSTANT: SECURITY_PRINCIPAL_SELF_RID 10
CONSTANT: SECURITY_AUTHENTICATED_USER_RID 11
CONSTANT: SECURITY_LOGON_IDS_RID 5
CONSTANT: SECURITY_LOGON_IDS_RID_COUNT 3
CONSTANT: SECURITY_LOCAL_SYSTEM_RID 18
CONSTANT: SECURITY_NT_NON_UNIQUE 21
CONSTANT: SECURITY_BUILTIN_DOMAIN_RID 32
CONSTANT: DOMAIN_USER_RID_ADMIN 500
CONSTANT: DOMAIN_USER_RID_GUEST 501
CONSTANT: DOMAIN_GROUP_RID_ADMINS 512
CONSTANT: DOMAIN_GROUP_RID_USERS 513
CONSTANT: DOMAIN_GROUP_RID_GUESTS 514
CONSTANT: DOMAIN_ALIAS_RID_ADMINS 544
CONSTANT: DOMAIN_ALIAS_RID_USERS 545
CONSTANT: DOMAIN_ALIAS_RID_GUESTS 546
CONSTANT: DOMAIN_ALIAS_RID_POWER_USERS 547
CONSTANT: DOMAIN_ALIAS_RID_ACCOUNT_OPS 548
CONSTANT: DOMAIN_ALIAS_RID_SYSTEM_OPS 549
CONSTANT: DOMAIN_ALIAS_RID_PRINT_OPS 550
CONSTANT: DOMAIN_ALIAS_RID_BACKUP_OPS 551
CONSTANT: DOMAIN_ALIAS_RID_REPLICATOR 552
CONSTANT: SE_GROUP_MANDATORY 1
CONSTANT: SE_GROUP_ENABLED_BY_DEFAULT 2
CONSTANT: SE_GROUP_ENABLED 4
CONSTANT: SE_GROUP_OWNER 8
CONSTANT: SE_GROUP_LOGON_ID -1073741824
! SID is a variable length structure
TYPEDEF: void* PSID
TYPEDEF: EXPLICIT_ACCESS* PEXPLICIT_ACCESS
TYPEDEF: DWORD SECURITY_INFORMATION
TYPEDEF: SECURITY_INFORMATION* PSECURITY_INFORMATION
CONSTANT: OWNER_SECURITY_INFORMATION 1
CONSTANT: GROUP_SECURITY_INFORMATION 2
CONSTANT: DACL_SECURITY_INFORMATION 4
CONSTANT: SACL_SECURITY_INFORMATION 8
CONSTANT: DELETE HEX: 00010000 CONSTANT: DELETE HEX: 00010000
CONSTANT: READ_CONTROL HEX: 00020000 CONSTANT: READ_CONTROL HEX: 00020000
CONSTANT: WRITE_DAC HEX: 00040000 CONSTANT: WRITE_DAC HEX: 00040000
@ -187,6 +350,34 @@ CONSTANT: TOKEN_ADJUST_DEFAULT HEX: 0080
TOKEN_ADJUST_DEFAULT TOKEN_ADJUST_DEFAULT
} flags ; foldable } flags ; foldable
CONSTANT: HKEY_CLASSES_ROOT 1
CONSTANT: HKEY_CURRENT_CONFIG 2
CONSTANT: HKEY_CURRENT_USER 3
CONSTANT: HKEY_LOCAL_MACHINE 4
CONSTANT: HKEY_USERS 5
CONSTANT: KEY_ALL_ACCESS HEX: 0001
CONSTANT: KEY_CREATE_LINK HEX: 0002
CONSTANT: KEY_CREATE_SUB_KEY HEX: 0004
CONSTANT: KEY_ENUMERATE_SUB_KEYS HEX: 0008
CONSTANT: KEY_EXECUTE HEX: 0010
CONSTANT: KEY_NOTIFY HEX: 0020
CONSTANT: KEY_QUERY_VALUE HEX: 0040
CONSTANT: KEY_READ HEX: 0080
CONSTANT: KEY_SET_VALUE HEX: 0100
CONSTANT: KEY_WOW64_64KEY HEX: 0200
CONSTANT: KEY_WOW64_32KEY HEX: 0400
CONSTANT: KEY_WRITE HEX: 0800
CONSTANT: REG_BINARY 1
CONSTANT: REG_DWORD 2
CONSTANT: REG_EXPAND_SZ 3
CONSTANT: REG_MULTI_SZ 4
CONSTANT: REG_QWORD 5
CONSTANT: REG_SZ 6
TYPEDEF: DWORD REGSAM
! : I_ScGetCurrentGroupStateW ; ! : I_ScGetCurrentGroupStateW ;
! : A_SHAFinal ; ! : A_SHAFinal ;
@ -224,7 +415,19 @@ FUNCTION: BOOL AdjustTokenPrivileges ( HANDLE TokenHandle,
PTOKEN_PRIVILEGES PreviousState, PTOKEN_PRIVILEGES PreviousState,
PDWORD ReturnLength ) ; PDWORD ReturnLength ) ;
! : AllocateAndInitializeSid ; FUNCTION: BOOL AllocateAndInitializeSid (
PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
BYTE nSubAuthorityCount,
DWORD dwSubAuthority0,
DWORD dwSubAuthority1,
DWORD dwSubAuthority2,
DWORD dwSubAuthority3,
DWORD dwSubAuthority4,
DWORD dwSubAuthority5,
DWORD dwSubAuthority6,
DWORD dwSubAuthority7,
PSID* pSid ) ;
! : AllocateLocallyUniqueId ; ! : AllocateLocallyUniqueId ;
! : AreAllAccessesGranted ; ! : AreAllAccessesGranted ;
! : AreAnyAccessesGranted ; ! : AreAnyAccessesGranted ;
@ -442,7 +645,8 @@ FUNCTION: BOOL CryptReleaseContext ( HCRYPTPROV hProv, DWORD dwFlags ) ;
! : GetExplicitEntriesFromAclA ; ! : GetExplicitEntriesFromAclA ;
! : GetExplicitEntriesFromAclW ; ! : GetExplicitEntriesFromAclW ;
! : GetFileSecurityA ; ! : GetFileSecurityA ;
! : GetFileSecurityW ; FUNCTION: BOOL GetFileSecurityW ( LPCTSTR lpFileName, SECURITY_INFORMATION RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded ) ;
ALIAS: GetFileSecurity GetFileSecurityW
! : GetInformationCodeAuthzLevelW ; ! : GetInformationCodeAuthzLevelW ;
! : GetInformationCodeAuthzPolicyW ; ! : GetInformationCodeAuthzPolicyW ;
! : GetInheritanceSourceA ; ! : GetInheritanceSourceA ;
@ -459,19 +663,20 @@ FUNCTION: BOOL CryptReleaseContext ( HCRYPTPROV hProv, DWORD dwFlags ) ;
! : GetMultipleTrusteeW ; ! : GetMultipleTrusteeW ;
! : GetNamedSecurityInfoA ; ! : GetNamedSecurityInfoA ;
! : GetNamedSecurityInfoExA ; ! : GetNamedSecurityInfoExA ;
! : GetNamedSecurityInfoExW ; ! FUNCTION: DWORD GetNamedSecurityInfoExW
! : GetNamedSecurityInfoW ; FUNCTION: DWORD GetNamedSecurityInfoW ( LPTSTR pObjectName, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl, PSECURITY_DESCRIPTOR* ppSecurityDescriptor ) ;
ALIAS: GetNamedSecurityInfo GetNamedSecurityInfoW
! : GetNumberOfEventLogRecords ; ! : GetNumberOfEventLogRecords ;
! : GetOldestEventLogRecord ; ! : GetOldestEventLogRecord ;
! : GetOverlappedAccessResults ; ! : GetOverlappedAccessResults ;
! : GetPrivateObjectSecurity ; ! : GetPrivateObjectSecurity ;
! : GetSecurityDescriptorControl ; FUNCTION: BOOL GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor, PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision ) ;
! : GetSecurityDescriptorDacl ; FUNCTION: BOOL GetSecurityDescriptorDacl ( PSECURITY_DESCRIPTOR pSecurityDescriptor, LPBOOL lpbDaclPresent, PACL* pDacl, LPBOOL lpDaclDefaulted ) ;
! : GetSecurityDescriptorGroup ; FUNCTION: BOOL GetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID* pGroup, LPBOOL lpGroupDefaulted ) ;
! : GetSecurityDescriptorLength ; FUNCTION: BOOL GetSecurityDescriptorLength ( PSECURITY_DESCRIPTOR pSecurityDescriptor ) ;
! : GetSecurityDescriptorOwner ; FUNCTION: BOOL GetSecurityDescriptorOwner ( PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID* pOwner, LPBOOL lpOwnerDefaulted ) ;
! : GetSecurityDescriptorRMControl ; FUNCTION: BOOL GetSecurityDescriptorRMControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor, PUCHAR RMControl ) ;
! : GetSecurityDescriptorSacl ; FUNCTION: BOOL GetSecurityDescriptorSacl ( PSECURITY_DESCRIPTOR pSecurityDescriptor, LPBOOL lpbSaclPresent, PACL* pSacl, LPBOOL lpSaclDefaulted ) ;
! : GetSecurityInfo ; ! : GetSecurityInfo ;
! : GetSecurityInfoExA ; ! : GetSecurityInfoExA ;
! : GetSecurityInfoExW ; ! : GetSecurityInfoExW ;
@ -510,7 +715,7 @@ ALIAS: GetUserName GetUserNameW
! : ImpersonateNamedPipeClient ; ! : ImpersonateNamedPipeClient ;
! : ImpersonateSelf ; ! : ImpersonateSelf ;
FUNCTION: BOOL InitializeAcl ( PACL pAcl, DWORD nAclLength, DWORD dwAclRevision ) ; FUNCTION: BOOL InitializeAcl ( PACL pAcl, DWORD nAclLength, DWORD dwAclRevision ) ;
! : InitializeSecurityDescriptor ; FUNCTION: BOOL InitializeSecurityDescriptor ( PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision ) ;
! : InitializeSid ; ! : InitializeSid ;
! : InitiateSystemShutdownA ; ! : InitiateSystemShutdownA ;
! : InitiateSystemShutdownExA ; ! : InitiateSystemShutdownExA ;
@ -674,8 +879,8 @@ FUNCTION: BOOL OpenThreadToken ( HANDLE ThreadHandle, DWORD DesiredAccess, BOOL
! : RegConnectRegistryW ; ! : RegConnectRegistryW ;
! : RegCreateKeyA ; ! : RegCreateKeyA ;
! : RegCreateKeyExA ; ! : RegCreateKeyExA ;
! : RegCreateKeyExW ; FUNCTION: LONG RegCreateKeyExW ( HKEY hKey, LPCTSTR lpSubKey, DWORD Reserved, LPTSTR lpClass, DWORD dwOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition ) ;
! : RegCreateKeyW ; ! : RegCreateKeyW
! : RegDeleteKeyA ; ! : RegDeleteKeyA ;
! : RegDeleteKeyW ; ! : RegDeleteKeyW ;
! : RegDeleteValueA ; ! : RegDeleteValueA ;
@ -692,7 +897,7 @@ FUNCTION: BOOL OpenThreadToken ( HANDLE ThreadHandle, DWORD DesiredAccess, BOOL
! : RegLoadKeyA ; ! : RegLoadKeyA ;
! : RegLoadKeyW ; ! : RegLoadKeyW ;
! : RegNotifyChangeKeyValue ; ! : RegNotifyChangeKeyValue ;
! : RegOpenCurrentUser ; FUNCTION: LONG RegOpenCurrentUser ( REGSAM samDesired, PHKEY phkResult ) ;
! : RegOpenKeyA ; ! : RegOpenKeyA ;
! : RegOpenKeyExA ; ! : RegOpenKeyExA ;
! : RegOpenKeyExW ; ! : RegOpenKeyExW ;
@ -705,7 +910,7 @@ FUNCTION: BOOL OpenThreadToken ( HANDLE ThreadHandle, DWORD DesiredAccess, BOOL
! : RegQueryMultipleValuesW ; ! : RegQueryMultipleValuesW ;
! : RegQueryValueA ; ! : RegQueryValueA ;
! : RegQueryValueExA ; ! : RegQueryValueExA ;
! : RegQueryValueExW ; FUNCTION: LONG RegQueryValueExW ( HKEY hKey, LPCTSTR lpValueName, LPWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ) ;
! : RegQueryValueW ; ! : RegQueryValueW ;
! : RegReplaceKeyA ; ! : RegReplaceKeyA ;
! : RegReplaceKeyW ; ! : RegReplaceKeyW ;
@ -756,7 +961,8 @@ FUNCTION: BOOL OpenThreadToken ( HANDLE ThreadHandle, DWORD DesiredAccess, BOOL
! : SetEntriesInAccessListA ; ! : SetEntriesInAccessListA ;
! : SetEntriesInAccessListW ; ! : SetEntriesInAccessListW ;
! : SetEntriesInAclA ; ! : SetEntriesInAclA ;
! : SetEntriesInAclW ; FUNCTION: DWORD SetEntriesInAclW ( ULONG cCountOfExplicitEntries, PEXPLICIT_ACCESS pListOfExplicitEntries, PACL OldAcl, PACL* NewAcl ) ;
ALIAS: SetEntriesInAcl SetEntriesInAclW
! : SetEntriesInAuditListA ; ! : SetEntriesInAuditListA ;
! : SetEntriesInAuditListW ; ! : SetEntriesInAuditListW ;
! : SetFileSecurityA ; ! : SetFileSecurityA ;
@ -767,7 +973,8 @@ FUNCTION: BOOL OpenThreadToken ( HANDLE ThreadHandle, DWORD DesiredAccess, BOOL
! : SetNamedSecurityInfoA ; ! : SetNamedSecurityInfoA ;
! : SetNamedSecurityInfoExA ; ! : SetNamedSecurityInfoExA ;
! : SetNamedSecurityInfoExW ; ! : SetNamedSecurityInfoExW ;
! : SetNamedSecurityInfoW ; FUNCTION: DWORD SetNamedSecurityInfoW ( LPTSTR pObjectName, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl ) ;
ALIAS: SetNamedSecurityInfo SetNamedSecurityInfoW
! : SetPrivateObjectSecurity ; ! : SetPrivateObjectSecurity ;
! : SetPrivateObjectSecurityEx ; ! : SetPrivateObjectSecurityEx ;
! : SetSecurityDescriptorControl ; ! : SetSecurityDescriptorControl ;

View File

@ -0,0 +1,5 @@
IN: windows.dinput.constants.tests
USING: tools.test windows.dinput.constants.private ;
[ ] [ define-constants ] unit-test
[ ] [ free-dinput-constants ] unit-test

View File

@ -27,12 +27,12 @@ SYMBOLS:
: (flag) ( thing -- integer ) : (flag) ( thing -- integer )
{ {
{ [ dup word? ] [ execute ] } { [ dup word? ] [ execute( -- value ) ] }
{ [ dup callable? ] [ call ] } { [ dup callable? ] [ call( -- value ) ] }
[ ] [ ]
} cond ; } cond ;
: (flags) ( array -- ) : (flags) ( array -- n )
0 [ (flag) bitor ] reduce ; 0 [ (flag) bitor ] reduce ;
: (DIOBJECTDATAFORMAT) ( pguid dwOfs dwType dwFlags alien -- alien ) : (DIOBJECTDATAFORMAT) ( pguid dwOfs dwType dwFlags alien -- alien )
@ -63,14 +63,16 @@ SYMBOLS:
] ; ] ;
: (DIDATAFORMAT) ( dwSize dwObjSize dwFlags dwDataSize dwNumObjs rgodf alien -- alien ) : (DIDATAFORMAT) ( dwSize dwObjSize dwFlags dwDataSize dwNumObjs rgodf alien -- alien )
[ { [
{
[ set-DIDATAFORMAT-rgodf ] [ set-DIDATAFORMAT-rgodf ]
[ set-DIDATAFORMAT-dwNumObjs ] [ set-DIDATAFORMAT-dwNumObjs ]
[ set-DIDATAFORMAT-dwDataSize ] [ set-DIDATAFORMAT-dwDataSize ]
[ set-DIDATAFORMAT-dwFlags ] [ set-DIDATAFORMAT-dwFlags ]
[ set-DIDATAFORMAT-dwObjSize ] [ set-DIDATAFORMAT-dwObjSize ]
[ set-DIDATAFORMAT-dwSize ] [ set-DIDATAFORMAT-dwSize ]
} cleave ] keep ; } cleave
] keep ;
: <DIDATAFORMAT> ( dwFlags dwDataSize struct rgodf-array -- alien ) : <DIDATAFORMAT> ( dwFlags dwDataSize struct rgodf-array -- alien )
[ "DIDATAFORMAT" heap-size "DIOBJECTDATAFORMAT" heap-size ] 4 ndip [ "DIDATAFORMAT" heap-size "DIOBJECTDATAFORMAT" heap-size ] 4 ndip
@ -78,9 +80,10 @@ SYMBOLS:
"DIDATAFORMAT" <c-object> (DIDATAFORMAT) ; "DIDATAFORMAT" <c-object> (DIDATAFORMAT) ;
: (malloc-guid-symbol) ( symbol guid -- ) : (malloc-guid-symbol) ( symbol guid -- )
global swap '[ [ '[
_ execute [ byte-length malloc ] [ over byte-array>memory ] bi _ execute( -- value )
] unless* ] change-at ; [ byte-length malloc ] [ over byte-array>memory ] bi
] initialize ;
: define-guid-constants ( -- ) : define-guid-constants ( -- )
{ {
@ -105,7 +108,7 @@ SYMBOLS:
} [ first2 (malloc-guid-symbol) ] each ; } [ first2 (malloc-guid-symbol) ] each ;
: define-joystick-format-constant ( -- ) : define-joystick-format-constant ( -- )
c_dfDIJoystick2 global [ [ c_dfDIJoystick2 [
DIDF_ABSAXIS DIDF_ABSAXIS
"DIJOYSTATE2" heap-size "DIJOYSTATE2" heap-size
"DIJOYSTATE2" { "DIJOYSTATE2" {
@ -274,10 +277,10 @@ SYMBOLS:
{ GUID_Slider_malloced "rglFSlider" 0 { DIDFT_OPTIONAL DIDFT_AXIS DIDFT_ANYINSTANCE } DIDOI_ASPECTFORCE } { GUID_Slider_malloced "rglFSlider" 0 { DIDFT_OPTIONAL DIDFT_AXIS DIDFT_ANYINSTANCE } DIDOI_ASPECTFORCE }
{ GUID_Slider_malloced "rglFSlider" 1 { DIDFT_OPTIONAL DIDFT_AXIS DIDFT_ANYINSTANCE } DIDOI_ASPECTFORCE } { GUID_Slider_malloced "rglFSlider" 1 { DIDFT_OPTIONAL DIDFT_AXIS DIDFT_ANYINSTANCE } DIDOI_ASPECTFORCE }
} <DIDATAFORMAT> } <DIDATAFORMAT>
] unless* ] change-at ; ] initialize ;
: define-mouse-format-constant ( -- ) : define-mouse-format-constant ( -- )
c_dfDIMouse2 global [ [ c_dfDIMouse2 [
DIDF_RELAXIS DIDF_RELAXIS
"DIMOUSESTATE2" heap-size "DIMOUSESTATE2" heap-size
"DIMOUSESTATE2" { "DIMOUSESTATE2" {
@ -293,13 +296,13 @@ SYMBOLS:
{ GUID_Button_malloced "rgbButtons" 6 { DIDFT_OPTIONAL DIDFT_ANYINSTANCE DIDFT_BUTTON } 0 } { GUID_Button_malloced "rgbButtons" 6 { DIDFT_OPTIONAL DIDFT_ANYINSTANCE DIDFT_BUTTON } 0 }
{ GUID_Button_malloced "rgbButtons" 7 { DIDFT_OPTIONAL DIDFT_ANYINSTANCE DIDFT_BUTTON } 0 } { GUID_Button_malloced "rgbButtons" 7 { DIDFT_OPTIONAL DIDFT_ANYINSTANCE DIDFT_BUTTON } 0 }
} <DIDATAFORMAT> } <DIDATAFORMAT>
] unless* ] change-at ; ] initialize ;
! Not a standard DirectInput format. Included for cross-platform niceness. ! Not a standard DirectInput format. Included for cross-platform niceness.
! This format returns the keyboard keys in USB HID order rather than Windows ! This format returns the keyboard keys in USB HID order rather than Windows
! order ! order
: define-hid-keyboard-format-constant ( -- ) : define-hid-keyboard-format-constant ( -- )
c_dfDIKeyboard_HID global [ [ c_dfDIKeyboard_HID [
DIDF_RELAXIS DIDF_RELAXIS
256 256
f { f {
@ -560,10 +563,10 @@ SYMBOLS:
{ GUID_Key_malloced f 254 { DIDFT_OPTIONAL DIDFT_BUTTON [ 0 DIDFT_MAKEINSTANCE ] } 0 } { GUID_Key_malloced f 254 { DIDFT_OPTIONAL DIDFT_BUTTON [ 0 DIDFT_MAKEINSTANCE ] } 0 }
{ GUID_Key_malloced f 255 { DIDFT_OPTIONAL DIDFT_BUTTON [ 0 DIDFT_MAKEINSTANCE ] } 0 } { GUID_Key_malloced f 255 { DIDFT_OPTIONAL DIDFT_BUTTON [ 0 DIDFT_MAKEINSTANCE ] } 0 }
} <DIDATAFORMAT> } <DIDATAFORMAT>
] unless* ] change-at ; ] initialize ;
: define-keyboard-format-constant ( -- ) : define-keyboard-format-constant ( -- )
c_dfDIKeyboard global [ [ c_dfDIKeyboard [
DIDF_RELAXIS DIDF_RELAXIS
256 256
f { f {
@ -824,7 +827,7 @@ SYMBOLS:
{ GUID_Key_malloced f 254 { DIDFT_OPTIONAL DIDFT_BUTTON [ 254 DIDFT_MAKEINSTANCE ] } 0 } { GUID_Key_malloced f 254 { DIDFT_OPTIONAL DIDFT_BUTTON [ 254 DIDFT_MAKEINSTANCE ] } 0 }
{ GUID_Key_malloced f 255 { DIDFT_OPTIONAL DIDFT_BUTTON [ 255 DIDFT_MAKEINSTANCE ] } 0 } { GUID_Key_malloced f 255 { DIDFT_OPTIONAL DIDFT_BUTTON [ 255 DIDFT_MAKEINSTANCE ] } 0 }
} <DIDATAFORMAT> } <DIDATAFORMAT>
] unless* ] change-at ; ] initialize ;
: define-format-constants ( -- ) : define-format-constants ( -- )
define-joystick-format-constant define-joystick-format-constant
@ -837,7 +840,9 @@ SYMBOLS:
define-format-constants ; define-format-constants ;
[ define-constants ] "windows.dinput.constants" add-init-hook [ define-constants ] "windows.dinput.constants" add-init-hook
define-constants
: uninitialize ( variable quot -- )
[ global ] dip '[ _ when* f ] change-at ; inline
: free-dinput-constants ( -- ) : free-dinput-constants ( -- )
{ {
@ -846,10 +851,11 @@ define-constants
GUID_Slider_malloced GUID_Button_malloced GUID_Key_malloced GUID_POV_malloced GUID_Unknown_malloced GUID_Slider_malloced GUID_Button_malloced GUID_Key_malloced GUID_POV_malloced GUID_Unknown_malloced
GUID_SysMouse_malloced GUID_SysKeyboard_malloced GUID_Joystick_malloced GUID_SysMouseEm_malloced GUID_SysMouse_malloced GUID_SysKeyboard_malloced GUID_Joystick_malloced GUID_SysMouseEm_malloced
GUID_SysMouseEm2_malloced GUID_SysKeyboardEm_malloced GUID_SysKeyboardEm2_malloced GUID_SysMouseEm2_malloced GUID_SysKeyboardEm_malloced GUID_SysKeyboardEm2_malloced
} [ global [ [ free ] when* f ] change-at ] each } [ [ free ] uninitialize ] each
{ {
c_dfDIKeyboard c_dfDIKeyboard_HID c_dfDIMouse2 c_dfDIJoystick2 c_dfDIKeyboard c_dfDIKeyboard_HID c_dfDIMouse2 c_dfDIJoystick2
} [ global [ [ DIDATAFORMAT-rgodf free ] when* f ] change-at ] each ; } [ [ DIDATAFORMAT-rgodf free ] uninitialize ] each ;
PRIVATE> PRIVATE>

View File

@ -1501,7 +1501,6 @@ DESTRUCTOR: DeleteObject
FUNCTION: BOOL ExtTextOutW ( HDC hdc, int X, int Y, UINT fuOptions, RECT* lprc, LPCTSTR lpString, UINT cbCount, INT* lpDx ) ; FUNCTION: BOOL ExtTextOutW ( HDC hdc, int X, int Y, UINT fuOptions, RECT* lprc, LPCTSTR lpString, UINT cbCount, INT* lpDx ) ;
ALIAS: ExtTextOut ExtTextOutW ALIAS: ExtTextOut ExtTextOutW
! FUNCTION: FillPath ! FUNCTION: FillPath
FUNCTION: int FillRect ( HDC hDC, RECT* lprc, HBRUSH hbr ) ;
! FUNCTION: FillRgn ! FUNCTION: FillRgn
! FUNCTION: FixBrushOrgEx ! FUNCTION: FixBrushOrgEx
! FUNCTION: FlattenPath ! FUNCTION: FlattenPath

View File

@ -1477,7 +1477,7 @@ ALIAS: LoadLibraryEx LoadLibraryExW
! FUNCTION: LoadLibraryW ! FUNCTION: LoadLibraryW
! FUNCTION: LoadModule ! FUNCTION: LoadModule
! FUNCTION: LoadResource ! FUNCTION: LoadResource
! FUNCTION: LocalAlloc FUNCTION: HLOCAL LocalAlloc ( UINT uFlags, SIZE_T uBytes ) ;
! FUNCTION: LocalCompact ! FUNCTION: LocalCompact
! FUNCTION: LocalFileTimeToFileTime ! FUNCTION: LocalFileTimeToFileTime
! FUNCTION: LocalFlags ! FUNCTION: LocalFlags

View File

@ -807,7 +807,7 @@ FUNCTION: UINT EnumClipboardFormats ( UINT format ) ;
! FUNCTION: EqualRect ! FUNCTION: EqualRect
! FUNCTION: ExcludeUpdateRgn ! FUNCTION: ExcludeUpdateRgn
! FUNCTION: ExitWindowsEx ! FUNCTION: ExitWindowsEx
! FUNCTION: FillRect FUNCTION: int FillRect ( HDC hDC, RECT* lprc, HBRUSH hbr ) ;
FUNCTION: HWND FindWindowA ( char* lpClassName, char* lpWindowName ) ; FUNCTION: HWND FindWindowA ( char* lpClassName, char* lpWindowName ) ;
FUNCTION: HWND FindWindowExA ( HWND hwndParent, HWND childAfter, char* lpClassName, char* lpWindowName ) ; FUNCTION: HWND FindWindowExA ( HWND hwndParent, HWND childAfter, char* lpClassName, char* lpWindowName ) ;
! FUNCTION: FindWindowExW ! FUNCTION: FindWindowExW

Some files were not shown because too many files have changed in this diff Show More