1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors namespaces math layouts sequences locals
4 combinators compiler.vops compiler.vops.builder
6 IN: compiler.cfg.elaboration
8 ! This pass must run before conversion to machine IR to ensure
11 GENERIC: elaborate* ( insn -- )
14 tag-bits get cell log2 - ;
16 :: compute-slot-known-tag ( insn -- addr )
17 { $1 $2 $3 $4 $5 } temps
19 $1 slot-shift %iconst emit ! load shift offset
20 $2 insn slot>> $1 %shr emit ! shift slot by shift offset
21 $3 insn tag>> %iconst emit ! load tag number
23 $5 insn obj>> $4 %iadd emit ! compute slot offset
27 :: compute-slot-any-tag ( insn -- addr )
30 $1 insn obj>> emit-untag ! untag object
31 $2 slot-shift %iconst emit ! load shift offset
32 $3 insn slot>> $2 %shr emit ! shift slot by shift offset
33 $4 $1 $3 %iadd emit ! compute slot offset
37 : compute-slot ( insn -- addr )
38 dup tag>> [ compute-slot-known-tag ] [ compute-slot-any-tag ] if ;
41 [ out>> ] [ compute-slot ] bi %load emit ;
43 M: %%set-slot elaborate*
44 [ in>> ] [ compute-slot ] bi %store emit ;
46 M: object elaborate* , ;
48 : elaboration ( insns -- insns )
49 [ [ elaborate* ] each ] { } make ;