moved global state from contexts and run into vm
Also renamed template type from T to TYPE to prevent clash with vm::T (true)db4
parent
ecfd9a6075
commit
80716a1b6e
|
@ -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);
|
||||
|
|
|
@ -5,8 +5,6 @@ factor::context *stack_chain;
|
|||
namespace factor
|
||||
{
|
||||
|
||||
cell ds_size, rs_size;
|
||||
context *unused_contexts;
|
||||
|
||||
void factorvm::reset_datastack()
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ factor::cell userenv[USER_ENV];
|
|||
namespace factor
|
||||
{
|
||||
|
||||
cell T;
|
||||
|
||||
inline void factorvm::vmprim_getenv()
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
34
vm/vm.hpp
34
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:
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue