From 810e309e0cea10a0836cb4c44822b08a1c71c981 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 23 Oct 2009 00:33:53 -0500 Subject: [PATCH] vm: rename userenv to special_objects --- vm/callbacks.cpp | 4 +-- vm/collector.hpp | 3 ++- vm/contexts.cpp | 12 ++++----- vm/contexts.hpp | 2 +- vm/debug.cpp | 5 ++-- vm/dispatch.cpp | 10 +++---- vm/errors.cpp | 6 ++--- vm/factor.cpp | 26 +++++++++--------- vm/image.cpp | 18 ++++++------- vm/image.hpp | 2 +- vm/inline_cache.cpp | 8 +++--- vm/io.cpp | 6 ++--- vm/jit.cpp | 4 +-- vm/jit.hpp | 29 ++++++++++++-------- vm/os-macosx.mm | 2 +- vm/profiler.cpp | 2 +- vm/quotations.cpp | 46 +++++++++++++++---------------- vm/run.cpp | 4 +-- vm/run.hpp | 66 ++++++++++++++++++++++----------------------- vm/vm.hpp | 2 +- vm/words.cpp | 2 +- 21 files changed, 133 insertions(+), 126 deletions(-) diff --git a/vm/callbacks.cpp b/vm/callbacks.cpp index 599271555b..4fe19c0bc0 100644 --- a/vm/callbacks.cpp +++ b/vm/callbacks.cpp @@ -21,7 +21,7 @@ void factor_vm::init_callbacks(cell size) void callback_heap::update(callback *stub) { - tagged code_template(parent->userenv[CALLBACK_STUB]); + tagged code_template(parent->special_objects[CALLBACK_STUB]); cell rel_class = untag_fixnum(array_nth(code_template.untagged(),1)); cell offset = untag_fixnum(array_nth(code_template.untagged(),3)); @@ -35,7 +35,7 @@ void callback_heap::update(callback *stub) callback *callback_heap::add(code_block *compiled) { - tagged code_template(parent->userenv[CALLBACK_STUB]); + tagged code_template(parent->special_objects[CALLBACK_STUB]); tagged insns(array_nth(code_template.untagged(),0)); cell size = array_capacity(insns.untagged()); diff --git a/vm/collector.hpp b/vm/collector.hpp index 4479fc7b45..a1a7dc5695 100644 --- a/vm/collector.hpp +++ b/vm/collector.hpp @@ -135,7 +135,8 @@ template struct collector { trace_registered_locals(); trace_registered_bignums(); - for(int i = 0; i < USER_ENV; i++) trace_handle(&parent->userenv[i]); + for(cell i = 0; i < special_object_count; i++) + trace_handle(&parent->special_objects[i]); } void trace_contexts() diff --git a/vm/contexts.cpp b/vm/contexts.cpp index ce52555a21..7af7fdaa57 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -80,9 +80,9 @@ void factor_vm::nest_stacks(stack_frame *magic_frame) new_ctx->magic_frame = magic_frame; - /* save per-callback userenv */ - new_ctx->current_callback_save = userenv[CURRENT_CALLBACK_ENV]; - new_ctx->catchstack_save = userenv[CATCHSTACK_ENV]; + /* save per-callback special_objects */ + new_ctx->current_callback_save = special_objects[OBJ_CURRENT_CALLBACK]; + new_ctx->catchstack_save = special_objects[OBJ_CATCHSTACK]; new_ctx->next = ctx; ctx = new_ctx; @@ -102,9 +102,9 @@ void factor_vm::unnest_stacks() ds = ctx->datastack_save; rs = ctx->retainstack_save; - /* restore per-callback userenv */ - userenv[CURRENT_CALLBACK_ENV] = ctx->current_callback_save; - userenv[CATCHSTACK_ENV] = ctx->catchstack_save; + /* restore per-callback special_objects */ + special_objects[OBJ_CURRENT_CALLBACK] = ctx->current_callback_save; + special_objects[OBJ_CATCHSTACK] = ctx->catchstack_save; context *old_ctx = ctx; ctx = old_ctx->next; diff --git a/vm/contexts.hpp b/vm/contexts.hpp index f66b5d0fe2..aa6f9ec8ce 100644 --- a/vm/contexts.hpp +++ b/vm/contexts.hpp @@ -41,7 +41,7 @@ struct context { /* memory region holding current retain stack */ segment *retainstack_region; - /* saved userenv slots on entry to callback */ + /* saved special_objects slots on entry to callback */ cell catchstack_save; cell current_callback_save; diff --git a/vm/debug.cpp b/vm/debug.cpp index b37a7e6f82..91fb1ea1d3 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -419,9 +419,8 @@ void factor_vm::factorbug() print_callstack(); else if(strcmp(cmd,"e") == 0) { - int i; - for(i = 0; i < USER_ENV; i++) - dump_cell((cell)&userenv[i]); + for(cell i = 0; i < special_object_count; i++) + dump_cell((cell)&special_objects[i]); } else if(strcmp(cmd,"g") == 0) dump_generations(); diff --git a/vm/dispatch.cpp b/vm/dispatch.cpp index 0abde2e711..bbe86c0fd6 100755 --- a/vm/dispatch.cpp +++ b/vm/dispatch.cpp @@ -187,21 +187,21 @@ void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, cell cac emit_class_lookup(index,PIC_HI_TAG_TUPLE); /* Do a cache lookup. */ - emit_with(parent->userenv[MEGA_LOOKUP],cache.value()); + emit_with(parent->special_objects[MEGA_LOOKUP],cache.value()); /* If we end up here, the cache missed. */ - emit(parent->userenv[JIT_PROLOG]); + emit(parent->special_objects[JIT_PROLOG]); /* Push index, method table and cache on the stack. */ push(methods.value()); push(tag_fixnum(index)); push(cache.value()); - word_call(parent->userenv[MEGA_MISS_WORD]); + word_call(parent->special_objects[MEGA_MISS_WORD]); /* Now the new method has been stored into the cache, and its on the stack. */ - emit(parent->userenv[JIT_EPILOG]); - emit(parent->userenv[JIT_EXECUTE_JUMP]); + emit(parent->special_objects[JIT_EPILOG]); + emit(parent->special_objects[JIT_EXECUTE_JUMP]); } } diff --git a/vm/errors.cpp b/vm/errors.cpp index 148799446a..3161f625cd 100755 --- a/vm/errors.cpp +++ b/vm/errors.cpp @@ -31,7 +31,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 && to_boolean(userenv[BREAK_ENV])) + if(!current_gc && to_boolean(special_objects[OBJ_BREAK])) { /* If error was thrown during heap scan, we re-enable the GC */ gc_off = false; @@ -55,7 +55,7 @@ void factor_vm::throw_error(cell error, stack_frame *callstack_top) else callstack_top = ctx->callstack_top; - throw_impl(userenv[BREAK_ENV],callstack_top,this); + throw_impl(special_objects[OBJ_BREAK],callstack_top,this); } /* Error was thrown in early startup before error handler is set, just crash. */ @@ -71,7 +71,7 @@ void factor_vm::throw_error(cell error, stack_frame *callstack_top) void factor_vm::general_error(vm_error_type error, cell arg1, cell arg2, stack_frame *callstack_top) { - throw_error(allot_array_4(userenv[ERROR_ENV], + throw_error(allot_array_4(special_objects[OBJ_ERROR], tag_fixnum(error),arg1,arg2),callstack_top); } diff --git a/vm/factor.cpp b/vm/factor.cpp index f3eb351d94..df27de84fd 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] = true_object; + special_objects[OBJ_STAGE2] = true_object; std::cout << "done\n"; } @@ -149,17 +149,17 @@ void factor_vm::init_factor(vm_parameters *p) init_profiler(); - 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(false_object,(cell)p->executable_path); - userenv[ARGS_ENV] = false_object; - userenv[EMBEDDED_ENV] = false_object; + special_objects[OBJ_CPU] = allot_alien(false_object,(cell)FACTOR_CPU_STRING); + special_objects[OBJ_OS] = allot_alien(false_object,(cell)FACTOR_OS_STRING); + special_objects[OBJ_CELL_SIZE] = tag_fixnum(sizeof(cell)); + special_objects[OBJ_EXECUTABLE] = allot_alien(false_object,(cell)p->executable_path); + special_objects[OBJ_ARGS] = false_object; + special_objects[OBJ_EMBEDDED] = false_object; /* We can GC now */ gc_off = false; - if(!to_boolean(userenv[STAGE2_ENV])) + if(!to_boolean(special_objects[OBJ_STAGE2])) do_stage1_init(); } @@ -174,7 +174,7 @@ void factor_vm::pass_args_to_factor(int argc, vm_char **argv) } args.trim(); - userenv[ARGS_ENV] = args.elements.value(); + special_objects[OBJ_ARGS] = args.elements.value(); } void factor_vm::start_factor(vm_parameters *p) @@ -182,13 +182,13 @@ void factor_vm::start_factor(vm_parameters *p) if(p->fep) factorbug(); nest_stacks(NULL); - c_to_factor_toplevel(userenv[BOOT_ENV]); + c_to_factor_toplevel(special_objects[OBJ_BOOT]); unnest_stacks(); } char *factor_vm::factor_eval_string(char *string) { - char *(*callback)(char *) = (char *(*)(char *))alien_offset(userenv[EVAL_CALLBACK_ENV]); + char *(*callback)(char *) = (char *(*)(char *))alien_offset(special_objects[OBJ_EVAL_CALLBACK]); return callback(string); } @@ -199,13 +199,13 @@ void factor_vm::factor_eval_free(char *result) void factor_vm::factor_yield() { - void (*callback)() = (void (*)())alien_offset(userenv[YIELD_CALLBACK_ENV]); + void (*callback)() = (void (*)())alien_offset(special_objects[OBJ_YIELD_CALLBACK]); callback(); } void factor_vm::factor_sleep(long us) { - void (*callback)(long) = (void (*)(long))alien_offset(userenv[SLEEP_CALLBACK_ENV]); + void (*callback)(long) = (void (*)(long))alien_offset(special_objects[OBJ_SLEEP_CALLBACK]); callback(us); } diff --git a/vm/image.cpp b/vm/image.cpp index f5879e7a32..1b7debc2b2 100755 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -6,7 +6,7 @@ namespace factor /* Certain special objects in the image are known to the runtime */ void factor_vm::init_objects(image_header *h) { - memcpy(userenv,h->userenv,sizeof(userenv)); + memcpy(special_objects,h->special_objects,sizeof(special_objects)); true_object = h->true_object; bignum_zero = h->bignum_zero; @@ -183,8 +183,8 @@ void factor_vm::relocate_object(object *object, where it is loaded, we need to fix up pointers in the image. */ void factor_vm::relocate_data(cell data_relocation_base, cell code_relocation_base) { - for(cell i = 0; i < USER_ENV; i++) - data_fixup(&userenv[i],data_relocation_base); + for(cell i = 0; i < special_object_count; i++) + data_fixup(&special_objects[i],data_relocation_base); data_fixup(&true_object,data_relocation_base); data_fixup(&bignum_zero,data_relocation_base); @@ -263,7 +263,7 @@ void factor_vm::load_image(vm_parameters *p) relocate_code(h.data_relocation_base); /* Store image path name */ - userenv[IMAGE_ENV] = allot_alien(false_object,(cell)p->image_path); + special_objects[OBJ_IMAGE] = allot_alien(false_object,(cell)p->image_path); } /* Save the current image to disk */ @@ -292,8 +292,8 @@ bool factor_vm::save_image(const vm_char *filename) 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] : false_object); + for(cell i = 0; i < special_object_count; i++) + h.special_objects[i] = (save_env_p(i) ? special_objects[i] : false_object); bool ok = true; @@ -326,9 +326,9 @@ void factor_vm::primitive_save_image_and_exit() gc_root path(dpop(),this); path.untag_check(this); - /* 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] = false_object; + /* strip out special_objects data which is set on startup anyway */ + for(cell i = 0; i < special_object_count; i++) + if(!save_env_p(i)) special_objects[i] = false_object; gc(collect_full_op, 0, /* requested size */ diff --git a/vm/image.hpp b/vm/image.hpp index 127709ffb7..3a5447c63b 100755 --- a/vm/image.hpp +++ b/vm/image.hpp @@ -25,7 +25,7 @@ struct image_header { /* tagged pointer to bignum -1 */ cell bignum_neg_one; /* Initial user environment */ - cell userenv[USER_ENV]; + cell special_objects[special_object_count]; }; struct vm_parameters { diff --git a/vm/inline_cache.cpp b/vm/inline_cache.cpp index 8d8709fdea..ee221c3797 100755 --- a/vm/inline_cache.cpp +++ b/vm/inline_cache.cpp @@ -86,9 +86,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->userenv[PIC_CHECK_TAG]; + code_template = parent->special_objects[PIC_CHECK_TAG]; else - code_template = parent->userenv[PIC_CHECK]; + code_template = parent->special_objects[PIC_CHECK]; emit_with(code_template,klass); } @@ -121,7 +121,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->userenv[PIC_HIT],method); + emit_with(parent->special_objects[PIC_HIT],method); } /* Generate machine code to handle a cache miss, which ultimately results in @@ -133,7 +133,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, push(methods.value()); push(tag_fixnum(index)); push(cache_entries.value()); - word_special(parent->userenv[tail_call_p ? PIC_MISS_TAIL_WORD : PIC_MISS_WORD]); + word_special(parent->special_objects[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) diff --git a/vm/io.cpp b/vm/io.cpp index a75f41c5bf..bbcac0b849 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(false_object,(cell)stdin); - userenv[STDOUT_ENV] = allot_alien(false_object,(cell)stdout); - userenv[STDERR_ENV] = allot_alien(false_object,(cell)stderr); + special_objects[OBJ_STDIN] = allot_alien(false_object,(cell)stdin); + special_objects[OBJ_STDOUT] = allot_alien(false_object,(cell)stdout); + special_objects[OBJ_STDERR] = allot_alien(false_object,(cell)stderr); } void factor_vm::io_error() diff --git a/vm/jit.cpp b/vm/jit.cpp index 98212d2efe..2fa948e4d6 100644 --- a/vm/jit.cpp +++ b/vm/jit.cpp @@ -79,8 +79,8 @@ void jit::emit_with(cell code_template_, cell argument_) { void jit::emit_class_lookup(fixnum index, cell type) { - emit_with(parent->userenv[PIC_LOAD],tag_fixnum(-index * sizeof(cell))); - emit(parent->userenv[type]); + emit_with(parent->special_objects[PIC_LOAD],tag_fixnum(-index * sizeof(cell))); + emit(parent->special_objects[type]); } /* Facility to convert compiled code offsets to quotation offsets. diff --git a/vm/jit.hpp b/vm/jit.hpp index 1940da9c7c..9feade4cc1 100644 --- a/vm/jit.hpp +++ b/vm/jit.hpp @@ -21,26 +21,31 @@ struct jit { void literal(cell literal) { literals.add(literal); } void emit_with(cell code_template_, cell literal_); - void push(cell literal) { - emit_with(parent->userenv[JIT_PUSH_IMMEDIATE],literal); + void push(cell literal) + { + emit_with(parent->special_objects[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.value()); - emit(parent->userenv[JIT_WORD_JUMP]); + emit(parent->special_objects[JIT_WORD_JUMP]); } - void word_call(cell word) { - emit_with(parent->userenv[JIT_WORD_CALL],word); + void word_call(cell word) + { + emit_with(parent->special_objects[JIT_WORD_CALL],word); } - void word_special(cell word) { - emit_with(parent->userenv[JIT_WORD_SPECIAL],word); + void word_special(cell word) + { + emit_with(parent->special_objects[JIT_WORD_SPECIAL],word); } - void emit_subprimitive(cell word_) { + void emit_subprimitive(cell word_) + { gc_root word(word_,parent); gc_root code_pair(word->subprimitive,parent); literals.append(untag(array_nth(code_pair.untagged(),0))); @@ -49,7 +54,8 @@ struct jit { void emit_class_lookup(fixnum index, cell type); - fixnum get_position() { + fixnum get_position() + { if(computing_offset_p) { /* If this is still on, emit() didn't clear it, @@ -60,7 +66,8 @@ struct jit { return position; } - void set_position(fixnum position_) { + void set_position(fixnum position_) + { if(computing_offset_p) position = position_; } diff --git a/vm/os-macosx.mm b/vm/os-macosx.mm index 96f169bbcf..438957bd04 100644 --- a/vm/os-macosx.mm +++ b/vm/os-macosx.mm @@ -14,7 +14,7 @@ NS_DURING NS_VOIDRETURN; NS_HANDLER dpush(allot_alien(false_object,(cell)localException)); - quot = userenv[COCOA_EXCEPTION_ENV]; + quot = special_objects[OBJ_COCOA_EXCEPTION]; if(!tagged(quot).type_p(QUOTATION_TYPE)) { /* No Cocoa exception handler was registered, so diff --git a/vm/profiler.cpp b/vm/profiler.cpp index df9d9ee67b..5113b55cf7 100755 --- a/vm/profiler.cpp +++ b/vm/profiler.cpp @@ -14,7 +14,7 @@ code_block *factor_vm::compile_profiling_stub(cell word_) gc_root word(word_,this); jit jit(code_block_profiling,word.value(),this); - jit.emit_with(userenv[JIT_PROFILING],word.value()); + jit.emit_with(special_objects[JIT_PROFILING],word.value()); return jit.to_code_block(); } diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 46087abeab..c65c0fe909 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->userenv[JIT_PRIMITIVE_WORD]; + return (i + 2) == length && array_nth(elements.untagged(),i + 1) == parent->special_objects[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->userenv[JIT_IF_WORD]; + && array_nth(elements.untagged(),i + 2) == parent->special_objects[JIT_IF_WORD]; } bool quotation_jit::fast_dip_p(cell i, cell length) { - return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_DIP_WORD]; + return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->special_objects[JIT_DIP_WORD]; } bool quotation_jit::fast_2dip_p(cell i, cell length) { - return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_2DIP_WORD]; + return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->special_objects[JIT_2DIP_WORD]; } bool quotation_jit::fast_3dip_p(cell i, cell length) { - return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_3DIP_WORD]; + return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent->special_objects[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->userenv[MEGA_LOOKUP_WORD]; + && array_nth(elements.untagged(),i + 3) == parent->special_objects[MEGA_LOOKUP_WORD]; } bool quotation_jit::declare_p(cell i, cell length) { return (i + 2) <= length - && array_nth(elements.untagged(),i + 1) == parent->userenv[JIT_DECLARE_WORD]; + && array_nth(elements.untagged(),i + 1) == parent->special_objects[JIT_DECLARE_WORD]; } bool quotation_jit::stack_frame_p() @@ -133,7 +133,7 @@ void quotation_jit::iterate_quotation() set_position(0); if(stack_frame) - emit(parent->userenv[JIT_PROLOG]); + emit(parent->special_objects[JIT_PROLOG]); cell i; cell length = array_capacity(elements.untagged()); @@ -152,23 +152,23 @@ void quotation_jit::iterate_quotation() if(parent->to_boolean(obj.as()->subprimitive)) emit_subprimitive(obj.value()); /* The (execute) primitive is special-cased */ - else if(obj.value() == parent->userenv[JIT_EXECUTE_WORD]) + else if(obj.value() == parent->special_objects[JIT_EXECUTE_WORD]) { if(i == length - 1) { - if(stack_frame) emit(parent->userenv[JIT_EPILOG]); + if(stack_frame) emit(parent->special_objects[JIT_EPILOG]); tail_call = true; - emit(parent->userenv[JIT_EXECUTE_JUMP]); + emit(parent->special_objects[JIT_EXECUTE_JUMP]); } else - emit(parent->userenv[JIT_EXECUTE_CALL]); + emit(parent->special_objects[JIT_EXECUTE_CALL]); } /* Everything else */ else { if(i == length - 1) { - if(stack_frame) emit(parent->userenv[JIT_EPILOG]); + if(stack_frame) emit(parent->special_objects[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->userenv[PIC_MISS_WORD] - || obj.value() == parent->userenv[PIC_MISS_TAIL_WORD]) + if(obj.value() == parent->special_objects[PIC_MISS_WORD] + || obj.value() == parent->special_objects[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->userenv[JIT_PRIMITIVE]); + emit(parent->special_objects[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->userenv[JIT_EPILOG]); + if(stack_frame) emit(parent->special_objects[JIT_EPILOG]); tail_call = true; emit_quot(array_nth(elements.untagged(),i)); emit_quot(array_nth(elements.untagged(),i + 1)); - emit(parent->userenv[JIT_IF]); + emit(parent->special_objects[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->userenv[JIT_DIP]); + emit(parent->special_objects[JIT_DIP]); i++; } /* 2dip */ else if(fast_2dip_p(i,length)) { emit_quot(obj.value()); - emit(parent->userenv[JIT_2DIP]); + emit(parent->special_objects[JIT_2DIP]); i++; } /* 3dip */ else if(fast_3dip_p(i,length)) { emit_quot(obj.value()); - emit(parent->userenv[JIT_3DIP]); + emit(parent->special_objects[JIT_3DIP]); i++; } else @@ -276,8 +276,8 @@ void quotation_jit::iterate_quotation() set_position(length); if(stack_frame) - emit(parent->userenv[JIT_EPILOG]); - emit(parent->userenv[JIT_RETURN]); + emit(parent->special_objects[JIT_EPILOG]); + emit(parent->special_objects[JIT_RETURN]); } } diff --git a/vm/run.cpp b/vm/run.cpp index 79aca937ca..b6e3324502 100755 --- a/vm/run.cpp +++ b/vm/run.cpp @@ -6,14 +6,14 @@ namespace factor void factor_vm::primitive_getenv() { fixnum e = untag_fixnum(dpeek()); - drepl(userenv[e]); + drepl(special_objects[e]); } void factor_vm::primitive_setenv() { fixnum e = untag_fixnum(dpop()); cell value = dpop(); - userenv[e] = value; + special_objects[e] = value; } void factor_vm::primitive_exit() diff --git a/vm/run.hpp b/vm/run.hpp index 9a23979066..714ac1f64a 100755 --- a/vm/run.hpp +++ b/vm/run.hpp @@ -1,39 +1,39 @@ namespace factor { -#define USER_ENV 70 +static const cell special_object_count = 70; enum special_object { - NAMESTACK_ENV, /* used by library only */ - CATCHSTACK_ENV, /* used by library only, per-callback */ + OBJ_NAMESTACK, /* used by library only */ + OBJ_CATCHSTACK, /* used by library only, per-callback */ - CURRENT_CALLBACK_ENV = 2, /* used by library only, per-callback */ - WALKER_HOOK_ENV, /* non-local exit hook, used by library only */ - CALLCC_1_ENV, /* used to pass the value in callcc1 */ + OBJ_CURRENT_CALLBACK = 2, /* used by library only, per-callback */ + OBJ_WALKER_HOOK, /* non-local exit hook, used by library only */ + OBJ_CALLCC_1, /* used to pass the value in callcc1 */ - BREAK_ENV = 5, /* quotation called by throw primitive */ - ERROR_ENV, /* a marker consed onto kernel errors */ + OBJ_BREAK = 5, /* quotation called by throw primitive */ + OBJ_ERROR, /* a marker consed onto kernel errors */ - CELL_SIZE_ENV = 7, /* sizeof(cell) */ - CPU_ENV, /* CPU architecture */ - OS_ENV, /* operating system name */ + OBJ_CELL_SIZE = 7, /* sizeof(cell) */ + OBJ_CPU, /* CPU architecture */ + OBJ_OS, /* operating system name */ - ARGS_ENV = 10, /* command line arguments */ - STDIN_ENV, /* stdin FILE* handle */ - STDOUT_ENV, /* stdout FILE* handle */ + OBJ_ARGS = 10, /* command line arguments */ + OBJ_STDIN, /* stdin FILE* handle */ + OBJ_STDOUT, /* stdout FILE* handle */ - IMAGE_ENV = 13, /* image path name */ - EXECUTABLE_ENV, /* runtime executable path name */ + OBJ_IMAGE = 13, /* image path name */ + OBJ_EXECUTABLE, /* runtime executable path name */ - EMBEDDED_ENV = 15, /* are we embedded in another app? */ - EVAL_CALLBACK_ENV, /* used when Factor is embedded in a C app */ - YIELD_CALLBACK_ENV, /* used when Factor is embedded in a C app */ - SLEEP_CALLBACK_ENV, /* used when Factor is embedded in a C app */ + OBJ_EMBEDDED = 15, /* are we embedded in another app? */ + OBJ_EVAL_CALLBACK, /* used when Factor is embedded in a C app */ + OBJ_YIELD_CALLBACK, /* used when Factor is embedded in a C app */ + OBJ_SLEEP_CALLBACK, /* used when Factor is embedded in a C app */ - COCOA_EXCEPTION_ENV = 19, /* Cocoa exception handler quotation */ + OBJ_COCOA_EXCEPTION = 19, /* Cocoa exception handler quotation */ - BOOT_ENV = 20, /* boot quotation */ - GLOBAL_ENV, /* global namespace */ + OBJ_BOOT = 20, /* boot quotation */ + OBJ_GLOBAL, /* global namespace */ /* Quotation compilation in quotations.c */ JIT_PROLOG = 23, @@ -79,25 +79,25 @@ enum special_object { MEGA_LOOKUP_WORD, MEGA_MISS_WORD, - UNDEFINED_ENV = 60, /* default quotation for undefined words */ + OBJ_UNDEFINED = 60, /* default quotation for undefined words */ - STDERR_ENV = 61, /* stderr FILE* handle */ + OBJ_STDERR = 61, /* stderr FILE* handle */ - STAGE2_ENV = 62, /* have we bootstrapped? */ + OBJ_STAGE2 = 62, /* have we bootstrapped? */ - CURRENT_THREAD_ENV = 63, + OBJ_CURRENT_THREAD = 63, - THREADS_ENV = 64, - RUN_QUEUE_ENV = 65, - SLEEP_QUEUE_ENV = 66, + OBJ_THREADS = 64, + OBJ_RUN_QUEUE = 65, + OBJ_SLEEP_QUEUE = 66, }; -#define FIRST_SAVE_ENV BOOT_ENV -#define LAST_SAVE_ENV STAGE2_ENV +#define OBJ_FIRST_SAVE OBJ_BOOT +#define OBJ_LAST_SAVE OBJ_STAGE2 inline static bool save_env_p(cell i) { - return (i >= FIRST_SAVE_ENV && i <= LAST_SAVE_ENV); + return (i >= OBJ_FIRST_SAVE && i <= OBJ_LAST_SAVE); } } diff --git a/vm/vm.hpp b/vm/vm.hpp index 78efc915d7..e22e45f22e 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -18,7 +18,7 @@ struct factor_vm cell decks_offset; /* TAGGED user environment data; see getenv/setenv prims */ - cell userenv[USER_ENV]; + cell special_objects[special_object_count]; /* Data stack and retain stack sizes */ cell ds_size, rs_size; diff --git a/vm/words.cpp b/vm/words.cpp index 9d3ccff3c3..37a3821069 100644 --- a/vm/words.cpp +++ b/vm/words.cpp @@ -13,7 +13,7 @@ word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) new_word->hashcode = hashcode_; new_word->vocabulary = vocab.value(); new_word->name = name.value(); - new_word->def = userenv[UNDEFINED_ENV]; + new_word->def = special_objects[OBJ_UNDEFINED]; new_word->props = false_object; new_word->counter = tag_fixnum(0); new_word->pic_def = false_object;