1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: layouts namespaces kernel accessors sequences
4 classes.algebra locals compiler.tree.propagation.info
5 compiler.cfg.stacks compiler.cfg.hats compiler.cfg.registers
6 compiler.cfg.instructions compiler.cfg.utilities
7 compiler.cfg.builder.blocks compiler.constants ;
8 IN: compiler.cfg.intrinsics.slots
10 : value-tag ( info -- n ) class>> class-tag ; inline
12 : ^^tag-offset>slot ( slot tag -- vreg' )
13 [ ^^offset>slot ] dip ^^sub-imm ;
15 : (emit-slot) ( infos -- dst )
16 [ 2inputs ] [ first value-tag ] bi*
17 ^^tag-offset>slot ^^slot ;
19 : (emit-slot-imm) ( infos -- dst )
22 [ [ second literal>> ] [ first value-tag ] bi ] bi*
25 : emit-slot ( node -- )
29 dup second value-info-small-fixnum?
30 [ (emit-slot-imm) ] [ (emit-slot) ] if
32 ] [ drop emit-primitive ] if ;
34 : emit-write-barrier? ( infos -- ? )
35 first class>> immediate class<= not ;
37 :: (emit-set-slot) ( infos -- )
38 3inputs :> slot :> obj :> src
40 slot infos second value-tag ^^tag-offset>slot :> slot
42 src obj slot ##set-slot
44 infos emit-write-barrier?
45 [ obj slot next-vreg next-vreg ##write-barrier ] when ;
47 :: (emit-set-slot-imm) ( infos -- )
52 infos third literal>> :> slot
53 infos second value-tag :> tag
55 src obj slot tag ##set-slot-imm
57 infos emit-write-barrier?
58 [ obj slot tag slot-offset next-vreg next-vreg ##write-barrier-imm ] when ;
60 : emit-set-slot ( node -- )
62 dup second value-tag [
64 dup third value-info-small-fixnum?
65 [ (emit-set-slot-imm) ] [ (emit-set-slot) ] if
66 ] [ drop emit-primitive ] if ;
68 : emit-string-nth ( -- )
69 2inputs swap ^^untag-fixnum ^^string-nth ^^tag-fixnum ds-push ;
71 : emit-set-string-nth-fast ( -- )
72 3inputs [ ^^untag-fixnum ] [ ^^untag-fixnum ] [ ] tri*
73 swap next-vreg ##set-string-nth-fast ;