| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #include "master.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | namespace factor { | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-03 08:13:28 -04:00
										 |  |  | bool factor_print_p = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | ostream& operator<<(ostream& out, const string* str) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   for (cell i = 0; i < string_capacity(str); i++) | 
					
						
							| 
									
										
										
										
											2013-05-13 00:53:47 -04:00
										 |  |  |     out << (char)str->data()[i]; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   return out; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_word(ostream& out, word* word, cell nesting) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   if (tagged<object>(word->vocabulary).type_p(STRING_TYPE)) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << untag<string>(word->vocabulary) << ":"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (tagged<object>(word->name).type_p(STRING_TYPE)) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << untag<string>(word->name); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   else { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "#<not a string: "; | 
					
						
							|  |  |  |     print_nested_obj(out, word->name, nesting); | 
					
						
							|  |  |  |     out << ">"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_factor_string(ostream& out, string* str) { | 
					
						
							|  |  |  |   out << '"' << str << '"'; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_array(ostream& out, array* array, cell nesting) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   cell length = array_capacity(array); | 
					
						
							|  |  |  |   cell i; | 
					
						
							|  |  |  |   bool trimmed; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (length > 10 && !full_output) { | 
					
						
							|  |  |  |     trimmed = true; | 
					
						
							|  |  |  |     length = 10; | 
					
						
							|  |  |  |   } else | 
					
						
							|  |  |  |     trimmed = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < length; i++) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << " "; | 
					
						
							|  |  |  |     print_nested_obj(out, array_nth(array, i), nesting); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (trimmed) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "..."; | 
					
						
							| 
									
										
										
										
											2011-11-06 23:26:10 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_alien(ostream& out, alien* alien, cell nesting) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   if (to_boolean(alien->expired)) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "#<expired alien>"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   else if (to_boolean(alien->base)) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "#<displaced alien " << alien->displacement << "+"; | 
					
						
							|  |  |  |     print_nested_obj(out, alien->base, nesting); | 
					
						
							|  |  |  |     out << ">"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "#<alien " << (void*)alien->address << ">"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-11-06 23:26:10 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_byte_array(ostream& out, byte_array* array, cell nesting) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   cell length = array->capacity; | 
					
						
							|  |  |  |   cell i; | 
					
						
							|  |  |  |   bool trimmed; | 
					
						
							|  |  |  |   unsigned char* data = array->data<unsigned char>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (length > 16 && !full_output) { | 
					
						
							|  |  |  |     trimmed = true; | 
					
						
							|  |  |  |     length = 16; | 
					
						
							|  |  |  |   } else | 
					
						
							|  |  |  |     trimmed = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < length; i++) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << " " << (unsigned) data[i]; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (trimmed) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "..."; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_tuple(ostream& out, tuple* tuple, cell nesting) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   tuple_layout* layout = untag<tuple_layout>(tuple->layout); | 
					
						
							| 
									
										
										
										
											2014-07-08 01:34:36 -04:00
										 |  |  |   cell length = to_cell(layout->size); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   out << " "; | 
					
						
							|  |  |  |   print_nested_obj(out, layout->klass, nesting); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool trimmed; | 
					
						
							|  |  |  |   if (length > 10 && !full_output) { | 
					
						
							|  |  |  |     trimmed = true; | 
					
						
							|  |  |  |     length = 10; | 
					
						
							|  |  |  |   } else | 
					
						
							|  |  |  |     trimmed = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (cell i = 0; i < length; i++) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << " "; | 
					
						
							|  |  |  |     print_nested_obj(out, tuple->data()[i], nesting); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (trimmed) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "..."; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_nested_obj(ostream& out, cell obj, fixnum nesting) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   if (nesting <= 0 && !full_output) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << " ... "; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   quotation* quot; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (tagged<object>(obj).type()) { | 
					
						
							|  |  |  |     case FIXNUM_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << untag_fixnum(obj); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case FLOAT_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << untag_float(obj); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case WORD_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       print_word(out, untag<word>(obj), nesting - 1); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case STRING_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       print_factor_string(out, untag<string>(obj)); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case F_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << "f"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case TUPLE_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << "T{"; | 
					
						
							|  |  |  |       print_tuple(out, untag<tuple>(obj), nesting - 1); | 
					
						
							|  |  |  |       out << " }"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case WRAPPER_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << "W{ "; | 
					
						
							|  |  |  |       print_nested_obj(out, untag<wrapper>(obj)->object, nesting - 1); | 
					
						
							|  |  |  |       out << " }"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case BYTE_ARRAY_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << "B{"; | 
					
						
							|  |  |  |       print_byte_array(out, untag<byte_array>(obj), nesting - 1); | 
					
						
							|  |  |  |       out << " }"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case ARRAY_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << "{"; | 
					
						
							|  |  |  |       print_array(out, untag<array>(obj), nesting - 1); | 
					
						
							|  |  |  |       out << " }"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case QUOTATION_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << "["; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       quot = untag<quotation>(obj); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       print_array(out, untag<array>(quot->array), nesting - 1); | 
					
						
							|  |  |  |       out << " ]"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case ALIEN_TYPE: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       print_alien(out, untag<alien>(obj), nesting - 1); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << "#<" << type_name(tagged<object>(obj).type()) << " @ "; | 
					
						
							|  |  |  |       out << (void*)obj << ">"; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   out << flush; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_obj(ostream& out, cell obj) { | 
					
						
							|  |  |  |   print_nested_obj(out, obj, 10); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_objects(ostream& out, cell* start, cell* end) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   for (; start <= end; start++) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     print_obj(out, *start); | 
					
						
							|  |  |  |     cout << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_datastack(ostream& out) { | 
					
						
							|  |  |  |   out << "==== DATA STACK:" << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   if (ctx) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     print_objects(out, | 
					
						
							|  |  |  |                   (cell*)ctx->datastack_seg->start, | 
					
						
							|  |  |  |                   (cell*)ctx->datastack); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "*** Context not initialized" << endl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_retainstack(ostream& out) { | 
					
						
							|  |  |  |   out << "==== RETAIN STACK:" << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   if (ctx) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     print_objects(out, | 
					
						
							|  |  |  |                   (cell*)ctx->retainstack_seg->start, | 
					
						
							|  |  |  |                   (cell*)ctx->retainstack); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "*** Context not initialized" << endl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-03 09:47:05 -04:00
										 |  |  | struct stack_frame_printer { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   factor_vm* parent; | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   ostream& out; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   explicit stack_frame_printer(factor_vm* parent, ostream& out) | 
					
						
							|  |  |  |       : parent(parent), out(out) {} | 
					
						
							| 
									
										
										
										
											2015-01-05 08:04:12 -05:00
										 |  |  |   void operator()(cell frame_top, cell size, code_block* owner, cell addr) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << endl; | 
					
						
							|  |  |  |     out << "frame: " << (void*)frame_top << " size " << size << endl; | 
					
						
							|  |  |  |     out << "executing: "; | 
					
						
							|  |  |  |     parent->print_obj(out, owner->owner); | 
					
						
							|  |  |  |     out << endl; | 
					
						
							|  |  |  |     out << "scan: "; | 
					
						
							|  |  |  |     parent->print_obj(out, owner->scan(parent, addr)); | 
					
						
							|  |  |  |     out << endl; | 
					
						
							|  |  |  |     out << "word/quot addr: "; | 
					
						
							|  |  |  |     out << hex << owner->owner << dec; | 
					
						
							|  |  |  |     out << endl; | 
					
						
							|  |  |  |     out << "word/quot xt: "; | 
					
						
							|  |  |  |     out << hex << owner->entry_point() << dec; | 
					
						
							|  |  |  |     out << endl; | 
					
						
							|  |  |  |     out << "return address: "; | 
					
						
							|  |  |  |     out << hex << addr << dec; | 
					
						
							|  |  |  |     out << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-10-03 09:47:05 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_callstack(ostream& out) { | 
					
						
							|  |  |  |   out << "==== CALL STACK:" << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   if (ctx) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     stack_frame_printer printer(this, out); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |     iterate_callstack(ctx, printer); | 
					
						
							|  |  |  |   } else | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     out << "*** Context not initialized" << endl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::print_callstack_object(ostream& out, callstack* obj) { | 
					
						
							|  |  |  |   stack_frame_printer printer(this, out); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   iterate_callstack_object(obj, printer); | 
					
						
							| 
									
										
										
										
											2011-12-20 17:38:01 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | struct padded_address { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   cell value; | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-12 23:20:43 -04:00
										 |  |  |   explicit padded_address(cell value) : value(value) {} | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | ostream& operator<<(ostream& out, const padded_address& value) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   char prev = out.fill('0'); | 
					
						
							|  |  |  |   out.width(sizeof(cell) * 2); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   out << hex << value.value << dec; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   out.fill(prev); | 
					
						
							|  |  |  |   return out; | 
					
						
							| 
									
										
										
										
											2009-10-21 21:12:57 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::dump_cell(ostream& out, cell x) { | 
					
						
							|  |  |  |   out << padded_address(x) << ": "; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   x = *(cell*)x; | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   out << padded_address(x) << " tag " << TAG(x) << endl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::dump_memory(ostream& out, cell from, cell to) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   from = UNTAG(from); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   for (; from <= to; from += sizeof(cell)) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     dump_cell(out, from); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | template <typename Generation> | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::dump_generation(ostream& out, const char* name, Generation* gen) { | 
					
						
							|  |  |  |   out << name << ": "; | 
					
						
							|  |  |  |   out << "Start=" << gen->start; | 
					
						
							|  |  |  |   out << ", size=" << gen->size; | 
					
						
							|  |  |  |   out << ", end=" << gen->end; | 
					
						
							|  |  |  |   out << endl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::dump_generations(ostream& out) { | 
					
						
							|  |  |  |   out << hex; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   dump_generation(out, "Nursery", &nursery); | 
					
						
							|  |  |  |   dump_generation(out, "Aging", data->aging); | 
					
						
							|  |  |  |   dump_generation(out, "Tenured", data->tenured); | 
					
						
							| 
									
										
										
										
											2010-09-09 23:36:50 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   out << "Cards:"; | 
					
						
							|  |  |  |   out << "base=" << (cell)data->cards << ", "; | 
					
						
							|  |  |  |   out << "size=" << (cell)(data->cards_end - data->cards) << endl; | 
					
						
							|  |  |  |   out << dec; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 12:31:44 -04:00
										 |  |  | void factor_vm::dump_objects(ostream& out, cell type) { | 
					
						
							|  |  |  |   primitive_full_gc(); | 
					
						
							|  |  |  |   auto object_dumper = [&](object* obj) { | 
					
						
							|  |  |  |      if (type == TYPE_COUNT || obj->type() == type) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << padded_address((cell)obj) << " "; | 
					
						
							| 
									
										
										
										
											2015-07-06 12:31:44 -04:00
										 |  |  |       print_nested_obj(out, tag_dynamic(obj), 2); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-06 12:31:44 -04:00
										 |  |  |   }; | 
					
						
							|  |  |  |   each_object(object_dumper); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-11 13:12:36 -05:00
										 |  |  | struct find_data_reference_slot_visitor { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   cell look_for; | 
					
						
							|  |  |  |   object* obj; | 
					
						
							|  |  |  |   factor_vm* parent; | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   ostream& out; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   find_data_reference_slot_visitor(cell look_for, | 
					
						
							|  |  |  |                                    object* obj, | 
					
						
							|  |  |  |                                    factor_vm* parent, | 
					
						
							|  |  |  |                                    ostream& out) | 
					
						
							|  |  |  |     : look_for(look_for), obj(obj), parent(parent), out(out) {} | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void operator()(cell* scan) { | 
					
						
							|  |  |  |     if (look_for == *scan) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << padded_address((cell)obj) << " "; | 
					
						
							|  |  |  |       parent->print_nested_obj(out, tag_dynamic(obj), 2); | 
					
						
							|  |  |  |       out << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-10-03 09:47:05 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-11 13:12:36 -05:00
										 |  |  | struct dump_edges_slot_visitor { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   object* obj; | 
					
						
							|  |  |  |   factor_vm* parent; | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   ostream& out; | 
					
						
							| 
									
										
										
										
											2011-11-11 13:12:36 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   dump_edges_slot_visitor(cell, object* obj, factor_vm* parent, ostream& out) | 
					
						
							|  |  |  |       : obj(obj), parent(parent), out(out) {} | 
					
						
							| 
									
										
										
										
											2011-11-11 13:12:36 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   void operator()(cell* scan) { | 
					
						
							|  |  |  |     if (TAG(*scan) > F_TYPE) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << (void*)tag_dynamic(obj) << " ==> " << (void*)*scan << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-11-11 13:12:36 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | template <typename SlotVisitor> struct data_reference_object_visitor { | 
					
						
							|  |  |  |   cell look_for; | 
					
						
							|  |  |  |   factor_vm* parent; | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   ostream& out; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   data_reference_object_visitor(cell look_for, factor_vm* parent, ostream& out) | 
					
						
							|  |  |  |       : look_for(look_for), parent(parent), out(out) {} | 
					
						
							| 
									
										
										
										
											2009-10-03 09:47:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   void operator()(object* obj) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     SlotVisitor visitor(look_for, obj, parent, out); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |     obj->each_slot(visitor); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-10-31 22:06:34 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::find_data_references(ostream& out, cell look_for) { | 
					
						
							|  |  |  |   data_reference_object_visitor<find_data_reference_slot_visitor> | 
					
						
							|  |  |  |       visitor(look_for, this, out); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   each_object(visitor); | 
					
						
							| 
									
										
										
										
											2011-11-11 13:12:36 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::dump_edges(ostream& out) { | 
					
						
							|  |  |  |   data_reference_object_visitor<dump_edges_slot_visitor> visitor(0, this, out); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   each_object(visitor); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 11:22:06 -04:00
										 |  |  | struct code_block_printer { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   factor_vm* parent; | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   ostream& out; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   cell reloc_size, parameter_size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   explicit code_block_printer(factor_vm* parent, ostream& out) | 
					
						
							|  |  |  |       : parent(parent), out(out), reloc_size(0), parameter_size(0) {} | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void operator()(code_block* scan, cell size) { | 
					
						
							|  |  |  |     const char* status; | 
					
						
							|  |  |  |     if (scan->free_p()) | 
					
						
							|  |  |  |       status = "free"; | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       reloc_size += parent->object_size(scan->relocation); | 
					
						
							|  |  |  |       parameter_size += parent->object_size(scan->parameters); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-13 22:11:49 -05:00
										 |  |  |       if (parent->code->allocator->state.marked_p((cell)scan)) | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |         status = "marked"; | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         status = "allocated"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       out << hex << (cell)scan << dec << " "; | 
					
						
							|  |  |  |       out << hex << size << dec << " "; | 
					
						
							|  |  |  |       out << status << " "; | 
					
						
							|  |  |  |       out << "stack frame " << scan->stack_frame_size(); | 
					
						
							|  |  |  |       out << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-10-20 11:22:06 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Dump all code blocks for debugging */ | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  | void factor_vm::dump_code_heap(ostream& out) { | 
					
						
							|  |  |  |   code_block_printer printer(this, out); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   code->allocator->iterate(printer); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   out << printer.reloc_size << " bytes used by relocation tables" << endl; | 
					
						
							|  |  |  |   out << printer.parameter_size << " bytes used by parameter tables" << endl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | void factor_vm::factorbug_usage(bool advanced_p) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   cout << "Basic commands:" << endl; | 
					
						
							| 
									
										
										
										
											2011-10-27 23:55:12 -04:00
										 |  |  | #ifdef WINDOWS
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   cout << "  q ^Z             -- quit Factor" << endl; | 
					
						
							| 
									
										
										
										
											2011-10-27 23:55:12 -04:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   cout << "  q ^D             -- quit Factor" << endl; | 
					
						
							| 
									
										
										
										
											2011-10-27 23:55:12 -04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   cout << "  c                -- continue executing Factor - NOT SAFE" | 
					
						
							|  |  |  |        << endl; | 
					
						
							|  |  |  |   cout << "  t                -- throw exception in Factor - NOT SAFE" | 
					
						
							|  |  |  |        << endl; | 
					
						
							|  |  |  |   cout << "  .s .r .c         -- print data, retain, call stacks" | 
					
						
							|  |  |  |        << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   if (advanced_p) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     cout << "  help             -- reprint this message" << endl; | 
					
						
							|  |  |  |     cout << "Advanced commands:" << endl; | 
					
						
							|  |  |  |     cout << "  e                -- dump environment" << endl; | 
					
						
							|  |  |  |     cout << "  d <addr> <count> -- dump memory" << endl; | 
					
						
							|  |  |  |     cout << "  u <addr>         -- dump object at tagged <addr>" | 
					
						
							|  |  |  |          << endl; | 
					
						
							|  |  |  |     cout << "  . <addr>         -- print object at tagged <addr>" | 
					
						
							|  |  |  |          << endl; | 
					
						
							|  |  |  |     cout << "  g                -- dump generations" << endl; | 
					
						
							|  |  |  |     cout << "  ds dr            -- dump data, retain stacks" << endl; | 
					
						
							|  |  |  |     cout << "  trim             -- toggle output trimming" << endl; | 
					
						
							|  |  |  |     cout << "  data             -- data heap dump" << endl; | 
					
						
							|  |  |  |     cout << "  words            -- words dump" << endl; | 
					
						
							|  |  |  |     cout << "  tuples           -- tuples dump" << endl; | 
					
						
							|  |  |  |     cout << "  edges            -- print all object-to-object references" | 
					
						
							|  |  |  |          << endl; | 
					
						
							|  |  |  |     cout << "  refs <addr>      -- find data heap references to object" | 
					
						
							|  |  |  |          << endl; | 
					
						
							|  |  |  |     cout << "  push <addr>      -- push object on data stack - NOT SAFE" | 
					
						
							|  |  |  |          << endl; | 
					
						
							|  |  |  |     cout << "  gc               -- trigger full GC - NOT SAFE" | 
					
						
							|  |  |  |          << endl; | 
					
						
							|  |  |  |     cout << "  compact-gc       -- trigger compacting GC - NOT SAFE" | 
					
						
							|  |  |  |          << endl; | 
					
						
							|  |  |  |     cout << "  code             -- code heap dump" << endl; | 
					
						
							|  |  |  |     cout << "  abort            -- call abort()" << endl; | 
					
						
							|  |  |  |     cout << "  breakpoint       -- trigger system breakpoint" << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     cout << "  help             -- full help, including advanced commands" | 
					
						
							|  |  |  |          << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   cout << endl; | 
					
						
							| 
									
										
										
										
											2011-10-27 23:55:12 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | static void exit_fep(factor_vm* vm) { | 
					
						
							| 
									
										
										
										
											2015-08-04 10:49:50 -04:00
										 |  |  |   unlock_console(); | 
					
						
							|  |  |  |   handle_ctrl_c(); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   vm->fep_p = false; | 
					
						
							| 
									
										
										
										
											2011-11-08 00:12:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | void factor_vm::factorbug() { | 
					
						
							|  |  |  |   if (fep_disabled) { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     cout << "Low level debugger disabled" << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |     exit(1); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (sampling_profiler_p) | 
					
						
							|  |  |  |     end_sampling_profiler(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   fep_p = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   cout << "Starting low level debugger..." << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Even though we've stopped the VM, the stdin_loop thread (see os-*.cpp)
 | 
					
						
							|  |  |  |   // that pumps the console is still running concurrently. We lock a mutex so
 | 
					
						
							|  |  |  |   // the thread will take a break and give us exclusive access to stdin.
 | 
					
						
							|  |  |  |   lock_console(); | 
					
						
							|  |  |  |   ignore_ctrl_c(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!fep_help_was_shown) { | 
					
						
							|  |  |  |     factorbug_usage(false); | 
					
						
							|  |  |  |     fep_help_was_shown = true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   bool seen_command = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (;;) { | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     std::string cmd; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     cout << "> " << flush; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |     cin >> setw(1024) >> cmd >> setw(0); | 
					
						
							|  |  |  |     if (!cin.good()) { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       if (!seen_command) { | 
					
						
							|  |  |  |         /* If we exit with an EOF immediately, then
 | 
					
						
							|  |  |  |            dump stacks. This is useful for builder and | 
					
						
							|  |  |  |            other cases where Factor is run with stdin | 
					
						
							|  |  |  |            redirected to /dev/null */ | 
					
						
							|  |  |  |         fep_disabled = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |         print_datastack(cout); | 
					
						
							|  |  |  |         print_retainstack(cout); | 
					
						
							|  |  |  |         print_callstack(cout); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     seen_command = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     if (cmd == "q") | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       exit(1); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     if (cmd == "d") { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       cell addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       if (cin.peek() == ' ') | 
					
						
							|  |  |  |         cin.ignore(); | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       if (!cin.good()) | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |         break; | 
					
						
							|  |  |  |       cell count = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_memory(cout, addr, addr + count); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     } else if (cmd == "u") { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       cell addr = read_cell_hex(); | 
					
						
							|  |  |  |       cell count = object_size(addr); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_memory(cout, addr, addr + count); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     } else if (cmd == ".") { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       cell addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       print_obj(cout, addr); | 
					
						
							|  |  |  |       cout << endl; | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     } else if (cmd == "trim") | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       full_output = !full_output; | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "ds") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_memory(cout, ctx->datastack_seg->start, ctx->datastack); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "dr") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_memory(cout, ctx->retainstack_seg->start, ctx->retainstack); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == ".s") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       print_datastack(cout); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == ".r") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       print_retainstack(cout); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == ".c") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       print_callstack(cout); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "e") { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       for (cell i = 0; i < special_object_count; i++) | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |         dump_cell(cout, (cell)&special_objects[i]); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     } else if (cmd == "g") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_generations(cout); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "c") { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       exit_fep(this); | 
					
						
							|  |  |  |       return; | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     } else if (cmd == "t") { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       exit_fep(this); | 
					
						
							|  |  |  |       general_error(ERROR_INTERRUPT, false_object, false_object); | 
					
						
							|  |  |  |       FACTOR_ASSERT(false); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     } else if (cmd == "data") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_objects(cout, TYPE_COUNT); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "edges") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_edges(cout); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "refs") { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       cell addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       cout << "Data heap references:" << endl; | 
					
						
							|  |  |  |       find_data_references(cout, addr); | 
					
						
							|  |  |  |       cout << endl; | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     } else if (cmd == "words") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_objects(cout, WORD_TYPE); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "tuples") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_objects(cout, TUPLE_TYPE); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "push") { | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       cell addr = read_cell_hex(); | 
					
						
							|  |  |  |       ctx->push(addr); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     } else if (cmd == "code") | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       dump_code_heap(cout); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "compact-gc") | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       primitive_compact_gc(); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "gc") | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       primitive_full_gc(); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "compact-gc") | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       primitive_compact_gc(); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "help") | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       factorbug_usage(true); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "abort") | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       abort(); | 
					
						
							| 
									
										
										
										
											2014-06-19 16:12:25 -04:00
										 |  |  |     else if (cmd == "breakpoint") | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |       breakpoint(); | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |       cout << "unknown command" << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  | void factor_vm::primitive_die() { | 
					
						
							| 
									
										
										
										
											2015-01-28 08:27:20 -05:00
										 |  |  |   cout << "The die word was called by the library. Unless you called it " | 
					
						
							|  |  |  |       "yourself," << endl; | 
					
						
							|  |  |  |   cout << "you have triggered a bug in Factor. Please report." | 
					
						
							|  |  |  |        << endl; | 
					
						
							| 
									
										
										
										
											2013-05-11 21:57:14 -04:00
										 |  |  |   factorbug(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |