vm: ensure that non-optimized calls to generic words which have not yet been compiled can still work

db4
Slava Pestov 2010-01-06 23:49:14 +13:00
parent 9508a5a083
commit c04fef10c7
4 changed files with 23 additions and 5 deletions

View File

@ -1,5 +1,5 @@
USING: compiler definitions compiler.units tools.test arrays sequences words kernel USING: compiler definitions compiler.units tools.test arrays sequences words kernel
accessors namespaces fry eval ; accessors namespaces fry eval quotations math ;
IN: compiler.units.tests IN: compiler.units.tests
[ [ [ ] define-temp ] with-compilation-unit ] must-infer [ [ [ ] define-temp ] with-compilation-unit ] must-infer
@ -56,3 +56,16 @@ DEFER: nesting-test
[ ] [ "IN: compiler.units.tests << : nesting-test ( -- ) ; >>" eval( -- ) ] unit-test [ ] [ "IN: compiler.units.tests << : nesting-test ( -- ) ; >>" eval( -- ) ] unit-test
observer remove-definition-observer observer remove-definition-observer
! Make sure that non-optimized calls to a generic word which
! hasn't been compiled yet work properly
GENERIC: uncompiled-generic-test ( a -- b )
M: integer uncompiled-generic-test 1 + ;
<< [ uncompiled-generic-test ] [ jit-compile ] [ suffix! ] bi >>
"q" set
[ 4 ] [ 3 "q" get call ] unit-test
FORGET: uncompiled-generic-test

View File

@ -24,7 +24,7 @@ cell factor_vm::compute_xt_pic_address(word *w, cell tagged_quot)
else else
{ {
quotation *quot = untag<quotation>(tagged_quot); quotation *quot = untag<quotation>(tagged_quot);
if(quot->code) if(quot_compiled_p(quot))
return (cell)quot->xt; return (cell)quot->xt;
else else
return (cell)w->xt; return (cell)w->xt;

View File

@ -293,8 +293,7 @@ code_block *factor_vm::jit_compile_quot(cell owner_, cell quot_, bool relocating
void factor_vm::jit_compile_quot(cell quot_, bool relocating) void factor_vm::jit_compile_quot(cell quot_, bool relocating)
{ {
data_root<quotation> quot(quot_,this); data_root<quotation> quot(quot_,this);
if(!quot_compiled_p(quot.untagged()))
if(quot->code == NULL || quot->code == lazy_jit_compile_block())
{ {
code_block *compiled = jit_compile_quot(quot.value(),quot.value(),relocating); code_block *compiled = jit_compile_quot(quot.value(),quot.value(),relocating);
set_quot_xt(quot.untagged(),compiled); set_quot_xt(quot.untagged(),compiled);
@ -356,11 +355,16 @@ VM_C_API cell lazy_jit_compile(cell quot, factor_vm *parent)
return parent->lazy_jit_compile(quot); return parent->lazy_jit_compile(quot);
} }
bool factor_vm::quot_compiled_p(quotation *quot)
{
return quot->code != NULL && quot->code != lazy_jit_compile_block();
}
void factor_vm::primitive_quot_compiled_p() void factor_vm::primitive_quot_compiled_p()
{ {
tagged<quotation> quot(ctx->pop()); tagged<quotation> quot(ctx->pop());
quot.untag_check(this); quot.untag_check(this);
ctx->push(tag_boolean(quot->code != lazy_jit_compile_block())); ctx->push(tag_boolean(quot_compiled_p(quot.untagged())));
} }
cell factor_vm::find_all_quotations() cell factor_vm::find_all_quotations()

View File

@ -606,6 +606,7 @@ struct factor_vm
void jit_compile_quot(cell quot_, bool relocating); void jit_compile_quot(cell quot_, bool relocating);
fixnum quot_code_offset_to_scan(cell quot_, cell offset); fixnum quot_code_offset_to_scan(cell quot_, cell offset);
cell lazy_jit_compile(cell quot); cell lazy_jit_compile(cell quot);
bool quot_compiled_p(quotation *quot);
void primitive_quot_compiled_p(); void primitive_quot_compiled_p();
cell find_all_quotations(); cell find_all_quotations();
void initialize_all_quotations(); void initialize_all_quotations();