]> gitweb.factorcode.org Git - factor.git/blob - vm/callstack.hpp
inlineimpl.hpp is toast
[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 TYPE> void factor_vm::iterate_callstack_object(callstack *stack_, TYPE &iterator)
14 {
15         gc_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,this);
23         }
24 }
25
26 template<typename TYPE> void factor_vm::iterate_callstack(cell top, cell bottom, TYPE &iterator)
27 {
28         stack_frame *frame = (stack_frame *)bottom - 1;
29
30         while((cell)frame >= top)
31         {
32                 iterator(frame,this);
33                 frame = frame_successor(frame);
34         }
35 }
36
37 /* Every object has a regular representation in the runtime, which makes GC
38 much simpler. Every slot of the object until binary_payload_start is a pointer
39 to some other object. */
40 struct factor_vm;
41 inline void factor_vm::do_slots(cell obj, void (* iter)(cell *,factor_vm*))
42 {
43         cell scan = obj;
44         cell payload_start = binary_payload_start((object *)obj);
45         cell end = obj + payload_start;
46
47         scan += sizeof(cell);
48
49         while(scan < end)
50         {
51                 iter((cell *)scan,this);
52                 scan += sizeof(cell);
53         }
54 }
55
56 }