https://github.com/sundown/rib
:leaves: A compiler backend
https://github.com/sundown/rib
backend compiler lisp llvm rib
Last synced: 6 months ago
JSON representation
:leaves: A compiler backend
- Host: GitHub
- URL: https://github.com/sundown/rib
- Owner: Sundown
- License: mit
- Created: 2021-03-24T15:34:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-04T20:46:40.000Z (over 4 years ago)
- Last Synced: 2023-09-14T23:07:47.608Z (over 2 years ago)
- Topics: backend, compiler, lisp, llvm, rib
- Language: C
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### rib
A LISP syntax compiler backend emitting LLVM.
:construction: Not currently usable for anything meaningful.
```clj
(define square real real {
(ret (* % %))
})
(define main void int {
(global arr [2 3 5 7 11])
(global b (square (cast (index arr 3) real))) ; and we epically do nothing with this
(print "stdout moment")
(global strucha <1 "string">) ; structs too (no they're tuples)
(ret 0)
})
```
compiles to
```llvm
; ModuleID = 'rib'
source_filename = "rib"
@arr = global <5 x i64>
@b = global double 0.000000e+00
@0 = private unnamed_addr constant [14 x i8] c"stdout moment\00", align 1
@1 = private unnamed_addr constant [7 x i8] c"string\00", align 1
@strucha = global { i64, i8* } { i64 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @1, i32 0, i32 0) }
define double @square(double %0) {
entry:
%1 = fmul double %0, %0
ret double %1
}
define i64 @main() {
entry:
%0 = load <5 x i64>, <5 x i64>* @arr, align 64
%1 = extractelement <5 x i64> %0, i64 3
%2 = sitofp i64 %1 to double
%3 = call double @square(double %2)
store double %3, double* @b, align 8
%4 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @0, i32 0, i32 0))
ret i64 0
}
declare i32 @puts(i8*)
```