| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  | namespace factor { | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  | inline static cell callstack_object_size(cell size) { | 
					
						
							|  |  |  |   return sizeof(callstack) + size; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-29 14:53:10 -04:00
										 |  |  | /* This is a little tricky. The iterator may allocate memory, so we
 | 
					
						
							|  |  |  | keep the callstack in a GC root and use relative offsets */ | 
					
						
							| 
									
										
										
										
											2014-02-13 23:42:44 -05:00
										 |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  | 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; | 
					
						
							| 
									
										
										
										
											2013-05-13 00:53:47 -04:00
										 |  |  |     code_block* owner = code->code_block_for_address((cell)fixed_addr); | 
					
						
							|  |  |  |     cell frame_size = owner->stack_frame_size_for_address((cell)fixed_addr); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     iterator(frame_top, frame_size, owner, fixed_addr); | 
					
						
							|  |  |  |     frame_offset += frame_size; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-02 12:11:34 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 23:42:44 -05:00
										 |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  | template <typename Iterator> | 
					
						
							| 
									
										
										
										
											2013-05-12 23:20:43 -04:00
										 |  |  | inline void factor_vm::iterate_callstack_object(callstack* stack, | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  |                                                 Iterator& iterator) { | 
					
						
							|  |  |  |   no_fixup none; | 
					
						
							| 
									
										
										
										
											2013-05-12 23:20:43 -04:00
										 |  |  |   iterate_callstack_object(stack, iterator, none); | 
					
						
							| 
									
										
										
										
											2011-12-06 17:51:41 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 23:42:44 -05:00
										 |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  | 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; | 
					
						
							| 
									
										
										
										
											2011-12-05 17:18:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  |   char* frame_top = (char*)ctx->callstack_top; | 
					
						
							| 
									
										
										
										
											2011-12-05 17:18:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  |   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; | 
					
						
							| 
									
										
										
										
											2011-12-05 17:18:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 00:53:47 -04:00
										 |  |  |     code_block* owner = code->code_block_for_address((cell)fixed_addr); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  |     code_block* fixed_owner = | 
					
						
							|  |  |  |         Fixup::translated_code_block_map ? owner : fixup.translate_code(owner); | 
					
						
							| 
									
										
										
										
											2011-12-06 12:14:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  |     cell frame_size = | 
					
						
							| 
									
										
										
										
											2013-05-13 00:53:47 -04:00
										 |  |  |         fixed_owner->stack_frame_size_for_address((cell)fixed_addr); | 
					
						
							| 
									
										
										
										
											2011-12-05 17:18:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  |     void* fixed_addr_for_iter = | 
					
						
							|  |  |  |         Fixup::translated_code_block_map ? fixed_addr : addr; | 
					
						
							| 
									
										
										
										
											2011-12-05 17:18:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  |     iterator(frame_top, frame_size, owner, fixed_addr_for_iter); | 
					
						
							|  |  |  |     frame_top += frame_size; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-05 17:18:42 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 23:42:44 -05:00
										 |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2013-05-11 21:47:34 -04:00
										 |  |  | template <typename Iterator> | 
					
						
							|  |  |  | inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator) { | 
					
						
							|  |  |  |   no_fixup none; | 
					
						
							|  |  |  |   iterate_callstack(ctx, iterator, none); | 
					
						
							| 
									
										
										
										
											2011-11-30 20:56:24 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | } |