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

db4
Eduardo Cavazos 2008-08-31 01:43:00 -05:00
commit df85ac4b5d
58 changed files with 563 additions and 251 deletions

View File

@ -42,12 +42,17 @@ SYMBOL: +failed+
[ compiled-unxref ] [ compiled-unxref ]
[ [
dup crossref? dup crossref?
[ dependencies get compiled-xref ] [ drop ] if [
dependencies get
generic-dependencies get
compiled-xref
] [ drop ] if
] tri ; ] tri ;
: (compile) ( word -- ) : (compile) ( word -- )
'[ '[
H{ } clone dependencies set H{ } clone dependencies set
H{ } clone generic-dependencies set
, { , {
[ compile-begins ] [ compile-begins ]

View File

@ -1,4 +1,5 @@
IN: compiler.tests IN: compiler.tests
USING: words kernel stack-checker alien.strings tools.test ; USING: words kernel stack-checker alien.strings tools.test
compiler.units ;
[ ] [ \ if redefined [ string>alien ] infer. ] unit-test [ ] [ [ \ if redefined ] with-compilation-unit [ string>alien ] infer. ] unit-test

View File

@ -0,0 +1,29 @@
USING: eval tools.test compiler.units vocabs multiline words
kernel ;
IN: compiler.tests
! Mixin redefinition did not recompile all necessary words.
[ ] [ [ "compiler.tests.redefine10" forget-vocab ] with-compilation-unit ] unit-test
[ ] [
<"
USING: kernel math classes ;
IN: compiler.tests.redefine10
MIXIN: my-mixin
INSTANCE: fixnum my-mixin
: my-inline ( a -- b ) dup my-mixin instance? [ 1 + ] when ;
"> eval
] unit-test
[ ] [
<"
USE: math
IN: compiler.tests.redefine10
INSTANCE: float my-mixin
"> eval
] unit-test
[ 2.0 ] [
1.0 "my-inline" "compiler.tests.redefine10" lookup execute
] unit-test

View File

@ -0,0 +1,32 @@
USING: eval tools.test compiler.units vocabs multiline words
kernel classes.mixin arrays ;
IN: compiler.tests
! Mixin redefinition did not recompile all necessary words.
[ ] [ [ "compiler.tests.redefine11" forget-vocab ] with-compilation-unit ] unit-test
[ ] [
<"
USING: kernel math classes arrays ;
IN: compiler.tests.redefine11
MIXIN: my-mixin
INSTANCE: array my-mixin
INSTANCE: fixnum my-mixin
GENERIC: my-generic ( a -- b )
M: my-mixin my-generic drop 0 ;
M: object my-generic drop 1 ;
: my-inline ( -- b ) { } my-generic ;
"> eval
] unit-test
[ ] [
[
array "my-mixin" "compiler.tests.redefine11" lookup
remove-mixin-instance
] with-compilation-unit
] unit-test
[ 1 ] [
"my-inline" "compiler.tests.redefine11" lookup execute
] unit-test

View File

@ -0,0 +1,33 @@
USING: eval tools.test compiler.units vocabs multiline words
kernel ;
IN: compiler.tests
! Mixin redefinition did not recompile all necessary words.
[ ] [ [ "compiler.tests.redefine6" forget-vocab ] with-compilation-unit ] unit-test
[ ] [
<"
USING: kernel kernel.private ;
IN: compiler.tests.redefine6
GENERIC: my-generic ( a -- b )
MIXIN: my-mixin
M: my-mixin my-generic drop 0 ;
: my-inline ( a -- b ) { my-mixin } declare my-generic ;
"> eval
] unit-test
[ ] [
<"
USING: kernel ;
IN: compiler.tests.redefine6
TUPLE: my-tuple ;
M: my-tuple my-generic drop 1 ;
INSTANCE: my-tuple my-mixin
"> eval
] unit-test
[ 1 ] [
"my-tuple" "compiler.tests.redefine6" lookup boa
"my-inline" "compiler.tests.redefine6" lookup execute
] unit-test

View File

@ -0,0 +1,29 @@
USING: eval tools.test compiler.units vocabs multiline words
kernel ;
IN: compiler.tests
! Mixin redefinition did not recompile all necessary words.
[ ] [ [ "compiler.tests.redefine7" forget-vocab ] with-compilation-unit ] unit-test
[ ] [
<"
USING: kernel math ;
IN: compiler.tests.redefine7
MIXIN: my-mixin
INSTANCE: fixnum my-mixin
: my-inline ( a -- b ) dup my-mixin? [ 1 + ] when ;
"> eval
] unit-test
[ ] [
<"
USE: math
IN: compiler.tests.redefine7
INSTANCE: float my-mixin
"> eval
] unit-test
[ 2.0 ] [
1.0 "my-inline" "compiler.tests.redefine7" lookup execute
] unit-test

View File

@ -0,0 +1,32 @@
USING: eval tools.test compiler.units vocabs multiline words
kernel ;
IN: compiler.tests
! Mixin redefinition did not recompile all necessary words.
[ ] [ [ "compiler.tests.redefine8" forget-vocab ] with-compilation-unit ] unit-test
[ ] [
<"
USING: kernel math math.order sorting ;
IN: compiler.tests.redefine8
MIXIN: my-mixin
INSTANCE: fixnum my-mixin
GENERIC: my-generic ( a -- b )
! We add the bogus quotation here to hinder inlining
! since otherwise we cannot trigger this bug.
M: my-mixin my-generic 1 + [ [ <=> ] sort ] drop ;
"> eval
] unit-test
[ ] [
<"
USE: math
IN: compiler.tests.redefine8
INSTANCE: float my-mixin
"> eval
] unit-test
[ 2.0 ] [
1.0 "my-generic" "compiler.tests.redefine8" lookup execute
] unit-test

View File

@ -0,0 +1,35 @@
USING: eval tools.test compiler.units vocabs multiline words
kernel generic.math ;
IN: compiler.tests
! Mixin redefinition did not recompile all necessary words.
[ ] [ [ "compiler.tests.redefine9" forget-vocab ] with-compilation-unit ] unit-test
[ ] [
<"
USING: kernel math math.order sorting ;
IN: compiler.tests.redefine9
MIXIN: my-mixin
INSTANCE: fixnum my-mixin
GENERIC: my-generic ( a -- b )
! We add the bogus quotation here to hinder inlining
! since otherwise we cannot trigger this bug.
M: my-mixin my-generic 1 + [ [ <=> ] sort ] drop ;
"> eval
] unit-test
[ ] [
<"
USE: math
IN: compiler.tests.redefine9
TUPLE: my-tuple ;
INSTANCE: my-tuple my-mixin
"> eval
] unit-test
[
"my-tuple" "compiler.tests.redefine9" lookup boa
"my-generic" "compiler.tests.redefine9" lookup
execute
] [ no-math-method? ] must-fail-with

View File

@ -42,7 +42,7 @@ GENERIC: cleanup* ( node -- node/nodes )
: cleanup-folding ( #call -- nodes ) : cleanup-folding ( #call -- nodes )
#! Replace a #call having a known result with a #drop of its #! Replace a #call having a known result with a #drop of its
#! inputs followed by #push nodes for the outputs. #! inputs followed by #push nodes for the outputs.
[ word>> +inlined+ depends-on ] [ word>> inlined-dependency depends-on ]
[ [
[ node-output-infos ] [ out-d>> ] bi [ node-output-infos ] [ out-d>> ] bi
[ [ literal>> ] dip #push ] 2map [ [ literal>> ] dip #push ] 2map
@ -50,11 +50,16 @@ GENERIC: cleanup* ( node -- node/nodes )
[ in-d>> #drop ] [ in-d>> #drop ]
tri prefix ; tri prefix ;
: add-method-dependency ( #call -- )
dup method>> word? [
[ word>> ] [ class>> ] bi depends-on-generic
] [ drop ] if ;
: cleanup-inlining ( #call -- nodes ) : cleanup-inlining ( #call -- nodes )
[ [
dup method>> dup method>>
[ method>> dup word? [ +called+ depends-on ] [ drop ] if ] [ add-method-dependency ]
[ word>> +inlined+ depends-on ] if [ word>> inlined-dependency depends-on ] if
] [ body>> cleanup ] bi ; ] [ body>> cleanup ] bi ;
! Removing overflow checks ! Removing overflow checks

View File

@ -106,7 +106,7 @@ M: #push remove-dead-code*
] [ drop f ] if ; ] [ drop f ] if ;
: remove-flushable-call ( #call -- node ) : remove-flushable-call ( #call -- node )
[ word>> +inlined+ depends-on ] [ word>> flushed-dependency depends-on ]
[ in-d>> #drop remove-dead-code* ] [ in-d>> #drop remove-dead-code* ]
bi ; bi ;

View File

@ -24,18 +24,19 @@ M: quotation splicing-nodes
body>> (propagate) ; body>> (propagate) ;
! Dispatch elimination ! Dispatch elimination
: eliminate-dispatch ( #call word/quot/f -- ? ) : eliminate-dispatch ( #call class/f word/f -- ? )
[ dup [
[ >>class ] dip
over method>> over = [ drop ] [ over method>> over = [ drop ] [
2dup splicing-nodes 2dup splicing-nodes
[ >>method ] [ >>body ] bi* [ >>method ] [ >>body ] bi*
] if ] if
propagate-body t propagate-body t
] [ f >>method f >>body drop f ] if* ; ] [ 2drop f >>method f >>body f >>class drop f ] if ;
: inlining-standard-method ( #call word -- method/f ) : inlining-standard-method ( #call word -- class/f method/f )
[ in-d>> <reversed> ] [ [ dispatch# ] keep ] bi* [ in-d>> <reversed> ] [ [ dispatch# ] keep ] bi*
[ swap nth value-info class>> ] dip [ swap nth value-info class>> dup ] dip
specific-method ; specific-method ;
: inline-standard-method ( #call word -- ? ) : inline-standard-method ( #call word -- ? )
@ -51,15 +52,17 @@ M: quotation splicing-nodes
object object
} [ class<= ] with find nip ; } [ class<= ] with find nip ;
: inlining-math-method ( #call word -- quot/f ) : inlining-math-method ( #call word -- class/f quot/f )
swap in-d>> swap in-d>>
first2 [ value-info class>> normalize-math-class ] bi@ first2 [ value-info class>> normalize-math-class ] bi@
3dup math-both-known? [ math-method* ] [ 3drop f ] if ; 3dup math-both-known?
[ math-method* ] [ 3drop f ] if
number swap ;
: inline-math-method ( #call word -- ? ) : inline-math-method ( #call word -- ? )
dupd inlining-math-method eliminate-dispatch ; dupd inlining-math-method eliminate-dispatch ;
: inlining-math-partial ( #call word -- quot/f ) : inlining-math-partial ( #call word -- class/f quot/f )
[ "derived-from" word-prop first inlining-math-method ] [ "derived-from" word-prop first inlining-math-method ]
[ nip 1quotation ] 2bi [ nip 1quotation ] 2bi
[ = not ] [ drop ] 2bi and ; [ = not ] [ drop ] 2bi and ;

View File

@ -5,6 +5,8 @@ math.partial-dispatch math.intervals math.parser math.order
layouts words sequences sequences.private arrays assocs classes layouts words sequences sequences.private arrays assocs classes
classes.algebra combinators generic.math splitting fry locals classes.algebra combinators generic.math splitting fry locals
classes.tuple alien.accessors classes.tuple.private slots.private classes.tuple alien.accessors classes.tuple.private slots.private
definitions
stack-checker.state
compiler.tree.comparisons compiler.tree.comparisons
compiler.tree.propagation.info compiler.tree.propagation.info
compiler.tree.propagation.nodes compiler.tree.propagation.nodes
@ -280,6 +282,14 @@ generic-comparison-ops [
] +constraints+ set-word-prop ] +constraints+ set-word-prop
\ instance? [ \ instance? [
! We need to force the caller word to recompile when the class
! is redefined, since now we're making assumptions but the
! class definition itself.
dup literal>> class? dup literal>> class?
[ literal>> predicate-output-infos ] [ 2drop object-info ] if [
literal>>
[ inlined-dependency depends-on ]
[ predicate-output-infos ]
bi
] [ 2drop object-info ] if
] +outputs+ set-word-prop ] +outputs+ set-word-prop

View File

@ -2,9 +2,10 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: fry accessors kernel sequences sequences.private assocs words USING: fry accessors kernel sequences sequences.private assocs words
namespaces classes.algebra combinators classes classes.tuple namespaces classes.algebra combinators classes classes.tuple
classes.tuple.private continuations arrays byte-arrays strings classes.tuple.private continuations arrays
math math.partial-dispatch math.private slots generic math math.partial-dispatch math.private slots generic definitions
generic.standard generic.math generic.standard generic.math
stack-checker.state
compiler.tree compiler.tree
compiler.tree.propagation.info compiler.tree.propagation.info
compiler.tree.propagation.nodes compiler.tree.propagation.nodes
@ -32,7 +33,14 @@ M: #push propagate-before
[ set-value-info ] 2each ; [ set-value-info ] 2each ;
M: #declare propagate-before M: #declare propagate-before
declaration>> [ <class-info> swap refine-value-info ] assoc-each ; #! We need to force the caller word to recompile when the
#! classes mentioned in the declaration are redefined, since
#! now we're making assumptions but their definitions.
declaration>> [
[ inlined-dependency depends-on ]
[ <class-info> swap refine-value-info ]
bi
] assoc-each ;
: predicate-constraints ( value class boolean-value -- constraint ) : predicate-constraints ( value class boolean-value -- constraint )
[ [ is-instance-of ] dip t--> ] [ [ is-instance-of ] dip t--> ]
@ -74,7 +82,11 @@ M: #declare propagate-before
} cond 2nip ; } cond 2nip ;
: propagate-predicate ( #call word -- infos ) : propagate-predicate ( #call word -- infos )
[ in-d>> first value-info ] [ "predicating" word-prop ] bi* #! We need to force the caller word to recompile when the class
#! is redefined, since now we're making assumptions but the
#! class definition itself.
[ in-d>> first value-info ]
[ "predicating" word-prop dup inlined-dependency depends-on ] bi*
predicate-output-infos 1array ; predicate-output-infos 1array ;
: default-output-value-infos ( #call word -- infos ) : default-output-value-infos ( #call word -- infos )

View File

@ -17,7 +17,7 @@ TUPLE: #introduce < node out-d ;
: #introduce ( out-d -- node ) : #introduce ( out-d -- node )
\ #introduce new swap >>out-d ; \ #introduce new swap >>out-d ;
TUPLE: #call < node word in-d out-d body method info ; TUPLE: #call < node word in-d out-d body method class info ;
: #call ( inputs outputs word -- node ) : #call ( inputs outputs word -- node )
\ #call new \ #call new

View File

@ -174,7 +174,7 @@ threads sequences calendar accessors ;
] ; ] ;
[ lock-timeout-test ] [ [ lock-timeout-test ] [
linked-error-thread name>> "Lock timeout-er" = thread>> name>> "Lock timeout-er" =
] must-fail-with ] must-fail-with
:: read/write-test ( -- ) :: read/write-test ( -- )

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: deques dlists kernel threads continuations math USING: deques dlists kernel threads continuations math
concurrency.conditions ; concurrency.conditions combinators.short-circuit accessors ;
IN: concurrency.locks IN: concurrency.locks
! Simple critical sections ! Simple critical sections
@ -16,13 +16,13 @@ TUPLE: lock threads owner reentrant? ;
<PRIVATE <PRIVATE
: acquire-lock ( lock timeout -- ) : acquire-lock ( lock timeout -- )
over lock-owner over owner>>
[ 2dup >r lock-threads r> "lock" wait ] when drop [ 2dup >r threads>> r> "lock" wait ] when drop
self swap set-lock-owner ; self >>owner drop ;
: release-lock ( lock -- ) : release-lock ( lock -- )
f over set-lock-owner f >>owner
lock-threads notify-1 ; threads>> notify-1 ;
: do-lock ( lock timeout quot acquire release -- ) : do-lock ( lock timeout quot acquire release -- )
>r >r pick rot r> call ! use up timeout acquire >r >r pick rot r> call ! use up timeout acquire
@ -34,8 +34,8 @@ TUPLE: lock threads owner reentrant? ;
PRIVATE> PRIVATE>
: with-lock-timeout ( lock timeout quot -- ) : with-lock-timeout ( lock timeout quot -- )
pick lock-reentrant? [ pick reentrant?>> [
pick lock-owner self eq? [ pick owner>> self eq? [
2nip call 2nip call
] [ ] [
(with-lock) (with-lock)
@ -56,44 +56,43 @@ TUPLE: rw-lock readers writers reader# writer ;
<PRIVATE <PRIVATE
: add-reader ( lock -- ) : add-reader ( lock -- )
dup rw-lock-reader# 1+ swap set-rw-lock-reader# ; [ 1+ ] change-reader# drop ;
: acquire-read-lock ( lock timeout -- ) : acquire-read-lock ( lock timeout -- )
over rw-lock-writer over writer>>
[ 2dup >r rw-lock-readers r> "read lock" wait ] when drop [ 2dup >r readers>> r> "read lock" wait ] when drop
add-reader ; add-reader ;
: notify-writer ( lock -- ) : notify-writer ( lock -- )
rw-lock-writers notify-1 ; writers>> notify-1 ;
: remove-reader ( lock -- ) : remove-reader ( lock -- )
dup rw-lock-reader# 1- swap set-rw-lock-reader# ; [ 1- ] change-reader# drop ;
: release-read-lock ( lock -- ) : release-read-lock ( lock -- )
dup remove-reader dup remove-reader
dup rw-lock-reader# zero? [ notify-writer ] [ drop ] if ; dup reader#>> zero? [ notify-writer ] [ drop ] if ;
: acquire-write-lock ( lock timeout -- ) : acquire-write-lock ( lock timeout -- )
over rw-lock-writer pick rw-lock-reader# 0 > or over writer>> pick reader#>> 0 > or
[ 2dup >r rw-lock-writers r> "write lock" wait ] when drop [ 2dup >r writers>> r> "write lock" wait ] when drop
self swap set-rw-lock-writer ; self >>writer drop ;
: release-write-lock ( lock -- ) : release-write-lock ( lock -- )
f over set-rw-lock-writer f >>writer
dup rw-lock-readers deque-empty? dup readers>> deque-empty?
[ notify-writer ] [ rw-lock-readers notify-all ] if ; [ notify-writer ] [ readers>> notify-all ] if ;
: reentrant-read-lock-ok? ( lock -- ? ) : reentrant-read-lock-ok? ( lock -- ? )
#! If we already have a write lock, then we can grab a read #! If we already have a write lock, then we can grab a read
#! lock too. #! lock too.
rw-lock-writer self eq? ; writer>> self eq? ;
: reentrant-write-lock-ok? ( lock -- ? ) : reentrant-write-lock-ok? ( lock -- ? )
#! The only case where we have a writer and > 1 reader is #! The only case where we have a writer and > 1 reader is
#! write -> read re-entrancy, and in this case we prohibit #! write -> read re-entrancy, and in this case we prohibit
#! a further write -> read -> write re-entrancy. #! a further write -> read -> write re-entrancy.
dup rw-lock-writer self eq? { [ writer>> self eq? ] [ reader#>> zero? ] } 1&& ;
swap rw-lock-reader# zero? and ;
PRIVATE> PRIVATE>

View File

@ -7,7 +7,7 @@ match quotations concurrency.messaging concurrency.mailboxes
concurrency.count-downs accessors ; concurrency.count-downs accessors ;
IN: concurrency.messaging.tests IN: concurrency.messaging.tests
[ ] [ my-mailbox mailbox-data clear-deque ] unit-test [ ] [ my-mailbox data>> clear-deque ] unit-test
[ "received" ] [ [ "received" ] [
[ [

View File

@ -18,5 +18,5 @@ IN: help.syntax
: ABOUT: : ABOUT:
scan-object scan-object
in get vocab in get vocab
dup +inlined+ changed-definition dup changed-definition
set-vocab-help ; parsing set-vocab-help ; parsing

View File

@ -55,7 +55,7 @@ IN: hints
: HINTS: : HINTS:
scan-word scan-word
[ +inlined+ changed-definition ] [ redefined ]
[ parse-definition "specializer" set-word-prop ] bi ; [ parse-definition "specializer" set-word-prop ] bi ;
parsing parsing

View File

@ -1,10 +1,11 @@
! Copyright (C) 2007 Daniel Ehrenberg ! Copyright (C) 2007 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: namespaces parser lexer kernel sequences words quotations math ; USING: namespaces parser lexer kernel sequences words quotations math
accessors ;
IN: multiline IN: multiline
: next-line-text ( -- str ) : next-line-text ( -- str )
lexer get dup next-line lexer-line-text ; lexer get dup next-line text>> ;
: (parse-here) ( -- ) : (parse-here) ( -- )
next-line-text [ next-line-text [
@ -22,7 +23,7 @@ IN: multiline
parse-here 1quotation define-inline ; parsing parse-here 1quotation define-inline ; parsing
: (parse-multiline-string) ( start-index end-text -- end-index ) : (parse-multiline-string) ( start-index end-text -- end-index )
lexer get lexer-line-text [ lexer get text>> [
2dup start 2dup start
[ rot dupd >r >r swap subseq % r> r> length + ] [ [ rot dupd >r >r swap subseq % r> r> length + ] [
rot tail % "\n" % 0 rot tail % "\n" % 0
@ -32,8 +33,8 @@ IN: multiline
: parse-multiline-string ( end-text -- str ) : parse-multiline-string ( end-text -- str )
[ [
lexer get lexer-column swap (parse-multiline-string) lexer get column>> swap (parse-multiline-string)
lexer get set-lexer-column lexer get (>>column)
] "" make rest but-last ; ] "" make rest but-last ;
: <" : <"

View File

@ -195,11 +195,11 @@ DEFER: parse-error-file
: string-layout : string-layout
{ {
"USING: debugger io kernel lexer ;" "USING: accessors debugger io kernel ;"
"IN: prettyprint.tests" "IN: prettyprint.tests"
": string-layout-test ( error -- )" ": string-layout-test ( error -- )"
" \"Expected \" write dup unexpected-want expected>string write" " \"Expected \" write dup want>> expected>string write"
" \" but got \" write unexpected-got expected>string print ;" " \" but got \" write got>> expected>string print ;"
} ; } ;

View File

@ -115,10 +115,10 @@ M: object short-section? section-fits? ;
: pprint-section ( section -- ) : pprint-section ( section -- )
dup short-section? [ dup short-section? [
dup section-style [ short-section ] with-style dup style>> [ short-section ] with-style
] [ ] [
[ <long-section ] [ <long-section ]
[ dup section-style [ long-section ] with-style ] [ dup style>> [ long-section ] with-style ]
[ long-section> ] [ long-section> ]
tri tri
] if ; ] if ;

View File

@ -8,29 +8,6 @@ sets generic.standard.engines.tuple stack-checker.state
stack-checker.visitor stack-checker.errors ; stack-checker.visitor stack-checker.errors ;
IN: stack-checker.backend IN: stack-checker.backend
! Word properties we use
SYMBOL: visited
: reset-on-redefine { "inferred-effect" "cannot-infer" } ; inline
: (redefined) ( word -- )
dup visited get key? [ drop ] [
[ reset-on-redefine reset-props ]
[ visited get conjoin ]
[
crossref get at keys
[ word? ] filter
[
[ reset-on-redefine [ word-prop ] with contains? ]
[ inline? ]
bi or
] filter
[ (redefined) ] each
] tri
] if ;
M: word redefined H{ } clone visited [ (redefined) ] with-variable ;
: push-d ( obj -- ) meta-d get push ; : push-d ( obj -- ) meta-d get push ;
: pop-d ( -- obj ) : pop-d ( -- obj )
@ -72,7 +49,7 @@ GENERIC: apply-object ( obj -- )
M: wrapper apply-object M: wrapper apply-object
wrapped>> wrapped>>
[ dup word? [ +called+ depends-on ] [ drop ] if ] [ dup word? [ called-dependency depends-on ] [ drop ] if ]
[ push-literal ] [ push-literal ]
bi ; bi ;
@ -175,6 +152,7 @@ M: object apply-object push-literal ;
init-known-values init-known-values
stack-visitor off stack-visitor off
dependencies off dependencies off
generic-dependencies off
[ [ def>> ] [ ] [ ] tri infer-quot-recursive end-infer ] [ [ def>> ] [ ] [ ] tri infer-quot-recursive end-infer ]
[ finish-word current-effect ] [ finish-word current-effect ]
bi bi

View File

@ -140,7 +140,7 @@ SYMBOL: enter-out
] [ undeclared-recursion-error inference-error ] if ; ] [ undeclared-recursion-error inference-error ] if ;
: inline-word ( word -- ) : inline-word ( word -- )
[ +inlined+ depends-on ] [ inlined-dependency depends-on ]
[ [
{ {
{ [ dup inline-recursive-label ] [ call-recursive-inline-word ] } { [ dup inline-recursive-label ] [ call-recursive-inline-word ] }

View File

@ -176,7 +176,7 @@ do-primitive alien-invoke alien-indirect alien-callback
SYMBOL: +primitive+ SYMBOL: +primitive+
: non-inline-word ( word -- ) : non-inline-word ( word -- )
dup +called+ depends-on dup called-dependency depends-on
{ {
{ [ dup "shuffle" word-prop ] [ infer-shuffle-word ] } { [ dup "shuffle" word-prop ] [ infer-shuffle-word ] }
{ [ dup "special" word-prop ] [ infer-special ] } { [ dup "special" word-prop ] [ infer-special ] }

View File

@ -9,22 +9,22 @@ definitions ;
SYMBOL: a SYMBOL: a
SYMBOL: b SYMBOL: b
[ ] [ a +called+ depends-on ] unit-test [ ] [ a called-dependency depends-on ] unit-test
[ H{ { a +called+ } } ] [ [ H{ { a called-dependency } } ] [
[ a +called+ depends-on ] computing-dependencies [ a called-dependency depends-on ] computing-dependencies
] unit-test ] unit-test
[ H{ { a +called+ } { b +inlined+ } } ] [ [ H{ { a called-dependency } { b inlined-dependency } } ] [
[ [
a +called+ depends-on b +inlined+ depends-on a called-dependency depends-on b inlined-dependency depends-on
] computing-dependencies ] computing-dependencies
] unit-test ] unit-test
[ H{ { a +inlined+ } { b +inlined+ } } ] [ [ H{ { a inlined-dependency } { b inlined-dependency } } ] [
[ [
a +inlined+ depends-on a inlined-dependency depends-on
a +called+ depends-on a called-dependency depends-on
b +inlined+ depends-on b inlined-dependency depends-on
] computing-dependencies ] computing-dependencies
] unit-test ] unit-test

View File

@ -1,7 +1,8 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: assocs namespaces sequences kernel definitions math USING: assocs namespaces sequences kernel definitions math
effects accessors words stack-checker.errors ; effects accessors words fry classes.algebra stack-checker.errors
compiler.units ;
IN: stack-checker.state IN: stack-checker.state
: <value> ( -- value ) \ <value> counter ; : <value> ( -- value ) \ <value> counter ;
@ -88,9 +89,15 @@ SYMBOL: meta-r
SYMBOL: dependencies SYMBOL: dependencies
: depends-on ( word how -- ) : depends-on ( word how -- )
swap dependencies get dup [ dependencies get dup
2dup at +inlined+ eq? [ 3drop ] [ set-at ] if [ swap '[ , strongest-dependency ] change-at ] [ 3drop ] if ;
] [ 3drop ] if ;
! Generic words that the current quotation depends on
SYMBOL: generic-dependencies
: depends-on-generic ( generic class -- )
generic-dependencies get dup
[ swap '[ null or , class-or ] change-at ] [ 3drop ] if ;
! Words we've inferred the stack effect of, for rollback ! Words we've inferred the stack effect of, for rollback
SYMBOL: recorded SYMBOL: recorded

View File

@ -46,7 +46,7 @@ SYMBOL: +transform-n+
] [ 2drop give-up-transform ] if ; ] [ 2drop give-up-transform ] if ;
: apply-transform ( word -- ) : apply-transform ( word -- )
[ +inlined+ depends-on ] [ [ inlined-dependency depends-on ] [
[ ] [ ]
[ +transform-quot+ word-prop ] [ +transform-quot+ word-prop ]
[ +transform-n+ word-prop ] [ +transform-n+ word-prop ]
@ -55,7 +55,7 @@ SYMBOL: +transform-n+
] bi ; ] bi ;
: apply-macro ( word -- ) : apply-macro ( word -- )
[ +inlined+ depends-on ] [ [ inlined-dependency depends-on ] [
[ ] [ ]
[ "macro" word-prop ] [ "macro" word-prop ]
[ "declared-effect" word-prop in>> length ] [ "declared-effect" word-prop in>> length ]
@ -92,13 +92,13 @@ SYMBOL: +transform-n+
\ spread [ spread>quot ] 1 define-transform \ spread [ spread>quot ] 1 define-transform
\ (call-next-method) [ \ (call-next-method) [
[ [ +inlined+ depends-on ] bi@ ] [ next-method-quot ] 2bi [ [ inlined-dependency depends-on ] bi@ ] [ next-method-quot ] 2bi
] 2 define-transform ] 2 define-transform
! Constructors ! Constructors
\ boa [ \ boa [
dup tuple-class? [ dup tuple-class? [
dup +inlined+ depends-on dup inlined-dependency depends-on
[ "boa-check" word-prop ] [ "boa-check" word-prop ]
[ tuple-layout '[ , <tuple-boa> ] ] [ tuple-layout '[ , <tuple-boa> ] ]
bi append bi append
@ -107,7 +107,7 @@ SYMBOL: +transform-n+
\ new [ \ new [
dup tuple-class? [ dup tuple-class? [
dup +inlined+ depends-on dup inlined-dependency depends-on
dup all-slots rest-slice ! delegate slot dup all-slots rest-slice ! delegate slot
[ [ initial>> literalize , ] each literalize , \ boa , ] [ ] make [ [ initial>> literalize , ] each literalize , \ boa , ] [ ] make
] [ drop f ] if ] [ drop f ] if

View File

@ -35,13 +35,13 @@ namespaces continuations layouts accessors ;
[ t ] [ 1200000 small-enough? ] unit-test [ t ] [ 1200000 small-enough? ] unit-test
[ ] [ "tetris" shake-and-bake ] unit-test ! [ ] [ "tetris" shake-and-bake ] unit-test
!
[ t ] [ 1500000 small-enough? ] unit-test ! [ t ] [ 1500000 small-enough? ] unit-test
!
[ ] [ "bunny" shake-and-bake ] unit-test ! [ ] [ "bunny" shake-and-bake ] unit-test
!
[ t ] [ 2500000 small-enough? ] unit-test ! [ t ] [ 2500000 small-enough? ] unit-test
{ {
"tools.deploy.test.1" "tools.deploy.test.1"

View File

@ -1,15 +1,15 @@
USING: tools.deploy.config ; USING: tools.deploy.config ;
H{ H{
{ deploy-word-defs? f }
{ deploy-random? f }
{ deploy-name "tools.deploy.test.2" }
{ deploy-threads? t }
{ deploy-compiler? t }
{ deploy-math? t } { deploy-math? t }
{ deploy-c-types? f } { deploy-compiler? t }
{ deploy-io 2 } { deploy-reflection 2 }
{ deploy-reflection 1 }
{ deploy-ui? f } { deploy-ui? f }
{ "stop-after-last-window?" t }
{ deploy-word-props? f } { deploy-word-props? f }
{ deploy-threads? t }
{ deploy-c-types? f }
{ deploy-random? f }
{ "stop-after-last-window?" t }
{ deploy-name "tools.deploy.test.2" }
{ deploy-io 2 }
{ deploy-word-defs? f }
} }

View File

@ -39,7 +39,7 @@ M: dimensions-not-equal summary drop "Dimensions do not match" ;
[ dimensions 2array ] bi@ = [ dimensions 2array ] bi@ =
[ dimensions-not-equal ] unless ; [ dimensions-not-equal ] unless ;
: 2values ( dim dim -- val val ) [ dimensioned-value ] bi@ ; : 2values ( dim dim -- val val ) [ value>> ] bi@ ;
: <dimension-op ( dim dim -- top bot val val ) : <dimension-op ( dim dim -- top bot val val )
2dup check-dimensions dup dimensions 2swap 2values ; 2dup check-dimensions dup dimensions 2swap 2values ;
@ -56,8 +56,8 @@ M: dimensions-not-equal summary drop "Dimensions do not match" ;
: d* ( d d -- d ) : d* ( d d -- d )
[ dup number? [ scalar ] when ] bi@ [ dup number? [ scalar ] when ] bi@
[ [ dimensioned-top ] bi@ append ] 2keep [ [ top>> ] bi@ append ] 2keep
[ [ dimensioned-bot ] bi@ append ] 2keep [ [ bot>> ] bi@ append ] 2keep
2values * dimension-op> ; 2values * dimension-op> ;
: d-neg ( d -- d ) -1 d* ; : d-neg ( d -- d ) -1 d* ;

View File

@ -110,6 +110,9 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
2dup [ assoc-size ] bi@ + pick new-assoc 2dup [ assoc-size ] bi@ + pick new-assoc
[ rot update ] keep [ swap update ] keep ; [ rot update ] keep [ swap update ] keep ;
: assoc-combine ( seq -- union )
H{ } clone [ dupd update ] reduce ;
: assoc-diff ( assoc1 assoc2 -- diff ) : assoc-diff ( assoc1 assoc2 -- diff )
[ nip key? not ] curry assoc-filter ; [ nip key? not ] curry assoc-filter ;
@ -186,7 +189,7 @@ M: sequence assoc-clone-like
>r >alist r> clone-like ; >r >alist r> clone-like ;
M: sequence assoc-like M: sequence assoc-like
over sequence? [ like ] [ assoc-clone-like ] if ; >r >alist r> like ;
M: sequence >alist ; M: sequence >alist ;

View File

@ -35,6 +35,7 @@ H{ } clone sub-primitives set
H{ } clone dictionary set H{ } clone dictionary set
H{ } clone new-classes set H{ } clone new-classes set
H{ } clone changed-definitions set H{ } clone changed-definitions set
H{ } clone changed-generics set
H{ } clone forgotten-definitions set H{ } clone forgotten-definitions set
H{ } clone root-cache set H{ } clone root-cache set
H{ } clone source-files set H{ } clone source-files set

View File

@ -310,3 +310,8 @@ SINGLETON: sb
SINGLETON: sc SINGLETON: sc
[ sa ] [ sa { sa sb sc } min-class ] unit-test [ sa ] [ sa { sa sb sc } min-class ] unit-test
[ +lt+ ] [ integer sequence class<=> ] unit-test
[ +lt+ ] [ sequence object class<=> ] unit-test
[ +gt+ ] [ object sequence class<=> ] unit-test
[ +eq+ ] [ integer integer class<=> ] unit-test

View File

@ -186,6 +186,13 @@ M: anonymous-complement (classes-intersect?)
[ [ rank-class ] bi@ < ] [ [ rank-class ] bi@ < ]
} cond ; } cond ;
: class<=> ( first second -- ? )
{
{ [ 2dup class<= not ] [ 2drop +gt+ ] }
{ [ 2dup swap class<= not ] [ 2drop +lt+ ] }
[ [ rank-class ] bi@ <=> ]
} cond ;
: class= ( first second -- ? ) : class= ( first second -- ? )
[ class<= ] [ swap class<= ] 2bi and ; [ class<= ] [ swap class<= ] 2bi and ;

View File

@ -122,6 +122,7 @@ M: sequence implementors [ implementors ] gather ;
dup class? [ dup [ implementors-map+ ] [ new-class ] bi ] unless dup class? [ dup [ implementors-map+ ] [ new-class ] bi ] unless
dup reset-class dup reset-class
dup deferred? [ dup define-symbol ] when dup deferred? [ dup define-symbol ] when
dup redefined
dup props>> dup props>>
r> assoc-union >>props r> assoc-union >>props
dup predicate-word dup predicate-word

View File

@ -63,8 +63,10 @@ TUPLE: check-mixin-class mixin ;
: remove-mixin-instance ( class mixin -- ) : remove-mixin-instance ( class mixin -- )
[ [
[ [ swap remove ] change-mixin-class ] keep [ class-usages update-methods ]
update-classes [ [ swap remove ] change-mixin-class ]
[ nip update-classes ]
2tri
] [ 2drop ] if-mixin-member? ; ] [ 2drop ] if-mixin-member? ;
M: mixin-class class-forgotten remove-mixin-instance ; M: mixin-class class-forgotten remove-mixin-instance ;

View File

@ -227,9 +227,8 @@ M: tuple-class update-class
2drop 2drop
[ [
[ update-tuples-after ] [ update-tuples-after ]
[ +inlined+ changed-definition ]
[ redefined ] [ redefined ]
tri bi
] each-subclass ] each-subclass
] ]
[ define-new-tuple-class ] [ define-new-tuple-class ]
@ -270,9 +269,6 @@ M: tuple-class define-tuple-class
tri* define-declared tri* define-declared
] 3tri ; ] 3tri ;
M: tuple-class update-generic
over new-class? [ 2drop ] [ call-next-method ] if ;
M: tuple-class reset-class M: tuple-class reset-class
[ [
dup "slots" word-prop [ dup "slots" word-prop [

View File

@ -0,0 +1,9 @@
IN: compiler.units.tests
USING: definitions compiler.units tools.test arrays sequences ;
[ flushed-dependency ] [ f flushed-dependency strongest-dependency ] unit-test
[ flushed-dependency ] [ flushed-dependency f strongest-dependency ] unit-test
[ inlined-dependency ] [ flushed-dependency inlined-dependency strongest-dependency ] unit-test
[ inlined-dependency ] [ called-dependency inlined-dependency strongest-dependency ] unit-test
[ flushed-dependency ] [ called-dependency flushed-dependency strongest-dependency ] unit-test
[ called-dependency ] [ called-dependency f strongest-dependency ] unit-test

View File

@ -1,7 +1,8 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel continuations assocs namespaces USING: accessors arrays kernel continuations assocs namespaces
sequences words vocabs definitions hashtables init sets ; sequences words vocabs definitions hashtables init sets
math.order classes classes.algebra ;
IN: compiler.units IN: compiler.units
SYMBOL: old-definitions SYMBOL: old-definitions
@ -72,9 +73,51 @@ GENERIC: definitions-changed ( assoc obj -- )
SYMBOL: outdated-tuples SYMBOL: outdated-tuples
SYMBOL: update-tuples-hook SYMBOL: update-tuples-hook
: strongest-dependency ( how1 how2 -- how )
[ called-dependency or ] bi@ max ;
: weakest-dependency ( how1 how2 -- how )
[ inlined-dependency or ] bi@ min ;
: compiled-usage ( word -- assoc )
compiled-crossref get at ;
: (compiled-usages) ( word -- assoc )
#! If the word is not flushable anymore, we have to recompile
#! all words which flushable away a call (presumably when the
#! word was still flushable). If the word is flushable, we
#! don't have to recompile words that folded this away.
[ compiled-usage ]
[ "flushable" word-prop inlined-dependency flushed-dependency ? ] bi
[ after=? nip ] curry assoc-filter ;
: compiled-usages ( assoc -- assocs )
[ drop word? ] assoc-filter
[ [ drop (compiled-usages) ] { } assoc>map ] keep suffix ;
: compiled-generic-usage ( word -- assoc )
compiled-generic-crossref get at ;
: (compiled-generic-usages) ( generic class -- assoc )
dup class? [
[ compiled-generic-usage ] dip
[ [ classes-intersect? ] [ null class<= ] bi or nip ]
curry assoc-filter
] [ 2drop f ] if ;
: compiled-generic-usages ( assoc -- assocs )
[ (compiled-generic-usages) ] { } assoc>map ;
: words-only ( assoc -- assoc' )
[ drop word? ] assoc-filter ;
: to-recompile ( -- seq )
changed-definitions get compiled-usages
changed-generics get compiled-generic-usages
append assoc-combine keys ;
: call-recompile-hook ( -- ) : call-recompile-hook ( -- )
changed-definitions get [ drop word? ] assoc-filter to-recompile recompile-hook get call ;
compiled-usages recompile-hook get call ;
: call-update-tuples-hook ( -- ) : call-update-tuples-hook ( -- )
update-tuples-hook get call ; update-tuples-hook get call ;
@ -93,13 +136,16 @@ SYMBOL: update-tuples-hook
: with-nested-compilation-unit ( quot -- ) : with-nested-compilation-unit ( quot -- )
[ [
H{ } clone changed-definitions set H{ } clone changed-definitions set
H{ } clone changed-generics set
H{ } clone outdated-tuples set H{ } clone outdated-tuples set
H{ } clone new-classes set
[ finish-compilation-unit ] [ ] cleanup [ finish-compilation-unit ] [ ] cleanup
] with-scope ; inline ] with-scope ; inline
: with-compilation-unit ( quot -- ) : with-compilation-unit ( quot -- )
[ [
H{ } clone changed-definitions set H{ } clone changed-definitions set
H{ } clone changed-generics set
H{ } clone forgotten-definitions set H{ } clone forgotten-definitions set
H{ } clone outdated-tuples set H{ } clone outdated-tuples set
H{ } clone new-classes set H{ } clone new-classes set

View File

@ -1,17 +1,38 @@
! Copyright (C) 2006, 2008 Slava Pestov. ! Copyright (C) 2006, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: definitions IN: definitions
USING: kernel sequences namespaces assocs graphs ; USING: kernel sequences namespaces assocs graphs math math.order ;
ERROR: no-compilation-unit definition ; ERROR: no-compilation-unit definition ;
SINGLETON: inlined-dependency
SINGLETON: flushed-dependency
SINGLETON: called-dependency
UNION: dependency
inlined-dependency
flushed-dependency
called-dependency ;
M: dependency <=>
[
{
called-dependency
flushed-dependency
inlined-dependency
} index
] bi@ <=> ;
SYMBOL: changed-definitions SYMBOL: changed-definitions
SYMBOL: +inlined+ : changed-definition ( defspec -- )
SYMBOL: +called+ inlined-dependency swap changed-definitions get
[ set-at ] [ no-compilation-unit ] if* ;
: changed-definition ( defspec how -- ) SYMBOL: changed-generics
swap changed-definitions get
: changed-generic ( class generic -- )
changed-generics get
[ set-at ] [ no-compilation-unit ] if* ; [ set-at ] [ no-compilation-unit ] if* ;
SYMBOL: new-classes SYMBOL: new-classes

View File

@ -53,22 +53,12 @@ GENERIC: next-method-quot* ( class generic combination -- quot )
TUPLE: check-method class generic ; TUPLE: check-method class generic ;
: check-method ( class generic -- class generic ) : check-method ( class generic -- class generic )
over class? over generic? and [ 2dup [ class? ] [ generic? ] bi* and [
\ check-method boa throw \ check-method boa throw
] unless ; inline ] unless ; inline
: affected-methods ( class generic -- seq )
"methods" word-prop swap
[ nip [ classes-intersect? ] [ class<= ] 2bi or ] curry assoc-filter
values ;
GENERIC# update-generic 1 ( class generic -- )
M: class update-generic
affected-methods [ +called+ changed-definition ] each ;
: with-methods ( class generic quot -- ) : with-methods ( class generic quot -- )
[ drop update-generic ] [ drop changed-generic ]
[ [ "methods" word-prop ] dip call ] [ [ "methods" word-prop ] dip call ]
[ drop make-generic drop ] [ drop make-generic drop ]
3tri ; inline 3tri ; inline
@ -168,7 +158,7 @@ M: method-body smart-usage
M: sequence update-methods ( class seq -- ) M: sequence update-methods ( class seq -- )
implementors [ implementors [
[ update-generic ] [ make-generic drop ] 2bi [ changed-generic ] [ make-generic drop ] 2bi
] with each ; ] with each ;
: define-generic ( word combination -- ) : define-generic ( word combination -- )

View File

@ -101,60 +101,79 @@ SYMBOL: compiled-crossref
compiled-crossref global [ H{ } assoc-like ] change-at compiled-crossref global [ H{ } assoc-like ] change-at
: compiled-xref ( word dependencies -- ) SYMBOL: compiled-generic-crossref
[ drop crossref? ] assoc-filter
[ "compiled-uses" set-word-prop ] compiled-generic-crossref global [ H{ } assoc-like ] change-at
[ compiled-crossref get add-vertex* ]
2bi ; : (compiled-xref) ( word dependencies word-prop variable -- )
[ [ set-word-prop ] curry ]
[ [ get add-vertex* ] curry ]
bi* 2bi ;
: compiled-xref ( word dependencies generic-dependencies -- )
[ [ drop crossref? ] assoc-filter ] bi@
[ over ] dip
[ "compiled-uses" compiled-crossref (compiled-xref) ]
[ "compiled-generic-uses" compiled-generic-crossref (compiled-xref) ]
2bi* ;
: (compiled-unxref) ( word word-prop variable -- )
[ [ [ dupd word-prop ] dip get remove-vertex* ] 2curry ]
[ drop [ f swap set-word-prop ] curry ]
2bi bi ;
: compiled-unxref ( word -- ) : compiled-unxref ( word -- )
[ [ "compiled-uses" compiled-crossref (compiled-unxref) ]
dup "compiled-uses" word-prop [ "compiled-generic-uses" compiled-generic-crossref (compiled-unxref) ]
compiled-crossref get remove-vertex* bi ;
]
[ f "compiled-uses" set-word-prop ] bi ;
: delete-compiled-xref ( word -- ) : delete-compiled-xref ( word -- )
dup compiled-unxref [ compiled-unxref ]
compiled-crossref get delete-at ; [ compiled-crossref get delete-at ]
[ compiled-generic-crossref get delete-at ]
tri ;
: compiled-usage ( word -- assoc ) GENERIC: inline? ( word -- ? )
compiled-crossref get at ;
: compiled-usages ( assoc -- seq ) M: word inline? "inline" word-prop ;
clone [
dup [ SYMBOL: visited
: reset-on-redefine { "inferred-effect" "cannot-infer" } ; inline
: (redefined) ( word -- )
dup visited get key? [ drop ] [
[ reset-on-redefine reset-props ]
[ visited get conjoin ]
[ [
[ compiled-usage ] dip crossref get at keys
+inlined+ eq? [ [ word? ] filter
[ nip +inlined+ eq? ] assoc-filter [
] when [ reset-on-redefine [ word-prop ] with contains? ]
] dip swap update [ inline? ]
] curry assoc-each bi or
] keep keys ; ] filter
[ (redefined) ] each
] tri
] if ;
GENERIC: redefined ( word -- ) : redefined ( word -- )
[ H{ } clone visited [ (redefined) ] with-variable ]
M: object redefined drop ; [ changed-definition ]
bi ;
: define ( word def -- ) : define ( word def -- )
[ ] like [ ] like
over unxref over unxref
over redefined over redefined
>>def >>def
dup +inlined+ changed-definition
dup crossref? [ dup xref ] when drop ; dup crossref? [ dup xref ] when drop ;
: set-stack-effect ( effect word -- ) : set-stack-effect ( effect word -- )
2dup "declared-effect" word-prop = [ 2drop ] [ 2dup "declared-effect" word-prop = [ 2drop ] [
swap swap
[ "declared-effect" set-word-prop ] [ "declared-effect" set-word-prop ]
[ [ drop dup primitive? [ dup redefined ] unless drop ] 2bi
drop
dup primitive? [ drop ] [
[ redefined ] [ +inlined+ changed-definition ] bi
] if
] 2bi
] if ; ] if ;
: define-declared ( word def effect -- ) : define-declared ( word def effect -- )
@ -226,10 +245,6 @@ ERROR: bad-create name vocab ;
: constructor-word ( name vocab -- word ) : constructor-word ( name vocab -- word )
>r "<" swap ">" 3append r> create ; >r "<" swap ">" 3append r> create ;
GENERIC: inline? ( word -- ? )
M: word inline? "inline" word-prop ;
PREDICATE: parsing-word < word "parsing" word-prop ; PREDICATE: parsing-word < word "parsing" word-prop ;
: delimiter? ( obj -- ? ) : delimiter? ( obj -- ? )

View File

@ -1,11 +1,11 @@
! Copyright (C) 2007 Doug Coleman. ! Copyright (C) 2007 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel macros sequences slots words classes.tuple USING: kernel macros sequences slots words classes.tuple
quotations combinators ; quotations combinators accessors ;
IN: classes.tuple.lib IN: classes.tuple.lib
: reader-slots ( seq -- quot ) : reader-slots ( seq -- quot )
[ slot-spec-reader 1quotation ] map [ cleave ] curry ; [ reader>> 1quotation ] map [ cleave ] curry ;
MACRO: >tuple< ( class -- ) MACRO: >tuple< ( class -- )
all-slots rest-slice reader-slots ; all-slots rest-slice reader-slots ;

View File

@ -353,11 +353,11 @@ M: quotation fjsc-parse ( object -- ast )
] with-string-writer ; ] with-string-writer ;
: fjsc-compile* ( string -- string ) : fjsc-compile* ( string -- string )
'statement' parse parse-result-ast fjsc-compile ; 'statement' parse ast>> fjsc-compile ;
: fc* ( string -- string ) : fc* ( string -- string )
[ [
'statement' parse parse-result-ast values>> do-expressions 'statement' parse ast>> values>> do-expressions
] { } make [ write ] each ; ] { } make [ write ] each ;

View File

@ -208,7 +208,7 @@ DEFER: _
: slot-readers ( class -- quot ) : slot-readers ( class -- quot )
all-slots rest ! tail gets rid of delegate all-slots rest ! tail gets rid of delegate
[ slot-spec-reader 1quotation [ keep ] curry ] map concat [ reader>> 1quotation [ keep ] curry ] map concat
[ ] like [ drop ] compose ; [ ] like [ drop ] compose ;
: ?wrapped ( object -- wrapped ) : ?wrapped ( object -- wrapped )

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: kernel parser-combinators namespaces sequences promises strings USING: kernel parser-combinators namespaces sequences promises strings
assocs math math.parser math.vectors math.functions math.order assocs math math.parser math.vectors math.functions math.order
lists hashtables ascii ; lists hashtables ascii accessors ;
IN: json.reader IN: json.reader
! Grammar for JSON from RFC 4627 ! Grammar for JSON from RFC 4627
@ -169,11 +169,12 @@ LAZY: 'value' ( -- parser )
'array' , 'array' ,
'number' , 'number' ,
] [<|>] spaced ; ] [<|>] spaced ;
ERROR: could-not-parse-json ;
: json> ( string -- object ) : json> ( string -- object )
#! Parse a json formatted string to a factor object #! Parse a json formatted string to a factor object
'value' parse dup nil? [ 'value' parse dup nil? [
"Could not parse json" throw could-not-parse-json
] [ ] [
car parse-result-parsed car parsed>>
] if ; ] if ;

View File

@ -24,7 +24,7 @@ TUPLE: lazy-cons car cdr ;
: lazy-cons ( car cdr -- promise ) : lazy-cons ( car cdr -- promise )
[ promise ] bi@ \ lazy-cons boa [ promise ] bi@ \ lazy-cons boa
T{ promise f f t f } clone T{ promise f f t f } clone
[ set-promise-value ] keep ; swap >>value ;
M: lazy-cons car ( lazy-cons -- car ) M: lazy-cons car ( lazy-cons -- car )
car>> force ; car>> force ;

View File

@ -116,7 +116,7 @@ LAZY: 'morse-words' ( -- parser )
PRIVATE> PRIVATE>
: morse> ( str -- str ) : morse> ( str -- str )
'morse-words' parse car parse-result-parsed [ 'morse-words' parse car parsed>> [
[ [
>string morse>ch >string morse>ch
] map >string ] map >string

View File

@ -1,5 +1,5 @@
USING: arrays kernel math opengl opengl.gl opengl.glu ui USING: arrays kernel math opengl opengl.gl opengl.glu ui
ui.gadgets ui.render threads ; ui.gadgets ui.render threads accessors ;
IN: nehe.4 IN: nehe.4
TUPLE: nehe4-gadget < gadget rtri rquad thread quit? ; TUPLE: nehe4-gadget < gadget rtri rquad thread quit? ;
@ -10,8 +10,8 @@ TUPLE: nehe4-gadget < gadget rtri rquad thread quit? ;
: <nehe4-gadget> ( -- gadget ) : <nehe4-gadget> ( -- gadget )
nehe4-gadget new-gadget nehe4-gadget new-gadget
0.0 over set-nehe4-gadget-rtri 0.0 >>rtri
0.0 over set-nehe4-gadget-rquad ; 0.0 >>rquad ;
M: nehe4-gadget pref-dim* ( gadget -- dim ) M: nehe4-gadget pref-dim* ( gadget -- dim )
drop width height 2array ; drop width height 2array ;
@ -53,22 +53,22 @@ M: nehe4-gadget draw-gadget* ( gadget -- )
1.0 -1.0 0.0 glVertex3f 1.0 -1.0 0.0 glVertex3f
-1.0 -1.0 0.0 glVertex3f -1.0 -1.0 0.0 glVertex3f
] do-state ] do-state
dup nehe4-gadget-rtri 0.2 + over set-nehe4-gadget-rtri [ 0.2 + ] change-rtri
dup nehe4-gadget-rquad 0.15 - swap set-nehe4-gadget-rquad ; [ 0.15 - ] change-rquad drop ;
: nehe4-update-thread ( gadget -- ) : nehe4-update-thread ( gadget -- )
dup nehe4-gadget-quit? [ drop ] [ dup quit?>> [ drop ] [
redraw-interval sleep redraw-interval sleep
dup relayout-1 dup relayout-1
nehe4-update-thread nehe4-update-thread
] if ; ] if ;
M: nehe4-gadget graft* ( gadget -- ) M: nehe4-gadget graft* ( gadget -- )
[ f swap set-nehe4-gadget-quit? ] keep f >>quit?
[ nehe4-update-thread ] in-thread drop ; [ nehe4-update-thread ] in-thread drop ;
M: nehe4-gadget ungraft* ( gadget -- ) M: nehe4-gadget ungraft* ( gadget -- )
t swap set-nehe4-gadget-quit? ; t >>quit? drop ;
: run4 ( -- ) : run4 ( -- )
<nehe4-gadget> "NeHe Tutorial 4" open-window ; <nehe4-gadget> "NeHe Tutorial 4" open-window ;

View File

@ -1,5 +1,5 @@
USING: arrays kernel math opengl opengl.gl opengl.glu ui USING: arrays kernel math opengl opengl.gl opengl.glu ui
ui.gadgets ui.render threads ; ui.gadgets ui.render threads accessors ;
IN: nehe.5 IN: nehe.5
TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ; TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ;
@ -9,8 +9,8 @@ TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ;
: <nehe5-gadget> ( -- gadget ) : <nehe5-gadget> ( -- gadget )
nehe5-gadget new-gadget nehe5-gadget new-gadget
0.0 over set-nehe5-gadget-rtri 0.0 >>rtri
0.0 over set-nehe5-gadget-rquad ; 0.0 >>rquad ;
M: nehe5-gadget pref-dim* ( gadget -- dim ) M: nehe5-gadget pref-dim* ( gadget -- dim )
drop width height 2array ; drop width height 2array ;
@ -103,11 +103,11 @@ M: nehe5-gadget draw-gadget* ( gadget -- )
1.0 -1.0 1.0 glVertex3f 1.0 -1.0 1.0 glVertex3f
1.0 -1.0 -1.0 glVertex3f 1.0 -1.0 -1.0 glVertex3f
] do-state ] do-state
dup nehe5-gadget-rtri 0.2 + over set-nehe5-gadget-rtri [ 0.2 + ] change-rtri
dup nehe5-gadget-rquad 0.15 - swap set-nehe5-gadget-rquad ; [ 0.15 - ] change-rquad drop ;
: nehe5-update-thread ( gadget -- ) : nehe5-update-thread ( gadget -- )
dup nehe5-gadget-quit? [ dup quit?>> [
drop drop
] [ ] [
redraw-interval sleep redraw-interval sleep
@ -116,11 +116,11 @@ M: nehe5-gadget draw-gadget* ( gadget -- )
] if ; ] if ;
M: nehe5-gadget graft* ( gadget -- ) M: nehe5-gadget graft* ( gadget -- )
[ f swap set-nehe5-gadget-quit? ] keep f >>quit?
[ nehe5-update-thread ] in-thread drop ; [ nehe5-update-thread ] in-thread drop ;
M: nehe5-gadget ungraft* ( gadget -- ) M: nehe5-gadget ungraft* ( gadget -- )
t swap set-nehe5-gadget-quit? ; t >>quit? drop ;
: run5 ( -- ) : run5 ( -- )

View File

@ -1,5 +1,5 @@
USING: kernel namespaces USING: kernel namespaces accessors
math math.constants math.functions math.matrices math.vectors math math.constants math.functions math.matrices math.vectors
sequences splitting grouping self math.trig ; sequences splitting grouping self math.trig ;
@ -11,9 +11,9 @@ C: <ori> ori
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: ori> ( -- val ) self> ori-val ; : ori> ( -- val ) self> val>> ;
: >ori ( val -- ) self> set-ori-val ; : >ori ( val -- ) self> (>>val) ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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: lists lists.lazy promises kernel sequences strings math USING: lists lists.lazy promises kernel sequences strings math
arrays splitting quotations combinators namespaces arrays splitting quotations combinators namespaces
unicode.case unicode.categories sequences.deep ; unicode.case unicode.categories sequences.deep accessors ;
IN: parser-combinators IN: parser-combinators
! Parser combinator protocol ! Parser combinator protocol
@ -13,11 +13,13 @@ M: promise parse ( input parser -- list )
TUPLE: parse-result parsed unparsed ; TUPLE: parse-result parsed unparsed ;
ERROR: cannot-parse input ;
: parse-1 ( input parser -- result ) : parse-1 ( input parser -- result )
dupd parse dup nil? [ dupd parse dup nil? [
"Cannot parse " rot append throw rot cannot-parse
] [ ] [
nip car parse-result-parsed nip car parsed>>
] if ; ] if ;
C: <parse-result> parse-result C: <parse-result> parse-result
@ -26,12 +28,12 @@ C: <parse-result> parse-result
<parse-result> 1list ; <parse-result> 1list ;
: parse-result-parsed-slice ( parse-result -- slice ) : parse-result-parsed-slice ( parse-result -- slice )
dup parse-result-parsed empty? [ dup parsed>> empty? [
parse-result-unparsed 0 0 rot <slice> unparsed>> 0 0 rot <slice>
] [ ] [
dup parse-result-unparsed dup unparsed>>
dup slice-from [ rot parse-result-parsed length - ] keep dup from>> [ rot parsed>> length - ] keep
rot slice-seq <slice> rot seq>> <slice>
] if ; ] if ;
: string= ( str1 str2 ignore-case -- ? ) : string= ( str1 str2 ignore-case -- ? )
@ -132,7 +134,7 @@ TUPLE: and-parser parsers ;
: <&> ( parser1 parser2 -- parser ) : <&> ( parser1 parser2 -- parser )
over and-parser? [ over and-parser? [
>r and-parser-parsers r> suffix >r parsers>> r> suffix
] [ ] [
2array 2array
] if and-parser boa ; ] if and-parser boa ;
@ -142,11 +144,11 @@ TUPLE: and-parser parsers ;
: and-parser-parse ( list p1 -- list ) : and-parser-parse ( list p1 -- list )
swap [ swap [
dup parse-result-unparsed rot parse dup unparsed>> rot parse
[ [
>r parse-result-parsed r> >r parsed>> r>
[ parse-result-parsed 2array ] keep [ parsed>> 2array ] keep
parse-result-unparsed <parse-result> unparsed>> <parse-result>
] lazy-map-with ] lazy-map-with
] lazy-map-with lconcat ; ] lazy-map-with lconcat ;

View File

@ -508,10 +508,10 @@ M: ebnf-non-terminal (transform) ( ast -- parser )
: check-parse-result ( result -- result ) : check-parse-result ( result -- result )
dup [ dup [
dup parse-result-remaining [ blank? ] trim empty? [ dup remaining>> [ blank? ] trim empty? [
[ [
"Unable to fully parse EBNF. Left to parse was: " % "Unable to fully parse EBNF. Left to parse was: " %
parse-result-remaining % remaining>> %
] "" make throw ] "" make throw
] unless ] unless
] [ ] [

View File

@ -1,5 +1,6 @@
USING: kernel math math.functions math.vectors sequences self ; USING: kernel math math.functions math.vectors sequences self
accessors ;
IN: pos IN: pos
@ -9,13 +10,13 @@ TUPLE: pos val ;
C: <pos> pos C: <pos> pos
: pos> ( -- val ) self> pos-val ; : pos> ( -- val ) self> val>> ;
: >pos ( val -- ) self> set-pos-val ; : >pos ( val -- ) self> (>>val) ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: distance ( pos pos -- n ) pos-val swap pos-val v- [ sq ] map sum sqrt ; : distance ( pos pos -- n ) val>> swap val>> v- [ sq ] map sum sqrt ;
: move-by ( point -- ) pos> v+ >pos ; : move-by ( point -- ) pos> v+ >pos ;

View File

@ -270,14 +270,14 @@ TUPLE: regexp source parser ignore-case? ;
] keep regexp boa ; ] keep regexp boa ;
: do-ignore-case ( string regexp -- string regexp ) : do-ignore-case ( string regexp -- string regexp )
dup regexp-ignore-case? [ >r >upper r> ] when ; dup ignore-case?>> [ >r >upper r> ] when ;
: matches? ( string regexp -- ? ) : matches? ( string regexp -- ? )
do-ignore-case regexp-parser just parse nil? not ; do-ignore-case parser>> just parse nil? not ;
: match-head ( string regexp -- end ) : match-head ( string regexp -- end )
do-ignore-case regexp-parser parse dup nil? do-ignore-case parser>> parse dup nil?
[ drop f ] [ car parse-result-unparsed from>> ] if ; [ drop f ] [ car unparsed>> from>> ] if ;
! Literal syntax for regexps ! Literal syntax for regexps
: parse-options ( string -- ? ) : parse-options ( string -- ? )

View File

@ -1,5 +1,6 @@
USING: kernel parser lexer strings math namespaces sequences words io USING: kernel parser lexer strings math namespaces
arrays quotations debugger kernel.private sequences.private ; sequences words io arrays quotations debugger accessors
sequences.private ;
IN: state-machine IN: state-machine
: STATES: : STATES:
@ -20,9 +21,9 @@ M: missing-state error.
! quot is ( state string -- output-string ) ! quot is ( state string -- output-string )
[ missing-state ] <array> dup [ missing-state ] <array> dup
[ [
[ >r dup dup state-data swap state-place r> ] % [ >r dup [ data>> ] [ place>> ] bi r> ] %
[ swapd bounds-check dispatch ] curry , [ swapd bounds-check dispatch ] curry ,
[ each pick set-state-place swap set-state-data ] % [ each pick (>>place) swap (>>date) ] %
] [ ] make [ over make ] curry ; ] [ ] make [ over make ] curry ;
: define-machine ( word state-class -- ) : define-machine ( word state-class -- )

View File

@ -1,6 +1,6 @@
IN: turing
USING: arrays assocs io kernel math namespaces USING: arrays assocs io kernel math namespaces
prettyprint sequences strings vectors words ; prettyprint sequences strings vectors words accessors ;
IN: turing
! A turing machine simulator. ! A turing machine simulator.
@ -55,9 +55,9 @@ SYMBOL: tape
: turing-step ( -- ) : turing-step ( -- )
#! Do one step of the turing machine. #! Do one step of the turing machine.
next-state next-state
dup state-sym set-sym dup sym>> set-sym
dup state-dir position [ + ] change dup dir>> position [ + ] change
state-next state set ; next>> state set ;
: c ( -- ) : c ( -- )
#! Print current turing machine state. #! Print current turing machine state.