]> gitweb.factorcode.org Git - factor.git/blob - vm/callstack.hpp
Merge branch 'master' into new_gc
[factor.git] / vm / callstack.hpp
1 namespace factor
2 {
3
4 inline static cell callstack_size(cell size)
5 {
6         return sizeof(callstack) + size;
7 }
8
9 VM_ASM_API void save_callstack_bottom(stack_frame *callstack_bottom, factor_vm *vm);
10
11 /* This is a little tricky. The iterator may allocate memory, so we
12 keep the callstack in a GC root and use relative offsets */
13 template<typename Iterator> void factor_vm::iterate_callstack_object(callstack *stack_, Iterator &iterator)
14 {
15         data_root<callstack> stack(stack_,this);
16         fixnum frame_offset = untag_fixnum(stack->length) - sizeof(stack_frame);
17
18         while(frame_offset >= 0)
19         {
20                 stack_frame *frame = stack->frame_at(frame_offset);
21                 frame_offset -= frame->size;
22                 iterator(frame);
23         }
24 }
25
26 template<typename Iterator> void factor_vm::iterate_callstack(context *ctx, Iterator &iterator)
27 {
28         cell top = (cell)ctx->callstack_top;
29         cell bottom = (cell)ctx->callstack_bottom;
30
31         stack_frame *frame = (stack_frame *)bottom - 1;
32
33         while((cell)frame >= top)
34         {
35                 iterator(frame);
36                 frame = frame_successor(frame);
37         }
38 }
39
40 }