1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors classes.algebra classes.builtin
4 combinators.short-circuit compiler.cfg.builder.blocks
5 compiler.cfg.hats compiler.cfg.instructions
6 compiler.cfg.registers compiler.cfg.stacks
7 compiler.tree.propagation.info cpu.architecture kernel layouts
8 math namespaces sequences ;
9 IN: compiler.cfg.intrinsics.slots
11 : class-tag ( class -- tag/f )
12 builtins get [ class<= ] with find drop ;
14 : value-tag ( info -- n/f )
17 : slot-indexing ( slot tag -- slot scale tag )
19 [ [ cell log2 ] dip ] [ [ ^^offset>slot ] dip ^^sub-imm 0 0 ] if ;
21 : (emit-slot) ( infos -- dst )
22 [ 2inputs ] [ first value-tag ] bi*
23 slot-indexing ^^slot ;
25 : (emit-slot-imm) ( infos -- dst )
28 [ [ second literal>> ] [ first value-tag ] bi ] bi*
31 : immediate-slot-offset? ( object -- ? )
32 { [ fixnum? ] [ cell * immediate-arithmetic? ] } 1&& ;
34 : emit-slot ( block node -- block' )
38 dup second literal>> immediate-slot-offset?
39 [ (emit-slot-imm) ] [ (emit-slot) ] if
41 ] [ drop emit-primitive ] if ;
43 :: (emit-set-slot-imm) ( write-barrier? tag slot -- )
46 2inputs :> ( src obj )
48 src obj slot tag ##set-slot-imm,
51 [ obj slot tag next-vreg next-vreg ##write-barrier-imm, ] when ;
53 :: (emit-set-slot) ( write-barrier? tag -- )
54 3inputs :> ( src obj slot )
56 slot tag slot-indexing :> ( slot scale tag )
58 src obj slot scale tag ##set-slot,
61 [ obj slot scale tag next-vreg next-vreg ##write-barrier, ] when ;
63 : node>set-slot-data ( #call -- write-barrier? tag literal )
64 node-input-infos first3
65 [ class>> immediate class<= not ] [ value-tag ] [ literal>> ] tri* ;
67 : emit-intrinsic-set-slot ( write-barrier? tag index-info -- )
68 dup immediate-slot-offset? [
70 ] [ drop (emit-set-slot) ] if ;
72 : emit-set-slot ( block #call -- block' )
73 dup node>set-slot-data over [
74 emit-intrinsic-set-slot drop
75 ] [ 3drop emit-primitive ] if ;