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-03-05 14:45:23 -05:00
|
|
|
] "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
|
2005-03-05 14:45:23 -05:00
|
|
|
] "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
|
2005-03-05 14:45:23 -05:00
|
|
|
] "generator" set-word-prop
|
2005-01-08 16:43:18 -05:00
|
|
|
|
|
|
|
#call-label [
|
|
|
|
compile-call-label
|
2005-03-05 14:45:23 -05:00
|
|
|
] "generator" set-word-prop
|
2005-01-08 16:43:18 -05:00
|
|
|
|
|
|
|
#jump-label [
|
|
|
|
compile-jump-label
|
2005-03-05 14:45:23 -05:00
|
|
|
] "generator" set-word-prop
|
2005-01-08 16:43:18 -05:00
|
|
|
|
2005-02-22 23:07:47 -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-02-22 23:07:47 -05:00
|
|
|
|
2005-03-14 20:09:32 -05:00
|
|
|
#jump-t-label [ compile-jump-t ] "generator" set-word-prop
|
2005-02-22 23:07:47 -05:00
|
|
|
|
2005-03-15 16:50:08 -05:00
|
|
|
#jump-t [ compile-jump-t ] "generator" set-word-prop
|
2005-02-22 23:07:47 -05:00
|
|
|
|
|
|
|
: 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-02-22 23:07:47 -05:00
|
|
|
|
2005-03-14 20:09:32 -05:00
|
|
|
#jump-f-label [ compile-jump-f ] "generator" set-word-prop
|
2005-02-22 23:07:47 -05:00
|
|
|
|
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
|
|
|
|
2005-03-05 14:45:23 -05:00
|
|
|
#return [ drop RET ] "generator" set-word-prop
|
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-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 -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
] "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
|
2005-03-05 14:45:23 -05:00
|
|
|
] "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
|
2005-03-05 14:45:23 -05:00
|
|
|
] "generator" set-word-prop
|
2005-01-08 16:43:18 -05:00
|
|
|
|
|
|
|
#c-call [
|
|
|
|
uncons load-dll 2dup dlsym CALL t rel-dlsym
|
2005-03-05 14:45:23 -05:00
|
|
|
] "generator" set-word-prop
|
2005-01-08 16:43:18 -05:00
|
|
|
|
|
|
|
#unbox [
|
|
|
|
dup f dlsym CALL f t rel-dlsym
|
|
|
|
EAX PUSH
|
2005-03-05 14:45:23 -05:00
|
|
|
] "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
|
2005-03-05 14:45:23 -05:00
|
|
|
] "generator" set-word-prop
|
2005-01-08 16:43:18 -05:00
|
|
|
|
|
|
|
#cleanup [
|
|
|
|
dup 0 = [ drop ] [ ESP swap ADD ] ifte
|
2005-03-05 14:45:23 -05:00
|
|
|
] "generator" set-word-prop
|