Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ratio IR generation #141

Merged
merged 1 commit into from
Dec 10, 2024
Merged

Conversation

jianlingzhong
Copy link
Contributor

@jianlingzhong jianlingzhong commented Dec 6, 2024

clojure.core=> (defn add [a b] (+ a b))
#'clojure.core/add
clojure.core=> (add 3 3/4)
15/4
clojure.core=> (jank.compiler/native-source '(add 3/4 3/5))
; ModuleID = 'clojure.core-26'
source_filename = "clojure.core-26"
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "arm64-apple-darwin23.6.0"

@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @jank_global_init_25, ptr null }]
@var_clojure.core_SLASH_add = internal global ptr null
@string_4144411177 = internal global ptr null
@0 = private unnamed_addr constant [13 x i8] c"clojure.core\00", align 1
@string_2554602521 = internal global ptr null
@1 = private unnamed_addr constant [4 x i8] c"add\00", align 1
@ratio_3334807096 = internal global ptr null
@ratio_1587924207 = internal global ptr null

define void @jank_global_init_25() {
entry:
  %0 = call ptr @jank_string_create(ptr @0)
  store ptr %0, ptr @string_4144411177, align 8
  %1 = call ptr @jank_string_create(ptr @1)
  store ptr %1, ptr @string_2554602521, align 8
  %2 = call ptr @jank_var_intern(ptr %0, ptr %1)
  store ptr %2, ptr @var_clojure.core_SLASH_add, align 8
  %3 = call ptr @jank_ratio_create(i64 3, i64 4)
  store ptr %3, ptr @ratio_3334807096, align 8
  %4 = call ptr @jank_ratio_create(i64 3, i64 5)
  store ptr %4, ptr @ratio_1587924207, align 8
  ret void
}

define ptr @repl_fn_24_0() {
entry:
  %0 = load ptr, ptr @var_clojure.core_SLASH_add, align 8
  %1 = call ptr @jank_deref(ptr %0)
  %2 = load ptr, ptr @ratio_3334807096, align 8
  %3 = load ptr, ptr @ratio_1587924207, align 8
  %4 = call ptr @jank_call2(ptr %1, ptr %2, ptr %3)
  ret ptr %4
}

declare ptr @jank_var_intern(ptr, ptr)

declare ptr @jank_string_create(ptr)

declare ptr @jank_deref(ptr)

declare ptr @jank_ratio_create(i64, i64)

declare ptr @jank_call2(ptr, ptr, ptr)
nil
clojure.core=> (defn add [a] (+ a 1/2))
#'clojure.core/add
clojure.core=> (add 1)
3/2

@jianlingzhong jianlingzhong force-pushed the llvm-ir branch 2 times, most recently from 8e7857c to b8d063a Compare December 6, 2024 23:51
@jeaye jeaye merged commit 60d835e into jank-lang:llvm-ir Dec 10, 2024
2 of 4 checks passed
@jeaye
Copy link
Member

jeaye commented Dec 10, 2024

Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants