mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	More work on the sysir.
This commit is contained in:
		
							
								
								
									
										62
									
								
								examples/sysir/basic2.janet
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								examples/sysir/basic2.janet
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | ||||
| ### typedef struct {float x; float y; float z;} Vec3; | ||||
| ### | ||||
| ### Vec3 addv(Vec3 a, Vec3 b) { | ||||
| ###     Vec3 ret; | ||||
| ###     ret.x = a.x + b.x; | ||||
| ###     ret.y = a.y + b.y; | ||||
| ###     ret.z = a.z + b.z; | ||||
| ###     return ret; | ||||
| ### } | ||||
|  | ||||
| # Use fgetp for code gen | ||||
|  | ||||
| (def ir-asm | ||||
|   @{:instructions | ||||
|    '( | ||||
|      # Types | ||||
|      (type-prim Real f32) | ||||
|      (type-struct Vec3 Real Real Real) | ||||
|      (type-pointer PReal Real) | ||||
|  | ||||
|      # Declarations | ||||
|      (bind position Vec3) | ||||
|      (bind velocity Vec3) | ||||
|      (bind next-position Vec3) | ||||
|      (bind dest Real) | ||||
|      (bind lhs Real) | ||||
|      (bind rhs Real) | ||||
|      (bind pdest PReal) | ||||
|      (bind plhs PReal) | ||||
|      (bind prhs PReal) | ||||
|  | ||||
|      # Code | ||||
|      (fgetp pdest next-position 0) | ||||
|      (fgetp plhs position 0) | ||||
|      (fgetp prhs velocity 0) | ||||
|      (load lhs plhs) | ||||
|      (load rhs prhs) | ||||
|      (add dest lhs rhs) | ||||
|      (store pdest dest) | ||||
|  | ||||
|      (fgetp pdest next-position 1) | ||||
|      (fgetp plhs position 1) | ||||
|      (fgetp prhs velocity 1) | ||||
|      (load lhs plhs) | ||||
|      (load rhs prhs) | ||||
|      (add dest lhs rhs) | ||||
|      (store pdest dest) | ||||
|  | ||||
|      (fgetp pdest next-position 2) | ||||
|      (fgetp plhs position 2) | ||||
|      (fgetp prhs velocity 2) | ||||
|      (load lhs plhs) | ||||
|      (load rhs prhs) | ||||
|      (add dest lhs rhs) | ||||
|      (store pdest dest) | ||||
|  | ||||
|      (return next-position)) | ||||
|    :parameter-count 2 | ||||
|    :link-name "addv"}) | ||||
|  | ||||
| (def as (sysir/asm ir-asm)) | ||||
| (print (sysir/to-c as)) | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose