1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-16 05:34:48 +00:00
janet/examples/sysir/basic2.janet
2023-08-12 13:42:52 -05:00

63 lines
1.3 KiB
Plaintext

### 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))