diff --git a/basis/tools/deploy/test/test.factor b/basis/tools/deploy/test/test.factor index 908540254a..b93fddc3fe 100755 --- a/basis/tools/deploy/test/test.factor +++ b/basis/tools/deploy/test/test.factor @@ -15,7 +15,7 @@ IN: tools.deploy.test [ cell 4 / * cpu ppc? [ 100000 + ] when - os windows? [ 150000 + ] when + os windows? [ 250000 + ] when ] bi* <= ; diff --git a/vm/aging_collector.hpp b/vm/aging_collector.hpp index 2191797020..1fa82972ff 100644 --- a/vm/aging_collector.hpp +++ b/vm/aging_collector.hpp @@ -2,13 +2,13 @@ namespace factor { struct aging_policy { - factor_vm *myvm; + factor_vm *parent; zone *aging, *tenured; - aging_policy(factor_vm *myvm_) : - myvm(myvm_), - aging(myvm->data->aging), - tenured(myvm->data->tenured) {} + aging_policy(factor_vm *parent_) : + parent(parent_), + aging(parent->data->aging), + tenured(parent->data->tenured) {} bool should_copy_p(object *untagged) { @@ -17,7 +17,7 @@ struct aging_policy { }; struct aging_collector : copying_collector { - aging_collector(factor_vm *myvm_); + aging_collector(factor_vm *parent_); }; } diff --git a/vm/alien.cpp b/vm/alien.cpp index 84e40a4613..ed3adf5c9b 100755 --- a/vm/alien.cpp +++ b/vm/alien.cpp @@ -12,8 +12,8 @@ char *factor_vm::pinned_alien_offset(cell obj) case ALIEN_TYPE: { alien *ptr = untag(obj); - if(ptr->expired != F) - general_error(ERROR_EXPIRED,obj,F,NULL); + if(to_boolean(ptr->expired)) + general_error(ERROR_EXPIRED,obj,false_object,NULL); return pinned_alien_offset(ptr->base) + ptr->displacement; } case F_TYPE: @@ -40,7 +40,7 @@ cell factor_vm::allot_alien(cell delegate_, cell displacement) new_alien->base = delegate.value(); new_alien->displacement = displacement; - new_alien->expired = F; + new_alien->expired = false_object; return new_alien.value(); } @@ -51,8 +51,8 @@ void factor_vm::primitive_displaced_alien() cell alien = dpop(); cell displacement = to_cell(dpop()); - if(alien == F && displacement == 0) - dpush(F); + if(!to_boolean(alien) && displacement == 0) + dpush(false_object); else { switch(tagged(alien).type()) @@ -87,12 +87,12 @@ void *factor_vm::alien_pointer() #define DEFINE_ALIEN_ACCESSOR(name,type,boxer,to) \ PRIMITIVE(alien_##name) \ { \ - ((factor_vm*)myvm)->boxer(*(type*)((factor_vm*)myvm)->alien_pointer()); \ + parent->boxer(*(type*)(parent->alien_pointer())); \ } \ PRIMITIVE(set_alien_##name) \ { \ - type *ptr = (type *)((factor_vm*)myvm)->alien_pointer(); \ - type value = ((factor_vm*)myvm)->to(dpop()); \ + type *ptr = (type *)parent->alien_pointer(); \ + type value = parent->to(dpop()); \ *ptr = value; \ } @@ -130,17 +130,17 @@ void factor_vm::primitive_dlsym() symbol_char *sym = name->data(); - if(library.value() == F) - box_alien(ffi_dlsym(NULL,sym)); - else + if(to_boolean(library.value())) { dll *d = untag_check(library.value()); if(d->dll == NULL) - dpush(F); + dpush(false_object); else box_alien(ffi_dlsym(d,sym)); } + else + box_alien(ffi_dlsym(NULL,sym)); } /* close a native library handle */ @@ -154,10 +154,10 @@ void factor_vm::primitive_dlclose() void factor_vm::primitive_dll_validp() { cell library = dpop(); - if(library == F) - dpush(T); + if(to_boolean(library)) + dpush(tag_boolean(untag_check(library)->dll != NULL)); else - dpush(untag_check(library)->dll == NULL ? F : T); + dpush(true_object); } /* gets the address of an object representing a C pointer */ @@ -170,8 +170,8 @@ char *factor_vm::alien_offset(cell obj) case ALIEN_TYPE: { alien *ptr = untag(obj); - if(ptr->expired != F) - general_error(ERROR_EXPIRED,obj,F,NULL); + if(to_boolean(ptr->expired)) + general_error(ERROR_EXPIRED,obj,false_object,NULL); return alien_offset(ptr->base) + ptr->displacement; } case F_TYPE: @@ -182,9 +182,9 @@ char *factor_vm::alien_offset(cell obj) } } -VM_C_API char *alien_offset(cell obj, factor_vm *myvm) +VM_C_API char *alien_offset(cell obj, factor_vm *parent) { - return myvm->alien_offset(obj); + return parent->alien_offset(obj); } /* pop an object representing a C pointer */ @@ -193,23 +193,23 @@ char *factor_vm::unbox_alien() return alien_offset(dpop()); } -VM_C_API char *unbox_alien(factor_vm *myvm) +VM_C_API char *unbox_alien(factor_vm *parent) { - return myvm->unbox_alien(); + return parent->unbox_alien(); } /* make an alien and push */ void factor_vm::box_alien(void *ptr) { if(ptr == NULL) - dpush(F); + dpush(false_object); else - dpush(allot_alien(F,(cell)ptr)); + dpush(allot_alien(false_object,(cell)ptr)); } -VM_C_API void box_alien(void *ptr, factor_vm *myvm) +VM_C_API void box_alien(void *ptr, factor_vm *parent) { - return myvm->box_alien(ptr); + return parent->box_alien(ptr); } /* for FFI calls passing structs by value */ @@ -218,9 +218,9 @@ void factor_vm::to_value_struct(cell src, void *dest, cell size) memcpy(dest,alien_offset(src),size); } -VM_C_API void to_value_struct(cell src, void *dest, cell size, factor_vm *myvm) +VM_C_API void to_value_struct(cell src, void *dest, cell size, factor_vm *parent) { - return myvm->to_value_struct(src,dest,size); + return parent->to_value_struct(src,dest,size); } /* for FFI callbacks receiving structs by value */ @@ -231,9 +231,9 @@ void factor_vm::box_value_struct(void *src, cell size) dpush(tag(bytes)); } -VM_C_API void box_value_struct(void *src, cell size,factor_vm *myvm) +VM_C_API void box_value_struct(void *src, cell size,factor_vm *parent) { - return myvm->box_value_struct(src,size); + return parent->box_value_struct(src,size); } /* On some x86 OSes, structs <= 8 bytes are returned in registers. */ @@ -245,9 +245,9 @@ void factor_vm::box_small_struct(cell x, cell y, cell size) box_value_struct(data,size); } -VM_C_API void box_small_struct(cell x, cell y, cell size, factor_vm *myvm) +VM_C_API void box_small_struct(cell x, cell y, cell size, factor_vm *parent) { - return myvm->box_small_struct(x,y,size); + return parent->box_small_struct(x,y,size); } /* On OS X/PPC, complex numbers are returned in registers. */ @@ -261,9 +261,9 @@ void factor_vm::box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size) box_value_struct(data,size); } -VM_C_API void box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size, factor_vm *myvm) +VM_C_API void box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size, factor_vm *parent) { - return myvm->box_medium_struct(x1, x2, x3, x4, size); + return parent->box_medium_struct(x1, x2, x3, x4, size); } void factor_vm::primitive_vm_ptr() diff --git a/vm/arrays.cpp b/vm/arrays.cpp index b09ff5c5af..09c6998e69 100644 --- a/vm/arrays.cpp +++ b/vm/arrays.cpp @@ -71,33 +71,33 @@ void factor_vm::primitive_resize_array() void growable_array::add(cell elt_) { - factor_vm *parent_vm = elements.parent_vm; - gc_root elt(elt_,parent_vm); + factor_vm *parent = elements.parent; + gc_root elt(elt_,parent); if(count == array_capacity(elements.untagged())) - elements = parent_vm->reallot_array(elements.untagged(),count * 2); + elements = parent->reallot_array(elements.untagged(),count * 2); - parent_vm->set_array_nth(elements.untagged(),count++,elt.value()); + parent->set_array_nth(elements.untagged(),count++,elt.value()); } void growable_array::append(array *elts_) { - factor_vm *parent_vm = elements.parent_vm; - gc_root elts(elts_,parent_vm); + factor_vm *parent = elements.parent; + gc_root elts(elts_,parent); cell capacity = array_capacity(elts.untagged()); if(count + capacity > array_capacity(elements.untagged())) { - elements = parent_vm->reallot_array(elements.untagged(), + elements = parent->reallot_array(elements.untagged(), (count + capacity) * 2); } for(cell index = 0; index < capacity; index++) - parent_vm->set_array_nth(elements.untagged(),count++,array_nth(elts.untagged(),index)); + parent->set_array_nth(elements.untagged(),count++,array_nth(elts.untagged(),index)); } void growable_array::trim() { - factor_vm *parent_vm = elements.parent_vm; - elements = parent_vm->reallot_array(elements.untagged(),count); + factor_vm *parent = elements.parent; + elements = parent->reallot_array(elements.untagged(),count); } } diff --git a/vm/arrays.hpp b/vm/arrays.hpp index accf8b3b04..48be881230 100755 --- a/vm/arrays.hpp +++ b/vm/arrays.hpp @@ -26,7 +26,8 @@ struct growable_array { cell count; gc_root elements; - explicit growable_array(factor_vm *myvm, cell capacity = 10) : count(0), elements(myvm->allot_array(capacity,F),myvm) {} + explicit growable_array(factor_vm *parent, cell capacity = 10) : + count(0), elements(parent->allot_array(capacity,false_object),parent) {} void add(cell elt); void append(array *elts); diff --git a/vm/booleans.cpp b/vm/booleans.cpp index f1f0230c13..a7871dcbcb 100644 --- a/vm/booleans.cpp +++ b/vm/booleans.cpp @@ -5,22 +5,17 @@ namespace factor void factor_vm::box_boolean(bool value) { - dpush(value ? T : F); + dpush(tag_boolean(value)); } -VM_C_API void box_boolean(bool value, factor_vm *myvm) +VM_C_API void box_boolean(bool value, factor_vm *parent) { - return myvm->box_boolean(value); + return parent->box_boolean(value); } -bool factor_vm::to_boolean(cell value) +VM_C_API bool to_boolean(cell value, factor_vm *parent) { - return value != F; -} - -VM_C_API bool to_boolean(cell value, factor_vm *myvm) -{ - return myvm->to_boolean(value); + return parent->to_boolean(value); } } diff --git a/vm/booleans.hpp b/vm/booleans.hpp index 498c3f74be..375c8e3756 100644 --- a/vm/booleans.hpp +++ b/vm/booleans.hpp @@ -6,7 +6,12 @@ VM_C_API bool to_boolean(cell value, factor_vm *vm); inline cell factor_vm::tag_boolean(cell untagged) { - return (untagged ? T : F); + return (untagged ? true_object : false_object); +} + +inline bool factor_vm::to_boolean(cell value) +{ + return value != false_object; } } diff --git a/vm/byte_arrays.cpp b/vm/byte_arrays.cpp index 91155c96d2..56b5db7ad8 100644 --- a/vm/byte_arrays.cpp +++ b/vm/byte_arrays.cpp @@ -32,9 +32,9 @@ void factor_vm::primitive_resize_byte_array() void growable_byte_array::append_bytes(void *elts, cell len) { cell new_size = count + len; - factor_vm *parent_vm = elements.parent_vm; + factor_vm *parent = elements.parent; if(new_size >= array_capacity(elements.untagged())) - elements = parent_vm->reallot_array(elements.untagged(),new_size * 2); + elements = parent->reallot_array(elements.untagged(),new_size * 2); memcpy(&elements->data()[count],elts,len); @@ -43,13 +43,13 @@ void growable_byte_array::append_bytes(void *elts, cell len) void growable_byte_array::append_byte_array(cell byte_array_) { - gc_root byte_array(byte_array_,elements.parent_vm); + gc_root byte_array(byte_array_,elements.parent); cell len = array_capacity(byte_array.untagged()); cell new_size = count + len; - factor_vm *parent_vm = elements.parent_vm; + factor_vm *parent = elements.parent; if(new_size >= array_capacity(elements.untagged())) - elements = parent_vm->reallot_array(elements.untagged(),new_size * 2); + elements = parent->reallot_array(elements.untagged(),new_size * 2); memcpy(&elements->data()[count],byte_array->data(),len); @@ -58,8 +58,8 @@ void growable_byte_array::append_byte_array(cell byte_array_) void growable_byte_array::trim() { - factor_vm *parent_vm = elements.parent_vm; - elements = parent_vm->reallot_array(elements.untagged(),count); + factor_vm *parent = elements.parent; + elements = parent->reallot_array(elements.untagged(),count); } } diff --git a/vm/byte_arrays.hpp b/vm/byte_arrays.hpp index e5a1e6a842..8ca95d9d1e 100755 --- a/vm/byte_arrays.hpp +++ b/vm/byte_arrays.hpp @@ -5,7 +5,7 @@ struct growable_byte_array { cell count; gc_root elements; - explicit growable_byte_array(factor_vm *myvm,cell capacity = 40) : count(0), elements(myvm->allot_byte_array(capacity),myvm) { } + explicit growable_byte_array(factor_vm *parent,cell capacity = 40) : count(0), elements(parent->allot_byte_array(capacity),parent) { } void append_bytes(void *elts, cell len); void append_byte_array(cell elts); diff --git a/vm/callbacks.cpp b/vm/callbacks.cpp index 2401800a9a..dca0eb6c24 100644 --- a/vm/callbacks.cpp +++ b/vm/callbacks.cpp @@ -3,10 +3,10 @@ namespace factor { -callback_heap::callback_heap(cell size, factor_vm *myvm_) : +callback_heap::callback_heap(cell size, factor_vm *parent_) : seg(new segment(size,true)), here(seg->start), - myvm(myvm_) {} + parent(parent_) {} callback_heap::~callback_heap() { @@ -21,12 +21,12 @@ void factor_vm::init_callbacks(cell size) void callback_heap::update(callback *stub) { - tagged code_template(myvm->userenv[CALLBACK_STUB]); + tagged code_template(parent->userenv[CALLBACK_STUB]); cell rel_class = untag_fixnum(array_nth(code_template.untagged(),1)); cell offset = untag_fixnum(array_nth(code_template.untagged(),3)); - myvm->store_address_in_code_block(rel_class, + parent->store_address_in_code_block(rel_class, (cell)(stub + 1) + offset, (cell)(stub->compiled + 1)); @@ -35,7 +35,7 @@ void callback_heap::update(callback *stub) callback *callback_heap::add(code_block *compiled) { - tagged code_template(myvm->userenv[CALLBACK_STUB]); + tagged code_template(parent->userenv[CALLBACK_STUB]); tagged insns(array_nth(code_template.untagged(),0)); cell size = array_capacity(insns.untagged()); diff --git a/vm/callbacks.hpp b/vm/callbacks.hpp index 571c7713c7..c499ad4719 100644 --- a/vm/callbacks.hpp +++ b/vm/callbacks.hpp @@ -10,9 +10,9 @@ struct callback { struct callback_heap { segment *seg; cell here; - factor_vm *myvm; + factor_vm *parent; - explicit callback_heap(cell size, factor_vm *myvm); + explicit callback_heap(cell size, factor_vm *parent); ~callback_heap(); callback *add(code_block *compiled); diff --git a/vm/callstack.cpp b/vm/callstack.cpp index 0b7663e513..4721fc4ece 100755 --- a/vm/callstack.cpp +++ b/vm/callstack.cpp @@ -100,22 +100,22 @@ cell factor_vm::frame_scan(stack_frame *frame) case QUOTATION_TYPE: { cell quot = frame_executing(frame); - if(quot == F) - return F; - else + if(to_boolean(quot)) { char *return_addr = (char *)FRAME_RETURN_ADDRESS(frame,this); char *quot_xt = (char *)(frame_code(frame) + 1); return tag_fixnum(quot_code_offset_to_scan( quot,(cell)(return_addr - quot_xt))); - } + } + else + return false_object; } case WORD_TYPE: - return F; + return false_object; default: critical_error("Bad frame type",frame_type(frame)); - return F; + return false_object; } } @@ -123,15 +123,15 @@ namespace { struct stack_frame_accumulator { - factor_vm *myvm; + factor_vm *parent; growable_array frames; - explicit stack_frame_accumulator(factor_vm *myvm_) : myvm(myvm_), frames(myvm_) {} + explicit stack_frame_accumulator(factor_vm *parent_) : parent(parent_), frames(parent_) {} void operator()(stack_frame *frame) { - gc_root executing(myvm->frame_executing(frame),myvm); - gc_root scan(myvm->frame_scan(frame),myvm); + gc_root executing(parent->frame_executing(frame),parent); + gc_root scan(parent->frame_scan(frame),parent); frames.add(executing.value()); frames.add(scan.value()); @@ -204,9 +204,9 @@ void factor_vm::save_callstack_bottom(stack_frame *callstack_bottom) ctx->callstack_bottom = callstack_bottom; } -VM_ASM_API void save_callstack_bottom(stack_frame *callstack_bottom, factor_vm *myvm) +VM_ASM_API void save_callstack_bottom(stack_frame *callstack_bottom, factor_vm *parent) { - return myvm->save_callstack_bottom(callstack_bottom); + return parent->save_callstack_bottom(callstack_bottom); } } diff --git a/vm/code_block.cpp b/vm/code_block.cpp index 0afd98dd0f..1f77148b5c 100755 --- a/vm/code_block.cpp +++ b/vm/code_block.cpp @@ -66,7 +66,7 @@ void *factor_vm::object_xt(cell obj) void *factor_vm::xt_pic(word *w, cell tagged_quot) { - if(tagged_quot == F || max_pic_size == 0) + if(!to_boolean(tagged_quot) || max_pic_size == 0) return w->xt; else { @@ -92,7 +92,7 @@ void *factor_vm::word_xt_pic_tail(word *w) image load */ void factor_vm::undefined_symbol() { - general_error(ERROR_UNDEFINED_SYMBOL,F,F,NULL); + general_error(ERROR_UNDEFINED_SYMBOL,false_object,false_object,NULL); } void undefined_symbol() @@ -106,7 +106,7 @@ void *factor_vm::get_rel_symbol(array *literals, cell index) cell symbol = array_nth(literals,index); cell library = array_nth(literals,index + 1); - dll *d = (library == F ? NULL : untag(library)); + dll *d = (to_boolean(library) ? untag(library) : NULL); if(d != NULL && !d->dll) return (void *)factor::undefined_symbol; @@ -147,8 +147,8 @@ void *factor_vm::get_rel_symbol(array *literals, cell index) cell factor_vm::compute_relocation(relocation_entry rel, cell index, code_block *compiled) { - array *literals = (compiled->literals == F - ? NULL : untag(compiled->literals)); + array *literals = (to_boolean(compiled->literals) + ? untag(compiled->literals) : NULL); cell offset = relocation_offset_of(rel) + (cell)compiled->xt(); #define ARG array_nth(literals,index) @@ -196,7 +196,7 @@ cell factor_vm::compute_relocation(relocation_entry rel, cell index, code_block template void factor_vm::iterate_relocations(code_block *compiled, Iterator &iter) { - if(compiled->relocation != F) + if(to_boolean(compiled->relocation)) { byte_array *relocation = untag(compiled->relocation); @@ -277,18 +277,18 @@ void factor_vm::store_address_in_code_block(cell klass, cell offset, fixnum abso } struct literal_references_updater { - factor_vm *myvm; + factor_vm *parent; - explicit literal_references_updater(factor_vm *myvm_) : myvm(myvm_) {} + explicit literal_references_updater(factor_vm *parent_) : parent(parent_) {} void operator()(relocation_entry rel, cell index, code_block *compiled) { - if(myvm->relocation_type_of(rel) == RT_IMMEDIATE) + if(parent->relocation_type_of(rel) == RT_IMMEDIATE) { - cell offset = myvm->relocation_offset_of(rel) + (cell)(compiled + 1); - array *literals = myvm->untag(compiled->literals); + cell offset = parent->relocation_offset_of(rel) + (cell)(compiled + 1); + array *literals = parent->untag(compiled->literals); fixnum absolute_value = array_nth(literals,index); - myvm->store_address_in_code_block(myvm->relocation_class_of(rel),offset,absolute_value); + parent->store_address_in_code_block(parent->relocation_class_of(rel),offset,absolute_value); } } }; @@ -308,9 +308,9 @@ void factor_vm::update_literal_references(code_block *compiled) void factor_vm::relocate_code_block_step(relocation_entry rel, cell index, code_block *compiled) { #ifdef FACTOR_DEBUG - if(compiled->literals != F) + if(to_boolean(compiled->literals)) tagged(compiled->literals).untag_check(this); - if(compiled->relocation != F) + if(to_boolean(compiled->relocation)) tagged(compiled->relocation).untag_check(this); #endif @@ -320,14 +320,14 @@ void factor_vm::relocate_code_block_step(relocation_entry rel, cell index, code_ } struct word_references_updater { - factor_vm *myvm; + factor_vm *parent; - explicit word_references_updater(factor_vm *myvm_) : myvm(myvm_) {} + explicit word_references_updater(factor_vm *parent_) : parent(parent_) {} void operator()(relocation_entry rel, cell index, code_block *compiled) { - relocation_type type = myvm->relocation_type_of(rel); + relocation_type type = parent->relocation_type_of(rel); if(type == RT_XT || type == RT_XT_PIC || type == RT_XT_PIC_TAIL) - myvm->relocate_code_block_step(rel,index,compiled); + parent->relocate_code_block_step(rel,index,compiled); } }; @@ -358,20 +358,20 @@ void factor_vm::update_word_references(code_block *compiled) /* This runs after a full collection */ struct literal_and_word_references_updater { - factor_vm *myvm; + factor_vm *parent; - explicit literal_and_word_references_updater(factor_vm *myvm_) : myvm(myvm_) {} + explicit literal_and_word_references_updater(factor_vm *parent_) : parent(parent_) {} void operator()(relocation_entry rel, cell index, code_block *compiled) { - relocation_type type = myvm->relocation_type_of(rel); + relocation_type type = parent->relocation_type_of(rel); switch(type) { case RT_IMMEDIATE: case RT_XT: case RT_XT_PIC: case RT_XT_PIC_TAIL: - myvm->relocate_code_block_step(rel,index,compiled); + parent->relocate_code_block_step(rel,index,compiled); break; default: break; @@ -399,13 +399,13 @@ void factor_vm::check_code_address(cell address) } struct code_block_relocator { - factor_vm *myvm; + factor_vm *parent; - explicit code_block_relocator(factor_vm *myvm_) : myvm(myvm_) {} + explicit code_block_relocator(factor_vm *parent_) : parent(parent_) {} void operator()(relocation_entry rel, cell index, code_block *compiled) { - myvm->relocate_code_block_step(rel,index,compiled); + parent->relocate_code_block_step(rel,index,compiled); } }; @@ -484,12 +484,12 @@ code_block *factor_vm::add_code_block(cell type, cell code_, cell labels_, cell /* slight space optimization */ if(relocation.type() == BYTE_ARRAY_TYPE && array_capacity(relocation.untagged()) == 0) - compiled->relocation = F; + compiled->relocation = false_object; else compiled->relocation = relocation.value(); if(literals.type() == ARRAY_TYPE && array_capacity(literals.untagged()) == 0) - compiled->literals = F; + compiled->literals = false_object; else compiled->literals = literals.value(); @@ -497,7 +497,7 @@ code_block *factor_vm::add_code_block(cell type, cell code_, cell labels_, cell memcpy(compiled + 1,code.untagged() + 1,code_length); /* fixup labels */ - if(labels.value() != F) + if(to_boolean(labels.value())) fixup_labels(labels.as().untagged(),compiled); /* next time we do a minor GC, we have to scan the code heap for diff --git a/vm/code_heap.cpp b/vm/code_heap.cpp index b7307dd7e6..288c2221f2 100755 --- a/vm/code_heap.cpp +++ b/vm/code_heap.cpp @@ -51,17 +51,17 @@ void factor_vm::jit_compile_word(cell word_, cell def_, bool relocate) word->code = def->code; - if(word->pic_def != F) jit_compile(word->pic_def,relocate); - if(word->pic_tail_def != F) jit_compile(word->pic_tail_def,relocate); + if(to_boolean(word->pic_def)) jit_compile(word->pic_def,relocate); + if(to_boolean(word->pic_tail_def)) jit_compile(word->pic_tail_def,relocate); } struct word_updater { - factor_vm *myvm; + factor_vm *parent; - explicit word_updater(factor_vm *myvm_) : myvm(myvm_) {} + explicit word_updater(factor_vm *parent_) : parent(parent_) {} void operator()(code_block *compiled) { - myvm->update_word_references(compiled); + parent->update_word_references(compiled); } }; @@ -143,18 +143,18 @@ code_block *code_heap::forward_code_block(code_block *compiled) } struct callframe_forwarder { - factor_vm *myvm; + factor_vm *parent; - explicit callframe_forwarder(factor_vm *myvm_) : myvm(myvm_) {} + explicit callframe_forwarder(factor_vm *parent_) : parent(parent_) {} void operator()(stack_frame *frame) { - cell offset = (cell)FRAME_RETURN_ADDRESS(frame,myvm) - (cell)frame->xt; + cell offset = (cell)FRAME_RETURN_ADDRESS(frame,parent) - (cell)frame->xt; - code_block *forwarded = myvm->code->forward_code_block(myvm->frame_code(frame)); + code_block *forwarded = parent->code->forward_code_block(parent->frame_code(frame)); frame->xt = forwarded->xt(); - FRAME_RETURN_ADDRESS(frame,myvm) = (void *)((cell)frame->xt + offset); + FRAME_RETURN_ADDRESS(frame,parent) = (void *)((cell)frame->xt + offset); } }; @@ -164,7 +164,7 @@ void factor_vm::forward_object_xts() cell obj; - while((obj = next_object()) != F) + while(to_boolean(obj = next_object())) { switch(tagged(obj).type()) { @@ -251,7 +251,7 @@ struct stack_trace_stripper { void operator()(code_block *compiled) { - compiled->owner = F; + compiled->owner = false_object; } }; diff --git a/vm/collector.hpp b/vm/collector.hpp index 8156fd1693..bbaad1d570 100644 --- a/vm/collector.hpp +++ b/vm/collector.hpp @@ -2,7 +2,7 @@ namespace factor { template struct collector { - factor_vm *myvm; + factor_vm *parent; data_heap *data; code_heap *code; gc_state *current_gc; @@ -10,18 +10,18 @@ template struct collector { TargetGeneration *target; Policy policy; - explicit collector(factor_vm *myvm_, generation_statistics *stats_, TargetGeneration *target_, Policy policy_) : - myvm(myvm_), - data(myvm_->data), - code(myvm_->code), - current_gc(myvm_->current_gc), + explicit collector(factor_vm *parent_, generation_statistics *stats_, TargetGeneration *target_, Policy policy_) : + parent(parent_), + data(parent_->data), + code(parent_->code), + current_gc(parent_->current_gc), stats(stats_), target(target_), policy(policy_) {} object *resolve_forwarding(object *untagged) { - myvm->check_data_pointer(untagged); + parent->check_data_pointer(untagged); /* is there another forwarding pointer? */ while(untagged->h.forwarding_pointer_p()) @@ -38,7 +38,7 @@ template struct collector { if(immediate_p(pointer)) return; - object *untagged = myvm->untag(pointer); + object *untagged = parent->untag(pointer); if(!policy.should_copy_p(untagged)) return; @@ -57,7 +57,7 @@ template struct collector { void trace_slots(object *ptr) { cell *slot = (cell *)ptr; - cell *end = (cell *)((cell)ptr + myvm->binary_payload_start(ptr)); + cell *end = (cell *)((cell)ptr + parent->binary_payload_start(ptr)); if(slot != end) { @@ -68,7 +68,7 @@ template struct collector { object *promote_object(object *untagged) { - cell size = myvm->untagged_object_size(untagged); + cell size = parent->untagged_object_size(untagged); object *newpointer = target->allot(size); /* XXX not exception-safe */ if(!newpointer) longjmp(current_gc->gc_unwind,1); @@ -90,8 +90,8 @@ template struct collector { void trace_registered_locals() { - std::vector::const_iterator iter = myvm->gc_locals.begin(); - std::vector::const_iterator end = myvm->gc_locals.end(); + std::vector::const_iterator iter = parent->gc_locals.begin(); + std::vector::const_iterator end = parent->gc_locals.end(); for(; iter < end; iter++) trace_handle((cell *)(*iter)); @@ -99,8 +99,8 @@ template struct collector { void trace_registered_bignums() { - std::vector::const_iterator iter = myvm->gc_bignums.begin(); - std::vector::const_iterator end = myvm->gc_bignums.end(); + std::vector::const_iterator iter = parent->gc_bignums.begin(); + std::vector::const_iterator end = parent->gc_bignums.end(); for(; iter < end; iter++) { @@ -119,20 +119,20 @@ template struct collector { the user environment and extra roots registered by local_roots.hpp */ void trace_roots() { - trace_handle(&myvm->T); - trace_handle(&myvm->bignum_zero); - trace_handle(&myvm->bignum_pos_one); - trace_handle(&myvm->bignum_neg_one); + trace_handle(&parent->true_object); + trace_handle(&parent->bignum_zero); + trace_handle(&parent->bignum_pos_one); + trace_handle(&parent->bignum_neg_one); trace_registered_locals(); trace_registered_bignums(); - for(int i = 0; i < USER_ENV; i++) trace_handle(&myvm->userenv[i]); + for(int i = 0; i < USER_ENV; i++) trace_handle(&parent->userenv[i]); } void trace_contexts() { - context *ctx = myvm->ctx; + context *ctx = parent->ctx; while(ctx) { diff --git a/vm/contexts.cpp b/vm/contexts.cpp index bed044250e..cc7029e7f1 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -91,9 +91,9 @@ void factor_vm::nest_stacks(stack_frame *magic_frame) reset_retainstack(); } -void nest_stacks(stack_frame *magic_frame, factor_vm *myvm) +void nest_stacks(stack_frame *magic_frame, factor_vm *parent) { - return myvm->nest_stacks(magic_frame); + return parent->nest_stacks(magic_frame); } /* called when leaving a compiled callback */ @@ -111,9 +111,9 @@ void factor_vm::unnest_stacks() dealloc_context(old_ctx); } -void unnest_stacks(factor_vm *myvm) +void unnest_stacks(factor_vm *parent) { - return myvm->unnest_stacks(); + return parent->unnest_stacks(); } /* called on startup */ @@ -143,13 +143,13 @@ bool factor_vm::stack_to_array(cell bottom, cell top) void factor_vm::primitive_datastack() { if(!stack_to_array(ds_bot,ds)) - general_error(ERROR_DS_UNDERFLOW,F,F,NULL); + general_error(ERROR_DS_UNDERFLOW,false_object,false_object,NULL); } void factor_vm::primitive_retainstack() { if(!stack_to_array(rs_bot,rs)) - general_error(ERROR_RS_UNDERFLOW,F,F,NULL); + general_error(ERROR_RS_UNDERFLOW,false_object,false_object,NULL); } /* returns pointer to top of stack */ @@ -180,7 +180,7 @@ void factor_vm::primitive_check_datastack() fixnum saved_height = array_capacity(saved_datastack); fixnum current_height = (ds - ds_bot + sizeof(cell)) / sizeof(cell); if(current_height - height != saved_height) - dpush(F); + dpush(false_object); else { fixnum i; @@ -188,11 +188,11 @@ void factor_vm::primitive_check_datastack() { if(((cell *)ds_bot)[i] != array_nth(saved_datastack,i)) { - dpush(F); + dpush(false_object); return; } } - dpush(T); + dpush(true_object); } } diff --git a/vm/copying_collector.hpp b/vm/copying_collector.hpp index 297e70e687..640d355bf4 100644 --- a/vm/copying_collector.hpp +++ b/vm/copying_collector.hpp @@ -15,8 +15,8 @@ template struct copying_collector : collector { cell scan; - explicit copying_collector(factor_vm *myvm_, generation_statistics *stats_, TargetGeneration *target_, Policy policy_) : - collector(myvm_,stats_,target_,policy_), scan(target_->here) {} + explicit copying_collector(factor_vm *parent_, generation_statistics *stats_, TargetGeneration *target_, Policy policy_) : + collector(parent_,stats_,target_,policy_), scan(target_->here) {} inline cell first_card_in_deck(cell deck) { @@ -82,7 +82,7 @@ struct copying_collector : collector { { if(decks[deck_index] & mask) { - this->myvm->gc_stats.decks_scanned++; + this->parent->gc_stats.decks_scanned++; cell first_card = first_card_in_deck(deck_index); cell last_card = last_card_in_deck(deck_index); @@ -91,13 +91,13 @@ struct copying_collector : collector { { if(cards[card_index] & mask) { - this->myvm->gc_stats.cards_scanned++; + this->parent->gc_stats.cards_scanned++; if(end < card_start_address(card_index)) { start = gen->find_object_containing_card(card_index - gen_start_card); - binary_start = start + this->myvm->binary_payload_start((object *)start); - end = start + this->myvm->untagged_object_size((object *)start); + binary_start = start + this->parent->binary_payload_start((object *)start); + end = start + this->parent->untagged_object_size((object *)start); } #ifdef FACTOR_DEBUG @@ -113,11 +113,11 @@ scan_next_object: { card_end_address(card_index)); if(end < card_end_address(card_index)) { - start = gen->next_object_after(this->myvm,start); + start = gen->next_object_after(this->parent,start); if(start) { - binary_start = start + this->myvm->binary_payload_start((object *)start); - end = start + this->myvm->untagged_object_size((object *)start); + binary_start = start + this->parent->binary_payload_start((object *)start); + end = start + this->parent->untagged_object_size((object *)start); goto scan_next_object; } } @@ -133,7 +133,7 @@ scan_next_object: { } } -end: this->myvm->gc_stats.card_scan_time += (current_micros() - start_time); +end: this->parent->gc_stats.card_scan_time += (current_micros() - start_time); } /* Trace all literals referenced from a code block. Only for aging and nursery collections */ @@ -142,7 +142,7 @@ end: this->myvm->gc_stats.card_scan_time += (current_micros() - start_time); this->trace_handle(&compiled->owner); this->trace_handle(&compiled->literals); this->trace_handle(&compiled->relocation); - this->myvm->gc_stats.code_blocks_scanned++; + this->parent->gc_stats.code_blocks_scanned++; } void trace_code_heap_roots(std::set *remembered_set) @@ -158,7 +158,7 @@ end: this->myvm->gc_stats.card_scan_time += (current_micros() - start_time); while(scan && scan < this->target->here) { this->trace_slots((object *)scan); - scan = this->target->next_object_after(this->myvm,scan); + scan = this->target->next_object_after(this->parent,scan); } } }; diff --git a/vm/data_heap.cpp b/vm/data_heap.cpp index 6b09953314..335938acab 100755 --- a/vm/data_heap.cpp +++ b/vm/data_heap.cpp @@ -240,10 +240,10 @@ void factor_vm::primitive_begin_scan() cell factor_vm::next_object() { if(!gc_off) - general_error(ERROR_HEAP_SCAN,F,F,NULL); + general_error(ERROR_HEAP_SCAN,false_object,false_object,NULL); if(heap_scan_ptr >= data->tenured->here) - return F; + return false_object; object *obj = (object *)heap_scan_ptr; heap_scan_ptr += untagged_object_size(obj); @@ -266,7 +266,7 @@ template void factor_vm::each_object(Iterator &iterator) { begin_scan(); cell obj; - while((obj = next_object()) != F) + while(to_boolean(obj = next_object())) iterator(tagged(obj)); end_scan(); } diff --git a/vm/debug.cpp b/vm/debug.cpp index da8c603254..abeaa0c3c3 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -165,23 +165,23 @@ void factor_vm::print_retainstack() } struct stack_frame_printer { - factor_vm *myvm; + factor_vm *parent; - explicit stack_frame_printer(factor_vm *myvm_) : myvm(myvm_) {} + explicit stack_frame_printer(factor_vm *parent_) : parent(parent_) {} void operator()(stack_frame *frame) { - myvm->print_obj(myvm->frame_executing(frame)); + parent->print_obj(parent->frame_executing(frame)); print_string("\n"); - myvm->print_obj(myvm->frame_scan(frame)); + parent->print_obj(parent->frame_scan(frame)); print_string("\n"); print_string("word/quot addr: "); - print_cell_hex((cell)myvm->frame_executing(frame)); + print_cell_hex((cell)parent->frame_executing(frame)); print_string("\n"); print_string("word/quot xt: "); print_cell_hex((cell)frame->xt); print_string("\n"); print_string("return address: "); - print_cell_hex((cell)FRAME_RETURN_ADDRESS(frame,myvm)); + print_cell_hex((cell)FRAME_RETURN_ADDRESS(frame,parent)); print_string("\n"); } }; @@ -236,7 +236,7 @@ void factor_vm::dump_objects(cell type) begin_scan(); cell obj; - while((obj = next_object()) != F) + while(to_boolean(obj = next_object())) { if(type == TYPE_COUNT || tagged(obj).type_p(type)) { @@ -252,10 +252,10 @@ void factor_vm::dump_objects(cell type) struct data_references_finder { cell look_for, obj; - factor_vm *myvm; + factor_vm *parent; - explicit data_references_finder(cell look_for_, cell obj_, factor_vm *myvm_) - : look_for(look_for_), obj(obj_), myvm(myvm_) { } + explicit data_references_finder(cell look_for_, cell obj_, factor_vm *parent_) + : look_for(look_for_), obj(obj_), parent(parent_) { } void operator()(cell *scan) { @@ -263,7 +263,7 @@ struct data_references_finder { { print_cell_hex_pad(obj); print_string(" "); - myvm->print_nested_obj(obj,2); + parent->print_nested_obj(obj,2); nl(); } } @@ -275,7 +275,7 @@ void factor_vm::find_data_references(cell look_for) cell obj; - while((obj = next_object()) != F) + while(to_boolean(obj = next_object())) { data_references_finder finder(look_for,obj,this); do_slots(UNTAG(obj),finder); diff --git a/vm/dispatch.cpp b/vm/dispatch.cpp index 03323f811d..0abde2e711 100755 --- a/vm/dispatch.cpp +++ b/vm/dispatch.cpp @@ -15,14 +15,14 @@ cell factor_vm::search_lookup_alist(cell table, cell klass) index -= 2; } - return F; + return false_object; } cell factor_vm::search_lookup_hash(cell table, cell klass, cell hashcode) { array *buckets = untag(table); cell bucket = array_nth(buckets,hashcode & (array_capacity(buckets) - 1)); - if(tagged(bucket).type_p(WORD_TYPE) || bucket == F) + if(tagged(bucket).type_p(WORD_TYPE) || !to_boolean(bucket)) return bucket; else return search_lookup_alist(bucket,klass); @@ -56,12 +56,12 @@ cell factor_vm::lookup_tuple_method(cell obj, cell methods) if(tagged(echelon_methods).type_p(WORD_TYPE)) return echelon_methods; - else if(echelon_methods != F) + else if(to_boolean(echelon_methods)) { cell klass = nth_superclass(layout,echelon); cell hashcode = untag_fixnum(nth_hashcode(layout,echelon)); cell result = search_lookup_hash(echelon_methods,klass,hashcode); - if(result != F) + if(to_boolean(result)) return result; } @@ -69,7 +69,7 @@ cell factor_vm::lookup_tuple_method(cell obj, cell methods) } critical_error("Cannot find tuple method",methods); - return F; + return false_object; } cell factor_vm::lookup_hi_tag_method(cell obj, cell methods) @@ -180,28 +180,28 @@ void factor_vm::primitive_dispatch_stats() void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, cell cache_) { - gc_root methods(methods_,parent_vm); - gc_root cache(cache_,parent_vm); + gc_root methods(methods_,parent); + gc_root cache(cache_,parent); /* Generate machine code to determine the object's class. */ emit_class_lookup(index,PIC_HI_TAG_TUPLE); /* Do a cache lookup. */ - emit_with(parent_vm->userenv[MEGA_LOOKUP],cache.value()); + emit_with(parent->userenv[MEGA_LOOKUP],cache.value()); /* If we end up here, the cache missed. */ - emit(parent_vm->userenv[JIT_PROLOG]); + emit(parent->userenv[JIT_PROLOG]); /* Push index, method table and cache on the stack. */ push(methods.value()); push(tag_fixnum(index)); push(cache.value()); - word_call(parent_vm->userenv[MEGA_MISS_WORD]); + word_call(parent->userenv[MEGA_MISS_WORD]); /* Now the new method has been stored into the cache, and its on the stack. */ - emit(parent_vm->userenv[JIT_EPILOG]); - emit(parent_vm->userenv[JIT_EXECUTE_JUMP]); + emit(parent->userenv[JIT_EPILOG]); + emit(parent->userenv[JIT_EXECUTE_JUMP]); } } diff --git a/vm/errors.cpp b/vm/errors.cpp index a3c0242d7e..a1fc71ffbc 100755 --- a/vm/errors.cpp +++ b/vm/errors.cpp @@ -29,7 +29,7 @@ void factor_vm::throw_error(cell error, stack_frame *callstack_top) { /* If the error handler is set, we rewind any C stack frames and pass the error to user-space. */ - if(!current_gc && userenv[BREAK_ENV] != F) + if(!current_gc && to_boolean(userenv[BREAK_ENV])) { /* If error was thrown during heap scan, we re-enable the GC */ gc_off = false; @@ -80,7 +80,7 @@ void factor_vm::type_error(cell type, cell tagged) void factor_vm::not_implemented_error() { - general_error(ERROR_NOT_IMPLEMENTED,F,F,NULL); + general_error(ERROR_NOT_IMPLEMENTED,false_object,false_object,NULL); } /* Test if 'fault' is in the guard page at the top or bottom (depending on @@ -97,32 +97,32 @@ bool factor_vm::in_page(cell fault, cell area, cell area_size, int offset) void factor_vm::memory_protection_error(cell addr, stack_frame *native_stack) { if(in_page(addr, ds_bot, 0, -1)) - general_error(ERROR_DS_UNDERFLOW,F,F,native_stack); + general_error(ERROR_DS_UNDERFLOW,false_object,false_object,native_stack); else if(in_page(addr, ds_bot, ds_size, 0)) - general_error(ERROR_DS_OVERFLOW,F,F,native_stack); + general_error(ERROR_DS_OVERFLOW,false_object,false_object,native_stack); else if(in_page(addr, rs_bot, 0, -1)) - general_error(ERROR_RS_UNDERFLOW,F,F,native_stack); + general_error(ERROR_RS_UNDERFLOW,false_object,false_object,native_stack); else if(in_page(addr, rs_bot, rs_size, 0)) - general_error(ERROR_RS_OVERFLOW,F,F,native_stack); + general_error(ERROR_RS_OVERFLOW,false_object,false_object,native_stack); else if(in_page(addr, nursery.end, 0, 0)) critical_error("allot_object() missed GC check",0); else - general_error(ERROR_MEMORY,allot_cell(addr),F,native_stack); + general_error(ERROR_MEMORY,allot_cell(addr),false_object,native_stack); } void factor_vm::signal_error(int signal, stack_frame *native_stack) { - general_error(ERROR_SIGNAL,tag_fixnum(signal),F,native_stack); + general_error(ERROR_SIGNAL,tag_fixnum(signal),false_object,native_stack); } void factor_vm::divide_by_zero_error() { - general_error(ERROR_DIVIDE_BY_ZERO,F,F,NULL); + general_error(ERROR_DIVIDE_BY_ZERO,false_object,false_object,NULL); } void factor_vm::fp_trap_error(unsigned int fpu_status, stack_frame *signal_callstack_top) { - general_error(ERROR_FP_TRAP,tag_fixnum(fpu_status),F,signal_callstack_top); + general_error(ERROR_FP_TRAP,tag_fixnum(fpu_status),false_object,signal_callstack_top); } void factor_vm::primitive_call_clear() diff --git a/vm/factor.cpp b/vm/factor.cpp index 8b1202ddb0..5548ebd610 100755 --- a/vm/factor.cpp +++ b/vm/factor.cpp @@ -100,7 +100,7 @@ void factor_vm::do_stage1_init() fflush(stdout); compile_all_words(); - userenv[STAGE2_ENV] = T; + userenv[STAGE2_ENV] = true_object; print_string("done\n"); fflush(stdout); @@ -148,17 +148,17 @@ void factor_vm::init_factor(vm_parameters *p) init_profiler(); - userenv[CPU_ENV] = allot_alien(F,(cell)FACTOR_CPU_STRING); - userenv[OS_ENV] = allot_alien(F,(cell)FACTOR_OS_STRING); + userenv[CPU_ENV] = allot_alien(false_object,(cell)FACTOR_CPU_STRING); + userenv[OS_ENV] = allot_alien(false_object,(cell)FACTOR_OS_STRING); userenv[CELL_SIZE_ENV] = tag_fixnum(sizeof(cell)); - userenv[EXECUTABLE_ENV] = allot_alien(F,(cell)p->executable_path); - userenv[ARGS_ENV] = F; - userenv[EMBEDDED_ENV] = F; + userenv[EXECUTABLE_ENV] = allot_alien(false_object,(cell)p->executable_path); + userenv[ARGS_ENV] = false_object; + userenv[EMBEDDED_ENV] = false_object; /* We can GC now */ gc_off = false; - if(userenv[STAGE2_ENV] == F) + if(!to_boolean(userenv[STAGE2_ENV])) do_stage1_init(); } @@ -169,7 +169,7 @@ void factor_vm::pass_args_to_factor(int argc, vm_char **argv) int i; for(i = 1; i < argc; i++){ - args.add(allot_alien(F,(cell)argv[i])); + args.add(allot_alien(false_object,(cell)argv[i])); } args.trim(); diff --git a/vm/full_collector.cpp b/vm/full_collector.cpp index 86f3216e9c..adb901b3b6 100644 --- a/vm/full_collector.cpp +++ b/vm/full_collector.cpp @@ -3,23 +3,23 @@ namespace factor { -full_collector::full_collector(factor_vm *myvm_) : +full_collector::full_collector(factor_vm *parent_) : copying_collector( - myvm_, - &myvm_->gc_stats.full_stats, - myvm_->data->tenured, - full_policy(myvm_)) {} + parent_, + &parent_->gc_stats.full_stats, + parent_->data->tenured, + full_policy(parent_)) {} struct stack_frame_marker { - factor_vm *myvm; + factor_vm *parent; full_collector *collector; explicit stack_frame_marker(full_collector *collector_) : - myvm(collector_->myvm), collector(collector_) {} + parent(collector_->parent), collector(collector_) {} void operator()(stack_frame *frame) { - collector->mark_code_block(myvm->frame_code(frame)); + collector->mark_code_block(parent->frame_code(frame)); } }; @@ -27,7 +27,7 @@ struct stack_frame_marker { void full_collector::mark_active_blocks() { stack_frame_marker marker(this); - myvm->iterate_active_frames(marker); + parent->iterate_active_frames(marker); } void full_collector::mark_object_code_block(object *obj) @@ -54,7 +54,7 @@ void full_collector::mark_object_code_block(object *obj) { callstack *stack = (callstack *)obj; stack_frame_marker marker(this); - myvm->iterate_callstack_object(stack,marker); + parent->iterate_callstack_object(stack,marker); break; } } @@ -74,7 +74,7 @@ struct callback_tracer { void full_collector::trace_callbacks() { callback_tracer tracer(this); - myvm->callbacks->iterate(tracer); + parent->callbacks->iterate(tracer); } /* Trace all literals referenced from a code block. Only for aging and nursery collections */ @@ -100,33 +100,33 @@ void full_collector::cheneys_algorithm() object *obj = (object *)scan; this->trace_slots(obj); this->mark_object_code_block(obj); - scan = target->next_object_after(this->myvm,scan); + scan = target->next_object_after(this->parent,scan); } } /* After growing the heap, we have to perform a full relocation to update references to card and deck arrays. */ struct big_code_heap_updater { - factor_vm *myvm; + factor_vm *parent; - big_code_heap_updater(factor_vm *myvm_) : myvm(myvm_) {} + big_code_heap_updater(factor_vm *parent_) : parent(parent_) {} void operator()(heap_block *block) { - myvm->relocate_code_block((code_block *)block); + parent->relocate_code_block((code_block *)block); } }; /* After a full GC that did not grow the heap, we have to update references to literals and other words. */ struct small_code_heap_updater { - factor_vm *myvm; + factor_vm *parent; - small_code_heap_updater(factor_vm *myvm_) : myvm(myvm_) {} + small_code_heap_updater(factor_vm *parent_) : parent(parent_) {} void operator()(heap_block *block) { - myvm->update_code_block_for_full_gc((code_block *)block); + parent->update_code_block_for_full_gc((code_block *)block); } }; diff --git a/vm/full_collector.hpp b/vm/full_collector.hpp index c01f1cd486..8cc37f782d 100644 --- a/vm/full_collector.hpp +++ b/vm/full_collector.hpp @@ -2,10 +2,10 @@ namespace factor { struct full_policy { - factor_vm *myvm; + factor_vm *parent; zone *tenured; - full_policy(factor_vm *myvm_) : myvm(myvm_), tenured(myvm->data->tenured) {} + full_policy(factor_vm *parent_) : parent(parent_), tenured(parent->data->tenured) {} bool should_copy_p(object *untagged) { @@ -16,7 +16,7 @@ struct full_policy { struct full_collector : copying_collector { bool trace_contexts_p; - full_collector(factor_vm *myvm_); + full_collector(factor_vm *parent_); void mark_active_blocks(); void mark_object_code_block(object *object); void trace_callbacks(); diff --git a/vm/gc.cpp b/vm/gc.cpp index c89add6066..a9b6a79449 100755 --- a/vm/gc.cpp +++ b/vm/gc.cpp @@ -205,9 +205,9 @@ void factor_vm::inline_gc(cell *gc_roots_base, cell gc_roots_size) gc_locals.pop_back(); } -VM_C_API void inline_gc(cell *gc_roots_base, cell gc_roots_size, factor_vm *myvm) +VM_C_API void inline_gc(cell *gc_roots_base, cell gc_roots_size, factor_vm *parent) { - myvm->inline_gc(gc_roots_base,gc_roots_size); + parent->inline_gc(gc_roots_base,gc_roots_size); } /* diff --git a/vm/gc.hpp b/vm/gc.hpp index 9469603d0c..18b926ed8c 100755 --- a/vm/gc.hpp +++ b/vm/gc.hpp @@ -37,6 +37,6 @@ struct gc_state { ~gc_state(); }; -VM_C_API void inline_gc(cell *gc_roots_base, cell gc_roots_size, factor_vm *myvm); +VM_C_API void inline_gc(cell *gc_roots_base, cell gc_roots_size, factor_vm *parent); } diff --git a/vm/image.cpp b/vm/image.cpp index 05e0d66724..27da9d5295 100755 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -8,7 +8,7 @@ void factor_vm::init_objects(image_header *h) { memcpy(userenv,h->userenv,sizeof(userenv)); - T = h->t; + true_object = h->true_object; bignum_zero = h->bignum_zero; bignum_pos_one = h->bignum_pos_one; bignum_neg_one = h->bignum_neg_one; @@ -88,13 +88,13 @@ bool factor_vm::save_image(const vm_char *filename) h.code_relocation_base = code->seg->start; h.code_size = code->heap_size(); - h.t = T; + h.true_object = true_object; h.bignum_zero = bignum_zero; h.bignum_pos_one = bignum_pos_one; h.bignum_neg_one = bignum_neg_one; for(cell i = 0; i < USER_ENV; i++) - h.userenv[i] = (save_env_p(i) ? userenv[i] : F); + h.userenv[i] = (save_env_p(i) ? userenv[i] : false_object); bool ok = true; @@ -132,7 +132,7 @@ void factor_vm::primitive_save_image_and_exit() /* strip out userenv data which is set on startup anyway */ for(cell i = 0; i < USER_ENV; i++) { - if(!save_env_p(i)) userenv[i] = F; + if(!save_env_p(i)) userenv[i] = false_object; } gc(collect_full_op, @@ -184,19 +184,19 @@ void factor_vm::fixup_quotation(quotation *quot, cell code_relocation_base) void factor_vm::fixup_alien(alien *d) { - if(d->base == F) d->expired = T; + if(!to_boolean(d->base)) d->expired = true_object; } struct stack_frame_fixupper { - factor_vm *myvm; + factor_vm *parent; cell code_relocation_base; - explicit stack_frame_fixupper(factor_vm *myvm_, cell code_relocation_base_) : - myvm(myvm_), code_relocation_base(code_relocation_base_) {} + explicit stack_frame_fixupper(factor_vm *parent_, cell code_relocation_base_) : + parent(parent_), code_relocation_base(code_relocation_base_) {} void operator()(stack_frame *frame) { - myvm->code_fixup(&frame->xt,code_relocation_base); - myvm->code_fixup(&FRAME_RETURN_ADDRESS(frame,myvm),code_relocation_base); + parent->code_fixup(&frame->xt,code_relocation_base); + parent->code_fixup(&FRAME_RETURN_ADDRESS(frame,parent),code_relocation_base); } }; @@ -207,15 +207,15 @@ void factor_vm::fixup_callstack_object(callstack *stack, cell code_relocation_ba } struct object_fixupper { - factor_vm *myvm; + factor_vm *parent; cell data_relocation_base; - explicit object_fixupper(factor_vm *myvm_, cell data_relocation_base_) : - myvm(myvm_), data_relocation_base(data_relocation_base_) { } + explicit object_fixupper(factor_vm *parent_, cell data_relocation_base_) : + parent(parent_), data_relocation_base(data_relocation_base_) { } void operator()(cell *scan) { - myvm->data_fixup(scan,data_relocation_base); + parent->data_fixup(scan,data_relocation_base); } }; @@ -273,7 +273,7 @@ void factor_vm::relocate_data(cell data_relocation_base, cell code_relocation_ba for(cell i = 0; i < USER_ENV; i++) data_fixup(&userenv[i],data_relocation_base); - data_fixup(&T,data_relocation_base); + data_fixup(&true_object,data_relocation_base); data_fixup(&bignum_zero,data_relocation_base); data_fixup(&bignum_pos_one,data_relocation_base); data_fixup(&bignum_neg_one,data_relocation_base); @@ -299,15 +299,15 @@ void factor_vm::fixup_code_block(code_block *compiled, cell data_relocation_base } struct code_block_fixupper { - factor_vm *myvm; + factor_vm *parent; cell data_relocation_base; - code_block_fixupper(factor_vm *myvm_, cell data_relocation_base_) : - myvm(myvm_), data_relocation_base(data_relocation_base_) { } + code_block_fixupper(factor_vm *parent_, cell data_relocation_base_) : + parent(parent_), data_relocation_base(data_relocation_base_) { } void operator()(code_block *compiled) { - myvm->fixup_code_block(compiled,data_relocation_base); + parent->fixup_code_block(compiled,data_relocation_base); } }; @@ -350,7 +350,7 @@ void factor_vm::load_image(vm_parameters *p) relocate_code(h.data_relocation_base); /* Store image path name */ - userenv[IMAGE_ENV] = allot_alien(F,(cell)p->image_path); + userenv[IMAGE_ENV] = allot_alien(false_object,(cell)p->image_path); } } diff --git a/vm/image.hpp b/vm/image.hpp index f071185852..8a7080110c 100755 --- a/vm/image.hpp +++ b/vm/image.hpp @@ -17,7 +17,7 @@ struct image_header { /* size of code heap */ cell code_size; /* tagged pointer to t singleton */ - cell t; + cell true_object; /* tagged pointer to bignum 0 */ cell bignum_zero; /* tagged pointer to bignum 1 */ diff --git a/vm/inline_cache.cpp b/vm/inline_cache.cpp index 7f7471ad1f..f6e756f758 100755 --- a/vm/inline_cache.cpp +++ b/vm/inline_cache.cpp @@ -92,9 +92,9 @@ void inline_cache_jit::emit_check(cell klass) { cell code_template; if(TAG(klass) == FIXNUM_TYPE && untag_fixnum(klass) < HEADER_TYPE) - code_template = parent_vm->userenv[PIC_CHECK_TAG]; + code_template = parent->userenv[PIC_CHECK_TAG]; else - code_template = parent_vm->userenv[PIC_CHECK]; + code_template = parent->userenv[PIC_CHECK]; emit_with(code_template,klass); } @@ -107,12 +107,12 @@ void inline_cache_jit::compile_inline_cache(fixnum index, cell cache_entries_, bool tail_call_p) { - gc_root generic_word(generic_word_,parent_vm); - gc_root methods(methods_,parent_vm); - gc_root cache_entries(cache_entries_,parent_vm); + gc_root generic_word(generic_word_,parent); + gc_root methods(methods_,parent); + gc_root cache_entries(cache_entries_,parent); - cell inline_cache_type = parent_vm->determine_inline_cache_type(cache_entries.untagged()); - parent_vm->update_pic_count(inline_cache_type); + cell inline_cache_type = parent->determine_inline_cache_type(cache_entries.untagged()); + parent->update_pic_count(inline_cache_type); /* Generate machine code to determine the object's class. */ emit_class_lookup(index,inline_cache_type); @@ -127,7 +127,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, /* Yes? Jump to method */ cell method = array_nth(cache_entries.untagged(),i + 1); - emit_with(parent_vm->userenv[PIC_HIT],method); + emit_with(parent->userenv[PIC_HIT],method); } /* Generate machine code to handle a cache miss, which ultimately results in @@ -139,7 +139,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, push(methods.value()); push(tag_fixnum(index)); push(cache_entries.value()); - word_special(parent_vm->userenv[tail_call_p ? PIC_MISS_TAIL_WORD : PIC_MISS_WORD]); + word_special(parent->userenv[tail_call_p ? PIC_MISS_TAIL_WORD : PIC_MISS_WORD]); } code_block *factor_vm::compile_inline_cache(fixnum index,cell generic_word_,cell methods_,cell cache_entries_,bool tail_call_p) @@ -248,9 +248,9 @@ void *factor_vm::inline_cache_miss(cell return_address) return xt; } -VM_C_API void *inline_cache_miss(cell return_address, factor_vm *myvm) +VM_C_API void *inline_cache_miss(cell return_address, factor_vm *parent) { - return myvm->inline_cache_miss(return_address); + return parent->inline_cache_miss(return_address); } void factor_vm::primitive_reset_inline_cache_stats() diff --git a/vm/io.cpp b/vm/io.cpp index 8e6eff730e..d5cfc1745c 100755 --- a/vm/io.cpp +++ b/vm/io.cpp @@ -16,9 +16,9 @@ normal operation. */ void factor_vm::init_c_io() { - userenv[STDIN_ENV] = allot_alien(F,(cell)stdin); - userenv[STDOUT_ENV] = allot_alien(F,(cell)stdout); - userenv[STDERR_ENV] = allot_alien(F,(cell)stderr); + userenv[STDIN_ENV] = allot_alien(false_object,(cell)stdin); + userenv[STDOUT_ENV] = allot_alien(false_object,(cell)stdout); + userenv[STDERR_ENV] = allot_alien(false_object,(cell)stderr); } void factor_vm::io_error() @@ -28,7 +28,7 @@ void factor_vm::io_error() return; #endif - general_error(ERROR_IO,tag_fixnum(errno),F,NULL); + general_error(ERROR_IO,tag_fixnum(errno),false_object,NULL); } void factor_vm::primitive_fopen() @@ -63,7 +63,7 @@ void factor_vm::primitive_fgetc() { if(feof(file)) { - dpush(F); + dpush(false_object); break; } else @@ -97,7 +97,7 @@ void factor_vm::primitive_fread() { if(feof(file)) { - dpush(F); + dpush(false_object); break; } else diff --git a/vm/jit.cpp b/vm/jit.cpp index 77a311cb24..ced487e659 100644 --- a/vm/jit.cpp +++ b/vm/jit.cpp @@ -19,12 +19,12 @@ jit::jit(cell type_, cell owner_, factor_vm *vm) computing_offset_p(false), position(0), offset(0), - parent_vm(vm) + parent(vm) {} void jit::emit_relocation(cell code_template_) { - gc_root code_template(code_template_,parent_vm); + gc_root code_template(code_template_,parent); cell capacity = array_capacity(code_template.untagged()); for(cell i = 1; i < capacity; i += 3) { @@ -43,11 +43,11 @@ void jit::emit_relocation(cell code_template_) /* Allocates memory */ void jit::emit(cell code_template_) { - gc_root code_template(code_template_,parent_vm); + gc_root code_template(code_template_,parent); emit_relocation(code_template.value()); - gc_root insns(array_nth(code_template.untagged(),0),parent_vm); + gc_root insns(array_nth(code_template.untagged(),0),parent); if(computing_offset_p) { @@ -71,16 +71,16 @@ void jit::emit(cell code_template_) } void jit::emit_with(cell code_template_, cell argument_) { - gc_root code_template(code_template_,parent_vm); - gc_root argument(argument_,parent_vm); + gc_root code_template(code_template_,parent); + gc_root argument(argument_,parent); literal(argument.value()); emit(code_template.value()); } void jit::emit_class_lookup(fixnum index, cell type) { - emit_with(parent_vm->userenv[PIC_LOAD],tag_fixnum(-index * sizeof(cell))); - emit(parent_vm->userenv[type]); + emit_with(parent->userenv[PIC_LOAD],tag_fixnum(-index * sizeof(cell))); + emit(parent->userenv[type]); } /* Facility to convert compiled code offsets to quotation offsets. @@ -100,10 +100,10 @@ code_block *jit::to_code_block() relocation.trim(); literals.trim(); - return parent_vm->add_code_block( + return parent->add_code_block( type, code.elements.value(), - F, /* no labels */ + false_object, /* no labels */ owner.value(), relocation.elements.value(), literals.elements.value()); diff --git a/vm/jit.hpp b/vm/jit.hpp index 63b4454514..d69f44d05d 100644 --- a/vm/jit.hpp +++ b/vm/jit.hpp @@ -10,7 +10,7 @@ struct jit { bool computing_offset_p; fixnum position; cell offset; - factor_vm *parent_vm; + factor_vm *parent; explicit jit(cell jit_type, cell owner, factor_vm *vm); void compute_position(cell offset); @@ -22,27 +22,28 @@ struct jit { void emit_with(cell code_template_, cell literal_); void push(cell literal) { - emit_with(parent_vm->userenv[JIT_PUSH_IMMEDIATE],literal); + emit_with(parent->userenv[JIT_PUSH_IMMEDIATE],literal); } - void word_jump(cell word) { + void word_jump(cell word_) { + gc_root word(word_,parent); literal(tag_fixnum(xt_tail_pic_offset)); - literal(word); - emit(parent_vm->userenv[JIT_WORD_JUMP]); + literal(word.value()); + emit(parent->userenv[JIT_WORD_JUMP]); } void word_call(cell word) { - emit_with(parent_vm->userenv[JIT_WORD_CALL],word); + emit_with(parent->userenv[JIT_WORD_CALL],word); } void word_special(cell word) { - emit_with(parent_vm->userenv[JIT_WORD_SPECIAL],word); + emit_with(parent->userenv[JIT_WORD_SPECIAL],word); } void emit_subprimitive(cell word_) { - gc_root word(word_,parent_vm); - gc_root code_pair(word->subprimitive,parent_vm); - literals.append(parent_vm->untag(array_nth(code_pair.untagged(),0))); + gc_root word(word_,parent); + gc_root code_pair(word->subprimitive,parent); + literals.append(parent->untag(array_nth(code_pair.untagged(),0))); emit(array_nth(code_pair.untagged(),1)); } diff --git a/vm/layouts.hpp b/vm/layouts.hpp index 2fba97d747..aef8b1b668 100644 --- a/vm/layouts.hpp +++ b/vm/layouts.hpp @@ -46,9 +46,6 @@ inline static cell align8(cell a) #define OBJECT_TYPE 6 #define TUPLE_TYPE 7 -/* Canonical F object */ -#define F F_TYPE - #define HEADER_TYPE 8 /* anything less than this is a tag */ #define GC_COLLECTED 5 /* can be anything other than FIXNUM_TYPE */ @@ -78,9 +75,12 @@ enum FP_TRAP_INEXACT = 1 << 4, }; +/* What Factor calls 'f' */ +static const cell false_object = F_TYPE; + inline static bool immediate_p(cell obj) { - return (obj == F || TAG(obj) == FIXNUM_TYPE); + return (obj == false_object || TAG(obj) == FIXNUM_TYPE); } inline static fixnum untag_fixnum(cell tagged) diff --git a/vm/local_roots.hpp b/vm/local_roots.hpp index 7becc906a0..6ae059f4c4 100644 --- a/vm/local_roots.hpp +++ b/vm/local_roots.hpp @@ -4,21 +4,21 @@ namespace factor template struct gc_root : public tagged { - factor_vm *parent_vm; + factor_vm *parent; - void push() { parent_vm->check_tagged_pointer(tagged::value()); parent_vm->gc_locals.push_back((cell)this); } + void push() { parent->check_tagged_pointer(tagged::value()); parent->gc_locals.push_back((cell)this); } - explicit gc_root(cell value_,factor_vm *vm) : tagged(value_),parent_vm(vm) { push(); } - explicit gc_root(Type *value_, factor_vm *vm) : tagged(value_),parent_vm(vm) { push(); } + explicit gc_root(cell value_,factor_vm *vm) : tagged(value_),parent(vm) { push(); } + explicit gc_root(Type *value_, factor_vm *vm) : tagged(value_),parent(vm) { push(); } const gc_root& operator=(const Type *x) { tagged::operator=(x); return *this; } const gc_root& operator=(const cell &x) { tagged::operator=(x); return *this; } ~gc_root() { #ifdef FACTOR_DEBUG - assert(parent_vm->gc_locals.back() == (cell)this); + assert(parent->gc_locals.back() == (cell)this); #endif - parent_vm->gc_locals.pop_back(); + parent->gc_locals.pop_back(); } }; @@ -26,18 +26,18 @@ struct gc_root : public tagged struct gc_bignum { bignum **addr; - factor_vm *parent_vm; - gc_bignum(bignum **addr_, factor_vm *vm) : addr(addr_), parent_vm(vm) { + factor_vm *parent; + gc_bignum(bignum **addr_, factor_vm *vm) : addr(addr_), parent(vm) { if(*addr_) - parent_vm->check_data_pointer(*addr_); - parent_vm->gc_bignums.push_back((cell)addr); + parent->check_data_pointer(*addr_); + parent->gc_bignums.push_back((cell)addr); } ~gc_bignum() { #ifdef FACTOR_DEBUG - assert(parent_vm->gc_bignums.back() == (cell)addr); + assert(parent->gc_bignums.back() == (cell)addr); #endif - parent_vm->gc_bignums.pop_back(); + parent->gc_bignums.pop_back(); } }; diff --git a/vm/math.cpp b/vm/math.cpp index e4caa0f5ca..169790d365 100755 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -219,9 +219,9 @@ unsigned int factor_vm::bignum_producer(unsigned int digit) return *(ptr + digit); } -unsigned int bignum_producer(unsigned int digit, factor_vm *myvm) +unsigned int bignum_producer(unsigned int digit, factor_vm *parent) { - return myvm->bignum_producer(digit); + return parent->bignum_producer(digit); } void factor_vm::primitive_byte_array_to_bignum() @@ -285,7 +285,7 @@ void factor_vm::primitive_str_to_float() if(end == c_str + capacity - 1) drepl(allot_float(f)); else - drepl(F); + drepl(false_object); } void factor_vm::primitive_float_to_str() @@ -393,9 +393,9 @@ fixnum factor_vm::to_fixnum(cell tagged) } } -VM_C_API fixnum to_fixnum(cell tagged,factor_vm *myvm) +VM_C_API fixnum to_fixnum(cell tagged,factor_vm *parent) { - return myvm->to_fixnum(tagged); + return parent->to_fixnum(tagged); } cell factor_vm::to_cell(cell tagged) @@ -403,9 +403,9 @@ cell factor_vm::to_cell(cell tagged) return (cell)to_fixnum(tagged); } -VM_C_API cell to_cell(cell tagged, factor_vm *myvm) +VM_C_API cell to_cell(cell tagged, factor_vm *parent) { - return myvm->to_cell(tagged); + return parent->to_cell(tagged); } void factor_vm::box_signed_1(s8 n) @@ -413,9 +413,9 @@ void factor_vm::box_signed_1(s8 n) dpush(tag_fixnum(n)); } -VM_C_API void box_signed_1(s8 n,factor_vm *myvm) +VM_C_API void box_signed_1(s8 n,factor_vm *parent) { - return myvm->box_signed_1(n); + return parent->box_signed_1(n); } void factor_vm::box_unsigned_1(u8 n) @@ -423,9 +423,9 @@ void factor_vm::box_unsigned_1(u8 n) dpush(tag_fixnum(n)); } -VM_C_API void box_unsigned_1(u8 n,factor_vm *myvm) +VM_C_API void box_unsigned_1(u8 n,factor_vm *parent) { - return myvm->box_unsigned_1(n); + return parent->box_unsigned_1(n); } void factor_vm::box_signed_2(s16 n) @@ -433,9 +433,9 @@ void factor_vm::box_signed_2(s16 n) dpush(tag_fixnum(n)); } -VM_C_API void box_signed_2(s16 n,factor_vm *myvm) +VM_C_API void box_signed_2(s16 n,factor_vm *parent) { - return myvm->box_signed_2(n); + return parent->box_signed_2(n); } void factor_vm::box_unsigned_2(u16 n) @@ -443,9 +443,9 @@ void factor_vm::box_unsigned_2(u16 n) dpush(tag_fixnum(n)); } -VM_C_API void box_unsigned_2(u16 n,factor_vm *myvm) +VM_C_API void box_unsigned_2(u16 n,factor_vm *parent) { - return myvm->box_unsigned_2(n); + return parent->box_unsigned_2(n); } void factor_vm::box_signed_4(s32 n) @@ -453,9 +453,9 @@ void factor_vm::box_signed_4(s32 n) dpush(allot_integer(n)); } -VM_C_API void box_signed_4(s32 n,factor_vm *myvm) +VM_C_API void box_signed_4(s32 n,factor_vm *parent) { - return myvm->box_signed_4(n); + return parent->box_signed_4(n); } void factor_vm::box_unsigned_4(u32 n) @@ -463,9 +463,9 @@ void factor_vm::box_unsigned_4(u32 n) dpush(allot_cell(n)); } -VM_C_API void box_unsigned_4(u32 n,factor_vm *myvm) +VM_C_API void box_unsigned_4(u32 n,factor_vm *parent) { - return myvm->box_unsigned_4(n); + return parent->box_unsigned_4(n); } void factor_vm::box_signed_cell(fixnum integer) @@ -473,9 +473,9 @@ void factor_vm::box_signed_cell(fixnum integer) dpush(allot_integer(integer)); } -VM_C_API void box_signed_cell(fixnum integer,factor_vm *myvm) +VM_C_API void box_signed_cell(fixnum integer,factor_vm *parent) { - return myvm->box_signed_cell(integer); + return parent->box_signed_cell(integer); } void factor_vm::box_unsigned_cell(cell cell) @@ -483,9 +483,9 @@ void factor_vm::box_unsigned_cell(cell cell) dpush(allot_cell(cell)); } -VM_C_API void box_unsigned_cell(cell cell,factor_vm *myvm) +VM_C_API void box_unsigned_cell(cell cell,factor_vm *parent) { - return myvm->box_unsigned_cell(cell); + return parent->box_unsigned_cell(cell); } void factor_vm::box_signed_8(s64 n) @@ -496,9 +496,9 @@ void factor_vm::box_signed_8(s64 n) dpush(tag_fixnum(n)); } -VM_C_API void box_signed_8(s64 n,factor_vm *myvm) +VM_C_API void box_signed_8(s64 n,factor_vm *parent) { - return myvm->box_signed_8(n); + return parent->box_signed_8(n); } s64 factor_vm::to_signed_8(cell obj) @@ -515,9 +515,9 @@ s64 factor_vm::to_signed_8(cell obj) } } -VM_C_API s64 to_signed_8(cell obj,factor_vm *myvm) +VM_C_API s64 to_signed_8(cell obj,factor_vm *parent) { - return myvm->to_signed_8(obj); + return parent->to_signed_8(obj); } void factor_vm::box_unsigned_8(u64 n) @@ -528,9 +528,9 @@ void factor_vm::box_unsigned_8(u64 n) dpush(tag_fixnum(n)); } -VM_C_API void box_unsigned_8(u64 n,factor_vm *myvm) +VM_C_API void box_unsigned_8(u64 n,factor_vm *parent) { - return myvm->box_unsigned_8(n); + return parent->box_unsigned_8(n); } u64 factor_vm::to_unsigned_8(cell obj) @@ -547,9 +547,9 @@ u64 factor_vm::to_unsigned_8(cell obj) } } -VM_C_API u64 to_unsigned_8(cell obj,factor_vm *myvm) +VM_C_API u64 to_unsigned_8(cell obj,factor_vm *parent) { - return myvm->to_unsigned_8(obj); + return parent->to_unsigned_8(obj); } void factor_vm::box_float(float flo) @@ -557,9 +557,9 @@ void factor_vm::box_float(float flo) dpush(allot_float(flo)); } -VM_C_API void box_float(float flo, factor_vm *myvm) +VM_C_API void box_float(float flo, factor_vm *parent) { - return myvm->box_float(flo); + return parent->box_float(flo); } float factor_vm::to_float(cell value) @@ -567,9 +567,9 @@ float factor_vm::to_float(cell value) return untag_float_check(value); } -VM_C_API float to_float(cell value,factor_vm *myvm) +VM_C_API float to_float(cell value,factor_vm *parent) { - return myvm->to_float(value); + return parent->to_float(value); } void factor_vm::box_double(double flo) @@ -577,9 +577,9 @@ void factor_vm::box_double(double flo) dpush(allot_float(flo)); } -VM_C_API void box_double(double flo,factor_vm *myvm) +VM_C_API void box_double(double flo,factor_vm *parent) { - return myvm->box_double(flo); + return parent->box_double(flo); } double factor_vm::to_double(cell value) @@ -587,9 +587,9 @@ double factor_vm::to_double(cell value) return untag_float_check(value); } -VM_C_API double to_double(cell value,factor_vm *myvm) +VM_C_API double to_double(cell value,factor_vm *parent) { - return myvm->to_double(value); + return parent->to_double(value); } /* The fixnum+, fixnum- and fixnum* primitives are defined in cpu_*.S. On @@ -600,9 +600,9 @@ inline void factor_vm::overflow_fixnum_add(fixnum x, fixnum y) untag_fixnum(x) + untag_fixnum(y)))); } -VM_ASM_API void overflow_fixnum_add(fixnum x, fixnum y, factor_vm *myvm) +VM_ASM_API void overflow_fixnum_add(fixnum x, fixnum y, factor_vm *parent) { - ((factor_vm*)myvm)->overflow_fixnum_add(x,y); + parent->overflow_fixnum_add(x,y); } inline void factor_vm::overflow_fixnum_subtract(fixnum x, fixnum y) @@ -611,9 +611,9 @@ inline void factor_vm::overflow_fixnum_subtract(fixnum x, fixnum y) untag_fixnum(x) - untag_fixnum(y)))); } -VM_ASM_API void overflow_fixnum_subtract(fixnum x, fixnum y, factor_vm *myvm) +VM_ASM_API void overflow_fixnum_subtract(fixnum x, fixnum y, factor_vm *parent) { - ((factor_vm*)myvm)->overflow_fixnum_subtract(x,y); + parent->overflow_fixnum_subtract(x,y); } inline void factor_vm::overflow_fixnum_multiply(fixnum x, fixnum y) @@ -625,9 +625,9 @@ inline void factor_vm::overflow_fixnum_multiply(fixnum x, fixnum y) drepl(tag(bignum_multiply(bx,by))); } -VM_ASM_API void overflow_fixnum_multiply(fixnum x, fixnum y, factor_vm *myvm) +VM_ASM_API void overflow_fixnum_multiply(fixnum x, fixnum y, factor_vm *parent) { - ((factor_vm*)myvm)->overflow_fixnum_multiply(x,y); + parent->overflow_fixnum_multiply(x,y); } } diff --git a/vm/nursery_collector.cpp b/vm/nursery_collector.cpp index 6eb6d840f1..909cde02f8 100644 --- a/vm/nursery_collector.cpp +++ b/vm/nursery_collector.cpp @@ -3,12 +3,12 @@ namespace factor { -nursery_collector::nursery_collector(factor_vm *myvm_) : +nursery_collector::nursery_collector(factor_vm *parent_) : copying_collector( - myvm_, - &myvm_->gc_stats.nursery_stats, - myvm_->data->aging, - nursery_policy(myvm_)) {} + parent_, + &parent_->gc_stats.nursery_stats, + parent_->data->aging, + nursery_policy(parent_)) {} void factor_vm::collect_nursery() { diff --git a/vm/nursery_collector.hpp b/vm/nursery_collector.hpp index cff988cf9d..f9d2172929 100644 --- a/vm/nursery_collector.hpp +++ b/vm/nursery_collector.hpp @@ -2,18 +2,18 @@ namespace factor { struct nursery_policy { - factor_vm *myvm; + factor_vm *parent; - nursery_policy(factor_vm *myvm_) : myvm(myvm_) {} + nursery_policy(factor_vm *parent_) : parent(parent_) {} bool should_copy_p(object *untagged) { - return myvm->nursery.contains_p(untagged); + return parent->nursery.contains_p(untagged); } }; struct nursery_collector : copying_collector { - nursery_collector(factor_vm *myvm_); + nursery_collector(factor_vm *parent_); }; } diff --git a/vm/old_space.cpp b/vm/old_space.cpp index 06e13a77ba..5fd78a7cf4 100644 --- a/vm/old_space.cpp +++ b/vm/old_space.cpp @@ -62,9 +62,9 @@ void old_space::clear_object_start_offsets() memset(object_start_offsets,card_starts_inside_object,addr_to_card(size)); } -cell old_space::next_object_after(factor_vm *myvm, cell scan) +cell old_space::next_object_after(factor_vm *parent, cell scan) { - cell size = myvm->untagged_object_size((object *)scan); + cell size = parent->untagged_object_size((object *)scan); if(scan + size < here) return scan + size; else diff --git a/vm/old_space.hpp b/vm/old_space.hpp index fff98e9343..d037a039ae 100644 --- a/vm/old_space.hpp +++ b/vm/old_space.hpp @@ -15,7 +15,7 @@ struct old_space : zone { void record_object_start_offset(object *obj); object *allot(cell size); void clear_object_start_offsets(); - cell next_object_after(factor_vm *myvm, cell scan); + cell next_object_after(factor_vm *parent, cell scan); }; } diff --git a/vm/os-linux.cpp b/vm/os-linux.cpp index 2bd313e1c0..ffc5a6097a 100644 --- a/vm/os-linux.cpp +++ b/vm/os-linux.cpp @@ -45,19 +45,19 @@ VM_C_API int inotify_rm_watch(int fd, u32 wd) VM_C_API int inotify_init() { - myvm->not_implemented_error(); + parent->not_implemented_error(); return -1; } VM_C_API int inotify_add_watch(int fd, const char *name, u32 mask) { - myvm->not_implemented_error(); + parent->not_implemented_error(); return -1; } VM_C_API int inotify_rm_watch(int fd, u32 wd) { - myvm->not_implemented_error(); + parent->not_implemented_error(); return -1; } diff --git a/vm/os-macosx.mm b/vm/os-macosx.mm index 3aa001774b..96f169bbcf 100644 --- a/vm/os-macosx.mm +++ b/vm/os-macosx.mm @@ -13,7 +13,7 @@ NS_DURING c_to_factor(quot,this); NS_VOIDRETURN; NS_HANDLER - dpush(allot_alien(F,(cell)localException)); + dpush(allot_alien(false_object,(cell)localException)); quot = userenv[COCOA_EXCEPTION_ENV]; if(!tagged(quot).type_p(QUOTATION_TYPE)) { diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index 70d7e395de..2f9d5a3c89 100644 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -72,7 +72,7 @@ void *factor_vm::ffi_dlsym(dll *dll, symbol_char *symbol) void factor_vm::ffi_dlclose(dll *dll) { if(dlclose(dll->dll)) - general_error(ERROR_FFI,F,F,NULL); + general_error(ERROR_FFI,false_object,false_object,NULL); dll->dll = NULL; } diff --git a/vm/primitives.hpp b/vm/primitives.hpp index 467eef473e..8e4efd8d14 100644 --- a/vm/primitives.hpp +++ b/vm/primitives.hpp @@ -2,18 +2,18 @@ namespace factor { #if defined(FACTOR_X86) - extern "C" __attribute__ ((regparm (1))) typedef void (*primitive_type)(void *myvm); - #define PRIMITIVE(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm) - #define PRIMITIVE_FORWARD(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm) \ - { \ - ((factor_vm*)myvm)->primitive_##name(); \ + extern "C" __attribute__ ((regparm (1))) typedef void (*primitive_type)(factor_vm *parent); + #define PRIMITIVE(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(factor_vm *parent) + #define PRIMITIVE_FORWARD(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(factor_vm *parent) \ + { \ + parent->primitive_##name(); \ } #else - extern "C" typedef void (*primitive_type)(void *myvm); - #define PRIMITIVE(name) extern "C" void primitive_##name(void *myvm) - #define PRIMITIVE_FORWARD(name) extern "C" void primitive_##name(void *myvm) \ - { \ - ((factor_vm*)myvm)->primitive_##name(); \ + extern "C" typedef void (*primitive_type)(factor_vm *parent); + #define PRIMITIVE(name) extern "C" void primitive_##name(factor_vm *parent) + #define PRIMITIVE_FORWARD(name) extern "C" void primitive_##name(factor_vm *parent) \ + { \ + parent->primitive_##name(); \ } #endif extern const primitive_type primitives[]; diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 60fdce1003..9c2c85215d 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -38,29 +38,29 @@ so this results in a big speedup for relatively little effort. */ bool quotation_jit::primitive_call_p(cell i, cell length) { - return (i + 2) == length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_PRIMITIVE_WORD]; + return (i + 2) == length && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_PRIMITIVE_WORD]; } bool quotation_jit::fast_if_p(cell i, cell length) { return (i + 3) == length && tagged(array_nth(elements.untagged(),i + 1)).type_p(QUOTATION_TYPE) - && array_nth(elements.untagged(),i + 2) == parent_vm->userenv[JIT_IF_WORD]; + && array_nth(elements.untagged(),i + 2) == parent->userenv[JIT_IF_WORD]; } bool quotation_jit::fast_dip_p(cell i, cell length) { - return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_DIP_WORD]; + return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_DIP_WORD]; } bool quotation_jit::fast_2dip_p(cell i, cell length) { - return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_2DIP_WORD]; + return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_2DIP_WORD]; } bool quotation_jit::fast_3dip_p(cell i, cell length) { - return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_3DIP_WORD]; + return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_3DIP_WORD]; } bool quotation_jit::mega_lookup_p(cell i, cell length) @@ -68,13 +68,13 @@ bool quotation_jit::mega_lookup_p(cell i, cell length) return (i + 4) <= length && tagged(array_nth(elements.untagged(),i + 1)).type_p(FIXNUM_TYPE) && tagged(array_nth(elements.untagged(),i + 2)).type_p(ARRAY_TYPE) - && array_nth(elements.untagged(),i + 3) == parent_vm->userenv[MEGA_LOOKUP_WORD]; + && array_nth(elements.untagged(),i + 3) == parent->userenv[MEGA_LOOKUP_WORD]; } bool quotation_jit::declare_p(cell i, cell length) { return (i + 2) <= length - && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_DECLARE_WORD]; + && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_DECLARE_WORD]; } bool quotation_jit::stack_frame_p() @@ -88,7 +88,7 @@ bool quotation_jit::stack_frame_p() switch(tagged(obj).type()) { case WORD_TYPE: - if(parent_vm->untag(obj)->subprimitive == F) + if(!parent->to_boolean(parent->untag(obj)->subprimitive)) return true; break; case QUOTATION_TYPE: @@ -110,9 +110,9 @@ bool quotation_jit::trivial_quotation_p(array *elements) void quotation_jit::emit_quot(cell quot_) { - gc_root quot(quot_,parent_vm); + gc_root quot(quot_,parent); - array *elements = parent_vm->untag(quot->array); + array *elements = parent->untag(quot->array); /* If the quotation consists of a single word, compile a direct call to the word. */ @@ -120,7 +120,7 @@ void quotation_jit::emit_quot(cell quot_) literal(array_nth(elements,0)); else { - if(compiling) parent_vm->jit_compile(quot.value(),relocate); + if(compiling) parent->jit_compile(quot.value(),relocate); literal(quot.value()); } } @@ -133,7 +133,7 @@ void quotation_jit::iterate_quotation() set_position(0); if(stack_frame) - emit(parent_vm->userenv[JIT_PROLOG]); + emit(parent->userenv[JIT_PROLOG]); cell i; cell length = array_capacity(elements.untagged()); @@ -143,32 +143,32 @@ void quotation_jit::iterate_quotation() { set_position(i); - gc_root obj(array_nth(elements.untagged(),i),parent_vm); + gc_root obj(array_nth(elements.untagged(),i),parent); switch(obj.type()) { case WORD_TYPE: /* Intrinsics */ - if(obj.as()->subprimitive != F) + if(parent->to_boolean(obj.as()->subprimitive)) emit_subprimitive(obj.value()); /* The (execute) primitive is special-cased */ - else if(obj.value() == parent_vm->userenv[JIT_EXECUTE_WORD]) + else if(obj.value() == parent->userenv[JIT_EXECUTE_WORD]) { if(i == length - 1) { - if(stack_frame) emit(parent_vm->userenv[JIT_EPILOG]); + if(stack_frame) emit(parent->userenv[JIT_EPILOG]); tail_call = true; - emit(parent_vm->userenv[JIT_EXECUTE_JUMP]); + emit(parent->userenv[JIT_EXECUTE_JUMP]); } else - emit(parent_vm->userenv[JIT_EXECUTE_CALL]); + emit(parent->userenv[JIT_EXECUTE_CALL]); } /* Everything else */ else { if(i == length - 1) { - if(stack_frame) emit(parent_vm->userenv[JIT_EPILOG]); + if(stack_frame) emit(parent->userenv[JIT_EPILOG]); tail_call = true; /* Inline cache misses are special-cased. The calling convention for tail @@ -178,8 +178,8 @@ void quotation_jit::iterate_quotation() the inline cache miss primitive, and we don't want to clobber the saved address. */ - if(obj.value() == parent_vm->userenv[PIC_MISS_WORD] - || obj.value() == parent_vm->userenv[PIC_MISS_TAIL_WORD]) + if(obj.value() == parent->userenv[PIC_MISS_WORD] + || obj.value() == parent->userenv[PIC_MISS_TAIL_WORD]) { word_special(obj.value()); } @@ -201,7 +201,7 @@ void quotation_jit::iterate_quotation() { literal(tag_fixnum(0)); literal(obj.value()); - emit(parent_vm->userenv[JIT_PRIMITIVE]); + emit(parent->userenv[JIT_PRIMITIVE]); i++; @@ -215,12 +215,12 @@ void quotation_jit::iterate_quotation() mutually recursive in the library, but both still work) */ if(fast_if_p(i,length)) { - if(stack_frame) emit(parent_vm->userenv[JIT_EPILOG]); + if(stack_frame) emit(parent->userenv[JIT_EPILOG]); tail_call = true; emit_quot(array_nth(elements.untagged(),i)); emit_quot(array_nth(elements.untagged(),i + 1)); - emit(parent_vm->userenv[JIT_IF]); + emit(parent->userenv[JIT_IF]); i += 2; } @@ -228,21 +228,21 @@ void quotation_jit::iterate_quotation() else if(fast_dip_p(i,length)) { emit_quot(obj.value()); - emit(parent_vm->userenv[JIT_DIP]); + emit(parent->userenv[JIT_DIP]); i++; } /* 2dip */ else if(fast_2dip_p(i,length)) { emit_quot(obj.value()); - emit(parent_vm->userenv[JIT_2DIP]); + emit(parent->userenv[JIT_2DIP]); i++; } /* 3dip */ else if(fast_3dip_p(i,length)) { emit_quot(obj.value()); - emit(parent_vm->userenv[JIT_3DIP]); + emit(parent->userenv[JIT_3DIP]); i++; } else @@ -276,8 +276,8 @@ void quotation_jit::iterate_quotation() set_position(length); if(stack_frame) - emit(parent_vm->userenv[JIT_EPILOG]); - emit(parent_vm->userenv[JIT_RETURN]); + emit(parent->userenv[JIT_EPILOG]); + emit(parent->userenv[JIT_RETURN]); } } @@ -313,8 +313,8 @@ void factor_vm::primitive_array_to_quotation() { quotation *quot = allot(sizeof(quotation)); quot->array = dpeek(); - quot->cached_effect = F; - quot->cache_counter = F; + quot->cached_effect = false_object; + quot->cache_counter = false_object; quot->xt = (void *)lazy_jit_compile; quot->code = NULL; drepl(tag(quot)); @@ -367,9 +367,9 @@ cell factor_vm::lazy_jit_compile_impl(cell quot_, stack_frame *stack) return quot.value(); } -VM_ASM_API cell lazy_jit_compile_impl(cell quot_, stack_frame *stack, factor_vm *myvm) +VM_ASM_API cell lazy_jit_compile_impl(cell quot_, stack_frame *stack, factor_vm *parent) { - return myvm->lazy_jit_compile_impl(quot_,stack); + return parent->lazy_jit_compile_impl(quot_,stack); } void factor_vm::primitive_quot_compiled_p() diff --git a/vm/quotations.hpp b/vm/quotations.hpp index aee4468102..feb2af1ce4 100755 --- a/vm/quotations.hpp +++ b/vm/quotations.hpp @@ -25,6 +25,6 @@ struct quotation_jit : public jit { void iterate_quotation(); }; -VM_ASM_API cell lazy_jit_compile_impl(cell quot, stack_frame *stack, factor_vm *myvm); +VM_ASM_API cell lazy_jit_compile_impl(cell quot, stack_frame *stack, factor_vm *parent); } diff --git a/vm/strings.cpp b/vm/strings.cpp index ecfc84ebef..d7434fe660 100644 --- a/vm/strings.cpp +++ b/vm/strings.cpp @@ -35,7 +35,9 @@ void factor_vm::set_string_nth_slow(string *str_, cell index, cell ch) str->data()[index] = ((ch & 0x7f) | 0x80); - if(str->aux == F) + if(to_boolean(str->aux)) + aux = untag(str->aux); + else { /* We don't need to pre-initialize the byte array with any data, since we @@ -48,8 +50,6 @@ void factor_vm::set_string_nth_slow(string *str_, cell index, cell ch) str->aux = tag(aux); write_barrier(&str->aux); } - else - aux = untag(str->aux); aux->data()[index] = ((ch >> 7) ^ 1); } @@ -69,8 +69,8 @@ string *factor_vm::allot_string_internal(cell capacity) string *str = allot(string_size(capacity)); str->length = tag_fixnum(capacity); - str->hashcode = F; - str->aux = F; + str->hashcode = false_object; + str->aux = false_object; return str; } @@ -109,7 +109,7 @@ void factor_vm::primitive_string() bool factor_vm::reallot_string_in_place_p(string *str, cell capacity) { return nursery.contains_p(str) - && (str->aux == F || nursery.contains_p(untag(str->aux))) + && (!to_boolean(str->aux) || nursery.contains_p(untag(str->aux))) && capacity <= string_capacity(str); } @@ -121,7 +121,7 @@ string* factor_vm::reallot_string(string *str_, cell capacity) { str->length = tag_fixnum(capacity); - if(str->aux != F) + if(to_boolean(str->aux)) { byte_array *aux = untag(str->aux); aux->capacity = tag_fixnum(capacity * 2); @@ -139,7 +139,7 @@ string* factor_vm::reallot_string(string *str_, cell capacity) memcpy(new_str->data(),str->data(),to_copy); - if(str->aux != F) + if(to_boolean(str->aux)) { byte_array *new_aux = allot_byte_array(capacity * sizeof(u16)); diff --git a/vm/tagged.hpp b/vm/tagged.hpp index e7a83d0111..a61c599aeb 100755 --- a/vm/tagged.hpp +++ b/vm/tagged.hpp @@ -29,9 +29,9 @@ struct tagged bool type_p(cell type_) const { return type() == type_; } - Type *untag_check(factor_vm *myvm) const { + Type *untag_check(factor_vm *parent) const { if(Type::type_number != TYPE_COUNT && !type_p(Type::type_number)) - myvm->type_error(Type::type_number,value_); + parent->type_error(Type::type_number,value_); return untagged(); } diff --git a/vm/tuples.cpp b/vm/tuples.cpp index 5fdde6596e..2d195ea13b 100755 --- a/vm/tuples.cpp +++ b/vm/tuples.cpp @@ -18,7 +18,7 @@ void factor_vm::primitive_tuple() tuple *t = allot_tuple(layout.value()); fixnum i; for(i = tuple_size(layout.untagged()) - 1; i >= 0; i--) - t->data()[i] = F; + t->data()[i] = false_object; dpush(tag(t)); } diff --git a/vm/vm.hpp b/vm/vm.hpp index c3d71dc6f2..d232d6153d 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -26,8 +26,8 @@ struct factor_vm /* Pooling unused contexts to make callbacks cheaper */ context *unused_contexts; - /* Canonical T object. It's just a word */ - cell T; + /* Canonical truth value. In Factor, 't' */ + cell true_object; /* Is call counting enabled? */ bool profiling_p; diff --git a/vm/words.cpp b/vm/words.cpp index 72460a64b9..6193a5c93c 100644 --- a/vm/words.cpp +++ b/vm/words.cpp @@ -14,11 +14,11 @@ word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) new_word->vocabulary = vocab.value(); new_word->name = name.value(); new_word->def = userenv[UNDEFINED_ENV]; - new_word->props = F; + new_word->props = false_object; new_word->counter = tag_fixnum(0); - new_word->pic_def = F; - new_word->pic_tail_def = F; - new_word->subprimitive = F; + new_word->pic_def = false_object; + new_word->pic_tail_def = false_object; + new_word->subprimitive = false_object; new_word->profiling = NULL; new_word->code = NULL;