1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-30 13:58:05 +00:00

Start removing NASM dependence.

Start setting up a test suite for sysir and work towards emitting jitted
x86 machine code.
This commit is contained in:
Calvin Rose
2025-05-04 20:20:11 -05:00
parent 3dd6e744de
commit 0066a5a304
14 changed files with 287 additions and 226 deletions

View File

@@ -1,28 +0,0 @@
(def types-asm
'((type-prim Double f64)
(type-array BigVec Double 100)))
(def add-asm
'((link-name "add_vector")
(parameter-count 2)
# Declarations
(bind a BigVec)
(bind b BigVec)
(bind c BigVec)
(add c a b)
(return c)))
(def sub-asm
'((link-name "sub_vector")
(parameter-count 2)
(bind a BigVec)
(bind b BigVec)
(bind c BigVec)
(subtract c a b)
(return c)))
(def ctx (sysir/context))
(sysir/asm ctx types-asm)
(sysir/asm ctx add-asm)
(sysir/asm ctx sub-asm)
(print (sysir/to-c ctx))

View File

@@ -1,23 +0,0 @@
(def ir-asm
'((link-name "add_vectorp")
(parameter-count 2)
# Types
(type-prim Double f64)
(type-array BigVec Double 100)
(type-pointer BigVecP BigVec)
# Declarations
(bind 0 BigVecP)
(bind 1 BigVecP)
(bind 2 BigVecP)
(add 2 0 1)
(return 2)))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))
(printf "%.99M" (sysir/to-ir ctx))
(print (sysir/scalarize ctx))
(printf "%.99M" (sysir/to-ir ctx))
(print (sysir/to-c ctx))

View File

@@ -1,35 +0,0 @@
(def ir-asm
'((link-name "test_function")
# Types
(type-prim Int s32)
(type-prim Double f64)
(type-struct MyPair 0 1)
(type-pointer PInt 0)
(type-array DoubleArray 1 1024)
# Declarations
(bind 0 Int)
(bind 1 Int)
(bind 2 Int)
(bind 3 Double)
(bind bob Double)
(bind 5 Double)
(bind 6 MyPair)
# Code
(constant 0 10)
(constant 0 21)
:location
(add 2 1 0)
(constant 3 1.77)
(call 3 sin 3)
(cast bob 2)
(call :default bob test_function)
(add 5 bob 3)
(jump :location)
(return 5)))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))

View File

@@ -1,62 +0,0 @@
### 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
'((link-name "addv")
(parameter-count 2)
# 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)))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))

View File

@@ -1,55 +0,0 @@
### 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;
### }
(def ir-asm
'((link-name "addv_with_err")
(parameter-count 2)
# 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 (has type errors)
(fgetp pdest next-position 0)
(fgetp plhs position 0)
(fgetp prhs velocity 0)
(add dest plhs prhs)
(store pdest dest)
(fgetp pdest next-position 1)
(fgetp plhs position 1)
(fgetp prhs velocity 1)
(add dest lhs rhs)
(load lhs plhs)
(load rhs prhs)
(store pdest dest)
(fgetp pdest next-position 2)
(fgetp plhs position 2)
(fgetp prhs velocity 2)
(add dest plhs prhs)
(store pdest dest)
(return next-position)))
(def ctx (sysir/context))
(sysir/asm ctx ir-asm)
(print (sysir/to-c ctx))