2009-10-24 04:54:53 -04:00
|
|
|
namespace factor
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename Visitor> struct slot_visitor {
|
|
|
|
factor_vm *parent;
|
|
|
|
Visitor visitor;
|
|
|
|
|
2009-10-25 00:02:58 -04:00
|
|
|
explicit slot_visitor<Visitor>(factor_vm *parent_, Visitor visitor_) :
|
2009-10-24 04:54:53 -04:00
|
|
|
parent(parent_), visitor(visitor_) {}
|
|
|
|
|
2009-11-06 01:54:28 -05:00
|
|
|
void visit_handle(cell *handle)
|
|
|
|
{
|
|
|
|
cell pointer = *handle;
|
2009-11-06 02:22:53 -05:00
|
|
|
if(immediate_p(pointer)) return;
|
|
|
|
|
|
|
|
object *untagged = untag<object>(pointer);
|
|
|
|
untagged = visitor(untagged);
|
|
|
|
*handle = RETAG(untagged,TAG(pointer));
|
2009-10-24 04:54:53 -04:00
|
|
|
}
|
|
|
|
|
2009-10-25 00:51:14 -04:00
|
|
|
void visit_slots(object *ptr, cell payload_start)
|
2009-10-24 04:54:53 -04:00
|
|
|
{
|
|
|
|
cell *slot = (cell *)ptr;
|
2009-10-25 00:51:14 -04:00
|
|
|
cell *end = (cell *)((cell)ptr + payload_start);
|
2009-10-24 04:54:53 -04:00
|
|
|
|
|
|
|
if(slot != end)
|
|
|
|
{
|
|
|
|
slot++;
|
|
|
|
for(; slot < end; slot++) visit_handle(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-25 00:51:14 -04:00
|
|
|
void visit_slots(object *ptr)
|
|
|
|
{
|
|
|
|
visit_slots(ptr,ptr->binary_payload_start());
|
|
|
|
}
|
|
|
|
|
2009-10-24 04:54:53 -04:00
|
|
|
void visit_stack_elements(segment *region, cell *top)
|
|
|
|
{
|
|
|
|
for(cell *ptr = (cell *)region->start; ptr <= top; ptr++)
|
|
|
|
visit_handle(ptr);
|
|
|
|
}
|
|
|
|
|
2009-11-02 19:10:34 -05:00
|
|
|
void visit_data_roots()
|
2009-10-24 04:54:53 -04:00
|
|
|
{
|
2009-11-06 06:30:37 -05:00
|
|
|
std::vector<data_root_range>::const_iterator iter = parent->data_roots.begin();
|
|
|
|
std::vector<data_root_range>::const_iterator end = parent->data_roots.end();
|
2009-10-24 04:54:53 -04:00
|
|
|
|
2009-11-06 06:30:37 -05:00
|
|
|
for(; iter < end; iter++)
|
2009-11-06 01:54:28 -05:00
|
|
|
{
|
2009-11-06 06:30:37 -05:00
|
|
|
data_root_range r = *iter;
|
|
|
|
for(cell index = 0; index < r.len; index++)
|
|
|
|
visit_handle(r.start + index);
|
2009-11-06 01:54:28 -05:00
|
|
|
}
|
2009-10-24 04:54:53 -04:00
|
|
|
}
|
|
|
|
|
2009-11-02 19:10:34 -05:00
|
|
|
void visit_bignum_roots()
|
2009-10-24 04:54:53 -04:00
|
|
|
{
|
2009-11-02 19:10:34 -05:00
|
|
|
std::vector<cell>::const_iterator iter = parent->bignum_roots.begin();
|
|
|
|
std::vector<cell>::const_iterator end = parent->bignum_roots.end();
|
2009-10-24 04:54:53 -04:00
|
|
|
|
|
|
|
for(; iter < end; iter++)
|
|
|
|
{
|
|
|
|
cell *handle = (cell *)(*iter);
|
|
|
|
|
|
|
|
if(*handle)
|
2009-11-01 04:47:09 -05:00
|
|
|
*handle = (cell)visitor(*(object **)handle);
|
2009-10-24 04:54:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void visit_roots()
|
|
|
|
{
|
|
|
|
visit_handle(&parent->true_object);
|
|
|
|
visit_handle(&parent->bignum_zero);
|
|
|
|
visit_handle(&parent->bignum_pos_one);
|
|
|
|
visit_handle(&parent->bignum_neg_one);
|
|
|
|
|
2009-11-02 19:10:34 -05:00
|
|
|
visit_data_roots();
|
|
|
|
visit_bignum_roots();
|
2009-10-24 04:54:53 -04:00
|
|
|
|
|
|
|
for(cell i = 0; i < special_object_count; i++)
|
|
|
|
visit_handle(&parent->special_objects[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void visit_contexts()
|
|
|
|
{
|
|
|
|
context *ctx = parent->ctx;
|
|
|
|
|
|
|
|
while(ctx)
|
|
|
|
{
|
|
|
|
visit_stack_elements(ctx->datastack_region,(cell *)ctx->datastack);
|
|
|
|
visit_stack_elements(ctx->retainstack_region,(cell *)ctx->retainstack);
|
|
|
|
|
|
|
|
visit_handle(&ctx->catchstack_save);
|
|
|
|
visit_handle(&ctx->current_callback_save);
|
|
|
|
|
|
|
|
ctx = ctx->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void visit_literal_references(code_block *compiled)
|
|
|
|
{
|
|
|
|
visit_handle(&compiled->owner);
|
|
|
|
visit_handle(&compiled->literals);
|
|
|
|
visit_handle(&compiled->relocation);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|