factor/library/compiler/x86/generator.factor

120 lines
2.7 KiB
Factor
Raw Normal View History

2005-02-14 21:58:07 -05:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2005-01-08 16:43:18 -05:00
IN: compiler
2005-02-14 21:58:07 -05:00
USING: alien assembler inference kernel kernel-internals lists
math memory namespaces words ;
2005-01-08 16:43:18 -05:00
\ slot [
PEEK-DS
2unlist type-tag >r cell * r> - EAX swap 2list EAX swap MOV
2005-02-16 23:24:35 -05:00
[ ESI ] EAX MOV
2005-01-08 16:43:18 -05:00
] "generator" set-word-property
: compile-call-label ( label -- )
0 CALL fixup compiled-offset defer-xt ;
: compile-jump-label ( label -- )
0 JMP fixup compiled-offset defer-xt ;
: compile-call ( word -- )
dup dup postpone-word compile-call-label t rel-word ;
2005-01-17 15:33:12 -05:00
: compile-target ( word -- )
compiled-offset 0 compile-cell 0 defer-xt ;
2005-01-08 16:43:18 -05:00
#call [
compile-call
] "generator" set-word-property
#jump [
dup dup postpone-word
compile-jump-label
t rel-word
] "generator" set-word-property
#call-label [
compile-call-label
] "generator" set-word-property
#jump-label [
compile-jump-label
] "generator" set-word-property
: compile-jump-t ( word -- )
POP-DS
! condition is now in EAX
EAX f address CMP
! jump w/ address added later
0 JNE fixup compiled-offset defer-xt ;
#jump-t-label [
compile-jump-t
] "generator" set-word-property
2005-01-08 16:43:18 -05:00
#jump-t [
dup compile-jump-t t rel-word
] "generator" set-word-property
: compile-jump-f ( word -- )
2005-01-08 16:43:18 -05:00
POP-DS
! condition is now in EAX
EAX f address CMP
! jump w/ address added later
0 JE fixup compiled-offset defer-xt ;
#jump-f-label [
compile-jump-f
] "generator" set-word-property
#jump-f [
dup compile-jump-f t rel-word
2005-01-08 16:43:18 -05:00
] "generator" set-word-property
#return-to [
0 PUSH fixup 0 defer-xt rel-address
] "generator" set-word-property
#return [ drop RET ] "generator" set-word-property
\ 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
EAX HEX: ffff ADD fixup rel-address
[ EAX ] JMP
compile-aligned
compiled-offset swap set-compiled-cell ( fixup -- )
] "generator" set-word-property
2005-01-17 15:33:12 -05:00
#target-label [
#! Jump table entries are absolute addresses.
compile-target rel-address
] "generator" set-word-property
2005-01-08 16:43:18 -05:00
#target [
#! Jump table entries are absolute addresses.
2005-01-17 15:33:12 -05:00
dup dup postpone-word compile-target f rel-word
2005-01-08 16:43:18 -05:00
] "generator" set-word-property
#c-call [
uncons load-dll 2dup dlsym CALL t rel-dlsym
] "generator" set-word-property
#unbox [
dup f dlsym CALL f t rel-dlsym
EAX PUSH
] "generator" set-word-property
#box [
EAX PUSH
dup f dlsym CALL f t rel-dlsym
ESP 4 ADD
] "generator" set-word-property
#cleanup [
dup 0 = [ drop ] [ ESP swap ADD ] ifte
] "generator" set-word-property