2007-09-21 23:29:38 -04:00
|
|
|
! Copyright (C) 2007 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: bootstrap.image.private kernel namespaces system
|
2008-01-09 04:52:08 -05:00
|
|
|
cpu.x86.assembler layouts compiler.units math generator.fixup
|
2008-01-02 19:36:36 -05:00
|
|
|
compiler.constants ;
|
2007-09-21 23:29:38 -04:00
|
|
|
IN: bootstrap.x86
|
|
|
|
|
|
|
|
big-endian off
|
|
|
|
|
|
|
|
1 jit-code-format set
|
|
|
|
|
2007-12-26 20:02:41 -05:00
|
|
|
: stack-frame-size 4 bootstrap-cells ;
|
2007-10-06 18:54:46 -04:00
|
|
|
|
2007-09-21 23:29:38 -04:00
|
|
|
[
|
2008-01-02 19:36:36 -05:00
|
|
|
! Load word
|
2008-01-02 22:07:25 -05:00
|
|
|
temp-reg 0 [] MOV
|
2008-01-02 19:36:36 -05:00
|
|
|
! Bump profiling counter
|
2008-01-02 22:07:25 -05:00
|
|
|
temp-reg profile-count-offset [+] 1 tag-fixnum ADD
|
2008-01-02 19:36:36 -05:00
|
|
|
! Load word->code
|
2008-01-02 22:07:25 -05:00
|
|
|
temp-reg temp-reg word-code-offset [+] MOV
|
2008-01-02 19:36:36 -05:00
|
|
|
! Compute word XT
|
2008-01-02 22:07:25 -05:00
|
|
|
temp-reg compiled-header-size ADD
|
2008-01-02 19:36:36 -05:00
|
|
|
! Jump to XT
|
2008-01-02 22:07:25 -05:00
|
|
|
temp-reg JMP
|
2008-01-02 19:36:36 -05:00
|
|
|
] rc-absolute-cell rt-literal 2 jit-profiling jit-define
|
|
|
|
|
|
|
|
[
|
2007-12-25 23:40:36 -05:00
|
|
|
stack-frame-size PUSH ! save stack frame size
|
2008-01-02 19:36:36 -05:00
|
|
|
0 PUSH ! push XT
|
2007-12-26 20:02:41 -05:00
|
|
|
arg1 PUSH ! alignment
|
2008-01-07 16:14:09 -05:00
|
|
|
] rc-absolute-cell rt-label 6 jit-prolog jit-define
|
2007-12-25 23:40:36 -05:00
|
|
|
|
|
|
|
[
|
2007-12-26 01:45:16 -05:00
|
|
|
arg0 0 [] MOV ! load literal
|
2007-09-21 23:29:38 -04:00
|
|
|
ds-reg bootstrap-cell ADD ! increment datastack pointer
|
|
|
|
ds-reg [] arg0 MOV ! store literal on datastack
|
2007-12-26 01:45:16 -05:00
|
|
|
] rc-absolute-cell rt-literal 2 jit-push-literal jit-define
|
2007-12-25 23:40:36 -05:00
|
|
|
|
|
|
|
[
|
2007-09-21 23:29:38 -04:00
|
|
|
arg1 stack-reg MOV ! pass callstack pointer as arg 2
|
2007-12-26 01:45:16 -05:00
|
|
|
(JMP) drop ! go
|
2008-01-02 19:36:36 -05:00
|
|
|
] rc-relative rt-primitive 3 jit-primitive jit-define
|
2007-12-25 23:40:36 -05:00
|
|
|
|
|
|
|
[
|
2007-12-26 02:33:49 -05:00
|
|
|
(JMP) drop
|
|
|
|
] rc-relative rt-xt 1 jit-word-jump jit-define
|
2007-12-25 23:40:36 -05:00
|
|
|
|
|
|
|
[
|
2007-12-26 02:33:49 -05:00
|
|
|
(CALL) drop
|
2007-12-26 20:02:41 -05:00
|
|
|
] rc-relative rt-xt 1 jit-word-call jit-define
|
2007-12-25 23:40:36 -05:00
|
|
|
|
2007-12-26 01:45:16 -05:00
|
|
|
[
|
|
|
|
arg1 0 MOV ! load addr of true quotation
|
2007-09-21 23:29:38 -04:00
|
|
|
arg0 ds-reg [] MOV ! load boolean
|
|
|
|
ds-reg bootstrap-cell SUB ! pop boolean
|
|
|
|
arg0 \ f tag-number CMP ! compare it with f
|
2007-12-26 01:45:16 -05:00
|
|
|
arg0 arg1 [] CMOVNE ! load true branch if not equal
|
|
|
|
arg0 arg1 bootstrap-cell [+] CMOVE ! load false branch if equal
|
|
|
|
arg0 quot-xt@ [+] JMP ! jump to quotation-xt
|
|
|
|
] rc-absolute-cell rt-literal 1 jit-if-jump jit-define
|
2007-09-21 23:29:38 -04:00
|
|
|
|
|
|
|
[
|
2007-12-26 01:45:16 -05:00
|
|
|
arg1 0 [] MOV ! load dispatch table
|
2007-09-21 23:29:38 -04:00
|
|
|
arg0 ds-reg [] MOV ! load index
|
|
|
|
fixnum>slot@ ! turn it into an array offset
|
|
|
|
ds-reg bootstrap-cell SUB ! pop index
|
2007-12-26 01:45:16 -05:00
|
|
|
arg0 arg1 ADD ! compute quotation location
|
2007-09-21 23:29:38 -04:00
|
|
|
arg0 arg0 array-start [+] MOV ! load quotation
|
2007-12-26 01:45:16 -05:00
|
|
|
arg0 quot-xt@ [+] JMP ! execute branch
|
|
|
|
] rc-absolute-cell rt-literal 2 jit-dispatch jit-define
|
2007-09-21 23:29:38 -04:00
|
|
|
|
|
|
|
[
|
2007-10-05 17:30:10 -04:00
|
|
|
stack-reg stack-frame-size bootstrap-cell - ADD ! unwind stack frame
|
2007-12-25 23:40:36 -05:00
|
|
|
] f f f jit-epilog jit-define
|
2007-09-21 23:29:38 -04:00
|
|
|
|
2007-12-25 23:40:36 -05:00
|
|
|
[ 0 RET ] f f f jit-return jit-define
|
2007-09-21 23:29:38 -04:00
|
|
|
|
2008-01-09 04:52:08 -05:00
|
|
|
[ "bootstrap.x86" forget-vocab ] with-compilation-unit
|