Clean up bootstrap.image, and implement new calling convention for tail calls; tail call sites now have PICs
parent
12a34d81f7
commit
4915e1ced7
|
@ -9,7 +9,7 @@ classes.builtin classes.tuple classes.tuple.private vocabs
|
||||||
vocabs.loader source-files definitions debugger quotations.private
|
vocabs.loader source-files definitions debugger quotations.private
|
||||||
sequences.private combinators math.order math.private accessors
|
sequences.private combinators math.order math.private accessors
|
||||||
slots.private generic.single.private compiler.units compiler.constants
|
slots.private generic.single.private compiler.units compiler.constants
|
||||||
fry ;
|
fry bootstrap.image.syntax ;
|
||||||
IN: bootstrap.image
|
IN: bootstrap.image
|
||||||
|
|
||||||
: arch ( os cpu -- arch )
|
: arch ( os cpu -- arch )
|
||||||
|
@ -123,96 +123,59 @@ SYMBOL: big-endian
|
||||||
! Bootstrap architecture name
|
! Bootstrap architecture name
|
||||||
SYMBOL: architecture
|
SYMBOL: architecture
|
||||||
|
|
||||||
! Bootstrap global namesapce
|
RESET
|
||||||
SYMBOL: bootstrap-global
|
|
||||||
|
|
||||||
! Boot quotation, set in stage1.factor
|
! Boot quotation, set in stage1.factor
|
||||||
SYMBOL: bootstrap-boot-quot
|
USERENV: bootstrap-boot-quot 20
|
||||||
|
|
||||||
|
! Bootstrap global namesapce
|
||||||
|
USERENV: bootstrap-global 21
|
||||||
|
|
||||||
! JIT parameters
|
! JIT parameters
|
||||||
SYMBOL: jit-prolog
|
USERENV: jit-prolog 23
|
||||||
SYMBOL: jit-primitive-word
|
USERENV: jit-primitive-word 24
|
||||||
SYMBOL: jit-primitive
|
USERENV: jit-primitive 25
|
||||||
SYMBOL: jit-word-jump
|
USERENV: jit-word-jump 26
|
||||||
SYMBOL: jit-word-call
|
USERENV: jit-word-call 27
|
||||||
SYMBOL: jit-push-immediate
|
USERENV: jit-word-special 28
|
||||||
SYMBOL: jit-if-word
|
USERENV: jit-if-word 29
|
||||||
SYMBOL: jit-if
|
USERENV: jit-if 30
|
||||||
SYMBOL: jit-dip-word
|
USERENV: jit-epilog 31
|
||||||
SYMBOL: jit-dip
|
USERENV: jit-return 32
|
||||||
SYMBOL: jit-2dip-word
|
USERENV: jit-profiling 33
|
||||||
SYMBOL: jit-2dip
|
USERENV: jit-push-immediate 34
|
||||||
SYMBOL: jit-3dip-word
|
USERENV: jit-dip-word 35
|
||||||
SYMBOL: jit-3dip
|
USERENV: jit-dip 36
|
||||||
SYMBOL: jit-execute-word
|
USERENV: jit-2dip-word 37
|
||||||
SYMBOL: jit-execute-jump
|
USERENV: jit-2dip 38
|
||||||
SYMBOL: jit-execute-call
|
USERENV: jit-3dip-word 39
|
||||||
SYMBOL: jit-epilog
|
USERENV: jit-3dip 40
|
||||||
SYMBOL: jit-return
|
USERENV: jit-execute-word 41
|
||||||
SYMBOL: jit-profiling
|
USERENV: jit-execute-jump 42
|
||||||
|
USERENV: jit-execute-call 43
|
||||||
|
|
||||||
! PIC stubs
|
! PIC stubs
|
||||||
SYMBOL: pic-load
|
USERENV: pic-load 47
|
||||||
SYMBOL: pic-tag
|
USERENV: pic-tag 48
|
||||||
SYMBOL: pic-hi-tag
|
USERENV: pic-hi-tag 49
|
||||||
SYMBOL: pic-tuple
|
USERENV: pic-tuple 50
|
||||||
SYMBOL: pic-hi-tag-tuple
|
USERENV: pic-hi-tag-tuple 51
|
||||||
SYMBOL: pic-check-tag
|
USERENV: pic-check-tag 52
|
||||||
SYMBOL: pic-check
|
USERENV: pic-check 53
|
||||||
SYMBOL: pic-hit
|
USERENV: pic-hit 54
|
||||||
SYMBOL: pic-miss-word
|
USERENV: pic-miss-word 55
|
||||||
SYMBOL: pic-miss-tail-word
|
USERENV: pic-miss-tail-word 56
|
||||||
|
|
||||||
! Megamorphic dispatch
|
! Megamorphic dispatch
|
||||||
SYMBOL: mega-lookup
|
USERENV: mega-lookup 57
|
||||||
SYMBOL: mega-lookup-word
|
USERENV: mega-lookup-word 58
|
||||||
SYMBOL: mega-miss-word
|
USERENV: mega-miss-word 59
|
||||||
|
|
||||||
! Default definition for undefined words
|
! Default definition for undefined words
|
||||||
SYMBOL: undefined-quot
|
USERENV: undefined-quot 60
|
||||||
|
|
||||||
: userenvs ( -- assoc )
|
|
||||||
H{
|
|
||||||
{ bootstrap-boot-quot 20 }
|
|
||||||
{ bootstrap-global 21 }
|
|
||||||
{ jit-prolog 23 }
|
|
||||||
{ jit-primitive-word 24 }
|
|
||||||
{ jit-primitive 25 }
|
|
||||||
{ jit-word-jump 26 }
|
|
||||||
{ jit-word-call 27 }
|
|
||||||
{ jit-if-word 28 }
|
|
||||||
{ jit-if 29 }
|
|
||||||
{ jit-epilog 33 }
|
|
||||||
{ jit-return 34 }
|
|
||||||
{ jit-profiling 35 }
|
|
||||||
{ jit-push-immediate 36 }
|
|
||||||
{ jit-dip-word 38 }
|
|
||||||
{ jit-dip 39 }
|
|
||||||
{ jit-2dip-word 40 }
|
|
||||||
{ jit-2dip 41 }
|
|
||||||
{ jit-3dip-word 42 }
|
|
||||||
{ jit-3dip 43 }
|
|
||||||
{ jit-execute-word 44 }
|
|
||||||
{ jit-execute-jump 45 }
|
|
||||||
{ jit-execute-call 46 }
|
|
||||||
{ pic-load 47 }
|
|
||||||
{ pic-tag 48 }
|
|
||||||
{ pic-hi-tag 49 }
|
|
||||||
{ pic-tuple 50 }
|
|
||||||
{ pic-hi-tag-tuple 51 }
|
|
||||||
{ pic-check-tag 52 }
|
|
||||||
{ pic-check 53 }
|
|
||||||
{ pic-hit 54 }
|
|
||||||
{ pic-miss-word 55 }
|
|
||||||
{ pic-miss-tail-word 56 }
|
|
||||||
{ mega-lookup 57 }
|
|
||||||
{ mega-lookup-word 58 }
|
|
||||||
{ mega-miss-word 59 }
|
|
||||||
{ undefined-quot 60 }
|
|
||||||
} ; inline
|
|
||||||
|
|
||||||
: userenv-offset ( symbol -- n )
|
: userenv-offset ( symbol -- n )
|
||||||
userenvs at header-size + ;
|
userenvs get at header-size + ;
|
||||||
|
|
||||||
: emit ( cell -- ) image get push ;
|
: emit ( cell -- ) image get push ;
|
||||||
|
|
||||||
|
@ -504,11 +467,7 @@ M: quotation '
|
||||||
class<=-cache class-not-cache classes-intersect-cache
|
class<=-cache class-not-cache classes-intersect-cache
|
||||||
class-and-cache class-or-cache next-method-quot-cache
|
class-and-cache class-or-cache next-method-quot-cache
|
||||||
} [ H{ } clone ] H{ } map>assoc assoc-union
|
} [ H{ } clone ] H{ } map>assoc assoc-union
|
||||||
bootstrap-global set
|
bootstrap-global set ;
|
||||||
bootstrap-global emit-userenv ;
|
|
||||||
|
|
||||||
: emit-boot-quot ( -- )
|
|
||||||
bootstrap-boot-quot emit-userenv ;
|
|
||||||
|
|
||||||
: emit-jit-data ( -- )
|
: emit-jit-data ( -- )
|
||||||
\ if jit-if-word set
|
\ if jit-if-word set
|
||||||
|
@ -521,43 +480,10 @@ M: quotation '
|
||||||
\ inline-cache-miss-tail \ pic-miss-tail-word set
|
\ inline-cache-miss-tail \ pic-miss-tail-word set
|
||||||
\ mega-cache-lookup \ mega-lookup-word set
|
\ mega-cache-lookup \ mega-lookup-word set
|
||||||
\ mega-cache-miss \ mega-miss-word set
|
\ mega-cache-miss \ mega-miss-word set
|
||||||
[ undefined ] undefined-quot set
|
[ undefined ] undefined-quot set ;
|
||||||
{
|
|
||||||
jit-prolog
|
: emit-userenvs ( -- )
|
||||||
jit-primitive-word
|
userenvs get keys [ emit-userenv ] each ;
|
||||||
jit-primitive
|
|
||||||
jit-word-jump
|
|
||||||
jit-word-call
|
|
||||||
jit-push-immediate
|
|
||||||
jit-if-word
|
|
||||||
jit-if
|
|
||||||
jit-dip-word
|
|
||||||
jit-dip
|
|
||||||
jit-2dip-word
|
|
||||||
jit-2dip
|
|
||||||
jit-3dip-word
|
|
||||||
jit-3dip
|
|
||||||
jit-execute-word
|
|
||||||
jit-execute-jump
|
|
||||||
jit-execute-call
|
|
||||||
jit-epilog
|
|
||||||
jit-return
|
|
||||||
jit-profiling
|
|
||||||
pic-load
|
|
||||||
pic-tag
|
|
||||||
pic-hi-tag
|
|
||||||
pic-tuple
|
|
||||||
pic-hi-tag-tuple
|
|
||||||
pic-check-tag
|
|
||||||
pic-check
|
|
||||||
pic-hit
|
|
||||||
pic-miss-word
|
|
||||||
pic-miss-tail-word
|
|
||||||
mega-lookup
|
|
||||||
mega-lookup-word
|
|
||||||
mega-miss-word
|
|
||||||
undefined-quot
|
|
||||||
} [ emit-userenv ] each ;
|
|
||||||
|
|
||||||
: fixup-header ( -- )
|
: fixup-header ( -- )
|
||||||
heap-size data-heap-size-offset fixup ;
|
heap-size data-heap-size-offset fixup ;
|
||||||
|
@ -574,8 +500,8 @@ M: quotation '
|
||||||
emit-jit-data
|
emit-jit-data
|
||||||
"Serializing global namespace..." print flush
|
"Serializing global namespace..." print flush
|
||||||
emit-global
|
emit-global
|
||||||
"Serializing boot quotation..." print flush
|
"Serializing user environment..." print flush
|
||||||
emit-boot-quot
|
emit-userenvs
|
||||||
"Performing word fixups..." print flush
|
"Performing word fixups..." print flush
|
||||||
fixup-words
|
fixup-words
|
||||||
"Performing header fixups..." print flush
|
"Performing header fixups..." print flush
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Slava Pestov
|
|
@ -0,0 +1,14 @@
|
||||||
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: parser kernel namespaces assocs words.symbol ;
|
||||||
|
IN: bootstrap.image.syntax
|
||||||
|
|
||||||
|
SYMBOL: userenvs
|
||||||
|
|
||||||
|
SYNTAX: RESET H{ } clone userenvs set-global ;
|
||||||
|
|
||||||
|
SYNTAX: USERENV:
|
||||||
|
CREATE-WORD scan-word
|
||||||
|
[ swap userenvs get set-at ]
|
||||||
|
[ drop define-symbol ]
|
||||||
|
2bi ;
|
|
@ -42,13 +42,18 @@ big-endian off
|
||||||
] jit-push-immediate jit-define
|
] jit-push-immediate jit-define
|
||||||
|
|
||||||
[
|
[
|
||||||
0 JMP rc-relative rt-xt jit-rel
|
temp3 0 MOV rc-absolute-cell rt-here jit-rel
|
||||||
|
0 JMP rc-relative rt-xt-pic-tail jit-rel
|
||||||
] jit-word-jump jit-define
|
] jit-word-jump jit-define
|
||||||
|
|
||||||
[
|
[
|
||||||
0 CALL rc-relative rt-xt-pic jit-rel
|
0 CALL rc-relative rt-xt-pic jit-rel
|
||||||
] jit-word-call jit-define
|
] jit-word-call jit-define
|
||||||
|
|
||||||
|
[
|
||||||
|
0 JMP rc-relative rt-xt jit-rel
|
||||||
|
] jit-word-special jit-define
|
||||||
|
|
||||||
[
|
[
|
||||||
! load boolean
|
! load boolean
|
||||||
temp0 ds-reg [] MOV
|
temp0 ds-reg [] MOV
|
||||||
|
|
|
@ -7,6 +7,8 @@ namespace factor
|
||||||
|
|
||||||
inline static void flush_icache(cell start, cell len) {}
|
inline static void flush_icache(cell start, cell len) {}
|
||||||
|
|
||||||
|
static const fixnum xt_tail_pic_offset = 2 * sizeof(cell) + 1;
|
||||||
|
|
||||||
static const unsigned char call_opcode = 0xe8;
|
static const unsigned char call_opcode = 0xe8;
|
||||||
static const unsigned char jmp_opcode = 0xe9;
|
static const unsigned char jmp_opcode = 0xe9;
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index,
|
||||||
push(methods.value());
|
push(methods.value());
|
||||||
push(tag_fixnum(index));
|
push(tag_fixnum(index));
|
||||||
push(cache_entries.value());
|
push(cache_entries.value());
|
||||||
word_jump(userenv[tail_call_p ? PIC_MISS_TAIL_WORD : PIC_MISS_WORD]);
|
word_special(userenv[tail_call_p ? PIC_MISS_TAIL_WORD : PIC_MISS_WORD]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static code_block *compile_inline_cache(fixnum index,
|
static code_block *compile_inline_cache(fixnum index,
|
||||||
|
|
|
@ -25,13 +25,19 @@ struct jit {
|
||||||
}
|
}
|
||||||
|
|
||||||
void word_jump(cell word) {
|
void word_jump(cell word) {
|
||||||
emit_with(userenv[JIT_WORD_JUMP],word);
|
literal(tag_fixnum(xt_tail_pic_offset));
|
||||||
|
literal(word);
|
||||||
|
emit(userenv[JIT_WORD_JUMP]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void word_call(cell word) {
|
void word_call(cell word) {
|
||||||
emit_with(userenv[JIT_WORD_CALL],word);
|
emit_with(userenv[JIT_WORD_CALL],word);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void word_special(cell word) {
|
||||||
|
emit_with(userenv[JIT_WORD_SPECIAL],word);
|
||||||
|
}
|
||||||
|
|
||||||
void emit_subprimitive(cell word_) {
|
void emit_subprimitive(cell word_) {
|
||||||
gc_root<word> word(word_);
|
gc_root<word> word(word_);
|
||||||
gc_root<array> code_template(word->subprimitive);
|
gc_root<array> code_template(word->subprimitive);
|
||||||
|
|
|
@ -152,8 +152,17 @@ void quotation_jit::iterate_quotation()
|
||||||
{
|
{
|
||||||
if(stack_frame) emit(userenv[JIT_EPILOG]);
|
if(stack_frame) emit(userenv[JIT_EPILOG]);
|
||||||
tail_call = true;
|
tail_call = true;
|
||||||
|
/* Inline cache misses are special-cased */
|
||||||
|
if(obj.value() == userenv[PIC_MISS_WORD]
|
||||||
|
|| obj.value() == userenv[PIC_MISS_TAIL_WORD])
|
||||||
|
{
|
||||||
|
word_special(obj.value());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
word_jump(obj.value());
|
word_jump(obj.value());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
word_call(obj.value());
|
word_call(obj.value());
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,14 @@ enum special_object {
|
||||||
JIT_PRIMITIVE,
|
JIT_PRIMITIVE,
|
||||||
JIT_WORD_JUMP,
|
JIT_WORD_JUMP,
|
||||||
JIT_WORD_CALL,
|
JIT_WORD_CALL,
|
||||||
|
JIT_WORD_SPECIAL,
|
||||||
JIT_IF_WORD,
|
JIT_IF_WORD,
|
||||||
JIT_IF,
|
JIT_IF,
|
||||||
JIT_EPILOG = 33,
|
JIT_EPILOG,
|
||||||
JIT_RETURN,
|
JIT_RETURN,
|
||||||
JIT_PROFILING,
|
JIT_PROFILING,
|
||||||
JIT_PUSH_IMMEDIATE,
|
JIT_PUSH_IMMEDIATE,
|
||||||
JIT_DIP_WORD = 38,
|
JIT_DIP_WORD,
|
||||||
JIT_DIP,
|
JIT_DIP,
|
||||||
JIT_2DIP_WORD,
|
JIT_2DIP_WORD,
|
||||||
JIT_2DIP,
|
JIT_2DIP,
|
||||||
|
|
Loading…
Reference in New Issue