From c04fef10c7be44a1ce53235a617a81850b5591e5 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 6 Jan 2010 23:49:14 +1300 Subject: [PATCH] vm: ensure that non-optimized calls to generic words which have not yet been compiled can still work --- core/compiler/units/units-tests.factor | 15 ++++++++++++++- vm/code_blocks.cpp | 2 +- vm/quotations.cpp | 10 +++++++--- vm/vm.hpp | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/core/compiler/units/units-tests.factor b/core/compiler/units/units-tests.factor index eccc292f26..4d308ff545 100644 --- a/core/compiler/units/units-tests.factor +++ b/core/compiler/units/units-tests.factor @@ -1,5 +1,5 @@ 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 [ [ [ ] define-temp ] with-compilation-unit ] must-infer @@ -56,3 +56,16 @@ DEFER: nesting-test [ ] [ "IN: compiler.units.tests << : nesting-test ( -- ) ; >>" eval( -- ) ] unit-test 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 diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index ec7a0e8998..d72d30cc96 100755 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -24,7 +24,7 @@ cell factor_vm::compute_xt_pic_address(word *w, cell tagged_quot) else { quotation *quot = untag(tagged_quot); - if(quot->code) + if(quot_compiled_p(quot)) return (cell)quot->xt; else return (cell)w->xt; diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 73c28875fa..c33f9b5d6f 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -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) { data_root quot(quot_,this); - - if(quot->code == NULL || quot->code == lazy_jit_compile_block()) + if(!quot_compiled_p(quot.untagged())) { code_block *compiled = jit_compile_quot(quot.value(),quot.value(),relocating); 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); } +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() { tagged quot(ctx->pop()); 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() diff --git a/vm/vm.hpp b/vm/vm.hpp index 5f0858dab3..92e921000b 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -606,6 +606,7 @@ struct factor_vm void jit_compile_quot(cell quot_, bool relocating); fixnum quot_code_offset_to_scan(cell quot_, cell offset); cell lazy_jit_compile(cell quot); + bool quot_compiled_p(quotation *quot); void primitive_quot_compiled_p(); cell find_all_quotations(); void initialize_all_quotations();