moved quotations functions to vm

db4
Phil Dawes 2009-08-17 21:37:08 +01:00
parent 28620619e9
commit 2eca2ddeaf
2 changed files with 66 additions and 10 deletions

65
vm/quotations.cpp Normal file → Executable file
View File

@ -265,7 +265,7 @@ void quotation_jit::iterate_quotation()
} }
} }
void set_quot_xt(quotation *quot, code_block *code) void factorvm::set_quot_xt(quotation *quot, code_block *code)
{ {
if(code->type != QUOTATION_TYPE) if(code->type != QUOTATION_TYPE)
critical_error("Bad param to set_quot_xt",(cell)code); critical_error("Bad param to set_quot_xt",(cell)code);
@ -274,8 +274,13 @@ void set_quot_xt(quotation *quot, code_block *code)
quot->xt = code->xt(); quot->xt = code->xt();
} }
void set_quot_xt(quotation *quot, code_block *code)
{
return vm->set_quot_xt(quot,code);
}
/* Allocates memory */ /* Allocates memory */
void jit_compile(cell quot_, bool relocating) void factorvm::jit_compile(cell quot_, bool relocating)
{ {
gc_root<quotation> quot(quot_); gc_root<quotation> quot(quot_);
if(quot->code) return; if(quot->code) return;
@ -289,13 +294,23 @@ void jit_compile(cell quot_, bool relocating)
if(relocating) relocate_code_block(compiled); if(relocating) relocate_code_block(compiled);
} }
PRIMITIVE(jit_compile) void jit_compile(cell quot_, bool relocating)
{
return vm->jit_compile(quot_,relocating);
}
inline void factorvm::vmprim_jit_compile()
{ {
jit_compile(dpop(),true); jit_compile(dpop(),true);
} }
PRIMITIVE(jit_compile)
{
PRIMITIVE_GETVM()->vmprim_jit_compile();
}
/* push a new quotation on the stack */ /* push a new quotation on the stack */
PRIMITIVE(array_to_quotation) inline void factorvm::vmprim_array_to_quotation()
{ {
quotation *quot = allot<quotation>(sizeof(quotation)); quotation *quot = allot<quotation>(sizeof(quotation));
quot->array = dpeek(); quot->array = dpeek();
@ -306,13 +321,23 @@ PRIMITIVE(array_to_quotation)
drepl(tag<quotation>(quot)); drepl(tag<quotation>(quot));
} }
PRIMITIVE(quotation_xt) PRIMITIVE(array_to_quotation)
{
PRIMITIVE_GETVM()->vmprim_array_to_quotation();
}
inline void factorvm::vmprim_quotation_xt()
{ {
quotation *quot = untag_check<quotation>(dpeek()); quotation *quot = untag_check<quotation>(dpeek());
drepl(allot_cell((cell)quot->xt)); drepl(allot_cell((cell)quot->xt));
} }
void compile_all_words() PRIMITIVE(quotation_xt)
{
PRIMITIVE_GETVM()->vmprim_quotation_xt();
}
void factorvm::compile_all_words()
{ {
gc_root<array> words(find_all_words()); gc_root<array> words(find_all_words());
@ -329,11 +354,16 @@ void compile_all_words()
} }
iterate_code_heap(relocate_code_block); iterate_code_heap(factor::relocate_code_block);
}
void compile_all_words()
{
return vm->compile_all_words();
} }
/* Allocates memory */ /* Allocates memory */
fixnum quot_code_offset_to_scan(cell quot_, cell offset) fixnum factorvm::quot_code_offset_to_scan(cell quot_, cell offset)
{ {
gc_root<quotation> quot(quot_); gc_root<quotation> quot(quot_);
gc_root<array> array(quot->array); gc_root<array> array(quot->array);
@ -345,7 +375,12 @@ fixnum quot_code_offset_to_scan(cell quot_, cell offset)
return compiler.get_position(); return compiler.get_position();
} }
VM_ASM_API cell lazy_jit_compile_impl(cell quot_, stack_frame *stack) fixnum quot_code_offset_to_scan(cell quot_, cell offset)
{
return vm->quot_code_offset_to_scan(quot_,offset);
}
cell factorvm::lazy_jit_compile_impl(cell quot_, stack_frame *stack)
{ {
gc_root<quotation> quot(quot_); gc_root<quotation> quot(quot_);
stack_chain->callstack_top = stack; stack_chain->callstack_top = stack;
@ -353,11 +388,21 @@ VM_ASM_API cell lazy_jit_compile_impl(cell quot_, stack_frame *stack)
return quot.value(); return quot.value();
} }
PRIMITIVE(quot_compiled_p) VM_ASM_API cell lazy_jit_compile_impl(cell quot_, stack_frame *stack)
{
return vm->lazy_jit_compile_impl(quot_,stack);
}
inline void factorvm::vmprim_quot_compiled_p()
{ {
tagged<quotation> quot(dpop()); tagged<quotation> quot(dpop());
quot.untag_check(); quot.untag_check();
dpush(tag_boolean(quot->code != NULL)); dpush(tag_boolean(quot->code != NULL));
} }
PRIMITIVE(quot_compiled_p)
{
PRIMITIVE_GETVM()->vmprim_quot_compiled_p();
}
} }

View File

@ -455,6 +455,17 @@ struct factorvm {
void box_value_struct(void *src, cell size); void box_value_struct(void *src, cell size);
void box_small_struct(cell x, cell y, cell size); void box_small_struct(cell x, cell y, cell size);
void box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size); void box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size);
//quotations
inline void vmprim_jit_compile();
inline void vmprim_array_to_quotation();
inline void vmprim_quotation_xt();
void set_quot_xt(quotation *quot, code_block *code);
void jit_compile(cell quot_, bool relocating);
void compile_all_words();
fixnum quot_code_offset_to_scan(cell quot_, cell offset);
cell lazy_jit_compile_impl(cell quot_, stack_frame *stack);
inline void vmprim_quot_compiled_p();
// next method here: // next method here: