diff --git a/vm/alien.cpp b/vm/alien.cpp index 84e40a4613..2287263442 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()) @@ -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: @@ -202,9 +202,9 @@ VM_C_API char *unbox_alien(factor_vm *myvm) 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) diff --git a/vm/arrays.hpp b/vm/arrays.hpp index accf8b3b04..d4cbcc11c3 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 *myvm, cell capacity = 10) : + count(0), elements(myvm->allot_array(capacity,false_object),myvm) {} void add(cell elt); void append(array *elts); diff --git a/vm/booleans.cpp b/vm/booleans.cpp index f1f0230c13..538f4b7dce 100644 --- a/vm/booleans.cpp +++ b/vm/booleans.cpp @@ -5,7 +5,7 @@ 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) @@ -13,11 +13,6 @@ VM_C_API void box_boolean(bool value, factor_vm *myvm) return myvm->box_boolean(value); } -bool factor_vm::to_boolean(cell value) -{ - return value != F; -} - VM_C_API bool to_boolean(cell value, factor_vm *myvm) { return myvm->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/callstack.cpp b/vm/callstack.cpp index 0b7663e513..838274cff8 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; } } diff --git a/vm/code_block.cpp b/vm/code_block.cpp index 0afd98dd0f..80862bc426 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); @@ -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 @@ -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..8caee005fb 100755 --- a/vm/code_heap.cpp +++ b/vm/code_heap.cpp @@ -51,8 +51,8 @@ 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 { @@ -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..69488e04ab 100644 --- a/vm/collector.hpp +++ b/vm/collector.hpp @@ -119,7 +119,7 @@ template struct collector { the user environment and extra roots registered by local_roots.hpp */ void trace_roots() { - trace_handle(&myvm->T); + trace_handle(&myvm->true_object); trace_handle(&myvm->bignum_zero); trace_handle(&myvm->bignum_pos_one); trace_handle(&myvm->bignum_neg_one); diff --git a/vm/contexts.cpp b/vm/contexts.cpp index bed044250e..c914271c89 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -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/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..8fad13d663 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -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)) { @@ -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..23b0b80765 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) 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/image.cpp b/vm/image.cpp index 05e0d66724..cb598a18c3 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,7 +184,7 @@ 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 { @@ -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); @@ -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/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..1a35cabbaf 100644 --- a/vm/jit.cpp +++ b/vm/jit.cpp @@ -103,7 +103,7 @@ code_block *jit::to_code_block() return parent_vm->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/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/math.cpp b/vm/math.cpp index e4caa0f5ca..679cdae166 100755 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -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() 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/quotations.cpp b/vm/quotations.cpp index 60fdce1003..4c15d2d57e 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -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_vm->to_boolean(parent_vm->untag(obj)->subprimitive)) return true; break; case QUOTATION_TYPE: @@ -149,7 +149,7 @@ void quotation_jit::iterate_quotation() { case WORD_TYPE: /* Intrinsics */ - if(obj.as()->subprimitive != F) + if(parent_vm->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]) @@ -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)); 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/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;