2005-03-14 13:20:57 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: compiler
|
2005-03-17 23:29:08 -05:00
|
|
|
USING: assembler inference kernel math words ;
|
2005-03-14 13:20:57 -05:00
|
|
|
|
2005-03-15 18:18:33 -05:00
|
|
|
! At the start of each word that calls a subroutine, we store
|
|
|
|
! the link register in r0, then push r0 on the C stack.
|
|
|
|
#prologue [
|
|
|
|
drop
|
|
|
|
0 MFLR
|
|
|
|
0 1 -4 STWU
|
|
|
|
] "generator" set-word-prop
|
|
|
|
|
|
|
|
! At the end of each word that calls a subroutine, we store
|
|
|
|
! the previous link register value in r0 by popping it off the
|
|
|
|
! stack, set the link register to the contents of r0, and jump
|
|
|
|
! to the link register.
|
2005-03-17 23:29:08 -05:00
|
|
|
: compile-epilogue
|
2005-03-15 18:18:33 -05:00
|
|
|
0 1 0 LWZ
|
|
|
|
1 1 4 ADDI
|
2005-03-17 23:29:08 -05:00
|
|
|
0 MTLR ;
|
|
|
|
|
|
|
|
#epilogue [ drop compile-epilogue ] "generator" set-word-prop
|
2005-03-15 18:18:33 -05:00
|
|
|
|
2005-03-19 00:30:49 -05:00
|
|
|
! #return-to [
|
|
|
|
!
|
|
|
|
! ] "generator" set-word-prop
|
|
|
|
|
2005-03-14 13:20:57 -05:00
|
|
|
#return [ drop BLR ] "generator" set-word-prop
|
2005-03-15 22:23:52 -05:00
|
|
|
|
2005-03-17 23:29:08 -05:00
|
|
|
! Far calls are made to addresses already known when the
|
|
|
|
! IR node is being generated. No forward reference far
|
|
|
|
! calls are possible.
|
|
|
|
: compile-call-far ( n -- )
|
|
|
|
19 LOAD
|
|
|
|
19 MTLR
|
|
|
|
BLRL ;
|
|
|
|
|
|
|
|
: compile-call-label ( label -- )
|
|
|
|
dup primitive? [
|
|
|
|
word-xt compile-call-far
|
|
|
|
] [
|
|
|
|
0 BL relative-24
|
|
|
|
] ifte ;
|
|
|
|
|
2005-03-19 00:30:49 -05:00
|
|
|
: compile-jump-far ( n -- )
|
|
|
|
19 LOAD
|
|
|
|
19 MTCTR
|
|
|
|
BCTR ;
|
|
|
|
|
2005-03-17 23:29:08 -05:00
|
|
|
: compile-jump-label ( label -- )
|
2005-03-19 00:30:49 -05:00
|
|
|
dup primitive? [
|
|
|
|
word-xt compile-jump-far
|
|
|
|
] [
|
|
|
|
0 B relative-24
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
#jump [
|
|
|
|
dup postpone-word compile-epilogue compile-jump-label
|
|
|
|
] "generator" set-word-prop
|
2005-03-17 23:29:08 -05:00
|
|
|
|
|
|
|
: compile-jump-t ( label -- )
|
|
|
|
POP-DS
|
|
|
|
0 18 3 CMPI
|
|
|
|
0 BNE relative-14 ;
|
2005-03-19 00:30:49 -05:00
|
|
|
|
|
|
|
: compile-jump-f ( label -- )
|
|
|
|
POP-DS
|
|
|
|
0 18 3 CMPI
|
|
|
|
0 BEQ relative-14 ;
|