From 80716a1b6e34fc31e43301753191a8f136572251 Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Mon, 17 Aug 2009 21:37:12 +0100 Subject: [PATCH] moved global state from contexts and run into vm Also renamed template type from T to TYPE to prevent clash with vm::T (true) --- vm/booleans.hpp | 4 ---- vm/contexts.cpp | 2 -- vm/contexts.hpp | 2 +- vm/data_gc.cpp | 8 ++++---- vm/data_heap.cpp | 4 ++-- vm/image.cpp | 8 ++++---- vm/jit.hpp | 2 +- vm/run.cpp | 1 - vm/run.hpp | 3 --- vm/vm.hpp | 34 +++++++++++++++++++++++++--------- 10 files changed, 37 insertions(+), 31 deletions(-) mode change 100644 => 100755 vm/run.hpp diff --git a/vm/booleans.hpp b/vm/booleans.hpp index ea16e0536b..c410f67481 100644 --- a/vm/booleans.hpp +++ b/vm/booleans.hpp @@ -1,10 +1,6 @@ namespace factor { -inline static cell tag_boolean(cell untagged) -{ - return (untagged ? T : F); -} VM_C_API void box_boolean(bool value); VM_C_API bool to_boolean(cell value); diff --git a/vm/contexts.cpp b/vm/contexts.cpp index 86156de3b5..03768ec0db 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -5,8 +5,6 @@ factor::context *stack_chain; namespace factor { -cell ds_size, rs_size; -context *unused_contexts; void factorvm::reset_datastack() { diff --git a/vm/contexts.hpp b/vm/contexts.hpp index 4a6f401f0b..56642bcd1a 100644 --- a/vm/contexts.hpp +++ b/vm/contexts.hpp @@ -36,7 +36,7 @@ struct context { context *next; }; -extern cell ds_size, rs_size; +//extern cell ds_size, rs_size; #define ds_bot (stack_chain->datastack_region->start) #define ds_top (stack_chain->datastack_region->end) diff --git a/vm/data_gc.cpp b/vm/data_gc.cpp index ea7098912e..ac0402b47d 100755 --- a/vm/data_gc.cpp +++ b/vm/data_gc.cpp @@ -123,22 +123,22 @@ object *resolve_forwarding(object *untagged) return vm->resolve_forwarding(untagged); } -template T *factorvm::copy_untagged_object(T *untagged) +template TYPE *factorvm::copy_untagged_object(TYPE *untagged) { check_data_pointer(untagged); if(untagged->h.forwarding_pointer_p()) - untagged = (T *)resolve_forwarding(untagged->h.forwarding_pointer()); + untagged = (TYPE *)resolve_forwarding(untagged->h.forwarding_pointer()); else { untagged->h.check_header(); - untagged = (T *)copy_object_impl(untagged); + untagged = (TYPE *)copy_object_impl(untagged); } return untagged; } -template T *copy_untagged_object(T *untagged) +template TYPE *copy_untagged_object(TYPE *untagged) { return vm->copy_untagged_object(untagged); } diff --git a/vm/data_heap.cpp b/vm/data_heap.cpp index 377cd6e943..34284659f0 100755 --- a/vm/data_heap.cpp +++ b/vm/data_heap.cpp @@ -453,7 +453,7 @@ PRIMITIVE(end_scan) PRIMITIVE_GETVM()->vmprim_end_scan(); } -template void factorvm::each_object(T &functor) +template void factorvm::each_object(TYPE &functor) { begin_scan(); cell obj; @@ -462,7 +462,7 @@ template void factorvm::each_object(T &functor) end_scan(); } -template void each_object(T &functor) +template void each_object(TYPE &functor) { return vm->each_object(functor); } diff --git a/vm/image.cpp b/vm/image.cpp index 24988b24b5..746461680c 100755 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -202,14 +202,14 @@ void data_fixup(cell *cell) return vm->data_fixup(cell); } -template void factorvm::code_fixup(T **handle) +template void factorvm::code_fixup(TYPE **handle) { - T *ptr = *handle; - T *new_ptr = (T *)(((cell)ptr) + (code.seg->start - code_relocation_base)); + TYPE *ptr = *handle; + TYPE *new_ptr = (TYPE *)(((cell)ptr) + (code.seg->start - code_relocation_base)); *handle = new_ptr; } -template void code_fixup(T **handle) +template void code_fixup(TYPE **handle) { return vm->code_fixup(handle); } diff --git a/vm/jit.hpp b/vm/jit.hpp index 0fa145cded..81754be26a 100644 --- a/vm/jit.hpp +++ b/vm/jit.hpp @@ -42,7 +42,7 @@ struct jit { void emit_subprimitive(cell word_) { gc_root word(word_,myvm); gc_root code_template(word->subprimitive,myvm); - if(array_capacity(code_template.untagged()) > 1) literal(T); + if(array_capacity(code_template.untagged()) > 1) literal(myvm->T); emit(code_template.value()); } diff --git a/vm/run.cpp b/vm/run.cpp index e0ad1abb12..7f4894f1ef 100755 --- a/vm/run.cpp +++ b/vm/run.cpp @@ -5,7 +5,6 @@ factor::cell userenv[USER_ENV]; namespace factor { -cell T; inline void factorvm::vmprim_getenv() { diff --git a/vm/run.hpp b/vm/run.hpp old mode 100644 new mode 100755 index 7527889efb..4b43a156e4 --- a/vm/run.hpp +++ b/vm/run.hpp @@ -98,9 +98,6 @@ inline static bool save_env_p(cell i) return (i >= FIRST_SAVE_ENV && i <= LAST_SAVE_ENV) || i == STACK_TRACES_ENV; } -/* Canonical T object. It's just a word */ -extern cell T; - PRIMITIVE(getenv); PRIMITIVE(setenv); PRIMITIVE(exit); diff --git a/vm/vm.hpp b/vm/vm.hpp index 1caa30040b..a58ac1ad9e 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -15,6 +15,8 @@ typedef u8 card_deck; struct factorvm { // contexts + cell ds_size, rs_size; + context *unused_contexts; void reset_datastack(); void reset_retainstack(); void fix_stacks(); @@ -33,6 +35,7 @@ struct factorvm { inline void vmprim_check_datastack(); // run + cell T; /* Canonical T object. It's just a word */ inline void vmprim_getenv(); inline void vmprim_setenv(); inline void vmprim_exit(); @@ -264,6 +267,7 @@ struct factorvm { //booleans void box_boolean(bool value); bool to_boolean(cell value); + inline cell tag_boolean(cell untagged); //byte arrays byte_array *allot_byte_array(cell size); @@ -853,26 +857,26 @@ struct gc_bignum #define GC_BIGNUM(x,vm) gc_bignum x##__gc_root(&x,vm) //generic_arrays.hpp -template T *factorvm::allot_array_internal(cell capacity) +template TYPE *factorvm::allot_array_internal(cell capacity) { - T *array = allot(array_size(capacity)); + TYPE *array = allot(array_size(capacity)); array->capacity = tag_fixnum(capacity); return array; } -template T *allot_array_internal(cell capacity) +template TYPE *allot_array_internal(cell capacity) { - return vm->allot_array_internal(capacity); + return vm->allot_array_internal(capacity); } -template bool factorvm::reallot_array_in_place_p(T *array, cell capacity) +template bool factorvm::reallot_array_in_place_p(TYPE *array, cell capacity) { return in_zone(&nursery,array) && capacity <= array_capacity(array); } -template bool reallot_array_in_place_p(T *array, cell capacity) +template bool reallot_array_in_place_p(TYPE *array, cell capacity) { - return vm->reallot_array_in_place_p(array,capacity); + return vm->reallot_array_in_place_p(array,capacity); } template TYPE *factorvm::reallot_array(TYPE *array_, cell capacity) @@ -1002,7 +1006,7 @@ inline double bignum_to_float(cell tagged) //callstack.hpp /* This is a little tricky. The iterator may allocate memory, so we keep the callstack in a GC root and use relative offsets */ -template void factorvm::iterate_callstack_object(callstack *stack_, T &iterator) +template void factorvm::iterate_callstack_object(callstack *stack_, TYPE &iterator) { gc_root stack(stack_,vm); fixnum frame_offset = untag_fixnum(stack->length) - sizeof(stack_frame); @@ -1015,11 +1019,23 @@ template void factorvm::iterate_callstack_object(callstack *stack_, } } -template void iterate_callstack_object(callstack *stack_, T &iterator) +template void iterate_callstack_object(callstack *stack_, TYPE &iterator) { return vm->iterate_callstack_object(stack_,iterator); } +//booleans.hpp +inline cell factorvm::tag_boolean(cell untagged) +{ + return (untagged ? T : F); +} + +inline cell tag_boolean(cell untagged) +{ + return vm->tag_boolean(untagged); +} + + // next method here: