moved local roots state to vm, shuffled includes around

db4
Phil Dawes 2009-08-17 21:37:09 +01:00
parent 8fea98ad7a
commit 386dafe747
8 changed files with 38 additions and 27 deletions

2
vm/code_gc.hpp Normal file → Executable file
View File

@ -14,7 +14,7 @@ struct heap {
heap_free_list free; heap_free_list free;
}; };
typedef void (*heap_iterator)(heap_block *compiled); //typedef void (*heap_iterator)(heap_block *compiled);
void new_heap(heap *h, cell size); void new_heap(heap *h, cell size);
void build_free_list(heap *h, cell size); void build_free_list(heap *h, cell size);

2
vm/code_heap.hpp Normal file → Executable file
View File

@ -10,7 +10,7 @@ bool in_code_heap_p(cell ptr);
void jit_compile_word(cell word, cell def, bool relocate); void jit_compile_word(cell word, cell def, bool relocate);
typedef void (*code_heap_iterator)(code_block *compiled); //typedef void (*code_heap_iterator)(code_block *compiled);
void iterate_code_heap(code_heap_iterator iter); void iterate_code_heap(code_heap_iterator iter);

View File

@ -10,6 +10,7 @@ struct jit {
bool computing_offset_p; bool computing_offset_p;
fixnum position; fixnum position;
cell offset; cell offset;
//factorvm *vm;
jit(cell jit_type, cell owner); jit(cell jit_type, cell owner);
void compute_position(cell offset); void compute_position(cell offset);

View File

@ -2,9 +2,4 @@
namespace factor namespace factor
{ {
std::vector<cell> gc_locals;
std::vector<cell> gc_bignums;
} }

View File

@ -1,16 +1,14 @@
namespace factor namespace factor
{ {
/* If a runtime function needs to call another function which potentially struct factorvm;
allocates memory, it must wrap any local variable references to Factor
objects in gc_root instances */
extern std::vector<cell> gc_locals;
template <typename T> template <typename T>
struct gc_root : public tagged<T> struct gc_root : public tagged<T>
{ {
void push() { check_tagged_pointer(tagged<T>::value()); gc_locals.push_back((cell)this); } void push() { check_tagged_pointer(tagged<T>::value()); vm->gc_locals.push_back((cell)this); }
//explicit gc_root(cell value_, factorvm *vm) : myvm(vm),tagged<T>(value_) { push(); }
explicit gc_root(cell value_) : tagged<T>(value_) { push(); } explicit gc_root(cell value_) : tagged<T>(value_) { push(); }
explicit gc_root(T *value_) : tagged<T>(value_) { push(); } explicit gc_root(T *value_) : tagged<T>(value_) { push(); }
@ -19,30 +17,29 @@ struct gc_root : public tagged<T>
~gc_root() { ~gc_root() {
#ifdef FACTOR_DEBUG #ifdef FACTOR_DEBUG
assert(gc_locals.back() == (cell)this); assert(vm->gc_locals.back() == (cell)this);
#endif #endif
gc_locals.pop_back(); vm->gc_locals.pop_back();
} }
}; };
/* A similar hack for the bignum implementation */ /* A similar hack for the bignum implementation */
extern std::vector<cell> gc_bignums;
struct gc_bignum struct gc_bignum
{ {
bignum **addr; bignum **addr;
factorvm *myvm;
gc_bignum(bignum **addr_) : addr(addr_) { //gc_bignum(bignum **addr_, factorvm *vm) : addr(addr_), myvm(vm) {
gc_bignum(bignum **addr_) : addr(addr_), myvm(vm) {
if(*addr_) if(*addr_)
check_data_pointer(*addr_); check_data_pointer(*addr_);
gc_bignums.push_back((cell)addr); vm->gc_bignums.push_back((cell)addr);
} }
~gc_bignum() { ~gc_bignum() {
#ifdef FACTOR_DEBUG #ifdef FACTOR_DEBUG
assert(gc_bignums.back() == (cell)addr); assert(vm->gc_bignums.back() == (cell)addr);
#endif #endif
gc_bignums.pop_back(); vm->gc_bignums.pop_back();
} }
}; };

View File

@ -46,6 +46,8 @@
#include "errors.hpp" #include "errors.hpp"
#include "bignumint.hpp" #include "bignumint.hpp"
#include "bignum.hpp" #include "bignum.hpp"
#include "code_block.hpp"
#include "vm.hpp"
#include "data_heap.hpp" #include "data_heap.hpp"
#include "write_barrier.hpp" #include "write_barrier.hpp"
#include "data_gc.hpp" #include "data_gc.hpp"
@ -62,7 +64,6 @@
#include "float_bits.hpp" #include "float_bits.hpp"
#include "io.hpp" #include "io.hpp"
#include "code_gc.hpp" #include "code_gc.hpp"
#include "code_block.hpp"
#include "code_heap.hpp" #include "code_heap.hpp"
#include "image.hpp" #include "image.hpp"
#include "callstack.hpp" #include "callstack.hpp"
@ -74,6 +75,6 @@
#include "factor.hpp" #include "factor.hpp"
#include "utilities.hpp" #include "utilities.hpp"
#include "vm.hpp"
#endif /* __FACTOR_MASTER_H__ */ #endif /* __FACTOR_MASTER_H__ */

View File

@ -2,15 +2,15 @@ namespace factor
{ {
#define DEFPUSHPOP(prefix,ptr) \ #define DEFPUSHPOP(prefix,ptr) \
inline static cell prefix##peek() { return *(cell *)ptr; } \ inline cell prefix##peek() { return *(cell *)ptr; } \
inline static void prefix##repl(cell tagged) { *(cell *)ptr = tagged; } \ inline void prefix##repl(cell tagged) { *(cell *)ptr = tagged; } \
inline static cell prefix##pop() \ inline cell prefix##pop() \
{ \ { \
cell value = prefix##peek(); \ cell value = prefix##peek(); \
ptr -= sizeof(cell); \ ptr -= sizeof(cell); \
return value; \ return value; \
} \ } \
inline static void prefix##push(cell tagged) \ inline void prefix##push(cell tagged) \
{ \ { \
ptr += sizeof(cell); \ ptr += sizeof(cell); \
prefix##repl(tagged); \ prefix##repl(tagged); \

View File

@ -1,6 +1,19 @@
namespace factor namespace factor
{ {
struct heap;
struct data_heap;
struct data;
struct zone;
struct vm_parameters;
struct image_header;
typedef u8 card;
typedef u8 card_deck;
typedef void (*heap_iterator)(heap_block *compiled);
typedef void (*code_heap_iterator)(code_block *compiled);
struct factorvm { struct factorvm {
// contexts // contexts
@ -174,6 +187,10 @@ struct factorvm {
inline void vmprim_become(); inline void vmprim_become();
void inline_gc(cell *gc_roots_base, cell gc_roots_size); void inline_gc(cell *gc_roots_base, cell gc_roots_size);
// local roots
std::vector<cell> gc_locals;
std::vector<cell> gc_bignums;
//debug //debug
void print_chars(string* str); void print_chars(string* str);
void print_word(word* word, cell nesting); void print_word(word* word, cell nesting);