| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #include "master.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-07 09:33:54 -04:00
										 |  |  | void fatal_error(const char *msg, cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | 	std::cout << "fatal_error: " << msg; | 
					
						
							|  |  |  | 	std::cout << ": " << std::hex << tagged << std::dec; | 
					
						
							|  |  |  | 	std::cout << std::endl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	exit(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-07 09:33:54 -04:00
										 |  |  | void critical_error(const char *msg, cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | 	std::cout << "You have triggered a bug in Factor. Please report.\n"; | 
					
						
							|  |  |  | 	std::cout << "critical_error: " << msg; | 
					
						
							|  |  |  | 	std::cout << ": " << std::hex << tagged << std::dec; | 
					
						
							|  |  |  | 	std::cout << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-27 03:44:40 -04:00
										 |  |  | 	current_vm()->factorbug(); | 
					
						
							| 
									
										
										
										
											2009-10-07 09:33:54 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void out_of_memory() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | 	std::cout << "Out of memory\n\n"; | 
					
						
							| 
									
										
										
										
											2010-03-27 03:44:40 -04:00
										 |  |  | 	current_vm()->dump_generations(); | 
					
						
							| 
									
										
										
										
											2009-10-07 09:33:54 -04:00
										 |  |  | 	exit(1); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | void factor_vm::throw_error(cell error, stack_frame *stack) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 	assert(stack); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	/* If the error handler is set, we rewind any C stack frames and
 | 
					
						
							|  |  |  | 	pass the error to user-space. */ | 
					
						
							| 
									
										
										
										
											2010-01-05 21:47:36 -05:00
										 |  |  | 	if(!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT])) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		/* If error was thrown during heap scan, we re-enable the GC */ | 
					
						
							|  |  |  | 		gc_off = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Reset local roots */ | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 		data_roots.clear(); | 
					
						
							|  |  |  | 		bignum_roots.clear(); | 
					
						
							| 
									
										
										
										
											2009-11-03 05:56:58 -05:00
										 |  |  | 		code_roots.clear(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 		/* If we had an underflow or overflow, data or retain stack
 | 
					
						
							|  |  |  | 		pointers might be out of bounds */ | 
					
						
							| 
									
										
										
										
											2009-12-18 16:59:56 -05:00
										 |  |  | 		ctx->fix_stacks(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-18 16:59:56 -05:00
										 |  |  | 		ctx->push(error); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 		unwind_native_frames(special_objects[ERROR_HANDLER_QUOT],stack); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	/* Error was thrown in early startup before error handler is set, just
 | 
					
						
							|  |  |  | 	crash. */ | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | 		std::cout << "You have triggered a bug in Factor. Please report.\n"; | 
					
						
							|  |  |  | 		std::cout << "early_error: "; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		print_obj(error); | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | 		std::cout << std::endl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		factorbug(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | void factor_vm::general_error(vm_error_type error, cell arg1, cell arg2, stack_frame *stack) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-23 01:33:53 -04:00
										 |  |  | 	throw_error(allot_array_4(special_objects[OBJ_ERROR], | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 		tag_fixnum(error),arg1,arg2),stack); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | void factor_vm::general_error(vm_error_type error, cell arg1, cell arg2) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 	throw_error(allot_array_4(special_objects[OBJ_ERROR], | 
					
						
							|  |  |  | 		tag_fixnum(error),arg1,arg2),ctx->callstack_top); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | void factor_vm::type_error(cell type, cell tagged) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 	general_error(ERROR_TYPE,tag_fixnum(type),tagged); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | void factor_vm::not_implemented_error() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 	general_error(ERROR_NOT_IMPLEMENTED,false_object,false_object); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | void factor_vm::memory_protection_error(cell addr, stack_frame *stack) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 07:45:11 -04:00
										 |  |  | 	/* Retain and call stack underflows are not supposed to happen */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 	if(ctx->datastack_seg->underflow_p(addr)) | 
					
						
							|  |  |  | 		general_error(ERROR_DATASTACK_UNDERFLOW,false_object,false_object,stack); | 
					
						
							|  |  |  | 	else if(ctx->datastack_seg->overflow_p(addr)) | 
					
						
							|  |  |  | 		general_error(ERROR_DATASTACK_OVERFLOW,false_object,false_object,stack); | 
					
						
							|  |  |  | 	else if(ctx->retainstack_seg->underflow_p(addr)) | 
					
						
							|  |  |  | 		general_error(ERROR_RETAINSTACK_UNDERFLOW,false_object,false_object,stack); | 
					
						
							|  |  |  | 	else if(ctx->retainstack_seg->overflow_p(addr)) | 
					
						
							|  |  |  | 		general_error(ERROR_RETAINSTACK_OVERFLOW,false_object,false_object,stack); | 
					
						
							| 
									
										
										
										
											2010-03-27 07:45:11 -04:00
										 |  |  | 	else if(ctx->callstack_seg->underflow_p(addr)) | 
					
						
							|  |  |  | 		general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object,stack); | 
					
						
							| 
									
										
										
										
											2010-03-29 01:53:20 -04:00
										 |  |  | 	else if(ctx->callstack_seg->overflow_p(addr)) | 
					
						
							|  |  |  | 		general_error(ERROR_CALLSTACK_UNDERFLOW,false_object,false_object,stack); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 		general_error(ERROR_MEMORY,allot_cell(addr),false_object,stack); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | void factor_vm::signal_error(cell signal, stack_frame *stack) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 	general_error(ERROR_SIGNAL,allot_cell(signal),false_object,stack); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void factor_vm::divide_by_zero_error() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 	general_error(ERROR_DIVIDE_BY_ZERO,false_object,false_object); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | void factor_vm::fp_trap_error(unsigned int fpu_status, stack_frame *stack) | 
					
						
							| 
									
										
										
										
											2009-09-06 09:44:25 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 07:33:28 -04:00
										 |  |  | 	general_error(ERROR_FP_TRAP,tag_fixnum(fpu_status),false_object,stack); | 
					
						
							| 
									
										
										
										
											2009-09-06 09:44:25 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 21:01:54 -04:00
										 |  |  | /* For testing purposes */ | 
					
						
							| 
									
										
										
										
											2009-09-27 14:42:18 -04:00
										 |  |  | void factor_vm::primitive_unimplemented() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-02 21:01:54 -04:00
										 |  |  | 	not_implemented_error(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void factor_vm::memory_signal_handler_impl() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-02 21:01:54 -04:00
										 |  |  | 	memory_protection_error(signal_fault_addr,signal_callstack_top); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:04 -04:00
										 |  |  | void memory_signal_handler_impl() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 03:44:40 -04:00
										 |  |  | 	current_vm()->memory_signal_handler_impl(); | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:04 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void factor_vm::misc_signal_handler_impl() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-02 21:01:54 -04:00
										 |  |  | 	signal_error(signal_number,signal_callstack_top); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:04 -04:00
										 |  |  | void misc_signal_handler_impl() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 03:44:40 -04:00
										 |  |  | 	current_vm()->misc_signal_handler_impl(); | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:04 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void factor_vm::fp_signal_handler_impl() | 
					
						
							| 
									
										
										
										
											2009-09-06 09:44:25 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-14 00:37:28 -04:00
										 |  |  | 	fp_trap_error(signal_fpu_status,signal_callstack_top); | 
					
						
							| 
									
										
										
										
											2009-09-06 09:44:25 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:04 -04:00
										 |  |  | void fp_signal_handler_impl() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-27 03:44:40 -04:00
										 |  |  | 	current_vm()->fp_signal_handler_impl(); | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:04 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | } |