Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 83 lines (66 sloc) 2.31 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
namespace factor
{

inline static cell callstack_object_size(cell size)
{
return sizeof(callstack) + size;
}

/* 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 Iterator, typename Fixup>
inline void factor_vm::iterate_callstack_object(callstack *stack_,
Iterator &iterator, Fixup &fixup)
{
data_root<callstack> stack(stack_,this);
fixnum frame_length = factor::untag_fixnum(stack->length);
fixnum frame_offset = 0;

while(frame_offset < frame_length)
{
void *frame_top = stack->frame_top_at(frame_offset);
void *addr = frame_return_address(frame_top);

void *fixed_addr = Fixup::translated_code_block_map
? (void*)fixup.translate_code((code_block*)addr)
: addr;
code_block *owner = code->code_block_for_address((cell)fixed_addr);
cell frame_size = owner->stack_frame_size_for_address((cell)fixed_addr);

iterator(frame_top, frame_size, owner, fixed_addr);
frame_offset += frame_size;
}
}

template<typename Iterator>
inline void factor_vm::iterate_callstack_object(callstack *stack_, Iterator &iterator)
{
no_fixup none;
iterate_callstack_object(stack_, iterator, none);
}

template<typename Iterator, typename Fixup>
inline void factor_vm::iterate_callstack(context *ctx, Iterator &iterator, Fixup &fixup)
{
if (ctx->callstack_top == ctx->callstack_bottom)
return;

char *frame_top = (char*)ctx->callstack_top;

while (frame_top < (char*)ctx->callstack_bottom)
{
void *addr = frame_return_address((void*)frame_top);
FACTOR_ASSERT(addr != 0);
void *fixed_addr = Fixup::translated_code_block_map
? (void*)fixup.translate_code((code_block*)addr)
: addr;

code_block *owner = code->code_block_for_address((cell)fixed_addr);
code_block *fixed_owner = Fixup::translated_code_block_map
? owner
: fixup.translate_code(owner);

cell frame_size = fixed_owner->stack_frame_size_for_address((cell)fixed_addr);

void *fixed_addr_for_iter = Fixup::translated_code_block_map
? fixed_addr
: addr;

iterator(frame_top, frame_size, owner, fixed_addr_for_iter);
frame_top += frame_size;
}
}

template<typename Iterator>
inline void factor_vm::iterate_callstack(context *ctx, Iterator &iterator)
{
no_fixup none;
iterate_callstack(ctx, iterator, none);
}


}
Something went wrong with that request. Please try again.