sbufs strings tools.test vectors words sequences.private
quotations classes classes.algebra classes.tuple.private
continuations growable namespaces hints alien.accessors
-compiler.tree.builder compiler.tree.optimizer ;
+compiler.tree.builder compiler.tree.optimizer sequences.deep ;
IN: optimizer.tests
GENERIC: xyz ( obj -- obj )
[ 1 ] [ B{ 0 0 0 0 0 0 0 0 } [ 0 alien-unsigned-8 1+ ] compile-call ] unit-test
[ 1 ] [ B{ 0 0 0 0 0 0 0 0 } [ 0 alien-signed-cell 1+ ] compile-call ] unit-test
[ 1 ] [ B{ 0 0 0 0 0 0 0 0 } [ 0 alien-unsigned-cell 1+ ] compile-call ] unit-test
+
+: deep-find-test ( seq -- ? ) [ 5 = ] deep-find ;
+
+[ 5 ] [ { 1 2 { 3 { 4 5 } } } deep-find-test ] unit-test
+[ f ] [ { 1 2 { 3 { 4 } } } deep-find-test ] unit-test
[ "" ] [ [ declaration-test ] with-string-writer ] unit-test
-[ ] [ "IN: compiler.tests USE: io : declaration-test-1 ( -- a ) \"X\" print f ;" eval ] unit-test
+[ ] [ "IN: compiler.tests USE: io : declaration-test-1 ( -- a ) \"X\" write f ;" eval ] unit-test
[ "X" ] [ [ declaration-test ] with-string-writer ] unit-test
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors sequences sequences.deep combinators fry
-classes.algebra namespaces assocs math math.private
-math.partial-dispatch classes.tuple classes.tuple.private
+classes.algebra namespaces assocs words math math.private
+math.partial-dispatch classes classes.tuple classes.tuple.private
definitions stack-checker.state stack-checker.branches
compiler.tree
compiler.tree.intrinsics
[ [ drop ] ] [ [ { integer } declare f <array> drop ] optimize-quot ] unit-test
[ [ f <array> drop ] ] [ [ f <array> drop ] optimize-quot ] unit-test
+
+: call-recursive-dce-7 ( obj -- elt ? )
+ dup 5 = [ t ] [ dup [ call-recursive-dce-7 ] [ drop f f ] if ] if ; inline recursive
+
+[ ] [ [ call-recursive-dce-7 ] optimize-quot drop ] unit-test
#! corresponding inputs to the #call-recursive are live also.
[ out-d>> ] [ recursive-phi-in ] bi look-at-phi ;
-: return-recursive-phi-in ( #return-recursive -- phi-in )
- [ label>> calls>> [ in-d>> ] map ] [ in-d>> ] bi suffix ;
-
M: #return-recursive compute-live-values*
- [ out-d>> ] [ return-recursive-phi-in ] bi look-at-phi ;
+ [ out-d>> ] [ in-d>> ] bi look-at-mapping ;
M: #call-recursive compute-live-values*
#! If the output of a #call-recursive is live, then the
drop-values
] ;
-M: #recursive remove-dead-code* ( node -- nodes )
- dup [ in-d>> ] [ label>> enter-out>> ] bi drop-dead-inputs
- {
- [ [ dup label>> enter-recursive>> ] [ out-d>> ] bi* '[ , >>in-d drop ] bi@ ]
- [ drop [ (remove-dead-code) ] change-child drop ]
- [ drop label>> [ filter-live ] change-enter-out drop ]
- [ swap 2array ]
- } 2cleave ;
-
M: #enter-recursive remove-dead-code*
[ filter-live ] change-out-d ;
[ drop-call-recursive-outputs ]
tri 3array ;
-M: #return-recursive remove-dead-code* ( node -- nodes )
- dup [ in-d>> ] [ out-d>> ] bi drop-dead-inputs
- [ drop [ filter-live ] change-out-d drop ]
- [ out-d>> >>in-d drop ]
- [ swap 2array ]
- 2tri ;
+:: drop-recursive-inputs ( node -- shuffle )
+ [let* | shuffle [ node [ in-d>> ] [ label>> enter-out>> ] bi drop-dead-inputs ]
+ new-outputs [ shuffle out-d>> ] |
+ node new-outputs
+ [ [ label>> enter-recursive>> ] dip >>in-d drop ] [ >>in-d drop ] 2bi
+ shuffle
+ ] ;
+
+:: drop-recursive-outputs ( node -- shuffle )
+ [let* | return [ node label>> return>> ]
+ new-inputs [ return in-d>> filter-live ]
+ new-outputs [ return [ in-d>> ] [ out-d>> ] bi filter-corresponding ] |
+ return
+ [ new-inputs >>in-d new-outputs >>out-d drop ]
+ [ drop-dead-outputs ]
+ bi
+ ] ;
+
+M:: #recursive remove-dead-code* ( node -- nodes )
+ [let* | drop-inputs [ node drop-recursive-inputs ]
+ drop-outputs [ node drop-recursive-outputs ] |
+ node [ (remove-dead-code) ] change-child drop
+ node label>> [ filter-live ] change-enter-out drop
+ drop-inputs node drop-outputs 3array
+ ] ;
+
+M: #return-recursive remove-dead-code* ;
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors words assocs sequences arrays namespaces
-fry locals classes.algebra stack-checker.backend
+fry locals definitions classes.algebra
+stack-checker.state
+stack-checker.backend
compiler.tree
compiler.tree.propagation.info
compiler.tree.dead-code.liveness ;
] ;
: drop-dead-outputs ( node -- nodes )
- dup out-d>> drop-dead-values
- [ in-d>> >>out-d drop ] [ 2array ] 2bi ;
+ dup out-d>> drop-dead-values tuck in-d>> >>out-d drop ;
M: #introduce remove-dead-code* ( #introduce -- nodes )
- drop-dead-outputs ;
+ dup drop-dead-outputs 2array ;
M: #>r remove-dead-code*
[ filter-live ] change-out-r
] [ drop f ] if ;
: remove-flushable-call ( #call -- node )
- in-d>> #drop remove-dead-code* ;
+ [ word>> +inlined+ depends-on ]
+ [ in-d>> #drop remove-dead-code* ]
+ bi ;
: some-outputs-dead? ( #call -- ? )
out-d>> [ live-value? not ] contains? ;
remove-flushable-call
] [
dup some-outputs-dead? [
- drop-dead-outputs
+ dup drop-dead-outputs 2array
] when
] if ;
: remember-inlining ( word -- )
history [ swap suffix ] change ;
-: inline-word ( #call word -- )
+: inline-word ( #call word -- ? )
dup history get memq? [
- 2drop
+ 2drop f
] [
[
dup remember-inlining
dupd def>> splicing-nodes >>body
propagate-body
] with-scope
+ t
] if ;
: inline-method-body ( #call word -- ? )
- 2dup should-inline? [ inline-word t ] [ 2drop f ] if ;
+ 2dup should-inline? [ inline-word ] [ 2drop f ] if ;
: always-inline-word? ( word -- ? )
{ curry compose } memq? ;
-
-: always-inline-word ( #call word -- ? ) inline-word t ;
: do-inlining ( #call word -- ? )
{
- { [ dup always-inline-word? ] [ always-inline-word ] }
+ { [ dup always-inline-word? ] [ inline-word ] }
{ [ dup standard-generic? ] [ inline-standard-method ] }
{ [ dup math-generic? ] [ inline-math-method ] }
{ [ dup math-partial? ] [ inline-math-partial ] }
[ entry-stack-height current-stack-height swap - ]
bi*
= [ 2drop ] [
- word>> current-stack-height
- unbalanced-recursion-error inference-error
+ terminated? get [ 2drop ] [
+ word>> current-stack-height
+ unbalanced-recursion-error inference-error
+ ] if
] if ;
: end-recursive-word ( word label -- )
: recursive-word-inputs ( label -- n )
entry-stack-height d-in get + ;
-: (inline-recursive-word) ( word -- label in out visitor )
+: (inline-recursive-word) ( word -- label in out visitor terminated? )
dup prepare-stack
[
init-inference
dup recursive-word-inputs
meta-d get
stack-visitor get
+ terminated? get
] with-scope ;
: inline-recursive-word ( word -- )
(inline-recursive-word)
- [ consume-d ] [ output-d ] [ ] tri* #recursive, ;
+ [ [ consume-d ] [ output-d ] [ ] tri* #recursive, ] dip
+ [ terminate ] when ;
: check-call-height ( label -- )
dup entry-stack-height current-stack-height >
: eee' ( ? -- ) >r swap [ ] r> ddd' call ; inline recursive
[ [ eee' ] infer ] [ inference-error? ] must-fail-with
+
+: bogus-error ( x -- )
+ dup "A" throw [ bogus-error ] [ drop ] if ; inline recursive
+
+[ bogus-error ] must-infer
: next* ( -- )\r
get-char [ (next) record ] when ;\r
\r
-: skip-until ( quot -- )\r
- #! quot: ( -- ? )\r
+: skip-until ( quot: ( -- ? ) -- )\r
get-char [\r
[ call ] keep swap [ drop ] [\r
next skip-until\r
[ ] [ "IN: classes.mixin.tests MIXIN: blah" <string-reader> "mixin-reset-test" parse-stream drop ] unit-test
[ t ] [ "blah" "classes.mixin.tests" lookup mixin-class? ] unit-test
+
+MIXIN: empty-mixin
+
+[ f ] [ "hi" empty-mixin? ] unit-test
dup mixin-class? [
drop
] [
- { } redefine-mixin-class
+ [ { } redefine-mixin-class ]
+ [ update-classes ]
+ bi
] if ;
TUPLE: check-mixin-class mixin ;
tri* define-declared
] 3tri ;
+M: tuple-class update-generic
+ over new-class? [ 2drop ] [ call-next-method ] if ;
+
M: tuple-class reset-class
[
dup "slots" word-prop [
[ nip [ classes-intersect? ] [ class<= ] 2bi or ] curry assoc-filter
values ;
-: update-generic ( class generic -- )
+GENERIC# update-generic 1 ( class generic -- )
+
+M: class update-generic
affected-methods [ +called+ changed-definition ] each ;
: with-methods ( class generic quot -- )
: note. ( str -- )
parser-notes? [
- file get [ path>> write ] when*
+ file get [ path>> write ":" write ] when*
lexer get line>> number>string write ": " write
"Note: " write dup print
] when drop ;