| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-26 22:44:43 -04:00
										 |  |  | inline static cell callstack_object_size(cell size) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	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 */ | 
					
						
							| 
									
										
										
										
											2009-10-03 09:47:05 -04:00
										 |  |  | template<typename Iterator> void factor_vm::iterate_callstack_object(callstack *stack_, Iterator &iterator) | 
					
						
							| 
									
										
										
										
											2009-09-29 14:53:10 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 	data_root<callstack> stack(stack_,this); | 
					
						
							| 
									
										
										
										
											2009-09-29 14:53:10 -04:00
										 |  |  | 	fixnum frame_offset = untag_fixnum(stack->length) - sizeof(stack_frame); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(frame_offset >= 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		stack_frame *frame = stack->frame_at(frame_offset); | 
					
						
							|  |  |  | 		frame_offset -= frame->size; | 
					
						
							| 
									
										
										
										
											2009-10-03 09:47:05 -04:00
										 |  |  | 		iterator(frame); | 
					
						
							| 
									
										
										
										
											2009-09-29 14:53:10 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-16 05:33:35 -04:00
										 |  |  | template<typename Iterator> void factor_vm::iterate_callstack(context *ctx, Iterator &iterator) | 
					
						
							| 
									
										
										
										
											2009-09-29 14:53:10 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 	stack_frame *frame = ctx->callstack_bottom - 1; | 
					
						
							| 
									
										
										
										
											2009-10-16 05:33:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 	while(frame >= ctx->callstack_top) | 
					
						
							| 
									
										
										
										
											2009-09-29 14:53:10 -04:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-10-03 09:47:05 -04:00
										 |  |  | 		iterator(frame); | 
					
						
							| 
									
										
										
										
											2009-09-29 14:53:10 -04:00
										 |  |  | 		frame = frame_successor(frame); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | } |