2005-02-14 21:58:07 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-05-09 02:34:15 -04:00
|
|
|
IN: compiler-backend
|
2005-12-02 02:25:44 -05:00
|
|
|
USING: alien arrays assembler compiler inference kernel
|
2005-05-09 02:34:15 -04:00
|
|
|
kernel-internals lists math memory namespaces sequences words ;
|
2005-01-08 16:43:18 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
! Not used on x86
|
|
|
|
M: %prologue generate-node drop ;
|
2005-01-08 16:43:18 -05:00
|
|
|
|
2005-12-10 01:02:13 -05:00
|
|
|
: (call-label)
|
|
|
|
label dup postpone-word
|
|
|
|
dup primitive? [ address-operand ] when ;
|
2005-05-07 22:39:00 -04:00
|
|
|
|
|
|
|
M: %call generate-node ( vop -- )
|
2005-12-10 01:02:13 -05:00
|
|
|
drop (call-label) CALL ;
|
2005-05-07 22:39:00 -04:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %call-label generate-node ( vop -- )
|
2005-12-04 19:56:42 -05:00
|
|
|
drop label CALL ;
|
2005-03-21 20:53:26 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %jump generate-node ( vop -- )
|
2005-12-10 01:02:13 -05:00
|
|
|
drop (call-label) JMP ;
|
2005-03-19 00:30:49 -05:00
|
|
|
|
2005-05-24 01:26:45 -04:00
|
|
|
M: %jump-label generate-node ( vop -- )
|
2005-12-04 19:56:42 -05:00
|
|
|
drop label JMP ;
|
2005-05-24 01:26:45 -04:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %jump-t generate-node ( vop -- )
|
2005-12-04 19:56:42 -05:00
|
|
|
drop
|
|
|
|
! Compare input with f
|
|
|
|
0 input-operand f address CMP
|
|
|
|
! If not equal, jump
|
|
|
|
label JNE ;
|
2005-05-06 18:33:40 -04:00
|
|
|
|
|
|
|
M: %return-to generate-node ( vop -- )
|
2005-12-06 22:39:05 -05:00
|
|
|
drop label address-operand PUSH ;
|
2005-05-06 18:33:40 -04:00
|
|
|
|
|
|
|
M: %return generate-node ( vop -- )
|
|
|
|
drop RET ;
|
|
|
|
|
2005-05-06 19:49:07 -04:00
|
|
|
M: %dispatch generate-node ( vop -- )
|
2005-01-08 16:43:18 -05:00
|
|
|
#! Compile a piece of code that jumps to an offset in a
|
|
|
|
#! jump table indexed by the fixnum at the top of the stack.
|
|
|
|
#! The jump table must immediately follow this macro.
|
2005-12-04 19:56:42 -05:00
|
|
|
drop
|
2005-12-07 03:37:05 -05:00
|
|
|
<label> "end" set
|
2005-12-04 22:55:02 -05:00
|
|
|
! Untag and multiply to get a jump table offset
|
|
|
|
0 input-operand fixnum>slot@
|
2005-12-07 03:37:05 -05:00
|
|
|
! Add to jump table base. We use a temporary register since
|
|
|
|
! on AMD4 we have to load a 64-bit immediate. On x86, this
|
|
|
|
! is redundant.
|
|
|
|
0 scratch HEX: ffffffff MOV "end" get absolute-cell
|
|
|
|
0 input-operand 0 scratch ADD
|
2005-05-08 00:21:00 -04:00
|
|
|
! Jump to jump table entry
|
2005-12-04 19:56:42 -05:00
|
|
|
0 input-operand 1array JMP
|
2005-05-08 00:21:00 -04:00
|
|
|
! Align for better performance
|
2005-01-08 16:43:18 -05:00
|
|
|
compile-aligned
|
2005-05-08 00:21:00 -04:00
|
|
|
! Fix up jump table pointer
|
2005-12-04 19:56:42 -05:00
|
|
|
"end" get save-xt ;
|
2005-05-06 19:49:07 -04:00
|
|
|
|
|
|
|
M: %type generate-node ( vop -- )
|
2005-09-10 02:56:33 -04:00
|
|
|
#! Intrinstic version of type primitive.
|
2005-12-04 19:56:42 -05:00
|
|
|
drop
|
2005-09-10 02:56:33 -04:00
|
|
|
<label> "header" set
|
2005-05-06 19:49:07 -04:00
|
|
|
<label> "f" set
|
|
|
|
<label> "end" set
|
|
|
|
! Make a copy
|
2005-12-04 22:06:12 -05:00
|
|
|
0 scratch 0 output-operand MOV
|
2005-05-06 19:49:07 -04:00
|
|
|
! Get the tag
|
2005-12-04 19:56:42 -05:00
|
|
|
0 output-operand tag-mask AND
|
2005-05-06 19:49:07 -04:00
|
|
|
! Compare with object tag number (3).
|
2005-12-04 19:56:42 -05:00
|
|
|
0 output-operand object-tag CMP
|
2005-05-08 00:21:00 -04:00
|
|
|
! Jump if the object doesn't store type info in its header
|
2005-09-10 02:56:33 -04:00
|
|
|
"header" get JE
|
2005-05-06 19:49:07 -04:00
|
|
|
! It doesn't store type info in its header
|
2005-12-04 19:56:42 -05:00
|
|
|
0 output-operand tag-bits SHL
|
2005-09-10 02:56:33 -04:00
|
|
|
"end" get JMP
|
|
|
|
"header" get save-xt
|
2005-05-06 19:49:07 -04:00
|
|
|
! It does store type info in its header
|
|
|
|
! Is the pointer itself equal to 3? Then its F_TYPE (9).
|
2005-12-04 22:06:12 -05:00
|
|
|
0 scratch object-tag CMP
|
2005-05-07 22:39:00 -04:00
|
|
|
"f" get JE
|
2005-05-06 19:49:07 -04:00
|
|
|
! The pointer is not equal to 3. Load the object header.
|
2005-12-04 19:56:42 -05:00
|
|
|
0 output-operand ECX object-tag neg 2array MOV
|
2005-09-10 02:56:33 -04:00
|
|
|
! Mask off header tag, making a fixnum.
|
2005-12-04 19:56:42 -05:00
|
|
|
0 output-operand object-tag XOR
|
2005-05-07 22:39:00 -04:00
|
|
|
"end" get JMP
|
2005-05-06 19:49:07 -04:00
|
|
|
"f" get save-xt
|
|
|
|
! The pointer is equal to 3. Load F_TYPE (9).
|
2005-12-04 19:56:42 -05:00
|
|
|
0 output-operand f type tag-bits shift MOV
|
2005-05-07 22:39:00 -04:00
|
|
|
"end" get save-xt ;
|
2005-08-15 15:34:00 -04:00
|
|
|
|
|
|
|
M: %tag generate-node ( vop -- )
|
2005-12-04 19:56:42 -05:00
|
|
|
drop
|
|
|
|
0 input-operand tag-mask AND
|
|
|
|
0 input-operand tag-bits SHL ;
|
2005-09-10 02:56:33 -04:00
|
|
|
|
|
|
|
M: %untag generate-node ( vop -- )
|
2005-12-04 19:56:42 -05:00
|
|
|
drop
|
|
|
|
0 output-operand tag-mask bitnot AND ;
|