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

db4
Doug Coleman 2009-03-23 20:04:20 -05:00
commit 86f6763725
272 changed files with 2381 additions and 1499 deletions

View File

@ -4,7 +4,7 @@ sequences system libc alien.strings io.encodings.utf8 ;
\ expand-constants must-infer \ expand-constants must-infer
: xyz 123 ; CONSTANT: xyz 123
[ { "blah" 123 } ] [ { "blah" xyz } expand-constants ] unit-test [ { "blah" 123 } ] [ { "blah" xyz } expand-constants ] unit-test

View File

@ -26,4 +26,4 @@ M: F-destructor dispose* alien>> F ;
;FUNCTOR ;FUNCTOR
: DESTRUCTOR: scan-word define-destructor ; parsing SYNTAX: DESTRUCTOR: scan-word define-destructor ;

View File

@ -416,7 +416,7 @@ PRIVATE>
: define-fortran-record ( name vocab fields -- ) : define-fortran-record ( name vocab fields -- )
[ >lower ] [ ] [ fortran-record>c-struct ] tri* define-struct ; [ >lower ] [ ] [ fortran-record>c-struct ] tri* define-struct ;
: RECORD: scan in get parse-definition define-fortran-record ; parsing SYNTAX: RECORD: scan in get parse-definition define-fortran-record ;
: set-fortran-abi ( library -- ) : set-fortran-abi ( library -- )
library-fortran-abis get-global at fortran-abi set ; library-fortran-abis get-global at fortran-abi set ;
@ -437,16 +437,16 @@ MACRO: fortran-invoke ( return library function parameters -- )
return library function parameters return [ "void" ] unless* parse-arglist return library function parameters return [ "void" ] unless* parse-arglist
[ \ fortran-invoke 5 [ ] nsequence ] dip define-declared ; [ \ fortran-invoke 5 [ ] nsequence ] dip define-declared ;
: SUBROUTINE: SYNTAX: SUBROUTINE:
f "c-library" get scan ";" parse-tokens f "c-library" get scan ";" parse-tokens
[ "()" subseq? not ] filter define-fortran-function ; parsing [ "()" subseq? not ] filter define-fortran-function ;
: FUNCTION: SYNTAX: FUNCTION:
scan "c-library" get scan ";" parse-tokens scan "c-library" get scan ";" parse-tokens
[ "()" subseq? not ] filter define-fortran-function ; parsing [ "()" subseq? not ] filter define-fortran-function ;
: LIBRARY: SYNTAX: LIBRARY:
scan scan
[ "c-library" set ] [ "c-library" set ]
[ set-fortran-abi ] bi ; parsing [ set-fortran-abi ] bi ;

View File

@ -1,4 +1,4 @@
! Copyright (C) 2005, 2008 Slava Pestov. ! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays kernel kernel.private math namespaces USING: accessors arrays kernel kernel.private math namespaces
make sequences strings words effects combinators alien.c-types ; make sequences strings words effects combinators alien.c-types ;
@ -6,28 +6,6 @@ IN: alien.structs.fields
TUPLE: field-spec name offset type reader writer ; TUPLE: field-spec name offset type reader writer ;
: reader-effect ( type spec -- effect )
[ 1array ] [ name>> 1array ] bi* <effect> ;
PREDICATE: slot-reader < word "reading" word-prop >boolean ;
: set-reader-props ( class spec -- )
2dup reader-effect
over reader>>
swap "declared-effect" set-word-prop
reader>> swap "reading" set-word-prop ;
: writer-effect ( type spec -- effect )
name>> swap 2array 0 <effect> ;
PREDICATE: slot-writer < word "writing" word-prop >boolean ;
: set-writer-props ( class spec -- )
2dup writer-effect
over writer>>
swap "declared-effect" set-word-prop
writer>> swap "writing" set-word-prop ;
: reader-word ( class name vocab -- word ) : reader-word ( class name vocab -- word )
[ "-" glue ] dip create ; [ "-" glue ] dip create ;
@ -55,17 +33,13 @@ PREDICATE: slot-writer < word "writing" word-prop >boolean ;
: define-struct-slot-word ( word quot spec effect -- ) : define-struct-slot-word ( word quot spec effect -- )
[ offset>> prefix ] dip define-inline ; [ offset>> prefix ] dip define-inline ;
: define-getter ( type spec -- ) : define-getter ( spec -- )
[ set-reader-props ] keep [ reader>> ] [ type>> c-type-getter-boxer ] [ ] tri
[ reader>> ]
[ type>> c-type-getter-boxer ]
[ ] tri
(( c-ptr -- value )) define-struct-slot-word ; (( c-ptr -- value )) define-struct-slot-word ;
: define-setter ( type spec -- ) : define-setter ( spec -- )
[ set-writer-props ] keep
[ writer>> ] [ type>> c-setter ] [ ] tri [ writer>> ] [ type>> c-setter ] [ ] tri
(( value c-ptr -- )) define-struct-slot-word ; (( value c-ptr -- )) define-struct-slot-word ;
: define-field ( type spec -- ) : define-field ( spec -- )
[ define-getter ] [ define-setter ] 2bi ; [ define-getter ] [ define-setter ] bi ;

View File

@ -24,7 +24,7 @@ os winnt? cpu x86? and [
] when ] when
] when ] when
: MAX_FOOS 30 ; CONSTANT: MAX_FOOS 30
C-STRUCT: foox C-STRUCT: foox
{ { "int" MAX_FOOS } "x" } ; { { "int" MAX_FOOS } "x" } ;

View File

