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
|
|
|
|
2005-03-15 18:18:33 -05:00
|
|
|
! Not used on x86
|
|
|
|
#prologue [ drop ] "generator" set-word-prop
|
|
|
|
|
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-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-03-21 20:53:26 -05:00
|
|
|
#call-label [
|
|
|
|
compile-call-label
|
|
|
|
] "generator" set-word-prop
|
|
|
|
|
2005-03-19 00:30:49 -05:00
|
|
|
#jump [
|
|
|
|
dup postpone-word compile-jump-label
|
|
|
|
] "generator" set-word-prop
|
|
|
|
|
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-15 22:23:52 -05:00
|
|
|
0 JNE relative ;
|
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-15 22:23:52 -05:00
|
|
|
0 JE relative ;
|
2005-02-22 23:07:47 -05:00
|
|
|
|
2005-03-15 22:23:52 -05:00
|
|
|
#return-to [ 0 PUSH absolute ] "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-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
|