2009-07-23 21:54:38 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-10-20 21:40:15 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: kernel math math.order sequences accessors arrays
|
|
|
|
byte-arrays layouts classes.tuple.private fry locals
|
|
|
|
compiler.tree.propagation.info compiler.cfg.hats
|
2008-10-21 04:20:48 -04:00
|
|
|
compiler.cfg.instructions compiler.cfg.stacks
|
2009-07-23 21:54:38 -04:00
|
|
|
compiler.cfg.utilities compiler.cfg.builder.blocks ;
|
2008-10-20 21:40:15 -04:00
|
|
|
IN: compiler.cfg.intrinsics.allot
|
|
|
|
|
|
|
|
: ##set-slots ( regs obj class -- )
|
2009-08-13 20:21:44 -04:00
|
|
|
'[ _ swap 1 + _ tag-number ##set-slot-imm ] each-index ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
|
|
|
: emit-simple-allot ( node -- )
|
|
|
|
[ in-d>> length ] [ node-output-infos first class>> ] bi
|
2009-08-13 20:21:44 -04:00
|
|
|
[ drop ds-load ] [ [ 1 + cells ] dip ^^allot ] [ nip ] 2tri
|
2008-11-02 02:50:48 -05:00
|
|
|
[ ##set-slots ] [ [ drop ] [ ds-push ] [ drop ] tri* ] 3bi ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
|
|
|
: tuple-slot-regs ( layout -- vregs )
|
2008-11-05 23:20:29 -05:00
|
|
|
[ second ds-load ] [ ^^load-literal ] bi prefix ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
2009-10-01 19:07:50 -04:00
|
|
|
: ^^allot-tuple ( n -- dst )
|
|
|
|
2 + cells tuple ^^allot ;
|
|
|
|
|
2008-10-22 00:17:32 -04:00
|
|
|
: emit-<tuple-boa> ( node -- )
|
2009-05-25 17:38:33 -04:00
|
|
|
dup node-input-infos last literal>>
|
2008-11-05 23:20:29 -05:00
|
|
|
dup array? [
|
2008-10-22 00:17:32 -04:00
|
|
|
nip
|
|
|
|
ds-drop
|
2008-11-05 23:20:29 -05:00
|
|
|
[ tuple-slot-regs ] [ second ^^allot-tuple ] bi
|
2008-10-22 00:17:32 -04:00
|
|
|
[ tuple ##set-slots ] [ ds-push drop ] 2bi
|
|
|
|
] [ drop emit-primitive ] if ;
|
|
|
|
|
2009-04-30 01:27:35 -04:00
|
|
|
: store-length ( len reg class -- )
|
|
|
|
[ [ ^^load-literal ] dip 1 ] dip tag-number ##set-slot-imm ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
2009-04-30 01:27:35 -04:00
|
|
|
:: store-initial-element ( len reg elt class -- )
|
|
|
|
len [ [ elt reg ] dip 2 + class tag-number ##set-slot-imm ] each ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
|
|
|
: expand-<array>? ( obj -- ? )
|
|
|
|
dup integer? [ 0 8 between? ] [ drop f ] if ;
|
|
|
|
|
2009-10-01 19:07:50 -04:00
|
|
|
: ^^allot-array ( n -- dst )
|
|
|
|
2 + cells array ^^allot ;
|
|
|
|
|
2008-10-20 21:40:15 -04:00
|
|
|
:: emit-<array> ( node -- )
|
|
|
|
[let | len [ node node-input-infos first literal>> ] |
|
|
|
|
len expand-<array>? [
|
2008-10-21 04:20:48 -04:00
|
|
|
[let | elt [ ds-pop ]
|
2008-10-20 21:40:15 -04:00
|
|
|
reg [ len ^^allot-array ] |
|
2008-10-21 04:20:48 -04:00
|
|
|
ds-drop
|
2009-04-30 01:27:35 -04:00
|
|
|
len reg array store-length
|
|
|
|
len reg elt array store-initial-element
|
2008-10-21 04:20:48 -04:00
|
|
|
reg ds-push
|
2008-10-20 21:40:15 -04:00
|
|
|
]
|
|
|
|
] [ node emit-primitive ] if
|
|
|
|
] ;
|
|
|
|
|
2009-10-05 06:27:49 -04:00
|
|
|
: expand-(byte-array)? ( obj -- ? )
|
|
|
|
dup integer? [ 0 1024 between? ] [ drop f ] if ;
|
|
|
|
|
2008-10-20 21:40:15 -04:00
|
|
|
: expand-<byte-array>? ( obj -- ? )
|
|
|
|
dup integer? [ 0 32 between? ] [ drop f ] if ;
|
|
|
|
|
|
|
|
: bytes>cells ( m -- n ) cell align cell /i ;
|
|
|
|
|
2009-10-01 19:07:50 -04:00
|
|
|
: ^^allot-byte-array ( n -- dst )
|
|
|
|
2 cells + byte-array ^^allot ;
|
|
|
|
|
2008-12-05 08:28:52 -05:00
|
|
|
: emit-allot-byte-array ( len -- dst )
|
|
|
|
ds-drop
|
|
|
|
dup ^^allot-byte-array
|
2009-04-30 01:27:35 -04:00
|
|
|
[ byte-array store-length ] [ ds-push ] [ ] tri ;
|
2008-12-05 08:28:52 -05:00
|
|
|
|
|
|
|
: emit-(byte-array) ( node -- )
|
2009-10-05 06:27:49 -04:00
|
|
|
dup node-input-infos first literal>> dup expand-(byte-array)?
|
2008-12-05 08:28:52 -05:00
|
|
|
[ nip emit-allot-byte-array drop ] [ drop emit-primitive ] if ;
|
|
|
|
|
2009-04-30 01:27:35 -04:00
|
|
|
:: emit-<byte-array> ( node -- )
|
|
|
|
node node-input-infos first literal>> dup expand-<byte-array>? [
|
|
|
|
:> len
|
|
|
|
0 ^^load-literal :> elt
|
|
|
|
len emit-allot-byte-array :> reg
|
|
|
|
len reg elt byte-array store-initial-element
|
|
|
|
] [ drop node emit-primitive ] if ;
|