@ -1,4 +1,4 @@
! Copyright (C) 2004, 2008 Slava Pestov. ! Copyright (C) 2004, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs generic hashtables kernel kernel.private USING: accessors arrays assocs generic hashtables kernel kernel.private
math namespaces parser sequences strings words libc fry math namespaces parser sequences strings words libc fry
@ -68,12 +68,11 @@ M: struct-type stack-size
[ c-type-align ] [ max ] map-reduce ; [ c-type-align ] [ max ] map-reduce ;
: define-struct ( name vocab fields -- ) : define-struct ( name vocab fields -- )
[
[ 2drop ] [ make-fields ] 3bi [ 2drop ] [ make-fields ] 3bi
[ struct-offsets ] keep [ struct-offsets ] keep
[ [ type>> ] map compute-struct-align ] keep [ [ type>> ] map compute-struct-align ] keep
[ (define-struct) ] keep [ (define-struct) ] keep
] [ 2drop '[ _ swap define-field ] ] 3bi each ; [ define-field ] each ;
: define-union ( name members -- ) : define-union ( name members -- )
[ expand-constants ] map [ expand-constants ] map
@ -83,4 +82,3 @@ M: struct-type stack-size
: offset-of ( field struct -- offset ) : offset-of ( field struct -- offset )
c-types get at fields>> c-types get at fields>>
[ name>> = ] with find nip offset>> ; [ name>> = ] with find nip offset>> ;

View File

@ -7,35 +7,34 @@ effects assocs combinators lexer strings.parser alien.parser
fry vocabs.parser words.constant ; fry vocabs.parser words.constant ;
IN: alien.syntax IN: alien.syntax
: DLL" lexer get skip-blank parse-string dlopen parsed ; parsing SYNTAX: DLL" lexer get skip-blank parse-string dlopen parsed ;
: ALIEN: scan string>number <alien> parsed ; parsing SYNTAX: ALIEN: scan string>number <alien> parsed ;
: BAD-ALIEN <bad-alien> parsed ; parsing SYNTAX: BAD-ALIEN <bad-alien> parsed ;
: LIBRARY: scan "c-library" set ; parsing SYNTAX: LIBRARY: scan "c-library" set ;
: FUNCTION: SYNTAX: FUNCTION:
scan "c-library" get scan ";" parse-tokens scan "c-library" get scan ";" parse-tokens
[ "()" subseq? not ] filter [ "()" subseq? not ] filter
define-function ; parsing define-function ;
: TYPEDEF: SYNTAX: TYPEDEF:
scan scan typedef ; parsing scan scan typedef ;
: C-STRUCT: SYNTAX: C-STRUCT:
scan in get parse-definition define-struct ; parsing scan in get parse-definition define-struct ;
: C-UNION: SYNTAX: C-UNION:
scan parse-definition define-union ; parsing scan parse-definition define-union ;
: C-ENUM: SYNTAX: C-ENUM:
";" parse-tokens ";" parse-tokens
[ [ create-in ] dip define-constant ] each-index ; [ [ create-in ] dip define-constant ] each-index ;
parsing
: address-of ( name library -- value ) : address-of ( name library -- value )
load-library dlsym [ "No such symbol" throw ] unless* ; load-library dlsym [ "No such symbol" throw ] unless* ;
: &: SYNTAX: &:
scan "c-library" get '[ _ _ address-of ] over push-all ; parsing scan "c-library" get '[ _ _ address-of ] over push-all ;

View File

@ -68,7 +68,7 @@ M: bit-array resize
M: bit-array byte-length length 7 + -3 shift ; M: bit-array byte-length length 7 + -3 shift ;
: ?{ \ } [ >bit-array ] parse-literal ; parsing SYNTAX: ?{ \ } [ >bit-array ] parse-literal ;
: integer>bit-array ( n -- bit-array ) : integer>bit-array ( n -- bit-array )
dup 0 = [ dup 0 = [

View File

@ -3,7 +3,7 @@ USING: tools.test bit-vectors vectors sequences kernel math ;
[ 0 ] [ 123 <bit-vector> length ] unit-test [ 0 ] [ 123 <bit-vector> length ] unit-test
: do-it : do-it ( seq -- )
1234 swap [ [ even? ] dip push ] curry each ; 1234 swap [ [ even? ] dip push ] curry each ;
[ t ] [ [ t ] [

View File

@ -31,7 +31,7 @@ M: bit-array new-resizable drop <bit-vector> ;
INSTANCE: bit-vector growable INSTANCE: bit-vector growable
: ?V{ \ } [ >bit-vector ] parse-literal ; parsing SYNTAX: ?V{ \ } [ >bit-vector ] parse-literal ;
M: bit-vector >pprint-sequence ; M: bit-vector >pprint-sequence ;
M: bit-vector pprint-delims drop \ ?V{ \ } ; M: bit-vector pprint-delims drop \ ?V{ \ } ;

View File

@ -95,10 +95,10 @@ CONSTANT: -1-offset 9
SYMBOL: sub-primitives SYMBOL: sub-primitives
: make-jit ( quot rc rt offset -- quad ) : make-jit ( quot rc rt offset -- quad )
[ { } make ] 3dip 4array ; inline [ [ call( -- ) ] { } make ] 3dip 4array ;
: jit-define ( quot rc rt offset name -- ) : jit-define ( quot rc rt offset name -- )
[ make-jit ] dip set ; inline [ make-jit ] dip set ;
: define-sub-primitive ( quot rc rt offset word -- ) : define-sub-primitive ( quot rc rt offset word -- )
[ make-jit ] dip sub-primitives get set-at ; [ make-jit ] dip sub-primitives get set-at ;
@ -398,9 +398,14 @@ M: byte-array '
] emit-object ; ] emit-object ;
! Tuples ! Tuples
ERROR: tuple-removed class ;
: require-tuple-layout ( word -- layout )
dup tuple-layout [ ] [ tuple-removed ] ?if ;
: (emit-tuple) ( tuple -- pointer ) : (emit-tuple) ( tuple -- pointer )
[ tuple-slots ] [ tuple-slots ]
[ class transfer-word tuple-layout ] bi prefix [ ' ] map [ class transfer-word require-tuple-layout ] bi prefix [ ' ] map
tuple type-number dup [ emit-seq ] emit-object ; tuple type-number dup [ emit-seq ] emit-object ;
: emit-tuple ( tuple -- pointer ) : emit-tuple ( tuple -- pointer )

View File

@ -4,7 +4,7 @@ prettyprint ;
[ 0 ] [ 123 <byte-vector> length ] unit-test [ 0 ] [ 123 <byte-vector> length ] unit-test
: do-it : do-it ( seq -- seq )
123 [ over push ] each ; 123 [ over push ] each ;
[ t ] [ [ t ] [

View File

@ -42,7 +42,7 @@ M: byte-array like
M: byte-array new-resizable drop <byte-vector> ; M: byte-array new-resizable drop <byte-vector> ;
: BV{ \ } [ >byte-vector ] parse-literal ; parsing SYNTAX: BV{ \ } [ >byte-vector ] parse-literal ;
M: byte-vector pprint* pprint-object ; M: byte-vector pprint* pprint-object ;
M: byte-vector pprint-delims drop \ BV{ \ } ; M: byte-vector pprint-delims drop \ BV{ \ } ;

View File

@ -148,7 +148,7 @@ IN: calendar.tests
[ t ] [ 123456789000000 [ micros>timestamp timestamp>micros ] keep = ] unit-test [ t ] [ 123456789000000 [ micros>timestamp timestamp>micros ] keep = ] unit-test
[ t ] [ 123456789123456000 [ micros>timestamp timestamp>micros ] keep = ] unit-test [ t ] [ 123456789123456000 [ micros>timestamp timestamp>micros ] keep = ] unit-test
: checktime+ now dup clone [ rot time+ drop ] keep = ; : checktime+ ( duration -- ? ) now dup clone [ rot time+ drop ] keep = ;
[ t ] [ 5 seconds checktime+ ] unit-test [ t ] [ 5 seconds checktime+ ] unit-test

View File

@ -46,6 +46,11 @@ IN: calendar.format
: read-0000 ( -- n ) 4 read string>number ; : read-0000 ( -- n ) 4 read string>number ;
: hhmm>timestamp ( hhmm -- timestamp )
[
0 0 0 read-00 read-00 0 instant <timestamp>
] with-string-reader ;
GENERIC: day. ( obj -- ) GENERIC: day. ( obj -- )
M: integer day. ( n -- ) M: integer day. ( n -- )

View File

@ -13,7 +13,7 @@ CLASS: {
[ gc "x" set 2drop ] [ gc "x" set 2drop ]
} ; } ;
: test-foo : test-foo ( -- )
Foo -> alloc -> init Foo -> alloc -> init
dup 1.0 2.0 101.0 102.0 <CGRect> -> foo: dup 1.0 2.0 101.0 102.0 <CGRect> -> foo:
-> release ; -> release ;

View File

@ -14,18 +14,14 @@ SYMBOL: sent-messages
: remember-send ( selector -- ) : remember-send ( selector -- )
sent-messages (remember-send) ; sent-messages (remember-send) ;
: -> SYNTAX: -> scan dup remember-send parsed \ send parsed ;
scan dup remember-send parsed \ send parsed ;
parsing
SYMBOL: super-sent-messages SYMBOL: super-sent-messages
: remember-super-send ( selector -- ) : remember-super-send ( selector -- )
super-sent-messages (remember-send) ; super-sent-messages (remember-send) ;
: SUPER-> SYNTAX: SUPER-> scan dup remember-super-send parsed \ super-send parsed ;
scan dup remember-super-send parsed \ super-send parsed ;
parsing
SYMBOL: frameworks SYMBOL: frameworks
@ -33,9 +29,9 @@ frameworks [ V{ } clone ] initialize
[ frameworks get [ load-framework ] each ] "cocoa.messages" add-init-hook [ frameworks get [ load-framework ] each ] "cocoa.messages" add-init-hook
: FRAMEWORK: scan [ load-framework ] [ frameworks get push ] bi ; parsing SYNTAX: FRAMEWORK: scan [ load-framework ] [ frameworks get push ] bi ;
: IMPORT: scan [ ] import-objc-class ; parsing SYNTAX: IMPORT: scan [ ] import-objc-class ;
"Compiling Objective C bridge..." print "Compiling Objective C bridge..." print

View File

@ -22,15 +22,13 @@ SYMBOL: super-message-senders
message-senders [ H{ } clone ] initialize message-senders [ H{ } clone ] initialize
super-message-senders [ H{ } clone ] initialize super-message-senders [ H{ } clone ] initialize
: cache-stub ( method function hash -- ) : cache-stub ( method assoc function -- )
[ '[ _ sender-stub ] cache drop ;
over get [ 2drop ] [ over [ sender-stub ] dip set ] if
] bind ;
: cache-stubs ( method -- ) : cache-stubs ( method -- )
dup [ super-message-senders get "objc_msgSendSuper" cache-stub ]
"objc_msgSendSuper" super-message-senders get cache-stub [ message-senders get "objc_msgSend" cache-stub ]
"objc_msgSend" message-senders get cache-stub ; bi ;
: <super> ( receiver -- super ) : <super> ( receiver -- super )
"objc-super" <c-object> [ "objc-super" <c-object> [

View File

@ -76,6 +76,6 @@ SYMBOL: +superclass+
import-objc-class import-objc-class
] bind ; ] bind ;
: CLASS: SYNTAX: CLASS:
parse-definition unclip parse-definition unclip
>hashtable define-objc-class ; parsing >hashtable define-objc-class ;

View File

@ -30,4 +30,4 @@ ERROR: no-such-color name ;
: named-color ( name -- color ) : named-color ( name -- color )
dup rgb.txt at [ ] [ no-such-color ] ?if ; dup rgb.txt at [ ] [ no-such-color ] ?if ;
: COLOR: scan named-color parsed ; parsing SYNTAX: COLOR: scan named-color parsed ;

View File

@ -13,10 +13,10 @@ IN: compiler.cfg.instructions.syntax
: insn-effect ( word -- effect ) : insn-effect ( word -- effect )
boa-effect in>> but-last f <effect> ; boa-effect in>> but-last f <effect> ;
: INSN: SYNTAX: INSN:
parse-tuple-definition "regs" suffix parse-tuple-definition "regs" suffix
[ dup tuple eq? [ drop insn-word ] when ] dip [ dup tuple eq? [ drop insn-word ] when ] dip
[ define-tuple-class ] [ define-tuple-class ]
[ 2drop save-location ] [ 2drop save-location ]
[ 2drop [ ] [ '[ f _ boa , ] ] [ insn-effect ] tri define-inline ] [ 2drop [ ] [ '[ f _ boa , ] ] [ insn-effect ] tri define-inline ]
3tri ; parsing 3tri ;

View File

@ -17,6 +17,6 @@ C: <ds-loc> ds-loc
TUPLE: rs-loc < loc ; TUPLE: rs-loc < loc ;
C: <rs-loc> rs-loc C: <rs-loc> rs-loc
: V scan-word scan-word vreg boa parsed ; parsing SYNTAX: V scan-word scan-word vreg boa parsed ;
: D scan-word <ds-loc> parsed ; parsing SYNTAX: D scan-word <ds-loc> parsed ;
: R scan-word <rs-loc> parsed ; parsing SYNTAX: R scan-word <rs-loc> parsed ;

View File

@ -35,11 +35,14 @@ SYMBOLS: +optimized+ +unoptimized+ ;
[ usage [ word? ] filter ] [ compiled-usage keys ] if [ usage [ word? ] filter ] [ compiled-usage keys ] if
[ queue-compile ] each ; [ queue-compile ] each ;
: ripple-up? ( word status -- ? ) : ripple-up? ( status word -- ? )
swap "compiled-status" word-prop [ = not ] keep and ; [
[ nip changed-effects get key? ]
[ "compiled-status" word-prop eq? not ] 2bi or
] keep "compiled-status" word-prop and ;
: save-compiled-status ( word status -- ) : save-compiled-status ( word status -- )
[ dupd ripple-up? [ ripple-up ] [ drop ] if ] [ over ripple-up? [ ripple-up ] [ drop ] if ]
[ "compiled-status" set-word-prop ] [ "compiled-status" set-word-prop ]
2bi ; 2bi ;

View File

@ -270,7 +270,7 @@ cell 8 = [
] when ] when
! Some randomized tests ! Some randomized tests
: compiled-fixnum* fixnum* ; : compiled-fixnum* ( a b -- c ) fixnum* ;
[ ] [ [ ] [
10000 [ 10000 [
@ -281,7 +281,7 @@ cell 8 = [
] times ] times
] unit-test ] unit-test
: compiled-fixnum>bignum fixnum>bignum ; : compiled-fixnum>bignum ( a -- b ) fixnum>bignum ;
[ bignum ] [ 0 compiled-fixnum>bignum class ] unit-test [ bignum ] [ 0 compiled-fixnum>bignum class ] unit-test
@ -293,7 +293,7 @@ cell 8 = [
] times ] times
] unit-test ] unit-test
: compiled-bignum>fixnum bignum>fixnum ; : compiled-bignum>fixnum ( a -- b ) bignum>fixnum ;
[ ] [ [ ] [
10000 [ 10000 [

View File

@ -13,7 +13,7 @@ M: array xyz xyz ;
[ t ] [ \ xyz optimized>> ] unit-test [ t ] [ \ xyz optimized>> ] unit-test
! Test predicate inlining ! Test predicate inlining
: pred-test-1 : pred-test-1 ( a -- b c )
dup fixnum? [ dup fixnum? [
dup integer? [ "integer" ] [ "nope" ] if dup integer? [ "integer" ] [ "nope" ] if
] [ ] [
@ -24,7 +24,7 @@ M: array xyz xyz ;
TUPLE: pred-test ; TUPLE: pred-test ;
: pred-test-2 : pred-test-2 ( a -- b c )
dup tuple? [ dup tuple? [
dup pred-test? [ "pred-test" ] [ "nope" ] if dup pred-test? [ "pred-test" ] [ "nope" ] if
] [ ] [
@ -33,7 +33,7 @@ TUPLE: pred-test ;
[ T{ pred-test } "pred-test" ] [ T{ pred-test } pred-test-2 ] unit-test [ T{ pred-test } "pred-test" ] [ T{ pred-test } pred-test-2 ] unit-test
: pred-test-3 : pred-test-3 ( a -- b c )
dup pred-test? [ dup pred-test? [
dup tuple? [ "pred-test" ] [ "nope" ] if dup tuple? [ "pred-test" ] [ "nope" ] if
] [ ] [
@ -42,14 +42,14 @@ TUPLE: pred-test ;
[ T{ pred-test } "pred-test" ] [ T{ pred-test } pred-test-3 ] unit-test [ T{ pred-test } "pred-test" ] [ T{ pred-test } pred-test-3 ] unit-test
: inline-test : inline-test ( a -- b )
"nom" = ; "nom" = ;
[ t ] [ "nom" inline-test ] unit-test [ t ] [ "nom" inline-test ] unit-test
[ f ] [ "shayin" inline-test ] unit-test [ f ] [ "shayin" inline-test ] unit-test
[ f ] [ 3 inline-test ] unit-test [ f ] [ 3 inline-test ] unit-test
: fixnum-declarations >fixnum 24 shift 1234 bitxor ; : fixnum-declarations ( a -- b ) >fixnum 24 shift 1234 bitxor ;
[ ] [ 1000000 fixnum-declarations . ] unit-test [ ] [ 1000000 fixnum-declarations . ] unit-test
@ -61,13 +61,13 @@ TUPLE: pred-test ;
! regression ! regression
: bad-kill-1 ( a b -- c d e ) [ 3 f ] [ dup bad-kill-1 ] if ; inline : bad-kill-1 ( a b -- c d e ) [ 3 f ] [ dup bad-kill-1 ] if ; inline recursive
: bad-kill-2 bad-kill-1 drop ; : bad-kill-2 ( a b -- c d ) bad-kill-1 drop ;
[ 3 ] [ t bad-kill-2 ] unit-test [ 3 ] [ t bad-kill-2 ] unit-test
! regression ! regression
: (the-test) ( x -- y ) dup 0 > [ 1- (the-test) ] when ; inline : (the-test) ( x -- y ) dup 0 > [ 1- (the-test) ] when ; inline recursive
: the-test ( -- x y ) 2 dup (the-test) ; : the-test ( -- x y ) 2 dup (the-test) ;
[ 2 0 ] [ the-test ] unit-test [ 2 0 ] [ the-test ] unit-test
@ -77,7 +77,7 @@ TUPLE: pred-test ;
< [ < [
6 1 (double-recursion) 6 1 (double-recursion)
3 2 (double-recursion) 3 2 (double-recursion)
] when ; inline ] when ; inline recursive
: double-recursion ( -- ) 0 2 (double-recursion) ; : double-recursion ( -- ) 0 2 (double-recursion) ;
@ -85,7 +85,7 @@ TUPLE: pred-test ;
! regression ! regression
: double-label-1 ( a b c -- d ) : double-label-1 ( a b c -- d )
[ f double-label-1 ] [ swap nth-unsafe ] if ; inline [ f double-label-1 ] [ swap nth-unsafe ] if ; inline recursive
: double-label-2 ( a -- b ) : double-label-2 ( a -- b )
dup array? [ ] [ ] if 0 t double-label-1 ; dup array? [ ] [ ] if 0 t double-label-1 ;
@ -100,7 +100,7 @@ GENERIC: void-generic ( obj -- * )
! regression ! regression
: branch-fold-regression-0 ( m -- n ) : branch-fold-regression-0 ( m -- n )
t [ ] [ 1+ branch-fold-regression-0 ] if ; inline t [ ] [ 1+ branch-fold-regression-0 ] if ; inline recursive
: branch-fold-regression-1 ( -- m ) : branch-fold-regression-1 ( -- m )
10 branch-fold-regression-0 ; 10 branch-fold-regression-0 ;
@ -224,7 +224,7 @@ USE: binary-search.private
] unit-test ] unit-test
! Regression ! Regression
: empty-compound ; : empty-compound ( -- ) ;
: node-successor-f-bug ( x -- * ) : node-successor-f-bug ( x -- * )
[ 3 throw ] [ empty-compound ] compose [ 3 throw ] if ; [ 3 throw ] [ empty-compound ] compose [ 3 throw ] if ;
@ -293,7 +293,7 @@ HINTS: recursive-inline-hang-3 array ;
! Wow ! Wow
: counter-example ( a b c d -- a' b' c' d' ) : counter-example ( a b c d -- a' b' c' d' )
dup 0 > [ 1 - [ rot 2 * ] dip counter-example ] when ; inline dup 0 > [ 1 - [ rot 2 * ] dip counter-example ] when ; inline recursive
: counter-example' ( -- a' b' c' d' ) : counter-example' ( -- a' b' c' d' )
1 2 3.0 3 counter-example ; 1 2 3.0 3 counter-example ;

View File

@ -0,0 +1,20 @@
USING: compiler.units words tools.test math kernel ;
IN: compiler.tests.redefine15
DEFER: word-1
: word-2 ( a -- b ) word-1 ;
[ \ word-1 [ ] (( a -- b )) define-declared ] with-compilation-unit
[ "a" ] [ "a" word-2 ] unit-test
: word-3 ( a -- b ) 1 + ;
: word-4 ( a -- b c ) 0 swap word-3 swap 1+ ;
[ 1 1 ] [ 0 word-4 ] unit-test
[ \ word-3 [ [ 2 + ] bi@ ] (( a b -- c d )) define-declared ] with-compilation-unit
[ 2 3 ] [ 0 word-4 ] unit-test

View File

@ -1,12 +1,14 @@
IN: compiler.tests IN: compiler.tests
USING: compiler compiler.units tools.test math parser kernel USING: compiler compiler.units tools.test math parser kernel
sequences sequences.private classes.mixin generic definitions sequences sequences.private classes.mixin generic definitions
arrays words assocs eval ; 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 new sequence? ] unit-test [ t ] [ redefine2-test new sequence? ] unit-test
[ 3 ] [ 0 redefine2-test new nth-unsafe ] unit-test [ 3 ] [ 0 redefine2-test new nth-unsafe ] unit-test

View File

@ -90,7 +90,7 @@ M: object xyz ;
[ swap [ call 1+ ] dip ] keep (i-repeat) [ swap [ call 1+ ] dip ] keep (i-repeat)
] if ; inline recursive ] if ; inline recursive
: i-repeat [ { integer } declare ] dip 0 -rot (i-repeat) ; inline : i-repeat ( n quot -- ) [ { integer } declare ] dip 0 -rot (i-repeat) ; inline
[ t ] [ [ t ] [
[ [ dup xyz drop ] i-repeat ] \ xyz inlined? [ [ dup xyz drop ] i-repeat ] \ xyz inlined?
@ -197,7 +197,7 @@ M: fixnum annotate-entry-test-1 drop ;
[ dup annotate-entry-test-1 1+ ] dip (annotate-entry-test-2) [ dup annotate-entry-test-1 1+ ] dip (annotate-entry-test-2)
] if ; inline recursive ] if ; inline recursive
: annotate-entry-test-2 0 -rot (annotate-entry-test-2) ; inline : annotate-entry-test-2 ( from to -- ) 0 -rot (annotate-entry-test-2) ; inline
[ f ] [ [ f ] [
[ { bignum } declare annotate-entry-test-2 ] [ { bignum } declare annotate-entry-test-2 ]

View File

@ -16,8 +16,8 @@ MACRO: set-slots ( slots -- quot )
[ [ in>> '[ _ _ construct ] ] dip compose ] [ drop ] 2bi [ [ in>> '[ _ _ construct ] ] dip compose ] [ drop ] 2bi
define-declared ; define-declared ;
: CONSTRUCTOR: SYNTAX: CONSTRUCTOR:
scan-word [ name>> "<" ">" surround create-in ] keep scan-word [ name>> "<" ">" surround create-in ] keep
"(" expect ")" parse-effect complete-effect
parse-definition parse-definition
define-constructor ; parsing define-constructor ;

View File

@ -3,7 +3,7 @@
USING: words parser alien alien.c-types kernel fry accessors ; USING: words parser alien alien.c-types kernel fry accessors ;
IN: core-text.utilities IN: core-text.utilities
: C-GLOBAL: SYNTAX: C-GLOBAL:
CREATE-WORD CREATE-WORD
dup name>> '[ _ f dlsym *void* ] dup name>> '[ _ f dlsym *void* ]
(( -- value )) define-declared ; parsing (( -- value )) define-declared ;

View File

@ -21,7 +21,7 @@ IN: cpu.ppc.assembler.backend
: define-d-insn ( word opcode -- ) : define-d-insn ( word opcode -- )
[ d-insn ] curry (( d a simm -- )) define-declared ; [ d-insn ] curry (( d a simm -- )) define-declared ;
: D: CREATE scan-word define-d-insn ; parsing SYNTAX: D: CREATE scan-word define-d-insn ;
: sd-insn ( d a simm opcode -- ) : sd-insn ( d a simm opcode -- )
[ s>u16 { 0 21 16 } bitfield ] dip insn ; [ s>u16 { 0 21 16 } bitfield ] dip insn ;
@ -29,7 +29,7 @@ IN: cpu.ppc.assembler.backend
: define-sd-insn ( word opcode -- ) : define-sd-insn ( word opcode -- )
[ sd-insn ] curry (( d a simm -- )) define-declared ; [ sd-insn ] curry (( d a simm -- )) define-declared ;
: SD: CREATE scan-word define-sd-insn ; parsing SYNTAX: SD: CREATE scan-word define-sd-insn ;
: i-insn ( li aa lk opcode -- ) : i-insn ( li aa lk opcode -- )
[ { 0 1 0 } bitfield ] dip insn ; [ { 0 1 0 } bitfield ] dip insn ;
@ -40,26 +40,26 @@ IN: cpu.ppc.assembler.backend
: (X) ( -- word quot ) : (X) ( -- word quot )
CREATE scan-word scan-word scan-word [ x-insn ] 3curry ; CREATE scan-word scan-word scan-word [ x-insn ] 3curry ;
: X: (X) (( a s b -- )) define-declared ; parsing SYNTAX: X: (X) (( a s b -- )) define-declared ;
: (1) ( quot -- quot' ) [ 0 ] prepose ; : (1) ( quot -- quot' ) [ 0 ] prepose ;
: X1: (X) (1) (( a s -- )) define-declared ; parsing SYNTAX: X1: (X) (1) (( a s -- )) define-declared ;
: xfx-insn ( d spr xo opcode -- ) : xfx-insn ( d spr xo opcode -- )
[ { 1 11 21 } bitfield ] dip insn ; [ { 1 11 21 } bitfield ] dip insn ;
: CREATE-MF ( -- word ) scan "MF" prepend create-in ; : CREATE-MF ( -- word ) scan "MF" prepend create-in ;
: MFSPR: SYNTAX: MFSPR:
CREATE-MF scan-word 5 shift [ 339 31 xfx-insn ] curry CREATE-MF scan-word 5 shift [ 339 31 xfx-insn ] curry
(( d -- )) define-declared ; parsing (( d -- )) define-declared ;
: CREATE-MT ( -- word ) scan "MT" prepend create-in ; : CREATE-MT ( -- word ) scan "MT" prepend create-in ;
: MTSPR: SYNTAX: MTSPR:
CREATE-MT scan-word 5 shift [ 467 31 xfx-insn ] curry CREATE-MT scan-word 5 shift [ 467 31 xfx-insn ] curry
(( d -- )) define-declared ; parsing (( d -- )) define-declared ;
: xo-insn ( d a b oe rc xo opcode -- ) : xo-insn ( d a b oe rc xo opcode -- )
[ { 1 0 10 11 16 21 } bitfield ] dip insn ; [ { 1 0 10 11 16 21 } bitfield ] dip insn ;
@ -68,9 +68,9 @@ IN: cpu.ppc.assembler.backend
CREATE scan-word scan-word scan-word scan-word CREATE scan-word scan-word scan-word scan-word
[ xo-insn ] 2curry 2curry ; [ xo-insn ] 2curry 2curry ;
: XO: (XO) (( a s b -- )) define-declared ; parsing SYNTAX: XO: (XO) (( a s b -- )) define-declared ;
: XO1: (XO) (1) (( a s -- )) define-declared ; parsing SYNTAX: XO1: (XO) (1) (( a s -- )) define-declared ;
GENERIC# (B) 2 ( dest aa lk -- ) GENERIC# (B) 2 ( dest aa lk -- )
M: integer (B) 18 i-insn ; M: integer (B) 18 i-insn ;
@ -84,11 +84,11 @@ M: label BC [ 0 BC ] dip rc-relative-ppc-2 label-fixup ;
: CREATE-B ( -- word ) scan "B" prepend create-in ; : CREATE-B ( -- word ) scan "B" prepend create-in ;
: BC: SYNTAX: BC:
CREATE-B scan-word scan-word CREATE-B scan-word scan-word
[ rot BC ] 2curry (( c -- )) define-declared ; parsing [ rot BC ] 2curry (( c -- )) define-declared ;
: B: SYNTAX: B:
CREATE-B scan-word scan-word scan-word scan-word scan-word CREATE-B scan-word scan-word scan-word scan-word scan-word
[ b-insn ] curry curry curry curry curry [ b-insn ] curry curry curry curry curry
(( bo -- )) define-declared ; parsing (( bo -- )) define-declared ;

View File

@ -11,8 +11,8 @@ big-endian on
4 jit-code-format set 4 jit-code-format set
: ds-reg 29 ; CONSTANT: ds-reg 29
: rs-reg 30 ; CONSTANT: rs-reg 30
: factor-area-size ( -- n ) 4 bootstrap-cells ; : factor-area-size ( -- n ) 4 bootstrap-cells ;

View File

@ -11,5 +11,4 @@ IN: cpu.x86.assembler.syntax
: define-registers ( names size -- ) : define-registers ( names size -- )
'[ _ define-register ] each-index ; '[ _ define-register ] each-index ;
: REGISTERS: ( -- ) SYNTAX: REGISTERS: scan-word ";" parse-tokens swap define-registers ;
scan-word ";" parse-tokens swap define-registers ; parsing

View File

@ -285,7 +285,7 @@ paste "PASTE"
[ test-cascade ] test-postgresql [ test-cascade ] test-postgresql
[ test-restrict ] test-postgresql [ test-restrict ] test-postgresql
: test-repeated-insert : test-repeated-insert ( -- )
[ ] [ person ensure-table ] unit-test [ ] [ person ensure-table ] unit-test
[ ] [ person1 get insert-tuple ] unit-test [ ] [ person1 get insert-tuple ] unit-test
[ person1 get insert-tuple ] must-fail ; [ person1 get insert-tuple ] must-fail ;
@ -458,7 +458,7 @@ TUPLE: bignum-test id m n o ;
swap >>n swap >>n
swap >>m ; swap >>m ;
: test-bignum : test-bignum ( -- )
bignum-test "BIGNUM_TEST" bignum-test "BIGNUM_TEST"
{ {
{ "id" "ID" +db-assigned-id+ } { "id" "ID" +db-assigned-id+ }
@ -478,7 +478,7 @@ TUPLE: bignum-test id m n o ;
TUPLE: secret n message ; TUPLE: secret n message ;
C: <secret> secret C: <secret> secret
: test-random-id : test-random-id ( -- )
secret "SECRET" secret "SECRET"
{ {
{ "n" "ID" +random-id+ system-random-generator } { "n" "ID" +random-id+ system-random-generator }

View File

@ -14,10 +14,10 @@ GENERIC: definition-icon ( definition -- path )
<< <<
: ICON: SYNTAX: ICON:
scan-word \ definition-icon create-method scan-word \ definition-icon create-method
scan '[ drop _ definition-icon-path ] scan '[ drop _ definition-icon-path ]
define ; parsing define ;
>> >>

View File

@ -41,13 +41,13 @@ M: hello bing hello-test ;
[ "USING: delegate ;\nIN: delegate.tests\nPROTOCOL: baz foo bar { whoa 1 } ; inline\n" ] [ [ baz see ] with-string-writer ] unit-test [ "USING: delegate ;\nIN: delegate.tests\nPROTOCOL: baz foo bar { whoa 1 } ; inline\n" ] [ [ baz see ] with-string-writer ] unit-test
GENERIC: one GENERIC: one ( a -- b )
M: integer one ; M: integer one ;
GENERIC: two GENERIC: two ( a -- b )
M: integer two ; M: integer two ;
GENERIC: three GENERIC: three ( a -- b )
M: integer three ; M: integer three ;
GENERIC: four GENERIC: four ( a -- b )
M: integer four ; M: integer four ;
PROTOCOL: alpha one two ; PROTOCOL: alpha one two ;

View File

@ -85,9 +85,9 @@ PRIVATE>
: define-consult ( consultation -- ) : define-consult ( consultation -- )
[ register-consult ] [ consult-methods ] bi ; [ register-consult ] [ consult-methods ] bi ;
: CONSULT: SYNTAX: CONSULT:
scan-word scan-word parse-definition <consultation> scan-word scan-word parse-definition <consultation>
[ save-location ] [ define-consult ] bi ; parsing [ save-location ] [ define-consult ] bi ;
M: consultation where loc>> ; M: consultation where loc>> ;
@ -144,8 +144,8 @@ PRIVATE>
[ initialize-protocol-props ] 2tri [ initialize-protocol-props ] 2tri
] 2bi ; ] 2bi ;
: PROTOCOL: SYNTAX: PROTOCOL:
CREATE-WORD parse-definition define-protocol ; parsing CREATE-WORD parse-definition define-protocol ;
PREDICATE: protocol < word protocol-words ; ! Subclass of symbol? PREDICATE: protocol < word protocol-words ; ! Subclass of symbol?
@ -159,7 +159,7 @@ M: protocol definer drop \ PROTOCOL: \ ; ;
M: protocol group-words protocol-words ; M: protocol group-words protocol-words ;
: SLOT-PROTOCOL: SYNTAX: SLOT-PROTOCOL:
CREATE-WORD ";" parse-tokens CREATE-WORD ";" parse-tokens
[ [ reader-word ] [ writer-word ] bi 2array ] map concat [ [ reader-word ] [ writer-word ] bi 2array ] map concat
define-protocol ; parsing define-protocol ;

View File

@ -17,7 +17,7 @@ HELP: (set-os-envs)
{ $notes "In most cases, use " { $link set-os-envs } " instead." } ; { $notes "In most cases, use " { $link set-os-envs } " instead." } ;
HELP: os-env ( key -- value ) HELP: os-env
{ $values { "key" string } { "value" string } } { $values { "key" string } { "value" string } }
{ $description "Looks up the value of a shell environment variable." } { $description "Looks up the value of a shell environment variable." }
{ $examples { $examples
@ -39,14 +39,14 @@ HELP: set-os-envs
"Names and values of environment variables are operating system-specific. Windows NT allows values up to 32766 characters in length." "Names and values of environment variables are operating system-specific. Windows NT allows values up to 32766 characters in length."
} ; } ;
HELP: set-os-env ( value key -- ) HELP: set-os-env
{ $values { "value" string } { "key" string } } { $values { "value" string } { "key" string } }
{ $description "Set an environment variable." } { $description "Set an environment variable." }
{ $notes { $notes
"Names and values of environment variables are operating system-specific." "Names and values of environment variables are operating system-specific."
} ; } ;
HELP: unset-os-env ( key -- ) HELP: unset-os-env
{ $values { "key" string } } { $values { "key" string } }
{ $description "Unset an environment variable." } { $description "Unset an environment variable." }
{ $notes { $notes

View File

@ -9,7 +9,7 @@ HELP: write-farkup
{ $values { "string" string } } { $values { "string" string } }
{ $description "Parse a Farkup string and writes the resulting HTML to " { $link output-stream } "." } ; { $description "Parse a Farkup string and writes the resulting HTML to " { $link output-stream } "." } ;
HELP: parse-farkup ( string -- farkup ) HELP: parse-farkup
{ $values { "string" string } { "farkup" "a Farkup syntax tree node" } } { $values { "string" string } { "farkup" "a Farkup syntax tree node" } }
{ $description "Parses Farkup and outputs a tree of " { $link "farkup-ast" } "." } ; { $description "Parses Farkup and outputs a tree of " { $link "farkup-ast" } "." } ;

View File

@ -34,7 +34,7 @@ sequences eval accessors ;
{ "a" "b" "c" } swap map { "a" "b" "c" } swap map
] unit-test ] unit-test
: funny-dip '[ [ @ ] dip ] call ; inline : funny-dip ( obj quot -- ) '[ [ @ ] dip ] call ; inline
[ "hi" 3 ] [ "h" "i" 3 [ append ] funny-dip ] unit-test [ "hi" 3 ] [ "h" "i" 3 [ append ] funny-dip ] unit-test

View File

@ -53,4 +53,4 @@ M: callable deep-fry
M: object deep-fry , ; M: object deep-fry , ;
: '[ parse-quotation fry over push-all ; parsing SYNTAX: '[ parse-quotation fry over push-all ;

View File

@ -13,7 +13,7 @@ WHERE
TUPLE: B { value T } ; TUPLE: B { value T } ;
C: <B> B C: <B> B ( T -- B )
;FUNCTOR ;FUNCTOR

View File

@ -14,7 +14,9 @@ IN: functors
: scan-param ( -- obj ) scan-object literalize ; : scan-param ( -- obj ) scan-object literalize ;
: define* ( word def effect -- ) pick set-word define-declared ; : define* ( word def -- ) over set-word define ;
: define-declared* ( word def effect -- ) pick set-word define-declared ;
TUPLE: fake-quotation seq ; TUPLE: fake-quotation seq ;
@ -39,9 +41,14 @@ M: object fake-quotations> ;
: parse-definition* ( accum -- accum ) : parse-definition* ( accum -- accum )
parse-definition >fake-quotations parsed \ fake-quotations> parsed ; parse-definition >fake-quotations parsed \ fake-quotations> parsed ;
: DEFINE* ( accum -- accum ) effect get parsed \ define* parsed ; : parse-declared* ( accum -- accum )
complete-effect
[ parse-definition* ] dip
parsed ;
: `TUPLE: : DEFINE* ( accum -- accum ) \ define-declared* parsed ;
SYNTAX: `TUPLE:
scan-param parsed scan-param parsed
scan { scan {
{ ";" [ tuple parsed f parsed ] } { ";" [ tuple parsed f parsed ] }
@ -52,40 +59,38 @@ M: object fake-quotations> ;
make parsed make parsed
] ]
} case } case
\ define-tuple-class parsed ; parsing \ define-tuple-class parsed ;
: `M: SYNTAX: `M:
effect off
scan-param parsed scan-param parsed
scan-param parsed scan-param parsed
\ create-method-in parsed \ create-method-in parsed
parse-definition* parse-definition*
DEFINE* ; parsing \ define* parsed ;
: `C: SYNTAX: `C:
effect off
scan-param parsed scan-param parsed
scan-param parsed scan-param parsed
[ [ boa ] curry ] over push-all complete-effect
DEFINE* ; parsing [ [ [ boa ] curry ] over push-all ] dip parsed
\ define-declared* parsed ;
: `: SYNTAX: `:
effect off scan-param parsed
parse-declared*
\ define-declared* parsed ;
SYNTAX: `SYNTAX:
scan-param parsed scan-param parsed
parse-definition* parse-definition*
DEFINE* ; parsing \ define-syntax parsed ;
: `INSTANCE: SYNTAX: `INSTANCE:
scan-param parsed scan-param parsed
scan-param parsed scan-param parsed
\ add-mixin-instance parsed ; parsing \ add-mixin-instance parsed ;
: `inline [ word make-inline ] over push-all ; parsing SYNTAX: `inline [ word make-inline ] over push-all ;
: `parsing [ word make-parsing ] over push-all ; parsing
: `(
")" parse-effect effect set ; parsing
: (INTERPOLATE) ( accum quot -- accum ) : (INTERPOLATE) ( accum quot -- accum )
[ scan interpolate-locals ] dip [ scan interpolate-locals ] dip
@ -93,11 +98,11 @@ M: object fake-quotations> ;
PRIVATE> PRIVATE>
: IS [ dup search [ ] [ no-word ] ?if ] (INTERPOLATE) ; parsing SYNTAX: IS [ dup search [ ] [ no-word ] ?if ] (INTERPOLATE) ;
: DEFINES [ create-in ] (INTERPOLATE) ; parsing SYNTAX: DEFINES [ create-in ] (INTERPOLATE) ;
: DEFINES-CLASS [ create-class-in ] (INTERPOLATE) ; parsing SYNTAX: DEFINES-CLASS [ create-class-in ] (INTERPOLATE) ;
DEFER: ;FUNCTOR delimiter DEFER: ;FUNCTOR delimiter
@ -110,9 +115,8 @@ DEFER: ;FUNCTOR delimiter
{ "C:" POSTPONE: `C: } { "C:" POSTPONE: `C: }
{ ":" POSTPONE: `: } { ":" POSTPONE: `: }
{ "INSTANCE:" POSTPONE: `INSTANCE: } { "INSTANCE:" POSTPONE: `INSTANCE: }
{ "SYNTAX:" POSTPONE: `SYNTAX: }
{ "inline" POSTPONE: `inline } { "inline" POSTPONE: `inline }
{ "parsing" POSTPONE: `parsing }
{ "(" POSTPONE: `( }
} ; } ;
: push-functor-words ( -- ) : push-functor-words ( -- )
@ -127,9 +131,9 @@ DEFER: ;FUNCTOR delimiter
[ \ ;FUNCTOR parse-until >quotation ] ((parse-lambda)) <let*> 1quotation [ \ ;FUNCTOR parse-until >quotation ] ((parse-lambda)) <let*> 1quotation
pop-functor-words ; pop-functor-words ;
: (FUNCTOR:) ( -- word def ) : (FUNCTOR:) ( -- word def effect )
CREATE-WORD [ parse-functor-body ] parse-locals-definition ; CREATE-WORD [ parse-functor-body ] parse-locals-definition ;
PRIVATE> PRIVATE>
: FUNCTOR: (FUNCTOR:) define ; parsing SYNTAX: FUNCTOR: (FUNCTOR:) define-declared ;

View File

@ -7,7 +7,7 @@ IN: furnace.actions.tests
[ "a" param "b" param [ string>number ] bi@ + ] >>display [ "a" param "b" param [ string>number ] bi@ + ] >>display
"action-1" set "action-1" set
: lf>crlf "\n" split "\r\n" join ; : lf>crlf ( string -- string' ) "\n" split "\r\n" join ;
STRING: action-request-test-1 STRING: action-request-test-1
GET http://foo/bar?a=12&b=13 HTTP/1.1 GET http://foo/bar?a=12&b=13 HTTP/1.1

View File

@ -4,7 +4,7 @@ http.server furnace furnace.utilities tools.test kernel
namespaces accessors io.streams.string urls xml.writer ; namespaces accessors io.streams.string urls xml.writer ;
TUPLE: funny-dispatcher < dispatcher ; TUPLE: funny-dispatcher < dispatcher ;
: <funny-dispatcher> funny-dispatcher new-dispatcher ; : <funny-dispatcher> ( -- dispatcher ) funny-dispatcher new-dispatcher ;
TUPLE: base-path-check-responder ; TUPLE: base-path-check-responder ;

View File

@ -6,7 +6,7 @@ io.streams.string io.files io.files.temp io.directories
splitting destructors sequences db db.tuples db.sqlite splitting destructors sequences db db.tuples db.sqlite
continuations urls math.parser furnace furnace.utilities ; continuations urls math.parser furnace furnace.utilities ;
: with-session : with-session ( session quot -- )
[ [
[ [ save-session-after ] [ session set ] bi ] dip call [ [ save-session-after ] [ session set ] bi ] dip call
] with-destructors ; inline ] with-destructors ; inline
@ -22,7 +22,7 @@ M: foo call-responder*
"x" [ 1+ ] schange "x" [ 1+ ] schange
"x" sget number>string "text/html" <content> ; "x" sget number>string "text/html" <content> ;
: url-responder-mock-test : url-responder-mock-test ( -- )
[ [
<request> <request>
"GET" >>method "GET" >>method
@ -34,7 +34,7 @@ M: foo call-responder*
[ write-response-body drop ] with-string-writer [ write-response-body drop ] with-string-writer
] with-destructors ; ] with-destructors ;
: sessions-mock-test : sessions-mock-test ( -- )
[ [
<request> <request>
"GET" >>method "GET" >>method
@ -45,7 +45,7 @@ M: foo call-responder*
[ write-response-body drop ] with-string-writer [ write-response-body drop ] with-string-writer
] with-destructors ; ] with-destructors ;
: <exiting-action> : <exiting-action> ( -- action )
<action> <action>
[ [ ] "text/plain" <content> exit-with ] >>display ; [ [ ] "text/plain" <content> exit-with ] >>display ;

View File

@ -97,8 +97,7 @@ HELP: <clumps>
{ $example { $example
"USING: grouping sequences math prettyprint kernel ;" "USING: grouping sequences math prettyprint kernel ;"
"IN: scratchpad" "IN: scratchpad"
": share-price" "CONSTANT: share-price { 13/50 51/100 13/50 1/10 4/5 17/20 33/50 3/25 19/100 3/100 }"
" { 13/50 51/100 13/50 1/10 4/5 17/20 33/50 3/25 19/100 3/100 } ;"
"" ""
"share-price 4 <clumps> [ [ sum ] [ length ] bi / ] map ." "share-price 4 <clumps> [ [ sum ] [ length ] bi / ] map ."
"{ 113/400 167/400 201/400 241/400 243/400 91/200 1/4 }" "{ 113/400 167/400 201/400 241/400 243/400 91/200 1/4 }"

View File

@ -4,7 +4,7 @@ IN: hash2.tests
[ t ] [ 1 2 { 1 2 } 2= ] unit-test [ t ] [ 1 2 { 1 2 } 2= ] unit-test
[ f ] [ 1 3 { 1 2 } 2= ] unit-test [ f ] [ 1 3 { 1 2 } 2= ] unit-test
: sample-hash : sample-hash ( -- )
5 <hash2> 5 <hash2>
dup 2 3 "foo" roll set-hash2 dup 2 3 "foo" roll set-hash2
dup 4 2 "bar" roll set-hash2 dup 4 2 "bar" roll set-hash2

View File

@ -121,16 +121,16 @@ $nl
"sequences" "sequences"
} ; } ;
ARTICLE: "cookbook-variables" "Variables cookbook" ARTICLE: "cookbook-variables" "Dynamic variables cookbook"
"Before using a variable, you must define a symbol for it:"
{ $code "SYMBOL: name" }
"A symbol is a word which pushes itself on the stack when executed. Try it:" "A symbol is a word which pushes itself on the stack when executed. Try it:"
{ $example "SYMBOL: foo" "foo ." "foo" } { $example "SYMBOL: foo" "foo ." "foo" }
"Before using a variable, you must define a symbol for it:"
{ $code "SYMBOL: name" }
"Symbols can be passed to the " { $link get } " and " { $link set } " words to read and write variable values:" "Symbols can be passed to the " { $link get } " and " { $link set } " words to read and write variable values:"
{ $example "\"Slava\" name set" "name get print" "Slava" } { $unchecked-example "\"Slava\" name set" "name get print" "Slava" }
"If you set variables inside a " { $link with-scope } ", their values will be lost after leaving the scope:" "If you set variables inside a " { $link with-scope } ", their values will be lost after leaving the scope:"
{ $example { $unchecked-example
": print-name name get print ;" ": print-name ( -- ) name get print ;"
"\"Slava\" name set" "\"Slava\" name set"
"[" "["
" \"Diana\" name set" " \"Diana\" name set"
@ -139,11 +139,8 @@ ARTICLE: "cookbook-variables" "Variables cookbook"
"\"Here, the name is \" write print-name" "\"Here, the name is \" write print-name"
"There, the name is Diana\nHere, the name is Slava" "There, the name is Diana\nHere, the name is Slava"
} }
{ $curious
"Variables are dynamically-scoped in Factor."
}
{ $references { $references
"There is a lot more to be said about variables and namespaces." "There is a lot more to be said about dynamically-scoped variables and namespaces."
"namespaces" "namespaces"
} ; } ;

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

@ -7,7 +7,7 @@ IN: help.definitions.tests
[ [
[ 4 ] [ [ 4 ] [
"IN: help.definitions.tests USING: help.syntax ; : hello ; HELP: hello \"test\" ; ARTICLE: \"hello\" \"world\" ; ARTICLE: \"hello2\" \"world\" ;" <string-reader> "foo" "IN: help.definitions.tests USING: help.syntax ; : hello ( -- ) ; HELP: hello \"test\" ; ARTICLE: \"hello\" \"world\" ; ARTICLE: \"hello2\" \"world\" ;" <string-reader> "foo"
parse-stream drop parse-stream drop
"foo" source-file definitions>> first assoc-size "foo" source-file definitions>> first assoc-size
@ -20,7 +20,7 @@ IN: help.definitions.tests
] unit-test ] unit-test
[ 2 ] [ [ 2 ] [
"IN: help.definitions.tests USING: help.syntax ; : hello ; ARTICLE: \"hello\" \"world\" ;" <string-reader> "foo" "IN: help.definitions.tests USING: help.syntax ; : hello ( -- ) ; ARTICLE: \"hello\" \"world\" ;" <string-reader> "foo"
parse-stream drop parse-stream drop
"foo" source-file definitions>> first assoc-size "foo" source-file definitions>> first assoc-size
@ -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

@ -11,7 +11,7 @@ TUPLE: blahblah quux ;
[ ] [ \ >>quux print-topic ] unit-test [ ] [ \ >>quux print-topic ] unit-test
[ ] [ \ blahblah? print-topic ] unit-test [ ] [ \ blahblah? print-topic ] unit-test
: fooey "fooey" throw ; : fooey ( -- * ) "fooey" throw ;
[ ] [ \ fooey print-topic ] unit-test [ ] [ \ fooey print-topic ] unit-test

View File

@ -4,7 +4,7 @@ USING: accessors arrays definitions generic io kernel assocs
hashtables namespaces make parser prettyprint sequences strings hashtables namespaces make parser prettyprint sequences strings
io.styles vectors words math sorting splitting classes slots fry io.styles vectors words math sorting splitting classes slots fry
sets vocabs help.stylesheet help.topics vocabs.loader quotations sets vocabs help.stylesheet help.topics vocabs.loader quotations
combinators see ; combinators see present ;
IN: help.markup IN: help.markup
PREDICATE: simple-element < array PREDICATE: simple-element < array
@ -276,7 +276,7 @@ M: f ($instance)
$snippet ; $snippet ;
: values-row ( seq -- seq ) : values-row ( seq -- seq )
unclip \ $snippet swap ?word-name 2array unclip \ $snippet swap present 2array
swap dup first word? [ \ $instance prefix ] when 2array ; swap dup first word? [ \ $instance prefix ] when 2array ;
: $values ( element -- ) : $values ( element -- )

View File

@ -1,23 +1,19 @@
! Copyright (C) 2005, 2008 Slava Pestov. ! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays kernel parser sequences words help USING: accessors arrays kernel parser sequences words help
help.topics namespaces vocabs definitions compiler.units help.topics namespaces vocabs definitions compiler.units
vocabs.parser ; vocabs.parser ;
IN: help.syntax IN: help.syntax
: HELP: SYNTAX: HELP:
scan-word bootstrap-word scan-word bootstrap-word
dup set-word [ >link save-location ] [ [ \ ; parse-until >array ] dip set-word-help ] bi ;
dup >link save-location
\ ; parse-until >array swap set-word-help ; parsing
: ARTICLE: SYNTAX: ARTICLE:
location [ location [
\ ; parse-until >array [ first2 ] keep 2 tail <article> \ ; parse-until >array [ first2 ] [ 2 tail ] bi <article>
over add-article >link over add-article >link
] dip remember-definition ; parsing ] dip remember-definition ;
: ABOUT: SYNTAX: ABOUT:
in get vocab in get vocab scan-object >>help changed-definition ;
dup changed-definition
scan-object >>help drop ; parsing

View File

@ -59,12 +59,11 @@ M: object specializer-declaration class ;
: specialized-length ( specializer -- n ) : specialized-length ( specializer -- n )
dup [ array? ] all? [ first ] when length ; dup [ array? ] all? [ first ] when length ;
: HINTS: SYNTAX: HINTS:
scan-object scan-object
dup method-spec? [ first2 method ] when dup method-spec? [ first2 method ] when
[ redefined ] [ redefined ]
[ parse-definition "specializer" set-word-prop ] bi ; [ parse-definition "specializer" set-word-prop ] bi ;
parsing
! Default specializers ! Default specializers
{ first first2 first3 first4 } { first first2 first3 first4 }

View File

@ -5,7 +5,7 @@ splitting unicode.categories furnace accessors
html.templates.chloe.compiler ; html.templates.chloe.compiler ;
IN: html.templates.chloe.tests IN: html.templates.chloe.tests
: run-template : run-template ( quot -- string )
with-string-writer [ "\r\n\t" member? not ] filter with-string-writer [ "\r\n\t" member? not ] filter
"?>" split1 nip ; inline "?>" split1 nip ; inline
@ -37,7 +37,7 @@ IN: html.templates.chloe.tests
] run-template ] run-template
] unit-test ] unit-test
: test4-aux? t ; : test4-aux? ( -- ? ) t ;
[ "True" ] [ [ "True" ] [
[ [
@ -45,7 +45,7 @@ IN: html.templates.chloe.tests
] run-template ] run-template
] unit-test ] unit-test
: test5-aux? f ; : test5-aux? ( -- ? ) f ;
[ "" ] [ [ "" ] [
[ [

View File

@ -25,8 +25,7 @@ M: tuple-class component-tag ( tag class -- )
[ compile-component-attrs ] 2bi [ compile-component-attrs ] 2bi
[ render ] [code] ; [ render ] [code] ;
: COMPONENT: SYNTAX: COMPONENT:
scan-word scan-word
[ name>> ] [ '[ _ component-tag ] ] bi [ name>> ] [ '[ _ component-tag ] ] bi
define-chloe-tag ; define-chloe-tag ;
parsing

View File

@ -15,8 +15,8 @@ tags [ H{ } clone ] initialize
: define-chloe-tag ( name quot -- ) swap tags get set-at ; : define-chloe-tag ( name quot -- ) swap tags get set-at ;
: CHLOE: SYNTAX: CHLOE:
scan parse-definition define-chloe-tag ; parsing scan parse-definition define-chloe-tag ;
CONSTANT: chloe-ns "http://factorcode.org/chloe/1.0" CONSTANT: chloe-ns "http://factorcode.org/chloe/1.0"

View File

@ -49,7 +49,7 @@ DEFER: <% delimiter
drop drop
] if ; ] if ;
: %> lexer get parse-%> ; parsing SYNTAX: %> lexer get parse-%> ;
: parse-template-lines ( lines -- quot ) : parse-template-lines ( lines -- quot )
<template-lexer> [ <template-lexer> [

View File

@ -13,7 +13,7 @@ IN: http.tests
[ "application/octet-stream" binary ] [ "application/octet-stream" parse-content-type ] unit-test [ "application/octet-stream" binary ] [ "application/octet-stream" parse-content-type ] unit-test
: lf>crlf "\n" split "\r\n" join ; : lf>crlf ( string -- string' ) "\n" split "\r\n" join ;
STRING: read-request-test-1 STRING: read-request-test-1
POST /bar HTTP/1.1 POST /bar HTTP/1.1
@ -180,14 +180,14 @@ accessors namespaces threads
http.server.responses http.server.redirection furnace.redirection http.server.responses http.server.redirection furnace.redirection
http.server.dispatchers db.tuples ; http.server.dispatchers db.tuples ;
: add-quit-action : add-quit-action ( responder -- responder )
<action> <action>
[ stop-this-server "Goodbye" "text/html" <content> ] >>display [ stop-this-server "Goodbye" "text/html" <content> ] >>display
"quit" add-responder ; "quit" add-responder ;
: test-db-file "test.db" temp-file ; : test-db-file ( -- path ) "test.db" temp-file ;
: test-db test-db-file <sqlite-db> ; : test-db ( -- db ) test-db-file <sqlite-db> ;
[ test-db-file delete-file ] ignore-errors [ test-db-file delete-file ] ignore-errors
@ -268,7 +268,7 @@ test-db [
test-httpd test-httpd
] unit-test ] unit-test
: 404? [ download-failed? ] [ response>> code>> 404 = ] bi and ; : 404? ( response -- ? ) [ download-failed? ] [ response>> code>> 404 = ] bi and ;
! This should give a 404 not an infinite redirect loop ! This should give a 404 not an infinite redirect loop
[ "http://localhost/d/blah" add-port http-get nip ] [ 404? ] must-fail-with [ "http://localhost/d/blah" add-port http-get nip ] [ 404? ] must-fail-with

View File

@ -38,6 +38,6 @@ MACRO: interpolate ( string -- )
: interpolate-locals ( string -- quot ) : interpolate-locals ( string -- quot )
[ search [ ] ] (interpolate) ; [ search [ ] ] (interpolate) ;
: I[ SYNTAX: I[
"]I" parse-multiline-string "]I" parse-multiline-string
interpolate-locals over push-all ; parsing interpolate-locals over push-all ;

View File

@ -1,22 +1,32 @@
USING: help.markup help.syntax ; ! Copyright (C) 2008, 2009 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax assocs kernel sequences ;
IN: interval-maps IN: interval-maps
HELP: interval-at* HELP: interval-at*
{ $values { "key" "an object" } { "map" "an interval map" } { "value" "the value for the key, or f" } { "?" "whether the key is present" } } { $values { "key" object } { "map" interval-map } { "value" "the value for the key, or f" } { "?" "whether the key is present" } }
{ $description "Looks up a key in an interval map, returning the corresponding value if the item is in an interval in the map, and a boolean flag. The operation takes O(log n) time." } ; { $description "Looks up a key in an interval map, returning the corresponding value if the item is in an interval in the map, and a boolean flag. The operation takes O(log n) time." } ;
HELP: interval-at HELP: interval-at
{ $values { "key" "an object" } { "map" "an interval map" } { "value" "the value for the key, or f" } } { $values { "key" object } { "map" interval-map } { "value" "the value for the key, or f" } }
{ $description "Looks up a key in an interval map, returning the value of the corresponding interval, or f if the interval is not present in the map." } ; { $description "Looks up a key in an interval map, returning the value of the corresponding interval, or f if the interval is not present in the map." } ;
HELP: interval-key? HELP: interval-key?
{ $values { "key" "an object" } { "map" "an interval map" } { "?" "a boolean" } } { $values { "key" object } { "map" interval-map } { "?" "a boolean" } }
{ $description "Tests whether an object is in an interval in the interval map, returning t if the object is present." } ; { $description "Tests whether an object is in an interval in the interval map, returning t if the object is present." } ;
HELP: <interval-map> HELP: <interval-map>
{ $values { "specification" "an assoc" } { "map" "an interval map" } } { $values { "specification" assoc } { "map" interval-map } }
{ $description "From a specification, produce an interval tree. The specification is an assoc where the keys are intervals, or pairs of numbers to represent intervals, or individual numbers to represent singleton intervals. The values are the values int he interval map. Construction time is O(n log n)." } ; { $description "From a specification, produce an interval tree. The specification is an assoc where the keys are intervals, or pairs of numbers to represent intervals, or individual numbers to represent singleton intervals. The values are the values int he interval map. Construction time is O(n log n)." } ;
HELP: interval-values
{ $values { "map" interval-map } { "values" sequence } }
{ $description "Constructs a list of all of the values that interval map keys are associated with. This list may contain duplicates." } ;
HELP: coalesce
{ $values { "alist" "an association list with integer keys" } { "specification" { "array of the format used by " { $link <interval-map> } } } }
{ $description "Finds ranges used in the given alist, coalescing them into a single range." } ;
ARTICLE: "interval-maps" "Interval maps" ARTICLE: "interval-maps" "Interval maps"
"The " { $vocab-link "interval-maps" } " vocabulary implements a data structure, similar to assocs, where a set of closed intervals of keys are associated with values. As such, interval maps do not conform to the assoc protocol, because intervals of floats, for example, can be used, and it is impossible to get a list of keys in between." "The " { $vocab-link "interval-maps" } " vocabulary implements a data structure, similar to assocs, where a set of closed intervals of keys are associated with values. As such, interval maps do not conform to the assoc protocol, because intervals of floats, for example, can be used, and it is impossible to get a list of keys in between."
$nl $nl
@ -24,7 +34,9 @@ $nl
{ $subsection interval-at* } { $subsection interval-at* }
{ $subsection interval-at } { $subsection interval-at }
{ $subsection interval-key? } { $subsection interval-key? }
{ $subsection interval-values }
"Use the following to construct interval maps" "Use the following to construct interval maps"
{ $subsection <interval-map> } ; { $subsection <interval-map> }
{ $subsection coalesce } ;
ABOUT: "interval-maps" ABOUT: "interval-maps"

View File

@ -8,17 +8,21 @@ TUPLE: interval-map array ;
<PRIVATE <PRIVATE
ALIAS: start first
ALIAS: end second
ALIAS: value third
: find-interval ( key interval-map -- interval-node ) : find-interval ( key interval-map -- interval-node )
[ first <=> ] with search nip ; array>> [ start <=> ] with search nip ;
: interval-contains? ( key interval-node -- ? ) : interval-contains? ( key interval-node -- ? )
first2 between? ; [ start ] [ end ] bi between? ;
: all-intervals ( sequence -- intervals ) : all-intervals ( sequence -- intervals )
[ [ dup number? [ dup 2array ] when ] dip ] { } assoc-map-as ; [ [ dup number? [ dup 2array ] when ] dip ] { } assoc-map-as ;
: disjoint? ( node1 node2 -- ? ) : disjoint? ( node1 node2 -- ? )
[ second ] [ first ] bi* < ; [ end ] [ start ] bi* < ;
: ensure-disjoint ( intervals -- intervals ) : ensure-disjoint ( intervals -- intervals )
dup [ disjoint? ] monotonic? dup [ disjoint? ] monotonic?
@ -30,14 +34,17 @@ TUPLE: interval-map array ;
PRIVATE> PRIVATE>
: interval-at* ( key map -- value ? ) : interval-at* ( key map -- value ? )
[ drop ] [ array>> find-interval ] 2bi [ drop ] [ find-interval ] 2bi
[ nip ] [ interval-contains? ] 2bi [ nip ] [ interval-contains? ] 2bi
[ third t ] [ drop f f ] if ; [ value t ] [ drop f f ] if ;
: interval-at ( key map -- value ) interval-at* drop ; : interval-at ( key map -- value ) interval-at* drop ;
: interval-key? ( key map -- ? ) interval-at* nip ; : interval-key? ( key map -- ? ) interval-at* nip ;
: interval-values ( map -- values )
array>> [ value ] map ;
: <interval-map> ( specification -- map ) : <interval-map> ( specification -- map )
all-intervals [ [ first second ] compare ] sort all-intervals [ [ first second ] compare ] sort
>intervals ensure-disjoint interval-map boa ; >intervals ensure-disjoint interval-map boa ;

View File

@ -5,7 +5,7 @@ io.streams.duplex destructors make io.launcher ;
IN: io.backend.unix.tests IN: io.backend.unix.tests
! Unix domain stream sockets ! Unix domain stream sockets
: socket-server "unix-domain-socket-test" temp-file ; : socket-server ( -- path ) "unix-domain-socket-test" temp-file ;
[ [
[ socket-server delete-file ] ignore-errors [ socket-server delete-file ] ignore-errors
@ -33,8 +33,8 @@ yield
] { } make ] { } make
] unit-test ] unit-test
: datagram-server "unix-domain-datagram-test" temp-file ; : datagram-server ( -- path ) "unix-domain-datagram-test" temp-file ;
: datagram-client "unix-domain-datagram-test-2" temp-file ; : datagram-client ( -- path ) "unix-domain-datagram-test-2" temp-file ;
! Unix domain datagram sockets ! Unix domain datagram sockets
[ datagram-server delete-file ] ignore-errors [ datagram-server delete-file ] ignore-errors
@ -104,7 +104,7 @@ datagram-client <local> <datagram>
[ ] [ "d" get dispose ] unit-test [ ] [ "d" get dispose ] unit-test
! Test error behavior ! Test error behavior
: another-datagram "unix-domain-datagram-test-3" temp-file ; : another-datagram ( -- path ) "unix-domain-datagram-test-3" temp-file ;
[ another-datagram delete-file ] ignore-errors [ another-datagram delete-file ] ignore-errors

View File

@ -63,6 +63,6 @@ SYMBOL: euc-table
PRIVATE> PRIVATE>
: EUC: SYNTAX: EUC:
! EUC: euc-kr "vocab:io/encodings/korean/cp949.txt" ! EUC: euc-kr "vocab:io/encodings/korean/cp949.txt"
CREATE-CLASS scan-object define-euc ; parsing CREATE-CLASS scan-object define-euc ;

View File

@ -7,30 +7,30 @@ IN: io.encodings.iso2022
[ "hello" ] [ "hello" >byte-array iso2022 decode ] unit-test [ "hello" ] [ "hello" >byte-array iso2022 decode ] unit-test
[ "hello" ] [ "hello" iso2022 encode >string ] unit-test [ "hello" ] [ "hello" iso2022 encode >string ] unit-test
[ "hi" ] [ B{ CHAR: h $ ESC CHAR: ( CHAR: B CHAR: i } iso2022 decode ] unit-test [ "hi" ] [ B{ CHAR: h ESC CHAR: ( CHAR: B CHAR: i } iso2022 decode ] unit-test
[ "hi" ] [ B{ CHAR: h CHAR: i $ ESC CHAR: ( CHAR: B } iso2022 decode ] unit-test [ "hi" ] [ B{ CHAR: h CHAR: i ESC CHAR: ( CHAR: B } iso2022 decode ] unit-test
[ "hi\u00fffd" ] [ B{ CHAR: h CHAR: i $ ESC CHAR: ( } iso2022 decode ] unit-test [ "hi\u00fffd" ] [ B{ CHAR: h CHAR: i ESC CHAR: ( } iso2022 decode ] unit-test
[ "hi\u00fffd" ] [ B{ CHAR: h CHAR: i $ ESC } iso2022 decode ] unit-test [ "hi\u00fffd" ] [ B{ CHAR: h CHAR: i ESC } iso2022 decode ] unit-test
[ B{ CHAR: h $ ESC CHAR: ( CHAR: J HEX: D8 } ] [ "h\u00ff98" iso2022 encode ] unit-test [ B{ CHAR: h ESC CHAR: ( CHAR: J HEX: D8 } ] [ "h\u00ff98" iso2022 encode ] unit-test
[ "h\u00ff98" ] [ B{ CHAR: h $ ESC CHAR: ( CHAR: J HEX: D8 } iso2022 decode ] unit-test [ "h\u00ff98" ] [ B{ CHAR: h ESC CHAR: ( CHAR: J HEX: D8 } iso2022 decode ] unit-test
[ "hi" ] [ B{ CHAR: h $ ESC CHAR: ( CHAR: J CHAR: i } iso2022 decode ] unit-test [ "hi" ] [ B{ CHAR: h ESC CHAR: ( CHAR: J CHAR: i } iso2022 decode ] unit-test
[ "h" ] [ B{ CHAR: h $ ESC CHAR: ( CHAR: J } iso2022 decode ] unit-test [ "h" ] [ B{ CHAR: h ESC CHAR: ( CHAR: J } iso2022 decode ] unit-test
[ "h\u00fffd" ] [ B{ CHAR: h $ ESC CHAR: ( CHAR: J HEX: 80 } iso2022 decode ] unit-test [ "h\u00fffd" ] [ B{ CHAR: h ESC CHAR: ( CHAR: J HEX: 80 } iso2022 decode ] unit-test
[ B{ CHAR: h $ ESC CHAR: $ CHAR: B HEX: 3E HEX: 47 } ] [ "h\u007126" iso2022 encode ] unit-test [ B{ CHAR: h ESC CHAR: $ CHAR: B HEX: 3E HEX: 47 } ] [ "h\u007126" iso2022 encode ] unit-test
[ "h\u007126" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: B HEX: 3E HEX: 47 } iso2022 decode ] unit-test [ "h\u007126" ] [ B{ CHAR: h ESC CHAR: $ CHAR: B HEX: 3E HEX: 47 } iso2022 decode ] unit-test
[ "h\u00fffd" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: B HEX: 3E } iso2022 decode ] unit-test [ "h\u00fffd" ] [ B{ CHAR: h ESC CHAR: $ CHAR: B HEX: 3E } iso2022 decode ] unit-test
[ "h" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: B } iso2022 decode ] unit-test [ "h" ] [ B{ CHAR: h ESC CHAR: $ CHAR: B } iso2022 decode ] unit-test
[ "h\u00fffd" ] [ B{ CHAR: h $ ESC CHAR: $ } iso2022 decode ] unit-test [ "h\u00fffd" ] [ B{ CHAR: h ESC CHAR: $ } iso2022 decode ] unit-test
[ "h\u00fffd" ] [ B{ CHAR: h $ ESC } iso2022 decode ] unit-test [ "h\u00fffd" ] [ B{ CHAR: h ESC } iso2022 decode ] unit-test
[ "h\u00fffd" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: B HEX: 80 HEX: 80 } iso2022 decode ] unit-test [ "h\u00fffd" ] [ B{ CHAR: h ESC CHAR: $ CHAR: B HEX: 80 HEX: 80 } iso2022 decode ] unit-test
[ B{ CHAR: h $ ESC CHAR: $ CHAR: ( CHAR: D HEX: 38 HEX: 54 } ] [ "h\u0058ce" iso2022 encode ] unit-test [ B{ CHAR: h ESC CHAR: $ CHAR: ( CHAR: D HEX: 38 HEX: 54 } ] [ "h\u0058ce" iso2022 encode ] unit-test
[ "h\u0058ce" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: ( CHAR: D HEX: 38 HEX: 54 } iso2022 decode ] unit-test [ "h\u0058ce" ] [ B{ CHAR: h ESC CHAR: $ CHAR: ( CHAR: D HEX: 38 HEX: 54 } iso2022 decode ] unit-test
[ "h\u00fffd" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: ( CHAR: D HEX: 38 } iso2022 decode ] unit-test [ "h\u00fffd" ] [ B{ CHAR: h ESC CHAR: $ CHAR: ( CHAR: D HEX: 38 } iso2022 decode ] unit-test
[ "h" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: ( CHAR: D } iso2022 decode ] unit-test [ "h" ] [ B{ CHAR: h ESC CHAR: $ CHAR: ( CHAR: D } iso2022 decode ] unit-test
[ "h\u00fffd" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: ( } iso2022 decode ] unit-test [ "h\u00fffd" ] [ B{ CHAR: h ESC CHAR: $ CHAR: ( } iso2022 decode ] unit-test
[ "h\u00fffd" ] [ B{ CHAR: h $ ESC CHAR: $ CHAR: ( CHAR: D HEX: 70 HEX: 70 } iso2022 decode ] unit-test [ "h\u00fffd" ] [ B{ CHAR: h ESC CHAR: $ CHAR: ( CHAR: D HEX: 70 HEX: 70 } iso2022 decode ] unit-test
[ "\u{syriac-music}" iso2022 encode ] must-fail [ "\u{syriac-music}" iso2022 encode ] must-fail

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: io.encodings kernel sequences io simple-flat-file sets math USING: io.encodings kernel sequences io simple-flat-file sets math
combinators.short-circuit io.binary values arrays assocs combinators.short-circuit io.binary values arrays assocs
locals accessors combinators literals biassocs byte-arrays ; locals accessors combinators biassocs byte-arrays parser ;
IN: io.encodings.iso2022 IN: io.encodings.iso2022
SINGLETON: iso2022 SINGLETON: iso2022
@ -31,12 +31,12 @@ M: iso2022 <encoder>
M: iso2022 <decoder> M: iso2022 <decoder>
make-iso-coder <decoder> ; make-iso-coder <decoder> ;
CONSTANT: ESC HEX: 16 << SYNTAX: ESC HEX: 16 parsed ; >>
CONSTANT: switch-ascii B{ $ ESC CHAR: ( CHAR: B } CONSTANT: switch-ascii B{ ESC CHAR: ( CHAR: B }
CONSTANT: switch-jis201 B{ $ ESC CHAR: ( CHAR: J } CONSTANT: switch-jis201 B{ ESC CHAR: ( CHAR: J }
CONSTANT: switch-jis208 B{ $ ESC CHAR: $ CHAR: B } CONSTANT: switch-jis208 B{ ESC CHAR: $ CHAR: B }
CONSTANT: switch-jis212 B{ $ ESC CHAR: $ CHAR: ( CHAR: D } CONSTANT: switch-jis212 B{ ESC CHAR: $ CHAR: ( CHAR: D }
: find-type ( char -- code type ) : find-type ( char -- code type )
{ {

View File

@ -3,6 +3,6 @@
USING: help.syntax help.markup ; USING: help.syntax help.markup ;
IN: io.encodings.strict IN: io.encodings.strict
HELP: strict ( encoding -- strict-encoding ) HELP: strict ( code -- strict )
{ $values { "encoding" "an encoding descriptor" } { "strict-encoding" "a strict encoding descriptor" } } { $values { "code" "an encoding descriptor" } { "strict" "a strict encoding descriptor" } }
{ $description "Makes an encoding strict, that is, in the presence of a malformed code point, an error is thrown. Note that the existence of a replacement character in a file (U+FFFD) also throws an error." } ; { $description "Makes an encoding strict, that is, in the presence of a malformed code point, an error is thrown. Note that the existence of a replacement character in a file (U+FFFD) also throws an error." } ;

View File

@ -2,7 +2,7 @@ USING: accessors alien.c-types kernel
io.encodings.utf16 io.streams.byte-array tools.test ; io.encodings.utf16 io.streams.byte-array tools.test ;
IN: io.encodings.utf16n IN: io.encodings.utf16n
: correct-endian : correct-endian ( obj -- ? )
code>> little-endian? [ utf16le = ] [ utf16be = ] if ; code>> little-endian? [ utf16le = ] [ utf16be = ] if ;
[ t ] [ B{ } utf16n <byte-reader> correct-endian ] unit-test [ t ] [ B{ } utf16n <byte-reader> correct-endian ] unit-test

View File

@ -23,7 +23,7 @@ HELP: unique-retries
{ unique-length unique-retries } related-words { unique-length unique-retries } related-words
HELP: make-unique-file ( prefix suffix -- path ) HELP: make-unique-file
{ $values { "prefix" "a string" } { "suffix" "a string" } { $values { "prefix" "a string" } { "suffix" "a string" }
{ "path" "a pathname string" } } { "path" "a pathname string" } }
{ $description "Creates a file that is guaranteed not to exist in the directory stored in " { $link current-temporary-directory } ". The file name is composed of a prefix, a number of random digits and letters, and the suffix. Returns the full pathname." } { $description "Creates a file that is guaranteed not to exist in the directory stored in " { $link current-temporary-directory } ". The file name is composed of a prefix, a number of random digits and letters, and the suffix. Returns the full pathname." }
@ -31,18 +31,18 @@ HELP: make-unique-file ( prefix suffix -- path )
{ unique-file make-unique-file cleanup-unique-file } related-words { unique-file make-unique-file cleanup-unique-file } related-words
HELP: cleanup-unique-file ( prefix suffix quot: ( path -- ) -- ) HELP: cleanup-unique-file
{ $values { "prefix" "a string" } { "suffix" "a string" } { $values { "prefix" "a string" } { "suffix" "a string" }
{ "quot" "a quotation" } } { "quot" "a quotation" } }
{ $description "Creates a file with " { $link make-unique-file } " and calls the quotation with the path name on the stack." } { $description "Creates a file with " { $link make-unique-file } " and calls the quotation with the path name on the stack." }
{ $notes "The unique file will be deleted after calling this word." } ; { $notes "The unique file will be deleted after calling this word." } ;
HELP: unique-directory ( -- path ) HELP: unique-directory
{ $values { "path" "a pathname string" } } { $values { "path" "a pathname string" } }
{ $description "Creates a directory in the value in " { $link current-temporary-directory } " that is guaranteed not to exist in and returns the full pathname." } { $description "Creates a directory in the value in " { $link current-temporary-directory } " that is guaranteed not to exist in and returns the full pathname." }
{ $errors "Throws an error if the directory cannot be created after a number of tries. The most likely error is incorrect directory permissions on the temporary directory." } ; { $errors "Throws an error if the directory cannot be created after a number of tries. The most likely error is incorrect directory permissions on the temporary directory." } ;
HELP: cleanup-unique-directory ( quot -- ) HELP: cleanup-unique-directory
{ $values { "quot" "a quotation" } } { $values { "quot" "a quotation" } }
{ $description "Creates a directory with " { $link unique-directory } " and calls the quotation with the pathname on the stack using the " { $link with-temporary-directory } " combinator. The quotation can access the " { $link current-temporary-directory } " symbol for the name of the temporary directory. Subsequent unique files will be created in this unique directory until the combinator returns." } { $description "Creates a directory with " { $link unique-directory } " and calls the quotation with the pathname on the stack using the " { $link with-temporary-directory } " combinator. The quotation can access the " { $link current-temporary-directory } " symbol for the name of the temporary directory. Subsequent unique files will be created in this unique directory until the combinator returns." }
{ $notes "The directory will be deleted after calling this word, even if an error is thrown in the quotation. This combinator is like " { $link with-unique-directory } " but does not delete the directory." } ; { $notes "The directory will be deleted after calling this word, even if an error is thrown in the quotation. This combinator is like " { $link with-unique-directory } " but does not delete the directory." } ;

View File

@ -5,13 +5,13 @@ IN: io.streams.duplex.tests
! Test duplex stream close behavior ! Test duplex stream close behavior
TUPLE: closing-stream < disposable ; TUPLE: closing-stream < disposable ;
: <closing-stream> closing-stream new ; : <closing-stream> ( -- stream ) closing-stream new ;
M: closing-stream dispose* drop ; M: closing-stream dispose* drop ;
TUPLE: unclosable-stream ; TUPLE: unclosable-stream ;
: <unclosable-stream> unclosable-stream new ; : <unclosable-stream> ( -- stream ) unclosable-stream new ;
M: unclosable-stream dispose M: unclosable-stream dispose
"Can't close me!" throw ; "Can't close me!" throw ;

View File

@ -3,7 +3,7 @@ tools.test parser math namespaces continuations vocabs kernel
compiler.units eval vocabs.parser ; compiler.units eval vocabs.parser ;
IN: listener.tests IN: listener.tests
: hello "Hi" print ; parsing SYNTAX: hello "Hi" print ;
: parse-interactive ( string -- quot ) : parse-interactive ( string -- quot )
<string-reader> stream-read-quot ; <string-reader> stream-read-quot ;
@ -50,7 +50,7 @@ IN: listener.tests
[ [
[ ] [ [ ] [
"IN: listener.tests : hello\n\"world\" ;" parse-interactive "IN: listener.tests : hello ( -- )\n\"world\" ;" parse-interactive
drop drop
] unit-test ] unit-test
] with-file-vocabs ] with-file-vocabs

View File

@ -108,7 +108,7 @@ HELP: lappend
{ $description "Perform a similar functionality to that of the " { $link append } " word, but in a lazy manner. No evaluation of the list elements occurs initially but a " { $link <lazy-append> } " object is returned which conforms to the list protocol. Calling " { $link car } ", " { $link cdr } " or " { $link nil? } " on this will evaluate elements as required. Successive calls to " { $link cdr } " will iterate through list1, followed by list2." } ; { $description "Perform a similar functionality to that of the " { $link append } " word, but in a lazy manner. No evaluation of the list elements occurs initially but a " { $link <lazy-append> } " object is returned which conforms to the list protocol. Calling " { $link car } ", " { $link cdr } " or " { $link nil? } " on this will evaluate elements as required. Successive calls to " { $link cdr } " will iterate through list1, followed by list2." } ;
HELP: lfrom-by HELP: lfrom-by
{ $values { "n" "an integer" } { "quot" { $quotation "( -- int )" } } { "list" "a lazy list of integers" } } { $values { "n" "an integer" } { "quot" { $quotation "( -- int )" } } { "lazy-from-by" "a lazy list of integers" } }
{ $description "Return an infinite lazy list of values starting from n, with each successive value being the result of applying quot to n." } ; { $description "Return an infinite lazy list of values starting from n, with each successive value being the result of applying quot to n." } ;
HELP: lfrom HELP: lfrom

View File

@ -203,7 +203,7 @@ M: lazy-append nil? ( lazy-append -- bool )
TUPLE: lazy-from-by n quot ; TUPLE: lazy-from-by n quot ;
C: lfrom-by lazy-from-by ( n quot -- list ) C: lfrom-by lazy-from-by
: lfrom ( n -- list ) : lfrom ( n -- list )
[ 1+ ] lfrom-by ; [ 1+ ] lfrom-by ;

View File

@ -83,10 +83,6 @@ HELP: nil?
{ nil nil? } related-words { nil nil? } related-words
HELP: list? ( object -- ? )
{ $values { "object" "an object" } { "?" "a boolean" } }
{ $description "Returns true if the object conforms to the list protocol." } ;
{ 1list 2list 3list } related-words { 1list 2list 3list } related-words
HELP: 1list HELP: 1list

View File

@ -2,7 +2,7 @@ USING: locals math sequences tools.test hashtables words kernel
namespaces arrays strings prettyprint io.streams.string parser namespaces arrays strings prettyprint io.streams.string parser
accessors generic eval combinators combinators.short-circuit accessors generic eval combinators combinators.short-circuit
combinators.short-circuit.smart math.order math.functions combinators.short-circuit.smart math.order math.functions
definitions compiler.units fry lexer words.symbol see ; definitions compiler.units fry lexer words.symbol see multiline ;
IN: locals.tests IN: locals.tests
:: foo ( a b -- a a ) a a ; :: foo ( a b -- a a ) a a ;
@ -192,14 +192,14 @@ M:: string lambda-generic ( a b -- c ) a b lambda-generic-2 ;
DEFER: xyzzy DEFER: xyzzy
[ ] [ [ ] [
"IN: locals.tests USE: math GENERIC: xyzzy M: integer xyzzy ;" "IN: locals.tests USE: math GENERIC: xyzzy ( a -- b ) M: integer xyzzy ;"
<string-reader> "lambda-generic-test" parse-stream drop <string-reader> "lambda-generic-test" parse-stream drop
] unit-test ] unit-test
[ 10 ] [ 10 xyzzy ] unit-test [ 10 ] [ 10 xyzzy ] unit-test
[ ] [ [ ] [
"IN: locals.tests USE: math USE: locals GENERIC: xyzzy M:: integer xyzzy ( n -- ) 5 ;" "IN: locals.tests USE: math USE: locals GENERIC: xyzzy ( a -- b ) M:: integer xyzzy ( n -- x ) 5 ;"
<string-reader> "lambda-generic-test" parse-stream drop <string-reader> "lambda-generic-test" parse-stream drop
] unit-test ] unit-test
@ -245,7 +245,7 @@ M:: fixnum next-method-test ( a -- b ) a call-next-method 1 + ;
[ 5 ] [ 1 next-method-test ] unit-test [ 5 ] [ 1 next-method-test ] unit-test
: no-with-locals-test { 1 2 3 } [| x | x 3 + ] map ; : no-with-locals-test ( -- seq ) { 1 2 3 } [| x | x 3 + ] map ;
[ { 4 5 6 } ] [ no-with-locals-test ] unit-test [ { 4 5 6 } ] [ no-with-locals-test ] unit-test
@ -259,7 +259,7 @@ M:: fixnum next-method-test ( a -- b ) a call-next-method 1 + ;
:: a-word-with-locals ( a b -- ) ; :: a-word-with-locals ( a b -- ) ;
: 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
@ -268,7 +268,7 @@ M:: fixnum next-method-test ( a -- b ) a call-next-method 1 + ;
new-definition = new-definition =
] unit-test ] unit-test
: method-definition "USING: locals locals.tests sequences ;\nM:: sequence method-with-locals ( a -- y ) a reverse ;\n" ; CONSTANT: method-definition "USING: locals locals.tests sequences ;\nM:: sequence method-with-locals ( a -- y ) a reverse ;\n"
GENERIC: method-with-locals ( x -- y ) GENERIC: method-with-locals ( x -- y )
@ -392,6 +392,65 @@ ERROR: punned-class x ;
[ 9 ] [ 3 big-case-test ] unit-test [ 9 ] [ 3 big-case-test ] unit-test
! Dan found this problem
: littledan-case-problem-1 ( a -- b )
{
{ t [ 3 ] }
{ f [ 4 ] }
[| x | x 12 + { "howdy" } nth ]
} case ;
\ littledan-case-problem-1 must-infer
[ "howdy" ] [ -12 \ littledan-case-problem-1 def>> call ] unit-test
[ "howdy" ] [ -12 littledan-case-problem-1 ] unit-test
:: littledan-case-problem-2 ( a -- b )
a {
{ t [ a not ] }
{ f [ 4 ] }
[| x | x a - { "howdy" } nth ]
} case ;
\ littledan-case-problem-2 must-infer
[ "howdy" ] [ -12 \ littledan-case-problem-2 def>> call ] unit-test
[ "howdy" ] [ -12 littledan-case-problem-2 ] unit-test
:: littledan-cond-problem-1 ( a -- b )
a {
{ [ dup 0 < ] [ drop a not ] }
{ [| y | y y 0 > ] [ drop 4 ] }
[| x | x a - { "howdy" } nth ]
} cond ;
\ littledan-cond-problem-1 must-infer
[ f ] [ -12 \ littledan-cond-problem-1 def>> call ] unit-test
[ 4 ] [ 12 \ littledan-cond-problem-1 def>> call ] unit-test
[ "howdy" ] [ 0 \ littledan-cond-problem-1 def>> call ] unit-test
[ f ] [ -12 littledan-cond-problem-1 ] unit-test
[ 4 ] [ 12 littledan-cond-problem-1 ] unit-test
[ "howdy" ] [ 0 littledan-cond-problem-1 ] unit-test
/*
:: littledan-case-problem-3 ( a quot -- b )
a {
{ t [ a not ] }
{ f [ 4 ] }
quot
} case ; inline
[ f ] [ t [ ] littledan-case-problem-3 ] unit-test
[ 144 ] [ 12 [ sq ] littledan-case-problem-3 ] unit-test
[| | [| a | a ] littledan-case-problem-3 ] must-infer
: littledan-case-problem-4 ( a -- b )
[ 1 + ] littledan-case-problem-3 ;
\ littledan-case-problem-4 must-infer
*/
GENERIC: lambda-method-forget-test ( a -- b ) GENERIC: lambda-method-forget-test ( a -- b )
M:: integer lambda-method-forget-test ( a -- b ) ; M:: integer lambda-method-forget-test ( a -- b ) ;

View File

@ -1,31 +1,29 @@
! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos. ! Copyright (C) 2007, 2009 Slava Pestov, Eduardo Cavazos.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: lexer macros memoize parser sequences vocabs USING: lexer macros memoize parser sequences vocabs
vocabs.loader words kernel namespaces locals.parser locals.types vocabs.loader words kernel namespaces locals.parser locals.types
locals.errors ; locals.errors ;
IN: locals IN: locals
: :> SYNTAX: :>
scan locals get [ :>-outside-lambda-error ] unless* scan locals get [ :>-outside-lambda-error ] unless*
[ make-local ] bind <def> parsed ; parsing [ make-local ] bind <def> parsed ;
: [| parse-lambda over push-all ; parsing SYNTAX: [| parse-lambda over push-all ;
: [let parse-let over push-all ; parsing SYNTAX: [let parse-let over push-all ;
: [let* parse-let* over push-all ; parsing SYNTAX: [let* parse-let* over push-all ;
: [wlet parse-wlet over push-all ; parsing SYNTAX: [wlet parse-wlet over push-all ;
: :: (::) define ; parsing SYNTAX: :: (::) define-declared ;
: M:: (M::) define ; parsing SYNTAX: M:: (M::) define ;
: MACRO:: (::) define-macro ; parsing SYNTAX: MACRO:: (::) define-macro ;
: MEMO:: (::) define-memoized ; parsing SYNTAX: MEMO:: (::) define-memoized ;
USE: syntax
{ {
"locals.macros" "locals.macros"

View File

@ -1,6 +1,6 @@
! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos. ! Copyright (C) 2007, 2009 Slava Pestov, Eduardo Cavazos.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs kernel locals.types macros.expander ; USING: accessors assocs kernel locals.types macros.expander fry ;
IN: locals.macros IN: locals.macros
M: lambda expand-macros clone [ expand-macros ] change-body ; M: lambda expand-macros clone [ expand-macros ] change-body ;
@ -14,3 +14,6 @@ M: binding-form expand-macros
M: binding-form expand-macros* expand-macros literal ; M: binding-form expand-macros* expand-macros literal ;
M: lambda condomize? drop t ;
M: lambda condomize '[ @ ] ;

View File

@ -103,18 +103,19 @@ M: lambda-parser parse-quotation ( -- quotation )
"|" expect "|" parse-wbindings "|" expect "|" parse-wbindings
(parse-lambda) <wlet> ?rewrite-closures ; (parse-lambda) <wlet> ?rewrite-closures ;
: parse-locals ( -- vars assoc ) : parse-locals ( -- effect vars assoc )
"(" expect ")" parse-effect complete-effect
word [ over "declared-effect" set-word-prop ] when* dup
in>> [ dup pair? [ first ] when ] map make-locals ; in>> [ dup pair? [ first ] when ] map make-locals ;
: parse-locals-definition ( word reader -- word quot ) : parse-locals-definition ( word reader -- word quot effect )
[ parse-locals ] dip [ parse-locals ] dip
((parse-lambda)) <lambda> ((parse-lambda)) <lambda>
[ "lambda" set-word-prop ] [ nip "lambda" set-word-prop ]
[ rewrite-closures dup length 1 = [ first ] [ bad-rewrite ] if ] 2bi ; inline [ nip rewrite-closures dup length 1 = [ first ] [ bad-rewrite ] if ]
[ drop nip ] 3tri ; inline
: (::) ( -- word def ) : (::) ( -- word def effect )
CREATE-WORD CREATE-WORD
[ parse-definition ] [ parse-definition ]
parse-locals-definition ; parse-locals-definition ;
@ -123,5 +124,5 @@ M: lambda-parser parse-quotation ( -- quotation )
CREATE-METHOD CREATE-METHOD
[ [
[ parse-definition ] [ parse-definition ]
parse-locals-definition parse-locals-definition drop
] with-method-definition ; ] with-method-definition ;

View File

@ -135,11 +135,11 @@ PRIVATE>
[ [ input-logging-quot ] 2keep drop error-logging-quot ] [ [ input-logging-quot ] 2keep drop error-logging-quot ]
(define-logging) ; (define-logging) ;
: LOG: SYNTAX: LOG:
#! Syntax: name level #! Syntax: name level
CREATE-WORD dup scan-word CREATE-WORD dup scan-word
'[ 1array stack>message _ _ log-message ] '[ 1array stack>message _ _ log-message ]
(( message -- )) define-declared ; parsing (( message -- )) define-declared ;
USE: vocabs.loader USE: vocabs.loader

View File

@ -1,8 +1,8 @@
! 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: kernel sequences sequences.private namespaces make USING: kernel sequences sequences.private namespaces make
quotations accessors words continuations vectors effects math quotations accessors words continuations vectors effects math
generalizations fry ; generalizations fry arrays ;
IN: macros.expander IN: macros.expander
GENERIC: expand-macros ( quot -- quot' ) GENERIC: expand-macros ( quot -- quot' )
@ -17,7 +17,23 @@ SYMBOL: stack
[ delete-all ] [ delete-all ]
bi ; bi ;
: literal ( obj -- ) stack get push ; GENERIC: condomize? ( obj -- ? )
M: array condomize? [ condomize? ] any? ;
M: callable condomize? [ condomize? ] any? ;
M: object condomize? drop f ;
GENERIC: condomize ( obj -- obj' )
M: array condomize [ condomize ] map ;
M: callable condomize [ condomize ] map ;
M: object condomize ;
: literal ( obj -- ) dup condomize? [ condomize ] when stack get push ;
GENERIC: expand-macros* ( obj -- ) GENERIC: expand-macros* ( obj -- )

View File

@ -2,16 +2,22 @@ IN: macros.tests
USING: tools.test macros math kernel arrays USING: tools.test macros math kernel arrays
vectors io.streams.string prettyprint parser eval see ; vectors io.streams.string prettyprint parser eval see ;
MACRO: see-test ( a b -- c ) + ; MACRO: see-test ( a b -- quot ) + ;
[ "USING: macros math ;\nIN: macros.tests\nMACRO: see-test ( a b -- c ) + ;\n" ] [ t ] [ \ see-test macro? ] unit-test
[ "USING: macros math ;\nIN: macros.tests\nMACRO: see-test ( a b -- quot ) + ;\n" ]
[ [ \ see-test see ] with-string-writer ] [ [ \ see-test see ] with-string-writer ]
unit-test 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
[ ] [ "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

@ -6,17 +6,18 @@ IN: macros
<PRIVATE <PRIVATE
: real-macro-effect ( word -- effect' ) : real-macro-effect ( effect -- effect' )
stack-effect in>> 1 <effect> ; in>> { "quot" } <effect> ;
PRIVATE> PRIVATE>
: define-macro ( word definition -- ) : define-macro ( word definition effect -- )
[ "macro" set-word-prop ] real-macro-effect
[ over real-macro-effect memoize-quot [ call ] append define ] [ [ memoize-quot [ call ] append ] keep define-declared ]
2bi ; [ drop "macro" set-word-prop ]
3bi ;
: MACRO: (:) define-macro ; parsing SYNTAX: MACRO: (:) define-macro ;
PREDICATE: macro < word "macro" word-prop >boolean ; PREDICATE: macro < word "macro" word-prop >boolean ;

View File

@ -16,8 +16,8 @@ SYMBOL: _
: define-match-vars ( seq -- ) : define-match-vars ( seq -- )
[ define-match-var ] each ; [ define-match-var ] each ;
: MATCH-VARS: ! vars ... SYNTAX: MATCH-VARS: ! vars ...
";" parse-tokens define-match-vars ; parsing ";" parse-tokens define-match-vars ;
: match-var? ( symbol -- bool ) : match-var? ( symbol -- bool )
dup word? [ "match-var" word-prop ] [ drop f ] if ; dup word? [ "match-var" word-prop ] [ drop f ] if ;

View File

@ -139,8 +139,8 @@ HELP: flags
{ $examples { $examples
{ $example "USING: math.bitwise kernel prettyprint ;" { $example "USING: math.bitwise kernel prettyprint ;"
"IN: scratchpad" "IN: scratchpad"
": MY-CONSTANT HEX: 1 ; inline" "CONSTANT: x HEX: 1"
"{ HEX: 20 MY-CONSTANT BIN: 100 } flags .h" "{ HEX: 20 x BIN: 100 } flags .h"
"25" "25"
} }
} ; } ;

View File

@ -289,7 +289,7 @@ M: MATRIX n*V(*)V+M!
M: MATRIX n*V(*)Vconj+M! M: MATRIX n*V(*)Vconj+M!
(prepare-ger) [ XGERC ] dip ; (prepare-ger) [ XGERC ] dip ;
: XMATRIX{ \ } [ >MATRIX ] parse-literal ; parsing SYNTAX: XMATRIX{ \ } [ >MATRIX ] parse-literal ;
M: MATRIX pprint-delims M: MATRIX pprint-delims
drop \ XMATRIX{ \ } ; drop \ XMATRIX{ \ } ;

View File

@ -179,7 +179,7 @@ M: VECTOR n*V+V!
M: VECTOR n*V! M: VECTOR n*V!
(prepare-scal) [ XSCAL ] dip ; (prepare-scal) [ XSCAL ] dip ;
: XVECTOR{ \ } [ >VECTOR ] parse-literal ; parsing SYNTAX: XVECTOR{ \ } [ >VECTOR ] parse-literal ;
M: VECTOR pprint-delims M: VECTOR pprint-delims
drop \ XVECTOR{ \ } ; drop \ XVECTOR{ \ } ;

View File

@ -31,7 +31,7 @@ M: complex sqrt >polar [ fsqrt ] [ 2.0 / ] bi* polar> ;
IN: syntax IN: syntax
: C{ \ } [ first2 rect> ] parse-literal ; parsing SYNTAX: C{ \ } [ first2 rect> ] parse-literal ;
USE: prettyprint.custom USE: prettyprint.custom

View File

@ -1,10 +1,10 @@
! Copyright (C) 2007 Slava Pestov, Daniel Ehrenberg. ! Copyright (C) 2007, 2009 Slava Pestov, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: help.syntax help.markup ; USING: help.syntax help.markup words quotations effects ;
IN: memoize IN: memoize
HELP: define-memoized HELP: define-memoized
{ $values { "word" "the word to be defined" } { "quot" "a quotation" } } { $values { "word" word } { "quot" quotation } { "effect" effect } }
{ $description "defines the given word at runtime as one which memoizes its output given a particular input" } { $description "defines the given word at runtime as one which memoizes its output given a particular input" }
{ $notes "A maximum of four input and four output arguments can be used" } { $notes "A maximum of four input and four output arguments can be used" }
{ $see-also POSTPONE: MEMO: } ; { $see-also POSTPONE: MEMO: } ;

View File

@ -34,14 +34,13 @@ M: too-many-arguments summary
PRIVATE> PRIVATE>
: define-memoized ( word quot -- ) : define-memoized ( word quot effect -- )
[ H{ } clone ] dip [ drop "memo-quot" set-word-prop ]
[ pick stack-effect make-memoizer define ] [ 2drop H{ } clone "memoize" set-word-prop ]
[ nip "memo-quot" set-word-prop ] [ [ [ dup "memoize" word-prop ] 2dip make-memoizer ] keep define-declared ]
[ drop "memoize" set-word-prop ]
3tri ; 3tri ;
: MEMO: (:) define-memoized ; parsing SYNTAX: MEMO: (:) define-memoized ;
PREDICATE: memoized < word "memoize" word-prop ; PREDICATE: memoized < word "memoize" word-prop ;

View File

@ -4,7 +4,7 @@ IN: models.tests
TUPLE: model-tester hit? ; TUPLE: model-tester hit? ;
: <model-tester> model-tester new ; : <model-tester> ( -- model-tester ) model-tester new ;
M: model-tester model-changed nip t >>hit? drop ; M: model-tester model-changed nip t >>hit? drop ;

View File

@ -3,7 +3,7 @@ USING: arrays generic kernel math models namespaces sequences assocs
tools.test models.range ; tools.test models.range ;
! Test <range> ! Test <range>
: setup-range 0 0 0 255 <range> ; : setup-range ( -- range ) 0 0 0 255 <range> ;
! clamp-value should not go past range ends ! clamp-value should not go past range ends
[ 0 ] [ -10 setup-range clamp-value ] unit-test [ 0 ] [ -10 setup-range clamp-value ] unit-test

View File

@ -20,10 +20,10 @@ PRIVATE>
[ (parse-here) ] "" make but-last [ (parse-here) ] "" make but-last
lexer get next-line ; lexer get next-line ;
: STRING: SYNTAX: STRING:
CREATE-WORD CREATE-WORD
parse-here 1quotation parse-here 1quotation
(( -- string )) define-inline ; parsing (( -- string )) define-inline ;
<PRIVATE <PRIVATE
@ -48,16 +48,16 @@ PRIVATE>
change-column drop change-column drop
] "" make ; ] "" make ;
: <" SYNTAX: <"
"\">" parse-multiline-string parsed ; parsing "\">" parse-multiline-string parsed ;
: <' SYNTAX: <'
"'>" parse-multiline-string parsed ; parsing "'>" parse-multiline-string parsed ;
: {' SYNTAX: {'
"'}" parse-multiline-string parsed ; parsing "'}" parse-multiline-string parsed ;
: {" SYNTAX: {"
"\"}" parse-multiline-string parsed ; parsing "\"}" parse-multiline-string parsed ;
: /* "*/" parse-multiline-string drop ; parsing SYNTAX: /* "*/" parse-multiline-string drop ;

View File

@ -62,7 +62,7 @@ M: nibble-array resize
M: nibble-array byte-length length nibbles>bytes ; M: nibble-array byte-length length nibbles>bytes ;
: N{ \ } [ >nibble-array ] parse-literal ; parsing SYNTAX: N{ \ } [ >nibble-array ] parse-literal ;
INSTANCE: nibble-array sequence INSTANCE: nibble-array sequence

View File

@ -47,7 +47,7 @@ reset-gl-function-number-counter
parameters return parse-arglist [ abi indirect-quot ] dip parameters return parse-arglist [ abi indirect-quot ] dip
define-declared ; define-declared ;
: GL-FUNCTION: SYNTAX: GL-FUNCTION:
gl-function-calling-convention gl-function-calling-convention
scan scan
scan dup scan dup
@ -55,5 +55,4 @@ reset-gl-function-number-counter
gl-function-number gl-function-number
[ gl-function-pointer ] 2curry swap [ gl-function-pointer ] 2curry swap
";" parse-tokens [ "()" subseq? not ] filter ";" parse-tokens [ "()" subseq? not ] filter
define-indirect define-indirect ;
; parsing

View File

@ -279,12 +279,12 @@ H{ } clone verify-messages set-global
: verify-message ( n -- word ) verify-messages get-global at ; : verify-message ( n -- word ) verify-messages get-global at ;
: X509_V_: SYNTAX: X509_V_:
scan "X509_V_" prepend create-in scan "X509_V_" prepend create-in
scan-word scan-word
[ 1quotation (( -- value )) define-inline ] [ 1quotation (( -- value )) define-inline ]
[ verify-messages get set-at ] [ verify-messages get set-at ]
2bi ; parsing 2bi ;
>> >>

View File

@ -34,9 +34,9 @@ TUPLE: tokenizer any one many ;
: reset-tokenizer ( -- ) : reset-tokenizer ( -- )
default-tokenizer \ tokenizer set-global ; default-tokenizer \ tokenizer set-global ;
: TOKENIZER: SYNTAX: TOKENIZER:
scan search [ "Tokenizer not found" throw ] unless* scan search [ "Tokenizer not found" throw ] unless*
execute( -- tokenizer ) \ tokenizer set-global ; parsing execute( -- tokenizer ) \ tokenizer set-global ;
TUPLE: ebnf-non-terminal symbol ; TUPLE: ebnf-non-terminal symbol ;
TUPLE: ebnf-terminal symbol ; TUPLE: ebnf-terminal symbol ;
@ -522,16 +522,14 @@ M: ebnf-non-terminal (transform) ( ast -- parser )
parse-ebnf dup dup parser [ main swap at compile ] with-variable parse-ebnf dup dup parser [ main swap at compile ] with-variable
[ compiled-parse ] curry [ with-scope ast>> ] curry ; [ compiled-parse ] curry [ with-scope ast>> ] curry ;
: <EBNF "EBNF>" reset-tokenizer parse-multiline-string parse-ebnf main swap at SYNTAX: <EBNF "EBNF>" reset-tokenizer parse-multiline-string parse-ebnf main swap at
parsed reset-tokenizer ; parsing parsed reset-tokenizer ;
: [EBNF "EBNF]" reset-tokenizer parse-multiline-string ebnf>quot nip SYNTAX: [EBNF "EBNF]" reset-tokenizer parse-multiline-string ebnf>quot nip
parsed \ call parsed reset-tokenizer ; parsing parsed \ call parsed reset-tokenizer ;
: EBNF: SYNTAX: EBNF:
reset-tokenizer CREATE-WORD dup ";EBNF" parse-multiline-string reset-tokenizer CREATE-WORD dup ";EBNF" parse-multiline-string
ebnf>quot swapd (( input -- ast )) define-declared "ebnf-parser" set-word-prop ebnf>quot swapd (( input -- ast )) define-declared "ebnf-parser" set-word-prop
reset-tokenizer ; parsing reset-tokenizer ;

View File

@ -9,14 +9,14 @@ TUPLE: just-parser p1 ;
CONSTANT: just-pattern CONSTANT: just-pattern
[ [
execute dup [ dup [
dup remaining>> empty? [ drop f ] unless dup remaining>> empty? [ drop f ] unless
] when ] when
] ]
M: just-parser (compile) ( parser -- quot ) M: just-parser (compile) ( parser -- quot )
p1>> compile-parser just-pattern curry ; p1>> compile-parser-quot just-pattern compose ;
: just ( parser -- parser ) : just ( parser -- parser )
just-parser boa wrap-peg ; just-parser boa wrap-peg ;

View File

@ -116,7 +116,7 @@ TUPLE: peg-head rule-id involved-set eval-set ;
#! Evaluate a rule, return an ast resulting from it. #! Evaluate a rule, return an ast resulting from it.
#! Return fail if the rule failed. The rule has #! Return fail if the rule failed. The rule has
#! stack effect ( -- parse-result ) #! stack effect ( -- parse-result )
pos get swap execute process-rule-result ; inline pos get swap execute( -- parse-result ) process-rule-result ; inline
: memo ( pos id -- memo-entry ) : memo ( pos id -- memo-entry )
#! Return the result from the memo cache. #! Return the result from the memo cache.
@ -244,14 +244,15 @@ TUPLE: peg-head rule-id involved-set eval-set ;
: with-packrat ( input quot -- result ) : with-packrat ( input quot -- result )
#! Run the quotation with a packrat cache active. #! Run the quotation with a packrat cache active.
swap [ [
input set swap input set
0 pos set 0 pos set
f lrstack set f lrstack set
V{ } clone error-stack set V{ } clone error-stack set
H{ } clone \ heads set H{ } clone \ heads set
H{ } clone \ packrat set H{ } clone \ packrat set
] H{ } make-assoc swap bind ; inline call
] with-scope ; inline
GENERIC: (compile) ( peg -- quot ) GENERIC: (compile) ( peg -- quot )
@ -264,20 +265,16 @@ GENERIC: (compile) ( peg -- quot )
] if ; ] if ;
: execute-parser ( word -- result ) : execute-parser ( word -- result )
pos get apply-rule process-parser-result ; inline pos get apply-rule process-parser-result ;
: parser-body ( parser -- quot )
#! Return the body of the word that is the compiled version
#! of the parser.
gensym 2dup swap peg>> (compile) (( -- result )) define-declared
swap dupd id>> "peg-id" set-word-prop
[ execute-parser ] curry ;
: preset-parser-word ( parser -- parser word ) : preset-parser-word ( parser -- parser word )
gensym [ >>compiled ] keep ; gensym [ >>compiled ] keep ;
: define-parser-word ( parser word -- ) : define-parser-word ( parser word -- )
swap parser-body (( -- result )) define-declared ; #! Return the body of the word that is the compiled version
#! of the parser.
2dup swap peg>> (compile) (( -- result )) define-declared
swap id>> "peg-id" set-word-prop ;
: compile-parser ( parser -- word ) : compile-parser ( parser -- word )
#! Look to see if the given parser has been compiled. #! Look to see if the given parser has been compiled.
@ -292,19 +289,22 @@ GENERIC: (compile) ( peg -- quot )
preset-parser-word [ define-parser-word ] keep preset-parser-word [ define-parser-word ] keep
] if* ; ] if* ;
: compile-parser-quot ( parser -- quot )
compile-parser [ execute-parser ] curry ;
SYMBOL: delayed SYMBOL: delayed
: fixup-delayed ( -- ) : fixup-delayed ( -- )
#! Work through all delayed parsers and recompile their #! Work through all delayed parsers and recompile their
#! words to have the correct bodies. #! words to have the correct bodies.
delayed get [ delayed get [
call( -- parser ) compile-parser 1quotation (( -- result )) define-declared call( -- parser ) compile-parser-quot (( -- result )) define-declared
] assoc-each ; ] assoc-each ;
: compile ( parser -- word ) : compile ( parser -- word )
[ [
H{ } clone delayed [ H{ } clone delayed [
compile-parser fixup-delayed compile-parser-quot (( -- result )) define-temp fixup-delayed
] with-variable ] with-variable
] with-compilation-unit ; ] with-compilation-unit ;
@ -411,8 +411,8 @@ M: seq-parser (compile) ( peg -- quot )
[ [
[ input-slice V{ } clone <parse-result> ] % [ input-slice V{ } clone <parse-result> ] %
[ [
parsers>> unclip compile-parser 1quotation [ parse-seq-element ] curry , parsers>> unclip compile-parser-quot [ parse-seq-element ] curry ,
[ compile-parser 1quotation [ merge-errors ] compose [ parse-seq-element ] curry , ] each [ compile-parser-quot [ merge-errors ] compose [ parse-seq-element ] curry , ] each
] { } make , \ 1&& , ] { } make , \ 1&& ,
] [ ] make ; ] [ ] make ;
@ -421,8 +421,8 @@ TUPLE: choice-parser parsers ;
M: choice-parser (compile) ( peg -- quot ) M: choice-parser (compile) ( peg -- quot )
[ [
[ [
parsers>> [ compile-parser ] map parsers>> [ compile-parser-quot ] map
unclip 1quotation , [ 1quotation [ merge-errors ] compose , ] each unclip , [ [ merge-errors ] compose , ] each
] { } make , \ 0|| , ] { } make , \ 0|| ,
] [ ] make ; ] [ ] make ;
@ -438,7 +438,7 @@ TUPLE: repeat0-parser p1 ;
] if* ; inline recursive ] if* ; inline recursive
M: repeat0-parser (compile) ( peg -- quot ) M: repeat0-parser (compile) ( peg -- quot )
p1>> compile-parser 1quotation '[ p1>> compile-parser-quot '[
input-slice V{ } clone <parse-result> _ swap (repeat) input-slice V{ } clone <parse-result> _ swap (repeat)
] ; ] ;
@ -452,7 +452,7 @@ TUPLE: repeat1-parser p1 ;
] if* ; ] if* ;
M: repeat1-parser (compile) ( peg -- quot ) M: repeat1-parser (compile) ( peg -- quot )
p1>> compile-parser 1quotation '[ p1>> compile-parser-quot '[
input-slice V{ } clone <parse-result> _ swap (repeat) repeat1-empty-check input-slice V{ } clone <parse-result> _ swap (repeat) repeat1-empty-check
] ; ] ;
@ -462,7 +462,7 @@ TUPLE: optional-parser p1 ;
[ input-slice f <parse-result> ] unless* ; [ input-slice f <parse-result> ] unless* ;
M: optional-parser (compile) ( peg -- quot ) M: optional-parser (compile) ( peg -- quot )
p1>> compile-parser 1quotation '[ @ check-optional ] ; p1>> compile-parser-quot '[ @ check-optional ] ;
TUPLE: semantic-parser p1 quot ; TUPLE: semantic-parser p1 quot ;
@ -474,7 +474,7 @@ TUPLE: semantic-parser p1 quot ;
] if ; inline ] if ; inline
M: semantic-parser (compile) ( peg -- quot ) M: semantic-parser (compile) ( peg -- quot )
[ p1>> compile-parser 1quotation ] [ quot>> ] bi [ p1>> compile-parser-quot ] [ quot>> ] bi
'[ @ _ check-semantic ] ; '[ @ _ check-semantic ] ;
TUPLE: ensure-parser p1 ; TUPLE: ensure-parser p1 ;
@ -483,7 +483,7 @@ TUPLE: ensure-parser p1 ;
[ ignore <parse-result> ] [ drop f ] if ; [ ignore <parse-result> ] [ drop f ] if ;
M: ensure-parser (compile) ( peg -- quot ) M: ensure-parser (compile) ( peg -- quot )
p1>> compile-parser 1quotation '[ input-slice @ check-ensure ] ; p1>> compile-parser-quot '[ input-slice @ check-ensure ] ;
TUPLE: ensure-not-parser p1 ; TUPLE: ensure-not-parser p1 ;
@ -491,7 +491,7 @@ TUPLE: ensure-not-parser p1 ;
[ drop f ] [ ignore <parse-result> ] if ; [ drop f ] [ ignore <parse-result> ] if ;
M: ensure-not-parser (compile) ( peg -- quot ) M: ensure-not-parser (compile) ( peg -- quot )
p1>> compile-parser 1quotation '[ input-slice @ check-ensure-not ] ; p1>> compile-parser-quot '[ input-slice @ check-ensure-not ] ;
TUPLE: action-parser p1 quot ; TUPLE: action-parser p1 quot ;
@ -503,12 +503,12 @@ TUPLE: action-parser p1 quot ;
] if ; inline ] if ; inline
M: action-parser (compile) ( peg -- quot ) M: action-parser (compile) ( peg -- quot )
[ p1>> compile-parser 1quotation ] [ quot>> ] bi '[ @ _ check-action ] ; [ p1>> compile-parser-quot ] [ quot>> ] bi '[ @ _ check-action ] ;
TUPLE: sp-parser p1 ; TUPLE: sp-parser p1 ;
M: sp-parser (compile) ( peg -- quot ) M: sp-parser (compile) ( peg -- quot )
p1>> compile-parser 1quotation '[ p1>> compile-parser-quot '[
input-slice [ blank? ] trim-head-slice input-from pos set @ input-slice [ blank? ] trim-head-slice input-from pos set @
] ; ] ;
@ -527,7 +527,7 @@ M: box-parser (compile) ( peg -- quot )
#! to produce the parser to be compiled. #! to produce the parser to be compiled.
#! This differs from 'delay' which calls #! This differs from 'delay' which calls
#! it at run time. #! it at run time.
quot>> call( -- parser ) compile-parser 1quotation ; quot>> call( -- parser ) compile-parser-quot ;
PRIVATE> PRIVATE>
@ -616,9 +616,9 @@ PRIVATE>
ERROR: parse-failed input word ; ERROR: parse-failed input word ;
: PEG: SYNTAX: PEG:
(:) (:)
[let | def [ ] word [ ] | [let | effect [ ] def [ ] word [ ] |
[ [
[ [
[let | compiled-def [ def call compile ] | [let | compiled-def [ def call compile ] |
@ -626,11 +626,11 @@ ERROR: parse-failed input word ;
dup compiled-def compiled-parse dup compiled-def compiled-parse
[ ast>> ] [ word parse-failed ] ?if [ ast>> ] [ word parse-failed ] ?if
] ]
word swap define word swap effect define-declared
] ]
] with-compilation-unit ] with-compilation-unit
] over push-all ] over push-all
] ; parsing ] ;
USING: vocabs vocabs.loader ; USING: vocabs vocabs.loader ;

View File

@ -48,7 +48,7 @@ M: persistent-hash hashcode* nip assoc-size ;
M: persistent-hash clone ; M: persistent-hash clone ;
: PH{ \ } [ >persistent-hash ] parse-literal ; parsing SYNTAX: PH{ \ } [ >persistent-hash ] parse-literal ;
M: persistent-hash pprint-delims drop \ PH{ \ } ; M: persistent-hash pprint-delims drop \ PH{ \ } ;
M: persistent-hash >pprint-sequence >alist ; M: persistent-hash >pprint-sequence >alist ;

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