2005-02-14 21:58:07 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-04-24 00:27:07 -04:00
|
|
|
IN: assembler
|
|
|
|
USING: alien compiler inference kernel kernel-internals lists
|
2005-05-06 18:33:40 -04:00
|
|
|
math memory namespaces sequences words ;
|
2005-01-08 16:43:18 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
GENERIC: v>operand
|
|
|
|
M: integer v>operand ;
|
|
|
|
M: vreg v>operand vreg-n { EAX ECX EDX } nth ;
|
2005-03-15 18:18:33 -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-03-15 22:23:52 -05:00
|
|
|
: compile-call-label ( label -- ) 0 CALL relative ;
|
|
|
|
: compile-jump-label ( label -- ) 0 JMP relative ;
|
2005-01-08 16:43:18 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %call-label generate-node ( vop -- )
|
|
|
|
vop-label compile-call-label ;
|
2005-03-21 20:53:26 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %jump generate-node ( vop -- )
|
|
|
|
vop-label dup postpone-word compile-jump-label ;
|
2005-03-19 00:30:49 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %jump-f generate-node ( vop -- )
|
|
|
|
dup vop-source v>operand f address CMP 0 JNE
|
|
|
|
vop-label relative ;
|
2005-02-22 23:07:47 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %jump-t generate-node ( vop -- )
|
|
|
|
dup vop-source v>operand f address CMP 0 JE
|
|
|
|
vop-label relative ;
|
|
|
|
|
|
|
|
M: %return-to generate-node ( vop -- )
|
|
|
|
0 PUSH vop-label absolute ;
|
|
|
|
|
|
|
|
M: %return generate-node ( vop -- )
|
|
|
|
drop RET ;
|
|
|
|
|
|
|
|
M: %untag generate-node ( vop -- )
|
|
|
|
vop-source v>operand BIN: 111 bitnot AND ;
|
|
|
|
|
|
|
|
M: %slot generate-node ( vop -- )
|
|
|
|
! the untagged object is in vop-dest, the tagged slot number
|
|
|
|
! is in vop-literal.
|
|
|
|
dup vop-literal v>operand swap vop-dest v>operand
|
|
|
|
! turn tagged fixnum slot # into an offset, multiple of 4
|
|
|
|
over 1 SHR
|
|
|
|
! compute slot address in vop-dest
|
|
|
|
dupd ADD
|
|
|
|
! load slot value in vop-dest
|
|
|
|
dup unit MOV ;
|
|
|
|
|
|
|
|
M: %fast-slot generate-node ( vop -- )
|
|
|
|
! the tagged object is in vop-dest, the pointer offset is
|
|
|
|
! in vop-literal. the offset already takes the type tag
|
|
|
|
! into account, so its just one instruction to load.
|
|
|
|
dup vop-literal swap vop-dest v>operand tuck >r 2list r>
|
|
|
|
swap MOV ;
|
2005-02-22 23:07:47 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %set-slot generate-node ( vop -- )
|
|
|
|
! the untagged object is in vop-dest, the new value is in
|
|
|
|
! vop-source, the tagged slot number is in vop-literal.
|
|
|
|
dup vop-literal v>operand over vop-dest v>operand
|
|
|
|
! turn tagged fixnum slot # into an offset, multiple of 4
|
|
|
|
over 1 SHR
|
|
|
|
! compute slot address in vop-dest
|
|
|
|
dupd ADD
|
|
|
|
! store new slot value
|
|
|
|
>r vop-source v>operand r> unit swap MOV ;
|
2005-01-08 16:43:18 -05:00
|
|
|
|
2005-05-06 18:33:40 -04:00
|
|
|
M: %fast-set-slot generate-node ( vop -- )
|
|
|
|
! the tagged object is in vop-dest, the new value is in
|
|
|
|
! vop-source, the pointer offset is in vop-literal. the
|
|
|
|
! offset already takes the type tag into account, so its
|
|
|
|
! just one instruction to load.
|
|
|
|
dup vop-literal over vop-dest v>operand swap 2list
|
|
|
|
swap vop-source v>operand MOV ;
|
2005-01-08 16:43:18 -05:00
|
|
|
|
2005-01-14 14:56:19 -05:00
|
|
|
\ dispatch [
|
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.
|
|
|
|
drop
|
|
|
|
POP-DS
|
|
|
|
EAX 1 SHR
|
2005-03-15 22:23:52 -05:00
|
|
|
EAX HEX: ffff ADD just-compiled f rel-address
|
2005-01-08 16:43:18 -05:00
|
|
|
[ EAX ] JMP
|
|
|
|
compile-aligned
|
|
|
|
compiled-offset swap set-compiled-cell ( fixup -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
] "generator" set-word-prop
|