]> gitweb.factorcode.org Git - factor.git/commitdiff
moved global state from contexts and run into vm
authorPhil Dawes <phil@phildawes.net>
Mon, 17 Aug 2009 20:37:12 +0000 (21:37 +0100)
committerPhil Dawes <phil@phildawes.net>
Wed, 16 Sep 2009 07:16:24 +0000 (08:16 +0100)
Also renamed template type from T to TYPE to prevent clash with vm::T (true)

vm/booleans.hpp
vm/contexts.cpp
vm/contexts.hpp
vm/data_gc.cpp
vm/data_heap.cpp
vm/image.cpp
vm/jit.hpp
vm/run.cpp
vm/run.hpp [changed mode: 0644->0755]
vm/vm.hpp

index ea16e0536b33d6aafefa02eae2bb9dbb21c375df..c410f67481b36fc62e8d770a6a1b566f3b8f07cc 100644 (file)
@@ -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);
index 86156de3b5066148072fb3f917b89d783f8076a9..03768ec0db7e0719416426b1e71ee189349d1d90 100644 (file)
@@ -5,8 +5,6 @@ factor::context *stack_chain;
 namespace factor
 {
 
-cell ds_size, rs_size;
-context *unused_contexts;
 
 void factorvm::reset_datastack()
 {
index 4a6f401f0b4a5df8507247d4eb7337f716ef1f28..56642bcd1a627844aab732bfd10f8081abc1647c 100644 (file)
@@ -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)
index ea7098912ebd98d5589199c2d253aec89a9a4c14..ac0402b47d8fde4d0fff515ced644ed34b3ea18a 100755 (executable)
@@ -123,22 +123,22 @@ object *resolve_forwarding(object *untagged)
        return vm->resolve_forwarding(untagged);
 }
 
-template <typename T> T *factorvm::copy_untagged_object(T *untagged)
+template <typename TYPE> 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 <typename T> T *copy_untagged_object(T *untagged)
+template <typename TYPE> TYPE *copy_untagged_object(TYPE *untagged)
 {
        return vm->copy_untagged_object(untagged);
 }
index 377cd6e943fd274de3617d90dec20d12234ee6e0..34284659f0ec07c377ef85c28b5b851181fa8f31 100755 (executable)
@@ -453,7 +453,7 @@ PRIMITIVE(end_scan)
        PRIMITIVE_GETVM()->vmprim_end_scan();
 }
 
-template<typename T> void factorvm::each_object(T &functor)
+template<typename TYPE> void factorvm::each_object(TYPE &functor)
 {
        begin_scan();
        cell obj;
@@ -462,7 +462,7 @@ template<typename T> void factorvm::each_object(T &functor)
        end_scan();
 }
 
-template<typename T> void each_object(T &functor)
+template<typename TYPE> void each_object(TYPE &functor)
 {
        return vm->each_object(functor);
 }
index 24988b24b538867861414cac80941dcc928eddb3..746461680c131c402492a45948f1c417ac512996 100755 (executable)
@@ -202,14 +202,14 @@ void data_fixup(cell *cell)
        return vm->data_fixup(cell);
 }
 
-template <typename T> void factorvm::code_fixup(T **handle)
+template <typename TYPE> 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 <typename T> void code_fixup(T **handle)
+template <typename TYPE> void code_fixup(TYPE **handle)
 {
        return vm->code_fixup(handle);
 }
index 0fa145cdeda6e8d795c46c51045702b032bb8355..81754be26a9cde286082bd215bffa5b7d2dd1443 100644 (file)
@@ -42,7 +42,7 @@ struct jit {
        void emit_subprimitive(cell word_) {
                gc_root<word> word(word_,myvm);
                gc_root<array> 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());
        }
 
index e0ad1abb1214c5136197b83c5f2f1f56e10e3071..7f4894f1eff225c3a3ae3c7b3e656913bf12ddce 100755 (executable)
@@ -5,7 +5,6 @@ factor::cell userenv[USER_ENV];
 namespace factor
 {
 
-cell T;
 
 inline void factorvm::vmprim_getenv()
 {
old mode 100644 (file)
new mode 100755 (executable)
index 7527889..4b43a15
@@ -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);
index 1caa30040b3ad39b1b9b77372e49ecb945a84bb8..a58ac1ad9eecc19f33569eadaeba5c1b2f187b90 100644 (file)
--- 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 <typename T> T *factorvm::allot_array_internal(cell capacity)
+template <typename TYPE> TYPE *factorvm::allot_array_internal(cell capacity)
 {
-       T *array = allot<T>(array_size<T>(capacity));
+       TYPE *array = allot<TYPE>(array_size<TYPE>(capacity));
        array->capacity = tag_fixnum(capacity);
        return array;
 }
 
-template <typename T> T *allot_array_internal(cell capacity)
+template <typename TYPE> TYPE *allot_array_internal(cell capacity)
 {
-       return vm->allot_array_internal<T>(capacity);
+       return vm->allot_array_internal<TYPE>(capacity);
 }
 
-template <typename T> bool factorvm::reallot_array_in_place_p(T *array, cell capacity)
+template <typename TYPE> bool factorvm::reallot_array_in_place_p(TYPE *array, cell capacity)
 {
        return in_zone(&nursery,array) && capacity <= array_capacity(array);
 }
 
-template <typename T> bool reallot_array_in_place_p(T *array, cell capacity)
+template <typename TYPE> bool reallot_array_in_place_p(TYPE *array, cell capacity)
 {
-       return vm->reallot_array_in_place_p<T>(array,capacity);
+       return vm->reallot_array_in_place_p<TYPE>(array,capacity);
 }
 
 template <typename TYPE> 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<typename T> void factorvm::iterate_callstack_object(callstack *stack_, T &iterator)
+template<typename TYPE> void factorvm::iterate_callstack_object(callstack *stack_, TYPE &iterator)
 {
        gc_root<callstack> stack(stack_,vm);
        fixnum frame_offset = untag_fixnum(stack->length) - sizeof(stack_frame);
@@ -1015,11 +1019,23 @@ template<typename T> void factorvm::iterate_callstack_object(callstack *stack_,
        }
 }
 
-template<typename T> void iterate_callstack_object(callstack *stack_, T &iterator)
+template<typename TYPE> 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: