| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | struct jit { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell type; | 
					
						
							|  |  |  | 	gc_root<object> owner; | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	growable_byte_array code; | 
					
						
							|  |  |  | 	growable_byte_array relocation; | 
					
						
							|  |  |  | 	growable_array literals; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	bool computing_offset_p; | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	fixnum position; | 
					
						
							|  |  |  | 	cell offset; | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:09 -04:00
										 |  |  | 	factorvm *myvm; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:09 -04:00
										 |  |  | 	jit(cell jit_type, cell owner, factorvm *vm); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void compute_position(cell offset); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-06 21:04:49 -04:00
										 |  |  | 	void emit_relocation(cell code_template); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void emit(cell code_template); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void literal(cell literal) { literals.add(literal); } | 
					
						
							|  |  |  | 	void emit_with(cell code_template_, cell literal_); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void push(cell literal) { | 
					
						
							| 
									
										
										
										
											2009-08-21 14:27:40 -04:00
										 |  |  | 		emit_with(myvm->userenv[JIT_PUSH_IMMEDIATE],literal); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void word_jump(cell word) { | 
					
						
							| 
									
										
										
										
											2009-05-06 23:04:01 -04:00
										 |  |  | 		literal(tag_fixnum(xt_tail_pic_offset)); | 
					
						
							|  |  |  | 		literal(word); | 
					
						
							| 
									
										
										
										
											2009-08-21 14:27:40 -04:00
										 |  |  | 		emit(myvm->userenv[JIT_WORD_JUMP]); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void word_call(cell word) { | 
					
						
							| 
									
										
										
										
											2009-08-21 14:27:40 -04:00
										 |  |  | 		emit_with(myvm->userenv[JIT_WORD_CALL],word); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-06 23:04:01 -04:00
										 |  |  | 	void word_special(cell word) { | 
					
						
							| 
									
										
										
										
											2009-08-21 14:27:40 -04:00
										 |  |  | 		emit_with(myvm->userenv[JIT_WORD_SPECIAL],word); | 
					
						
							| 
									
										
										
										
											2009-05-06 23:04:01 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void emit_subprimitive(cell word_) { | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:09 -04:00
										 |  |  | 		gc_root<word> word(word_,myvm); | 
					
						
							|  |  |  | 		gc_root<array> code_template(word->subprimitive,myvm); | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:12 -04:00
										 |  |  | 		if(array_capacity(code_template.untagged()) > 1) literal(myvm->T); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 		emit(code_template.value()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void emit_class_lookup(fixnum index, cell type); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	fixnum get_position() { | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 		if(computing_offset_p) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			/* If this is still on, emit() didn't clear it,
 | 
					
						
							|  |  |  | 			   so the offset was out of bounds */ | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			return position; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  |         void set_position(fixnum position_) { | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 		if(computing_offset_p) | 
					
						
							|  |  |  | 			position = position_; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	code_block *to_code_block(); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |