factor/library/compiler/x86/slots.factor

75 lines
2.1 KiB
Factor
Raw Normal View History

2006-02-23 19:01:12 -05:00
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2005-05-13 00:09:49 -04:00
IN: compiler-backend
2005-12-02 02:25:44 -05:00
USING: alien arrays assembler compiler inference kernel
2005-05-13 00:09:49 -04:00
kernel-internals lists math memory namespaces sequences words ;
M: %slot generate-node ( vop -- )
2005-12-04 22:06:12 -05:00
drop
2005-05-13 00:09:49 -04:00
! turn tagged fixnum slot # into an offset, multiple of 4
2005-12-07 03:37:05 -05:00
0 input-operand fixnum>slot@
2005-12-07 21:46:54 -05:00
! compute slot address
2005-12-06 20:42:17 -05:00
dest/src ADD
2005-12-07 21:46:54 -05:00
! load slot value
0 output-operand dup [] MOV ;
2005-05-13 00:09:49 -04:00
M: %fast-slot generate-node ( vop -- )
drop 0 output-operand 1 input-operand 0 input [+] MOV ;
2005-05-13 00:09:49 -04:00
2005-12-05 19:07:41 -05:00
: card-offset 1 getenv ; inline
M: %write-barrier generate-node ( vop -- )
2006-02-23 19:01:12 -05:00
#! Mark the card pointed to by vreg.
2005-12-04 22:06:12 -05:00
drop
2005-12-06 20:42:17 -05:00
0 input-operand card-bits SHR
2006-03-28 23:25:52 -05:00
0 input-operand card-offset ADD rel-absolute-cell rel-cards
0 input-operand [] card-mark OR ;
2005-05-13 00:09:49 -04:00
M: %set-slot generate-node ( vop -- )
2005-12-04 22:06:12 -05:00
drop
2005-12-04 22:55:02 -05:00
! turn tagged fixnum slot # into an offset
2 input-operand fixnum>slot@
2005-12-07 21:46:54 -05:00
! compute slot address
2005-12-04 22:06:12 -05:00
2 input-operand 1 input-operand ADD
2005-05-13 00:09:49 -04:00
! store new slot value
2 input-operand [] 0 input-operand MOV ;
2005-05-13 00:09:49 -04:00
M: %fast-set-slot generate-node ( vop -- )
drop 1 input-operand 2 input [+] 0 input-operand MOV ;
2006-01-31 21:31:53 -05:00
: >register-16 ( reg -- reg )
"register" word-prop { AX CX DX } nth ;
: scratch-16 ( n -- reg ) scratch >register-16 ;
M: %char-slot generate-node ( vop -- )
drop
0 input-operand 2 SHR
0 scratch dup XOR
dest/src ADD
0 scratch-16 0 output-operand string-offset [+] MOV
2006-01-31 21:31:53 -05:00
0 scratch tag-bits SHL
0 output-operand 0 scratch MOV ;
M: %set-char-slot generate-node ( vop -- )
drop
0 input-operand tag-bits SHR
2 input-operand 2 SHR
2 input-operand 1 input-operand ADD
2 input-operand string-offset [+]
0 input-operand >register-16 MOV ;
2006-01-31 21:31:53 -05:00
: userenv@ ( n -- addr ) cells "userenv" f dlsym + ;
M: %getenv generate-node ( vop -- )
2005-12-04 22:06:12 -05:00
drop
2005-12-10 01:02:13 -05:00
0 output-operand 0 input userenv@ MOV
2005-12-11 15:14:41 -05:00
0 input rel-absolute-cell rel-userenv
0 output-operand dup [] MOV ;
M: %setenv generate-node ( vop -- )
2005-12-04 22:06:12 -05:00
drop
2005-12-10 01:02:13 -05:00
0 scratch 1 input userenv@ MOV
2005-12-11 15:14:41 -05:00
1 input rel-absolute-cell rel-userenv
0 scratch [] 0 input-operand MOV ;