1 USING: arrays compiler.cfg.gc-checks
2 compiler.cfg.gc-checks.private compiler.cfg.debugger
3 compiler.cfg.registers compiler.cfg.instructions compiler.cfg
4 compiler.cfg.predecessors compiler.cfg.rpo cpu.architecture
5 tools.test kernel vectors namespaces accessors sequences alien
6 memory classes make combinators.short-circuit byte-arrays ;
7 IN: compiler.cfg.gc-checks.tests
9 : test-gc-checks ( -- )
10 H{ } clone representations set
11 cfg new 0 get >>entry cfg set ;
15 T{ ##replace f 0 D 1 }
19 T{ ##box-alien f 0 1 }
24 [ ] [ test-gc-checks ] unit-test
26 [ t ] [ cfg get blocks-with-gc 1 get 1array sequence= ] unit-test
28 [ ] [ 1 get allocation-size 123 <alien> size assert= ] unit-test
30 2 \ vreg-counter set-global
34 T{ ##load-tagged f 3 0 }
35 T{ ##replace f 3 D 0 }
36 T{ ##replace f 3 R 3 }
38 ] [ [ { D 0 R 3 } wipe-locs ] V{ } make ] unit-test
40 : gc-check? ( bb -- ? )
44 [ first ##check-nursery-branch? ]
47 [ t ] [ V{ } 100 <gc-check> gc-check? ] unit-test
49 4 \ vreg-counter set-global
53 T{ ##load-tagged f 5 0 }
54 T{ ##replace f 5 D 0 }
55 T{ ##replace f 5 R 3 }
56 T{ ##call-gc f { 0 1 2 } }
61 { D 0 R 3 } { 0 1 2 } <gc-call> instructions>>
64 30 \ vreg-counter set-global
91 [ ] [ test-gc-checks ] unit-test
93 [ ] [ cfg get needs-predecessors drop ] unit-test
95 [ ] [ { D 1 R 2 } { 10 20 } V{ } 31337 3 get (insert-gc-check) ] unit-test
97 [ t ] [ 1 get successors>> first gc-check? ] unit-test
99 [ t ] [ 2 get successors>> first gc-check? ] unit-test
101 [ t ] [ 3 get predecessors>> first gc-check? ] unit-test
103 30 \ vreg-counter set-global
117 T{ ##allot f 1 64 byte-array }
126 T{ ##replace f 2 D 1 }
141 [ ] [ test-gc-checks ] unit-test
145 } representations set
147 [ ] [ cfg get insert-gc-checks drop ] unit-test
149 [ 2 ] [ 2 get predecessors>> length ] unit-test
151 [ t ] [ 1 get successors>> first gc-check? ] unit-test
153 [ 64 ] [ 1 get successors>> first instructions>> first size>> ] unit-test
155 [ t ] [ 2 get predecessors>> first gc-check? ] unit-test
159 T{ ##load-tagged f 31 0 }
160 T{ ##replace f 31 D 0 }
161 T{ ##replace f 31 D 1 }
162 T{ ##replace f 31 D 2 }
163 T{ ##call-gc f { 2 } }
166 ] [ 2 get predecessors>> second instructions>> ] unit-test
168 ! Don't forget to invalidate RPO after inserting basic blocks!
169 [ 8 ] [ cfg get reverse-post-order length ] unit-test
171 ! Do the right thing with ##phi instructions
177 T{ ##load-reference f 1 "hi" }
182 T{ ##load-reference f 2 "bye" }
187 T{ ##phi f 3 H{ { 1 1 } { 2 2 } } }
188 T{ ##allot f 1 64 byte-array }
196 [ ] [ test-gc-checks ] unit-test
202 } representations set
204 [ ] [ cfg get insert-gc-checks drop ] unit-test
205 [ t ] [ 2 get successors>> first instructions>> first ##phi? ] unit-test
206 [ 2 ] [ 3 get instructions>> length ] unit-test