factor/library/compiler/x86/generator.factor

105 lines
2.4 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
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
2005-03-14 20:09:32 -05:00
: compile-call-label ( label -- ) 0 CALL fixup t defer-xt ;
: compile-jump-label ( label -- ) 0 JMP fixup t defer-xt ;
2005-01-08 16:43:18 -05:00
: compile-call ( word -- )
2005-03-14 20:09:32 -05:00
dup postpone-word compile-call-label ;
2005-01-08 16:43:18 -05:00
2005-01-17 15:33:12 -05:00
: compile-target ( word -- )
2005-03-14 20:09:32 -05:00
compiled-offset 0 compile-cell f defer-xt ;
2005-01-17 15:33:12 -05:00
2005-01-08 16:43:18 -05:00
#call [
compile-call
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
#jump [
2005-03-14 20:09:32 -05:00
dup postpone-word compile-jump-label
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
#call-label [
compile-call-label
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
#jump-label [
compile-jump-label
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
: compile-jump-t ( word -- )
POP-DS
! condition is now in EAX
EAX f address CMP
! jump w/ address added later
2005-03-14 20:09:32 -05:00
0 JNE fixup t defer-xt ;
2005-03-14 20:09:32 -05:00
#jump-t-label [ compile-jump-t ] "generator" set-word-prop
2005-03-15 16:50:08 -05:00
#jump-t [ compile-jump-t ] "generator" set-word-prop
: 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
2005-03-14 20:09:32 -05:00
0 JE fixup t defer-xt ;
2005-03-14 20:09:32 -05:00
#jump-f-label [ compile-jump-f ] "generator" set-word-prop
2005-03-15 16:50:08 -05:00
#jump-f [ compile-jump-f ] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
2005-03-14 20:09:32 -05:00
#return-to [ 0 PUSH fixup f defer-xt ] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
#return [ drop RET ] "generator" set-word-prop
2005-01-08 16:43:18 -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-14 20:09:32 -05:00
EAX HEX: ffff ADD fixup f rel-address
2005-01-08 16:43:18 -05:00
[ EAX ] JMP
compile-aligned
compiled-offset swap set-compiled-cell ( fixup -- )
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
2005-01-17 15:33:12 -05:00
#target-label [
#! Jump table entries are absolute addresses.
2005-03-14 20:09:32 -05:00
compile-target
] "generator" set-word-prop
2005-01-17 15:33:12 -05:00
2005-01-08 16:43:18 -05:00
#target [
#! Jump table entries are absolute addresses.
2005-03-14 20:09:32 -05:00
dup postpone-word compile-target
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
#c-call [
uncons load-dll 2dup dlsym CALL t rel-dlsym
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
#unbox [
dup f dlsym CALL f t rel-dlsym
EAX PUSH
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
#box [
EAX PUSH
dup f dlsym CALL f t rel-dlsym
ESP 4 ADD
] "generator" set-word-prop
2005-01-08 16:43:18 -05:00
#cleanup [
dup 0 = [ drop ] [ ESP swap ADD ] ifte
] "generator" set-word-prop