2010-02-11 08:50:59 -05:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
2008-07-25 03:07:45 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2014-12-13 19:10:21 -05:00
|
|
|
USING: accessors arrays assocs byte-arrays classes
|
|
|
|
classes.algebra classes.tuple classes.tuple.private combinators
|
|
|
|
combinators.short-circuit compiler.tree.propagation.info kernel
|
2015-09-21 06:24:22 -04:00
|
|
|
math sequences slots.private strings words ;
|
2008-07-25 03:07:45 -04:00
|
|
|
IN: compiler.tree.propagation.slots
|
|
|
|
|
2008-07-30 04:38:10 -04:00
|
|
|
: sequence-constructor? ( word -- ? )
|
2009-10-28 16:02:00 -04:00
|
|
|
{ <array> <byte-array> (byte-array) <string> } member-eq? ;
|
2008-07-25 03:07:45 -04:00
|
|
|
|
2008-07-30 04:38:10 -04:00
|
|
|
: propagate-sequence-constructor ( #call word -- infos )
|
2010-03-09 15:58:44 -05:00
|
|
|
[ in-d>> first value-info ]
|
2015-09-21 06:24:22 -04:00
|
|
|
[ "default-output-classes" word-prop first ] bi*
|
2010-03-09 21:15:49 -05:00
|
|
|
<sequence-info> 1array ;
|
2008-07-25 03:07:45 -04:00
|
|
|
|
2008-07-26 20:01:43 -04:00
|
|
|
: fold-<tuple-boa> ( values class -- info )
|
2014-11-29 19:54:50 -05:00
|
|
|
[ [ literal>> ] map ] dip slots>tuple
|
2008-07-26 20:01:43 -04:00
|
|
|
<literal-info> ;
|
|
|
|
|
2009-05-01 10:36:53 -04:00
|
|
|
: read-only-slots ( values class -- slots )
|
|
|
|
all-slots
|
|
|
|
[ read-only>> [ value-info ] [ drop f ] if ] 2map
|
|
|
|
f prefix ;
|
|
|
|
|
2010-03-26 22:44:56 -04:00
|
|
|
: fold-<tuple-boa>? ( values class -- ? )
|
|
|
|
[ rest-slice [ dup [ literal?>> ] when ] all? ]
|
|
|
|
[ identity-tuple class<= not ]
|
|
|
|
bi* and ;
|
|
|
|
|
|
|
|
: (propagate-<tuple-boa>) ( values class -- info )
|
|
|
|
[ read-only-slots ] keep 2dup fold-<tuple-boa>?
|
|
|
|
[ [ rest-slice ] dip fold-<tuple-boa> ] [ <tuple-info> ] if ;
|
2008-07-25 03:07:45 -04:00
|
|
|
|
2009-04-30 01:27:35 -04:00
|
|
|
: propagate-<tuple-boa> ( #call -- infos )
|
2008-07-30 18:36:24 -04:00
|
|
|
in-d>> unclip-last
|
2010-03-26 22:44:56 -04:00
|
|
|
value-info literal>> first (propagate-<tuple-boa>) 1array ;
|
2008-07-25 03:07:45 -04:00
|
|
|
|
2008-07-30 04:38:10 -04:00
|
|
|
: read-only-slot? ( n class -- ? )
|
|
|
|
all-slots [ offset>> = ] with find nip
|
|
|
|
dup [ read-only>> ] when ;
|
|
|
|
|
|
|
|
: literal-info-slot ( slot object -- info/f )
|
2010-02-11 08:50:59 -05:00
|
|
|
{
|
2011-10-24 07:47:42 -04:00
|
|
|
[ class-of read-only-slot? ]
|
2010-02-11 08:50:59 -05:00
|
|
|
[ nip layout-up-to-date? ]
|
|
|
|
[ swap slot <literal-info> ]
|
|
|
|
} 2&& ;
|
2008-07-30 04:38:10 -04:00
|
|
|
|
|
|
|
: length-accessor? ( slot info -- ? )
|
|
|
|
[ 1 = ] [ length>> ] bi* and ;
|
2008-07-26 20:01:43 -04:00
|
|
|
|
2008-07-25 03:07:45 -04:00
|
|
|
: value-info-slot ( slot info -- info' )
|
2008-07-26 20:01:43 -04:00
|
|
|
{
|
|
|
|
{ [ over 0 = ] [ 2drop fixnum <class-info> ] }
|
2008-07-30 04:38:10 -04:00
|
|
|
{ [ dup literal?>> ] [ literal>> literal-info-slot ] }
|
2009-08-13 20:21:44 -04:00
|
|
|
[ [ 1 - ] [ slots>> ] bi* ?nth ]
|
2008-07-30 16:37:40 -04:00
|
|
|
} cond [ object-info ] unless* ;
|