2016-09-06 23:16:14 -04:00
|
|
|
USING: accessors compiler.cfg compiler.cfg.instructions
|
2016-08-29 06:07:47 -04:00
|
|
|
compiler.cfg.registers compiler.cfg.stacks.local
|
|
|
|
compiler.cfg.utilities compiler.test cpu.architecture kernel
|
|
|
|
kernel.private make math namespaces sequences.private slots.private
|
|
|
|
tools.test ;
|
2015-04-01 22:56:40 -04:00
|
|
|
QUALIFIED: sets
|
2014-12-30 20:56:00 -05:00
|
|
|
IN: compiler.cfg.stacks.local.tests
|
|
|
|
|
2015-03-31 19:34:56 -04:00
|
|
|
! end-local-analysis
|
|
|
|
{
|
2015-04-01 22:56:40 -04:00
|
|
|
HS{ }
|
2016-03-16 11:29:49 -04:00
|
|
|
HS{ }
|
2015-04-01 22:56:40 -04:00
|
|
|
HS{ }
|
2015-03-31 19:34:56 -04:00
|
|
|
} [
|
2015-04-07 09:05:34 -04:00
|
|
|
V{ } 137 insns>block
|
|
|
|
[ [ "eh" , end-local-analysis ] V{ } make drop ]
|
2016-09-07 19:58:30 -04:00
|
|
|
[ [ peeks>> ] [ replaces>> ] [ kills>> ] tri ] bi
|
2015-03-31 19:34:56 -04:00
|
|
|
] cfg-unit-test
|
|
|
|
|
2015-04-01 22:56:40 -04:00
|
|
|
{
|
2016-03-16 11:29:49 -04:00
|
|
|
HS{ D: 3 }
|
2015-04-01 22:56:40 -04:00
|
|
|
} [
|
2015-04-07 09:05:34 -04:00
|
|
|
V{ } 137 insns>block
|
2015-08-13 18:23:10 -04:00
|
|
|
[ [ 3 D: 3 replace-loc "eh" , end-local-analysis ] V{ } make drop ]
|
2016-09-07 19:58:30 -04:00
|
|
|
[ replaces>> ] bi
|
2015-04-07 09:05:34 -04:00
|
|
|
] cfg-unit-test
|
2015-04-01 22:56:40 -04:00
|
|
|
|
2016-09-06 23:16:14 -04:00
|
|
|
! local-loc>global
|
|
|
|
{ D: 6 } [
|
2016-09-07 19:58:30 -04:00
|
|
|
D: 3 3 0 0 0 height-state boa
|
|
|
|
local-loc>global
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
{
|
|
|
|
D: 4
|
|
|
|
R: 5
|
|
|
|
} [
|
|
|
|
3 4 0 0 height-state boa
|
|
|
|
[ D: 1 swap local-loc>global ]
|
|
|
|
[ R: 1 swap local-loc>global ] bi
|
2016-09-06 23:16:14 -04:00
|
|
|
] unit-test
|
|
|
|
|
2016-08-01 15:51:40 -04:00
|
|
|
! kill-locations
|
|
|
|
{
|
|
|
|
{ 10 11 12 13 14 15 }
|
|
|
|
{ }
|
|
|
|
{ }
|
|
|
|
{ -6 -5 -4 -3 }
|
2016-09-06 16:46:10 -04:00
|
|
|
{ -7 -6 -5 }
|
2016-08-01 15:51:40 -04:00
|
|
|
} [
|
2016-09-06 16:46:10 -04:00
|
|
|
-10 -6 kill-locations
|
2016-08-01 15:51:40 -04:00
|
|
|
0 0 kill-locations
|
2016-09-06 16:46:10 -04:00
|
|
|
2 4 kill-locations
|
|
|
|
6 -4 kill-locations
|
|
|
|
7 -3 kill-locations
|
2016-08-01 15:51:40 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! loc>vreg
|
|
|
|
{ 1 } [
|
|
|
|
D: 0 loc>vreg
|
|
|
|
] cfg-unit-test
|
|
|
|
|
|
|
|
! replace-loc
|
|
|
|
{ 80 } [
|
|
|
|
80 D: 77 replace-loc
|
|
|
|
D: 77 peek-loc
|
|
|
|
] cfg-unit-test
|
|
|
|
|
|
|
|
! stack-changes
|
|
|
|
{
|
|
|
|
{
|
|
|
|
T{ ##copy { dst 1 } { src 25 } { rep any-rep } }
|
|
|
|
T{ ##copy { dst 2 } { src 26 } { rep any-rep } }
|
|
|
|
}
|
|
|
|
} [
|
|
|
|
{ { D: 0 25 } { R: 0 26 } } replaces>copy-insns
|
|
|
|
] cfg-unit-test
|
|
|
|
|
2015-04-01 22:56:40 -04:00
|
|
|
! remove-redundant-replaces
|
|
|
|
{
|
|
|
|
H{ { T{ ds-loc { n 3 } } 7 } }
|
|
|
|
} [
|
2015-08-13 18:23:10 -04:00
|
|
|
D: 0 loc>vreg D: 2 loc>vreg 2drop
|
|
|
|
2 D: 2 replace-loc 7 D: 3 replace-loc
|
2015-04-07 09:05:34 -04:00
|
|
|
replaces get remove-redundant-replaces
|
2015-04-01 22:56:40 -04:00
|
|
|
] cfg-unit-test
|
|
|
|
|
2016-09-05 06:12:01 -04:00
|
|
|
! emit-insns
|
2015-04-01 22:56:40 -04:00
|
|
|
{
|
2015-04-08 02:08:17 -04:00
|
|
|
V{
|
|
|
|
T{ ##copy { dst 1 } { src 3 } { rep any-rep } }
|
|
|
|
"eh"
|
|
|
|
}
|
2015-04-01 22:56:40 -04:00
|
|
|
} [
|
2015-08-13 18:23:10 -04:00
|
|
|
3 D: 0 replace-loc [
|
2015-08-06 18:05:12 -04:00
|
|
|
"eh" ,
|
2016-09-05 06:12:01 -04:00
|
|
|
replaces get height-state get emit-insns
|
2015-04-01 22:56:40 -04:00
|
|
|
] V{ } make
|
|
|
|
] cfg-unit-test
|
|
|
|
|
2015-04-29 11:03:50 -04:00
|
|
|
! compute-local-kill-set
|
2016-09-06 09:44:07 -04:00
|
|
|
{ HS{ } } [
|
|
|
|
0 0 0 0 height-state boa compute-local-kill-set
|
2015-04-29 11:03:50 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-08-13 18:23:10 -04:00
|
|
|
{ HS{ R: -4 } } [
|
2016-09-06 09:44:07 -04:00
|
|
|
0 4 0 -1 height-state boa compute-local-kill-set
|
2015-04-29 11:03:50 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-08-13 18:23:10 -04:00
|
|
|
{ HS{ D: -1 D: -2 } } [
|
2016-09-06 09:44:07 -04:00
|
|
|
2 0 -2 0 height-state boa compute-local-kill-set
|
|
|
|
] unit-test
|
2015-04-29 11:03:50 -04:00
|
|
|
|
2016-09-06 09:44:07 -04:00
|
|
|
! global-loc>local
|
2015-08-13 18:23:10 -04:00
|
|
|
{ D: 2 } [
|
2016-09-06 09:44:07 -04:00
|
|
|
D: 3 1 0 0 0 height-state boa global-loc>local
|
2015-04-07 09:05:34 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-03-31 19:34:56 -04:00
|
|
|
! height-state
|
2015-03-15 19:14:41 -04:00
|
|
|
{
|
2016-09-06 09:44:07 -04:00
|
|
|
T{ height-state f 0 0 3 0 }
|
2015-03-15 19:14:41 -04:00
|
|
|
} [
|
2015-08-13 18:23:10 -04:00
|
|
|
D: 3 inc-stack height-state get
|
2015-03-26 18:46:37 -04:00
|
|
|
] cfg-unit-test
|
2015-03-15 19:14:41 -04:00
|
|
|
|
|
|
|
{
|
2016-09-06 09:44:07 -04:00
|
|
|
T{ height-state f 2 0 3 0 }
|
2015-03-15 19:14:41 -04:00
|
|
|
} [
|
2016-09-06 09:44:07 -04:00
|
|
|
2 0 0 0 height-state boa height-state set
|
2015-08-13 18:23:10 -04:00
|
|
|
D: 3 inc-stack height-state get
|
2015-03-26 18:46:37 -04:00
|
|
|
] cfg-unit-test
|
2014-12-30 20:56:00 -05:00
|
|
|
|
|
|
|
{
|
2015-08-13 18:23:10 -04:00
|
|
|
{ T{ ##inc { loc D: 4 } } T{ ##inc { loc R: -2 } } }
|
2014-12-30 20:56:00 -05:00
|
|
|
} [
|
2016-09-06 09:44:07 -04:00
|
|
|
0 0 4 -2 height-state boa height-state>insns
|
2014-12-30 20:56:00 -05:00
|
|
|
] unit-test
|
|
|
|
|
2015-08-13 18:23:10 -04:00
|
|
|
{ H{ { D: -1 40 } } } [
|
|
|
|
D: 1 inc-stack 40 D: 0 replace-loc replaces get
|
2015-03-26 18:46:37 -04:00
|
|
|
] cfg-unit-test
|
2016-03-16 11:29:49 -04:00
|
|
|
|
|
|
|
! Compiling these words used to make the compiler hang due to a bug in
|
|
|
|
! end-local-analysis. So the test is just to compile them and if it
|
|
|
|
! doesn't hang, the bug is fixed! See #1507
|
|
|
|
: my-new-key4 ( a i j -- i/j )
|
|
|
|
2over
|
|
|
|
slot
|
2018-06-19 20:15:05 -04:00
|
|
|
tuck
|
2016-03-16 11:29:49 -04:00
|
|
|
! a i el j el
|
|
|
|
[
|
|
|
|
! a i el j
|
|
|
|
swap
|
|
|
|
! a i j el
|
|
|
|
77 eq?
|
|
|
|
[
|
|
|
|
rot drop and
|
|
|
|
]
|
|
|
|
[
|
|
|
|
! a i j
|
|
|
|
over or my-new-key4
|
|
|
|
] if
|
|
|
|
]
|
|
|
|
[
|
|
|
|
! a i el j
|
|
|
|
2drop t
|
|
|
|
! a i t
|
|
|
|
my-new-key4
|
|
|
|
] if ; inline recursive
|
|
|
|
|
|
|
|
: badword ( y -- )
|
|
|
|
0 swap dup
|
|
|
|
{ integer object } declare
|
|
|
|
[
|
|
|
|
{ array-capacity object } declare nip
|
|
|
|
1234 1234 pick
|
|
|
|
f
|
|
|
|
my-new-key4
|
|
|
|
set-slot
|
|
|
|
]
|
|
|
|
curry (each-integer) ;
|