case ALIEN_TYPE:
{
alien *ptr = untag<alien>(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:
new_alien->base = delegate.value();
new_alien->displacement = displacement;
- new_alien->expired = F;
+ new_alien->expired = false_object;
return new_alien.value();
}
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<object>(alien).type())
symbol_char *sym = name->data<symbol_char>();
- if(library.value() == F)
- box_alien(ffi_dlsym(NULL,sym));
- else
+ if(to_boolean(library.value()))
{
dll *d = untag_check<dll>(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 */
void factor_vm::primitive_dll_validp()
{
cell library = dpop();
- if(library == F)
- dpush(T);
+ if(to_boolean(library))
+ dpush(tag_boolean(untag_check<dll>(library)->dll != NULL));
else
- dpush(untag_check<dll>(library)->dll == NULL ? F : T);
+ dpush(true_object);
}
/* gets the address of an object representing a C pointer */
case ALIEN_TYPE:
{
alien *ptr = untag<alien>(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:
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)
cell count;
gc_root<array> 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);
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)
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);
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;
}
}
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;
}
}
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
{
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()
cell symbol = array_nth(literals,index);
cell library = array_nth(literals,index + 1);
- dll *d = (library == F ? NULL : untag<dll>(library));
+ dll *d = (to_boolean(library) ? untag<dll>(library) : NULL);
if(d != NULL && !d->dll)
return (void *)factor::undefined_symbol;
cell factor_vm::compute_relocation(relocation_entry rel, cell index, code_block *compiled)
{
- array *literals = (compiled->literals == F
- ? NULL : untag<array>(compiled->literals));
+ array *literals = (to_boolean(compiled->literals)
+ ? untag<array>(compiled->literals) : NULL);
cell offset = relocation_offset_of(rel) + (cell)compiled->xt();
#define ARG array_nth(literals,index)
template<typename Iterator> void factor_vm::iterate_relocations(code_block *compiled, Iterator &iter)
{
- if(compiled->relocation != F)
+ if(to_boolean(compiled->relocation))
{
byte_array *relocation = untag<byte_array>(compiled->relocation);
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<array>(compiled->literals).untag_check(this);
- if(compiled->relocation != F)
+ if(to_boolean(compiled->relocation))
tagged<byte_array>(compiled->relocation).untag_check(this);
#endif
/* 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();
memcpy(compiled + 1,code.untagged() + 1,code_length);
/* fixup labels */
- if(labels.value() != F)
+ if(to_boolean(labels.value()))
fixup_labels(labels.as<array>().untagged(),compiled);
/* next time we do a minor GC, we have to scan the code heap for
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 {
cell obj;
- while((obj = next_object()) != F)
+ while(to_boolean(obj = next_object()))
{
switch(tagged<object>(obj).type())
{
void operator()(code_block *compiled)
{
- compiled->owner = F;
+ compiled->owner = false_object;
}
};
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);
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 */
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;
{
if(((cell *)ds_bot)[i] != array_nth(saved_datastack,i))
{
- dpush(F);
+ dpush(false_object);
return;
}
}
- dpush(T);
+ dpush(true_object);
}
}
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);
{
begin_scan();
cell obj;
- while((obj = next_object()) != F)
+ while(to_boolean(obj = next_object()))
iterator(tagged<object>(obj));
end_scan();
}
begin_scan();
cell obj;
- while((obj = next_object()) != F)
+ while(to_boolean(obj = next_object()))
{
if(type == TYPE_COUNT || tagged<object>(obj).type_p(type))
{
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);
index -= 2;
}
- return F;
+ return false_object;
}
cell factor_vm::search_lookup_hash(cell table, cell klass, cell hashcode)
{
array *buckets = untag<array>(table);
cell bucket = array_nth(buckets,hashcode & (array_capacity(buckets) - 1));
- if(tagged<object>(bucket).type_p(WORD_TYPE) || bucket == F)
+ if(tagged<object>(bucket).type_p(WORD_TYPE) || !to_boolean(bucket))
return bucket;
else
return search_lookup_alist(bucket,klass);
if(tagged<object>(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;
}
}
critical_error("Cannot find tuple method",methods);
- return F;
+ return false_object;
}
cell factor_vm::lookup_hi_tag_method(cell obj, cell methods)
{
/* 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;
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
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()
fflush(stdout);
compile_all_words();
- userenv[STAGE2_ENV] = T;
+ userenv[STAGE2_ENV] = true_object;
print_string("done\n");
fflush(stdout);
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();
}
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();
{
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;
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;
/* 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,
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 {
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);
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);
}
}
/* 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 */
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()
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()
{
if(feof(file))
{
- dpush(F);
+ dpush(false_object);
break;
}
else
{
if(feof(file))
{
- dpush(F);
+ dpush(false_object);
break;
}
else
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());
#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 */
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)
if(end == c_str + capacity - 1)
drepl(allot_float(f));
else
- drepl(F);
+ drepl(false_object);
}
void factor_vm::primitive_float_to_str()
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<object>(quot).type_p(QUOTATION_TYPE))
{
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;
}
switch(tagged<object>(obj).type())
{
case WORD_TYPE:
- if(parent_vm->untag<word>(obj)->subprimitive == F)
+ if(!parent_vm->to_boolean(parent_vm->untag<word>(obj)->subprimitive))
return true;
break;
case QUOTATION_TYPE:
{
case WORD_TYPE:
/* Intrinsics */
- if(obj.as<word>()->subprimitive != F)
+ if(parent_vm->to_boolean(obj.as<word>()->subprimitive))
emit_subprimitive(obj.value());
/* The (execute) primitive is special-cased */
else if(obj.value() == parent_vm->userenv[JIT_EXECUTE_WORD])
{
quotation *quot = allot<quotation>(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<quotation>(quot));
str->data()[index] = ((ch & 0x7f) | 0x80);
- if(str->aux == F)
+ if(to_boolean(str->aux))
+ aux = untag<byte_array>(str->aux);
+ else
{
/* We don't need to pre-initialize the
byte array with any data, since we
str->aux = tag<byte_array>(aux);
write_barrier(&str->aux);
}
- else
- aux = untag<byte_array>(str->aux);
aux->data<u16>()[index] = ((ch >> 7) ^ 1);
}
string *str = allot<string>(string_size(capacity));
str->length = tag_fixnum(capacity);
- str->hashcode = F;
- str->aux = F;
+ str->hashcode = false_object;
+ str->aux = false_object;
return str;
}
bool factor_vm::reallot_string_in_place_p(string *str, cell capacity)
{
return nursery.contains_p(str)
- && (str->aux == F || nursery.contains_p(untag<byte_array>(str->aux)))
+ && (!to_boolean(str->aux) || nursery.contains_p(untag<byte_array>(str->aux)))
&& capacity <= string_capacity(str);
}
{
str->length = tag_fixnum(capacity);
- if(str->aux != F)
+ if(to_boolean(str->aux))
{
byte_array *aux = untag<byte_array>(str->aux);
aux->capacity = tag_fixnum(capacity * 2);
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));
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<tuple>(t));
}
/* 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;
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;