| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #include "master.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  | namespace factor { | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-25 17:05:05 -04:00
										 |  |  | /* Compile a word definition with the non-optimizing compiler. */ | 
					
						
							|  |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  | void factor_vm::jit_compile_word(cell word_, cell def_, bool relocating) { | 
					
						
							|  |  |  |   data_root<word> word(word_, this); | 
					
						
							|  |  |  |   data_root<quotation> def(def_, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Refuse to compile this word more than once, because quot_compiled_p()
 | 
					
						
							|  |  |  |      depends on the identity of its code block */ | 
					
						
							|  |  |  |   if (word->entry_point && | 
					
						
							|  |  |  |       word.value() == special_objects[LAZY_JIT_COMPILE_WORD]) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   code_block* compiled = | 
					
						
							| 
									
										
										
										
											2015-07-15 14:13:52 -04:00
										 |  |  |       jit_compile_quotation(word.value(), def.value(), relocating); | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  |   word->entry_point = compiled->entry_point(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (to_boolean(word->pic_def)) | 
					
						
							| 
									
										
										
										
											2015-07-15 14:13:52 -04:00
										 |  |  |     jit_compile_quotation(word->pic_def, relocating); | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  |   if (to_boolean(word->pic_tail_def)) | 
					
						
							| 
									
										
										
										
											2015-07-15 14:13:52 -04:00
										 |  |  |     jit_compile_quotation(word->pic_tail_def, relocating); | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-16 00:30:55 -04:00
										 |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  | word* factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) { | 
					
						
							|  |  |  |   data_root<object> vocab(vocab_, this); | 
					
						
							|  |  |  |   data_root<object> name(name_, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   data_root<word> new_word(allot<word>(sizeof(word)), this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   new_word->hashcode = hashcode_; | 
					
						
							|  |  |  |   new_word->vocabulary = vocab.value(); | 
					
						
							|  |  |  |   new_word->name = name.value(); | 
					
						
							|  |  |  |   new_word->def = special_objects[OBJ_UNDEFINED]; | 
					
						
							|  |  |  |   new_word->props = false_object; | 
					
						
							|  |  |  |   new_word->pic_def = false_object; | 
					
						
							|  |  |  |   new_word->pic_tail_def = false_object; | 
					
						
							|  |  |  |   new_word->subprimitive = false_object; | 
					
						
							| 
									
										
										
										
											2015-01-07 05:51:19 -05:00
										 |  |  |   new_word->entry_point = 0; | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   jit_compile_word(new_word.value(), new_word->def, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return new_word.untagged(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-27 22:09:11 -04:00
										 |  |  | /* (word) ( name vocabulary hashcode -- word ) */ | 
					
						
							| 
									
										
										
										
											2013-03-25 14:59:33 -04:00
										 |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  | void factor_vm::primitive_word() { | 
					
						
							|  |  |  |   cell hashcode = ctx->pop(); | 
					
						
							|  |  |  |   cell vocab = ctx->pop(); | 
					
						
							|  |  |  |   cell name = ctx->pop(); | 
					
						
							|  |  |  |   ctx->push(tag<word>(allot_word(name, vocab, hashcode))); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | /* word-code ( word -- start end ) */ | 
					
						
							| 
									
										
										
										
											2013-03-25 14:59:33 -04:00
										 |  |  | /* Allocates memory (from_unsigned_cell allocates) */ | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  | void factor_vm::primitive_word_code() { | 
					
						
							|  |  |  |   data_root<word> w(ctx->pop(), this); | 
					
						
							| 
									
										
										
										
											2015-11-24 10:00:50 -05:00
										 |  |  |   check_tagged(w); | 
					
						
							| 
									
										
										
										
											2009-09-25 22:42:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-07 05:51:19 -05:00
										 |  |  |   ctx->push(from_unsigned_cell(w->entry_point)); | 
					
						
							| 
									
										
										
										
											2013-05-13 00:53:47 -04:00
										 |  |  |   ctx->push(from_unsigned_cell((cell)w->code() + w->code()->size())); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-15 14:13:52 -04:00
										 |  |  | void factor_vm::primitive_word_optimized_p() { | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  |   word* w = untag_check<word>(ctx->peek()); | 
					
						
							|  |  |  |   ctx->replace(tag_boolean(w->code()->optimized_p())); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-16 00:30:55 -04:00
										 |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2013-05-11 22:32:09 -04:00
										 |  |  | void factor_vm::primitive_wrapper() { | 
					
						
							|  |  |  |   wrapper* new_wrapper = allot<wrapper>(sizeof(wrapper)); | 
					
						
							|  |  |  |   new_wrapper->object = ctx->peek(); | 
					
						
							|  |  |  |   ctx->replace(tag<wrapper>(new_wrapper)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |