classes.algebra classes.union sets quotations assocs combinators
combinators.short-circuit words namespaces continuations classes
fry hints locals
+stack-checker.dependencies
compiler.tree
compiler.tree.builder
compiler.tree.recursive
] if
] [ 2drop undo-inlining ] if ;
+ERROR: bad-splitting class generic ;
+
+:: split-code ( class generic -- quot/f )
+ class generic method :> my-method
+ my-method [ class generic bad-splitting ] unless
+ class generic my-method depends-on-method-is
+ generic dispatch# (picker) :> picker
+ [
+ picker call class instance?
+ [ my-method execute ]
+ [ generic no-method ] if
+ ] ;
+
+:: split-method-call ( class generic -- quot/f )
+ class generic subclass-with-only-method [
+ [ class generic depends-on-single-method ]
+ [ generic split-code ] bi
+ ] [ f ] if* ;
+
: inlining-standard-method ( #call word -- class/f method/f )
dup "methods" word-prop assoc-empty? [ 2drop f f ] [
2dup [ in-d>> length ] [ dispatch# ] bi* <= [ 2drop f f ] [
[ in-d>> <reversed> ] [ [ dispatch# ] keep ] bi*
[ swap nth value-info class>> dup ] dip
- method-for-class
+ { [ method-for-class ] [ split-method-call ] } 2||
] if
] if ;
word already-inlined? [ f ] [
#call word splicing-body [
word add-to-history
- #call (>>body)
+ #call body<<
#call propagate-body
] [ f ] if*
] if ;
hashtables classes assocs locals specialized-arrays system
sorting math.libm math.floats.private math.integers.private
math.intervals quotations effects alien alien.data sets
-strings.private ;
+strings.private classes.tuple eval ;
FROM: math => float ;
SPECIALIZED-ARRAY: double
SPECIALIZED-ARRAY: void*
[ V{ fixnum } ] [ [ bad-behavior ] final-classes ] unit-test
-[ V{ number } ] [
+[ V{ integer } ] [
[
0 10 [ bad-generic dup 123 bitand drop bad-generic 1 + ] times
] final-classes
GENERIC: whatever ( x -- y )
M: number whatever drop foo ; inline
-[ t ] [ [ 1 whatever new ] { new } inlined? ] unit-test
+[ t ] [ [ 1 whatever new ] { new } M\ tuple-class new suffix inlined? ] unit-test
: that-thing ( -- class ) foo ;
-[ f ] [ [ that-thing new ] { new } inlined? ] unit-test
+[ f ] [ [ that-thing new ] { new } M\ tuple-class new suffix inlined? ] unit-test
GENERIC: whatever2 ( x -- y )
M: number whatever2 drop H{ { 1 1 } { 2 2 } { 3 3 } { 4 4 } { 5 6 } } ; inline
[ string-nth ] final-info first interval>> 0 23 2^ [a,b] =
] unit-test
+! Optimization on instance?
+[ f ] [ [ { number } declare fixnum instance? ] { tag fixnum? } inlined? ] unit-test
+
+UNION: ?fixnum fixnum POSTPONE: f ;
+[ t ] [ [ { ?fixnum } declare fixnum instance? ] { tag fixnum? } inlined? ] unit-test
+[ t ] [ [ { fixnum } declare fixnum instance? ] { tag fixnum? } inlined? ] unit-test
+
+! Actually check to make sure that the generated code works properly
+: instance-test-1 ( x -- ? ) { ?fixnum } declare fixnum instance? ;
+: instance-test-2 ( x -- ? ) { number } declare fixnum instance? ;
+: instance-test-3 ( x -- ? ) { POSTPONE: f } declare \ f instance? ;
+
+[ t ] [ 1 instance-test-1 ] unit-test
+[ f ] [ f instance-test-1 ] unit-test
+[ t ] [ 1 instance-test-2 ] unit-test
+[ f ] [ 1.1 instance-test-2 ] unit-test
+[ t ] [ f instance-test-3 ] unit-test
+
+[ t ] [ [ { ?fixnum } declare >fixnum ] { >fixnum } inlined? ] unit-test
+[ f ] [ [ { integer } declare >fixnum ] { >fixnum } inlined? ] unit-test
+
+[ f ] [ [ { word } declare parent-word ] { parent-word } inlined? ] unit-test
+
+! Make sure guarded method inlining installs the right dependencies
+
+[ ] [
+ "IN: compiler.tree.propagation.tests
+ USING: kernel.private accessors ;
+ TUPLE: foo bar ;
+ UNION: ?foo foo POSTPONE: f ;
+ : baz ( ?foo -- bar ) { ?foo } declare bar>> ;" eval( -- )
+] unit-test
+
+[ 3 ] [ "USE: kernel IN: compiler.tree.propagation.tests 3 foo boa baz" eval( -- x ) ] unit-test
+
+[ ] [ "IN: compiler.tree.propagation.tests TUPLE: foo baz bar ;" eval( -- ) ] unit-test
+
+[ 3 ] [ "USE: kernel IN: compiler.tree.propagation.tests 2 3 foo boa baz" eval( -- x ) ] unit-test
++
+ ! Non-zero displacement for <displaced-alien> restricts the output type
+ [ t ] [
+ [ { byte-array } declare <displaced-alien> ] final-classes
+ first byte-array alien class-or class=
+ ] unit-test
+
+ [ V{ alien } ] [
+ [ { alien } declare <displaced-alien> ] final-classes
+ ] unit-test
+
+ [ t ] [
+ [ { POSTPONE: f } declare <displaced-alien> ] final-classes
+ first \ f alien class-or class=
+ ] unit-test
+
+ [ V{ alien } ] [
+ [ { byte-array } declare [ 10 bitand 2 + ] dip <displaced-alien> ] final-classes
+ ] unit-test