]> gitweb.factorcode.org Git - factor.git/blob - vm/callstack.hpp
remove iterate_callstack now that it's unused
[factor.git] / vm / callstack.hpp
1 namespace factor
2 {
3
4 inline static cell callstack_object_size(cell size)
5 {
6         return sizeof(callstack) + size;
7 }
8
9 /* This is a little tricky. The iterator may allocate memory, so we
10 keep the callstack in a GC root and use relative offsets */
11 template<typename Iterator, typename Fixup>
12 void factor_vm::iterate_callstack_object_reversed(callstack *stack_,
13         Iterator &iterator, Fixup &fixup)
14 {
15         data_root<callstack> stack(stack_,this);
16         fixnum frame_length = factor::untag_fixnum(stack->length);
17         fixnum frame_offset = 0;
18
19         while(frame_offset < frame_length)
20         {
21                 void *frame_top = stack->frame_top_at(frame_offset);
22                 void *addr = frame_return_address(frame_top);
23
24                 void *fixed_addr = Fixup::translated_code_block_map
25                         ? (void*)fixup.translate_code((code_block*)addr)
26                         : addr;
27                 code_block *owner = code->code_block_for_address((cell)fixed_addr);
28                 cell frame_size = owner->stack_frame_size_for_address((cell)fixed_addr);
29
30 #ifdef FACTOR_DEBUG
31                 // check our derived owner and frame size against the ones stored in the frame
32                 // by the function prolog
33                 stack_frame *frame = (stack_frame*)((char*)frame_top + frame_size) - 1;
34                 void *fixed_entry_point =
35                         (void*)fixup.translate_code((code_block*)frame->entry_point);
36                 FACTOR_ASSERT(owner->entry_point() == fixed_entry_point);
37                 FACTOR_ASSERT(frame_size == frame->size);
38 #endif
39
40                 iterator(frame_top, frame_size, owner, fixed_addr);
41                 frame_offset += frame_size;
42         }
43 }
44
45 template<typename Iterator>
46 void factor_vm::iterate_callstack_object(callstack *stack_, Iterator &iterator)
47 {
48         data_root<callstack> stack(stack_,this);
49         fixnum frame_offset = factor::untag_fixnum(stack->length) - sizeof(stack_frame);
50
51         while(frame_offset >= 0)
52         {
53                 stack_frame *frame = stack->frame_at(frame_offset);
54                 frame_offset -= frame->size;
55                 iterator(frame);
56         }
57 }
58
59 template<typename Iterator, typename Fixup>
60 void factor_vm::iterate_callstack_reversed(context *ctx, Iterator &iterator, Fixup &fixup)
61 {
62         if (ctx->callstack_top == ctx->callstack_bottom)
63                 return;
64
65         char *frame_top = (char*)ctx->callstack_top;
66
67         while (frame_top < (char*)ctx->callstack_bottom)
68         {
69                 void *addr = frame_return_address((void*)frame_top);
70                 FACTOR_ASSERT(addr != 0);
71                 void *fixed_addr = Fixup::translated_code_block_map
72                         ? (void*)fixup.translate_code((code_block*)addr)
73                         : addr;
74
75                 code_block *owner = code->code_block_for_address((cell)fixed_addr);
76                 code_block *fixed_owner = Fixup::translated_code_block_map
77                         ? owner
78                         : fixup.translate_code(owner);
79
80                 cell frame_size = fixed_owner->stack_frame_size_for_address((cell)fixed_addr);
81
82 #ifdef FACTOR_DEBUG
83                 // check our derived owner and frame size against the ones stored in the frame
84                 // by the function prolog
85                 stack_frame *frame = (stack_frame*)(frame_top + frame_size) - 1;
86                 void *fixed_entry_point = Fixup::translated_code_block_map
87                         ? (void*)fixup.translate_code((code_block*)frame->entry_point)
88                         : frame->entry_point;
89                 FACTOR_ASSERT(owner->entry_point() == fixed_entry_point);
90                 FACTOR_ASSERT(frame_size == frame->size);
91 #endif
92                 void *fixed_addr_for_iter = Fixup::translated_code_block_map
93                         ? fixed_addr
94                         : addr;
95
96                 iterator(frame_top, frame_size, owner, fixed_addr_for_iter);
97                 frame_top += frame_size;
98         }
99 }
100
101 template<typename Iterator>
102 void factor_vm::iterate_callstack_reversed(context *ctx, Iterator &iterator)
103 {
104         if (ctx->callstack_top == ctx->callstack_bottom)
105                 return;
106
107         char *frame_top = (char*)ctx->callstack_top;
108
109         while (frame_top < (char*)ctx->callstack_bottom)
110         {
111                 void *addr = frame_return_address((void*)frame_top);
112                 FACTOR_ASSERT(addr != 0);
113
114                 code_block *owner = code->code_block_for_address((cell)addr);
115                 cell frame_size = owner->stack_frame_size_for_address((cell)addr);
116
117 #ifdef FACTOR_DEBUG
118                 // check our derived owner and frame size against the ones stored in the frame
119                 // by the function prolog
120                 stack_frame *frame = (stack_frame*)(frame_top + frame_size) - 1;
121                 FACTOR_ASSERT(owner->entry_point() == frame->entry_point);
122                 FACTOR_ASSERT(frame_size == frame->size);
123 #endif
124
125                 iterator(frame_top, frame_size, owner, addr);
126                 frame_top += frame_size;
127         }
128 }
129
130 }