| 
									
										
										
										
											2010-04-18 16:26:31 -04:00
										 |  |  | ! Copyright (C) 2008, 2010 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2008-10-20 02:56:28 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2014-12-13 19:10:21 -05:00
										 |  |  | USING: accessors alien byte-arrays classes.algebra combinators | 
					
						
							|  |  |  | compiler.cfg.instructions compiler.cfg.instructions.syntax | 
					
						
							|  |  |  | compiler.cfg.registers compiler.constants effects kernel layouts | 
					
						
							|  |  |  | math namespaces parser sequences splitting words ;
 | 
					
						
							| 
									
										
										
										
											2008-10-20 21:40:15 -04:00
										 |  |  | IN: compiler.cfg.hats | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-02 07:22:37 -04:00
										 |  |  | << | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : hat-name ( insn -- word )
 | 
					
						
							| 
									
										
										
										
											2015-06-08 15:38:38 -04:00
										 |  |  |     name>> "##" ?head drop "^^" prepend create-word-in ;
 | 
					
						
							| 
									
										
										
										
											2009-09-02 07:22:37 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : hat-quot ( insn -- quot )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         "insn-slots" word-prop [ ] [ | 
					
						
							|  |  |  |             type>> { | 
					
						
							|  |  |  |                 { def [ [ next-vreg dup ] ] } | 
					
						
							|  |  |  |                 { temp [ [ next-vreg ] ] } | 
					
						
							|  |  |  |                 [ drop [ ] ] | 
					
						
							|  |  |  |             } case swap [ dip ] curry compose
 | 
					
						
							|  |  |  |         ] reduce
 | 
					
						
							| 
									
										
										
										
											2011-11-07 02:00:03 -05:00
										 |  |  |     ] keep insn-ctor-name "compiler.cfg.instructions" lookup-word suffix ;
 | 
					
						
							| 
									
										
										
										
											2009-09-02 07:22:37 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : hat-effect ( insn -- effect )
 | 
					
						
							|  |  |  |     "insn-slots" word-prop | 
					
						
							| 
									
										
										
										
											2015-05-12 21:50:34 -04:00
										 |  |  |     [ type>> { def temp } member-eq? ] reject [ name>> ] map
 | 
					
						
							| 
									
										
										
										
											2009-09-02 07:22:37 -04:00
										 |  |  |     { "vreg" } <effect> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : define-hat ( insn -- )
 | 
					
						
							|  |  |  |     [ hat-name ] [ hat-quot ] [ hat-effect ] tri define-inline ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | insn-classes get [ | 
					
						
							| 
									
										
										
										
											2010-07-13 07:40:14 -04:00
										 |  |  |     dup [ insn-def-slots length 1 = ] [ name>> "##" head? ] bi and
 | 
					
						
							| 
									
										
										
										
											2009-09-02 07:22:37 -04:00
										 |  |  |     [ define-hat ] [ drop ] if
 | 
					
						
							|  |  |  | ] each
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | >> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ^^load-literal ( obj -- dst )
 | 
					
						
							| 
									
										
										
										
											2010-04-21 03:08:52 -04:00
										 |  |  |     dup fixnum? [ ^^load-integer ] [ ^^load-reference ] if ;
 | 
					
						
							| 
									
										
										
										
											2009-09-02 07:22:37 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-26 02:39:48 -04:00
										 |  |  | : ^^offset>slot ( slot -- vreg' )
 | 
					
						
							| 
									
										
										
										
											2010-04-21 03:08:52 -04:00
										 |  |  |     cell 4 = 2 3 ? ^^shl-imm ;
 | 
					
						
							| 
									
										
										
										
											2009-09-26 02:39:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-21 03:08:52 -04:00
										 |  |  | : ^^unbox-f ( src -- dst )
 | 
					
						
							|  |  |  |     drop 0 ^^load-literal ;
 | 
					
						
							| 
									
										
										
										
											2009-09-26 01:28:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-21 03:08:52 -04:00
										 |  |  | : ^^unbox-byte-array ( src -- dst )
 | 
					
						
							|  |  |  |     ^^tagged>integer byte-array-offset ^^add-imm ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ^^unbox-c-ptr ( src class -- dst )
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         { [ dup \ f class<= ] [ drop ^^unbox-f ] } | 
					
						
							|  |  |  |         { [ dup alien class<= ] [ drop ^^unbox-alien ] } | 
					
						
							|  |  |  |         { [ dup byte-array class<= ] [ drop ^^unbox-byte-array ] } | 
					
						
							|  |  |  |         [ drop ^^unbox-any-c-ptr ] | 
					
						
							|  |  |  |     } cond ;
 |