Skip to content

Commit

Permalink
Pass tests again for autogen, modules and mvs
Browse files Browse the repository at this point in the history
  • Loading branch information
tjammer committed Jan 8, 2024
1 parent 7fbdc22 commit 0a8c09f
Show file tree
Hide file tree
Showing 74 changed files with 720 additions and 704 deletions.
4 changes: 2 additions & 2 deletions test/autogen.t/arr_of_strings.smu
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(def a ["test" "toast"])
(print (copy a).[1])
let a = ["test", "toast"]
print(copy(a).[1])
32 changes: 15 additions & 17 deletions test/autogen.t/closure.smu
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
(defn hmm ()
(def {a} {1})
(defn capture ()
(+ a 1))
capture)
fun hmm():
let a, _ = (1, 0)
fun capture(): a + 1
capture

(def _ {(copy (hmm))})
let _, _ = (copy(hmm), 0)

(defn hmm-move ()
(def {a} {1})
fun hmm_move():
let a, _ = (1, 0)
-- a is not explicitly copied, thus moved
(defn capture ()
(+ a 1))
capture)
fun capture(): a + 1
capture

(def _ {(hmm-move)})
let _, _ = (copy(hmm_move), 0)

(defn test ()
(def a ["hello"])
(fn :copy a () (print a.[0])))
fun test():
let a = ["hello"]
fun () [a]: print(a.[0])

(def c (test))
((copy c))
let c = test()
copy(c)()
6 changes: 3 additions & 3 deletions test/autogen.t/copy_array.smu
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(def [a (array u8)] [])
(def b& (copy a))
(array/push &b !'2')
let a : array(u8) = []
let b& = copy(a)
Array.push(&b, !'2')
13 changes: 7 additions & 6 deletions test/autogen.t/copy_string_lit.smu
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(def a ["aoeu"])
(def b& "aoeu")
(string/modify-buf &b (fn (arr&) (__unsafe_ptr_set &(array/data arr) 1 !'i')))
(print b)
(print "aoeu")
(print a.[0])
let a = ["aoeu"]
let b& = "aoeu"
String.modify_buf(&b, fun(arr&):
__unsafe_ptr_set(&Array.data(arr), 1, !'i'))
print(b)
print("aoeu")
print(a.[0])
8 changes: 4 additions & 4 deletions test/autogen.t/records.smu
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

-- (print (fmt-str (copy "test ") 1))

(type t {:c float :a string :b int :d (array int)})
(type (cont 'a) {:a 'a})
type t = {c : float, a : string, b : int, d : array(int)}
type cont('a) = {a : 'a}

(def a {:a {:a "lul" :b 10 :c 10.0 :d [10 20 30]}})
let a = {a = {a = "lul", b = 10, c = 10.0, d = [10, 20, 30]}}

(print (copy a).a.a)
print(copy(a).a.a)
150 changes: 85 additions & 65 deletions test/autogen.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,17 @@ Copy variants
source_filename = "context"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

%option.t_tuple_array_u8 = type { i32, %tuple_array_u8 }
%tuple_array_u8 = type { i8* }
%option.t_tuple_array_u8_int = type { i32, %tuple_array_u8_int }
%tuple_array_u8_int = type { i8*, i64 }

@schmu_a = global %option.t_tuple_array_u8 zeroinitializer, align 8
@schmu_a = global %option.t_tuple_array_u8_int zeroinitializer, align 8
@0 = private unnamed_addr constant { i64, i64, [6 x i8] } { i64 5, i64 5, [6 x i8] c"thing\00" }

declare void @string_print(i8* %0)

define i64 @main(i64 %arg) {
entry:
store i32 0, i32* getelementptr inbounds (%option.t_tuple_array_u8, %option.t_tuple_array_u8* @schmu_a, i32 0, i32 0), align 4
store i32 0, i32* getelementptr inbounds (%option.t_tuple_array_u8_int, %option.t_tuple_array_u8_int* @schmu_a, i32 0, i32 0), align 4
%0 = alloca i8*, align 8
store i8* bitcast ({ i64, i64, [6 x i8] }* @0 to i8*), i8** %0, align 8
%1 = alloca i8*, align 8
Expand All @@ -400,26 +400,28 @@ Copy variants
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 8, i1 false)
call void @__copy_ac(i8** %1)
%4 = load i8*, i8** %1, align 8
store i8* %4, i8** getelementptr inbounds (%option.t_tuple_array_u8, %option.t_tuple_array_u8* @schmu_a, i32 0, i32 1, i32 0), align 8
%5 = alloca %option.t_tuple_array_u8, align 8
%6 = bitcast %option.t_tuple_array_u8* %5 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %6, i8* bitcast (%option.t_tuple_array_u8* @schmu_a to i8*), i64 16, i1 false)
call void @__copy_option.ttup-ac(%option.t_tuple_array_u8* %5)
%tag1 = bitcast %option.t_tuple_array_u8* %5 to i32*
store i8* %4, i8** getelementptr inbounds (%option.t_tuple_array_u8_int, %option.t_tuple_array_u8_int* @schmu_a, i32 0, i32 1, i32 0), align 8
store i64 0, i64* getelementptr inbounds (%option.t_tuple_array_u8_int, %option.t_tuple_array_u8_int* @schmu_a, i32 0, i32 1, i32 1), align 8
%5 = alloca %option.t_tuple_array_u8_int, align 8
%6 = bitcast %option.t_tuple_array_u8_int* %5 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %6, i8* bitcast (%option.t_tuple_array_u8_int* @schmu_a to i8*), i64 24, i1 false)
call void @__copy_option.ttup-ac-i(%option.t_tuple_array_u8_int* %5)
%tag1 = bitcast %option.t_tuple_array_u8_int* %5 to i32*
%index = load i32, i32* %tag1, align 4
%eq = icmp eq i32 %index, 0
br i1 %eq, label %then, label %ifcont

then: ; preds = %entry
%data = getelementptr inbounds %option.t_tuple_array_u8, %option.t_tuple_array_u8* %5, i32 0, i32 1
%7 = bitcast %tuple_array_u8* %data to i8**
%8 = load i8*, i8** %7, align 8
call void @string_print(i8* %8)
%data = getelementptr inbounds %option.t_tuple_array_u8_int, %option.t_tuple_array_u8_int* %5, i32 0, i32 1
%7 = getelementptr inbounds %tuple_array_u8_int, %tuple_array_u8_int* %data, i32 0, i32 1
%8 = bitcast %tuple_array_u8_int* %data to i8**
%9 = load i8*, i8** %8, align 8
call void @string_print(i8* %9)
br label %ifcont

ifcont: ; preds = %entry, %then
call void @__free_option.ttup-ac(%option.t_tuple_array_u8* %5)
call void @__free_option.ttup-ac(%option.t_tuple_array_u8* @schmu_a)
call void @__free_option.ttup-ac-i(%option.t_tuple_array_u8_int* %5)
call void @__free_option.ttup-ac-i(%option.t_tuple_array_u8_int* @schmu_a)
ret i64 0
}

Expand All @@ -445,32 +447,32 @@ Copy variants
; Function Attrs: argmemonly nofree nounwind willreturn
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly %0, i8* noalias nocapture readonly %1, i64 %2, i1 immarg %3) #0

define linkonce_odr void @__copy_tup-ac(%tuple_array_u8* %0) {
define linkonce_odr void @__copy_tup-ac-i(%tuple_array_u8_int* %0) {
entry:
%1 = bitcast %tuple_array_u8* %0 to i8**
%1 = bitcast %tuple_array_u8_int* %0 to i8**
call void @__copy_ac(i8** %1)
ret void
}

define linkonce_odr void @__copy_option.ttup-ac(%option.t_tuple_array_u8* %0) {
define linkonce_odr void @__copy_option.ttup-ac-i(%option.t_tuple_array_u8_int* %0) {
entry:
%tag1 = bitcast %option.t_tuple_array_u8* %0 to i32*
%tag1 = bitcast %option.t_tuple_array_u8_int* %0 to i32*
%index = load i32, i32* %tag1, align 4
%1 = icmp eq i32 %index, 0
br i1 %1, label %match, label %cont

match: ; preds = %entry
%data = getelementptr inbounds %option.t_tuple_array_u8, %option.t_tuple_array_u8* %0, i32 0, i32 1
call void @__copy_tup-ac(%tuple_array_u8* %data)
%data = getelementptr inbounds %option.t_tuple_array_u8_int, %option.t_tuple_array_u8_int* %0, i32 0, i32 1
call void @__copy_tup-ac-i(%tuple_array_u8_int* %data)
br label %cont

cont: ; preds = %match, %entry
ret void
}

define linkonce_odr void @__free_tup-ac(%tuple_array_u8* %0) {
define linkonce_odr void @__free_tup-ac-i(%tuple_array_u8_int* %0) {
entry:
%1 = bitcast %tuple_array_u8* %0 to i8**
%1 = bitcast %tuple_array_u8_int* %0 to i8**
call void @__free_ac(i8** %1)
ret void
}
Expand All @@ -484,16 +486,16 @@ Copy variants
ret void
}

define linkonce_odr void @__free_option.ttup-ac(%option.t_tuple_array_u8* %0) {
define linkonce_odr void @__free_option.ttup-ac-i(%option.t_tuple_array_u8_int* %0) {
entry:
%tag1 = bitcast %option.t_tuple_array_u8* %0 to i32*
%tag1 = bitcast %option.t_tuple_array_u8_int* %0 to i32*
%index = load i32, i32* %tag1, align 4
%1 = icmp eq i32 %index, 0
br i1 %1, label %match, label %cont

match: ; preds = %entry
%data = getelementptr inbounds %option.t_tuple_array_u8, %option.t_tuple_array_u8* %0, i32 0, i32 1
call void @__free_tup-ac(%tuple_array_u8* %data)
%data = getelementptr inbounds %option.t_tuple_array_u8_int, %option.t_tuple_array_u8_int* %0, i32 0, i32 1
call void @__free_tup-ac-i(%tuple_array_u8_int* %data)
br label %cont

cont: ; preds = %match, %entry
Expand All @@ -514,8 +516,8 @@ Copy closures
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

%closure = type { i8*, i8* }
%tuple_int = type { i64 }
%tuple_fn_.int = type { %closure }
%tuple_int_int = type { i64, i64 }
%tuple_fn_.fn_.int_int = type { %closure, i64 }

@schmu_c = global %closure zeroinitializer, align 8
@0 = private unnamed_addr constant { i64, i64, [6 x i8] } { i64 5, i64 5, [6 x i8] c"hello\00" }
Expand Down Expand Up @@ -555,9 +557,11 @@ Copy closures

define void @schmu_hmm(%closure* noalias %0) {
entry:
%1 = alloca %tuple_int, align 8
%"01" = bitcast %tuple_int* %1 to i64*
%1 = alloca %tuple_int_int, align 8
%"01" = bitcast %tuple_int_int* %1 to i64*
store i64 1, i64* %"01", align 8
%"1" = getelementptr inbounds %tuple_int_int, %tuple_int_int* %1, i32 0, i32 1
store i64 0, i64* %"1", align 8
%funptr2 = bitcast %closure* %0 to i8**
store i8* bitcast (i64 (i8*)* @schmu_capture to i8*), i8** %funptr2, align 8
%2 = tail call i8* @malloc(i64 24)
Expand All @@ -573,11 +577,13 @@ Copy closures
ret void
}

define void @schmu_hmm-move(%closure* noalias %0) {
define void @schmu_hmm_move(%closure* noalias %0) {
entry:
%1 = alloca %tuple_int, align 8
%"01" = bitcast %tuple_int* %1 to i64*
%1 = alloca %tuple_int_int, align 8
%"01" = bitcast %tuple_int_int* %1 to i64*
store i64 1, i64* %"01", align 8
%"1" = getelementptr inbounds %tuple_int_int, %tuple_int_int* %1, i32 0, i32 1
store i64 0, i64* %"1", align 8
%funptr2 = bitcast %closure* %0 to i8**
store i8* bitcast (i64 (i8*)* @schmu_capture__2 to i8*), i8** %funptr2, align 8
%2 = tail call i8* @malloc(i64 24)
Expand Down Expand Up @@ -775,37 +781,51 @@ Copy closures

define i64 @main(i64 %arg) {
entry:
%0 = alloca %tuple_fn_.int, align 8
%"03" = bitcast %tuple_fn_.int* %0 to %closure*
%ret = alloca %closure, align 8
call void @schmu_hmm(%closure* %ret)
%1 = bitcast %closure* %"03" to i8*
%2 = bitcast %closure* %ret to i8*
%0 = alloca %tuple_fn_.fn_.int_int, align 8
%"08" = bitcast %tuple_fn_.fn_.int_int* %0 to %closure*
%clstmp = alloca %closure, align 8
%funptr9 = bitcast %closure* %clstmp to i8**
store i8* bitcast (void (%closure*)* @schmu_hmm to i8*), i8** %funptr9, align 8
%envptr = getelementptr inbounds %closure, %closure* %clstmp, i32 0, i32 1
store i8* null, i8** %envptr, align 8
%1 = bitcast %closure* %"08" to i8*
%2 = bitcast %closure* %clstmp to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* %2, i64 16, i1 false)
call void @__copy_.i(%closure* %"03")
%3 = alloca %tuple_fn_.int, align 8
%"014" = bitcast %tuple_fn_.int* %3 to %closure*
call void @schmu_hmm-move(%closure* %"014")
call void @__copy_..i(%closure* %"08")
%"1" = getelementptr inbounds %tuple_fn_.fn_.int_int, %tuple_fn_.fn_.int_int* %0, i32 0, i32 1
store i64 0, i64* %"1", align 8
%3 = alloca %tuple_fn_.fn_.int_int, align 8
%"0110" = bitcast %tuple_fn_.fn_.int_int* %3 to %closure*
%clstmp2 = alloca %closure, align 8
%funptr311 = bitcast %closure* %clstmp2 to i8**
store i8* bitcast (void (%closure*)* @schmu_hmm_move to i8*), i8** %funptr311, align 8
%envptr4 = getelementptr inbounds %closure, %closure* %clstmp2, i32 0, i32 1
store i8* null, i8** %envptr4, align 8
%4 = bitcast %closure* %"0110" to i8*
%5 = bitcast %closure* %clstmp2 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %4, i8* %5, i64 16, i1 false)
call void @__copy_..i(%closure* %"0110")
%"15" = getelementptr inbounds %tuple_fn_.fn_.int_int, %tuple_fn_.fn_.int_int* %3, i32 0, i32 1
store i64 0, i64* %"15", align 8
call void @schmu_test(%closure* @schmu_c)
%4 = alloca %closure, align 8
%5 = bitcast %closure* %4 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %5, i8* bitcast (%closure* @schmu_c to i8*), i64 16, i1 false)
call void @__copy_.u(%closure* %4)
%funcptr5 = bitcast %closure* %4 to i8**
%loadtmp = load i8*, i8** %funcptr5, align 8
%6 = alloca %closure, align 8
%7 = bitcast %closure* %6 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %7, i8* bitcast (%closure* @schmu_c to i8*), i64 16, i1 false)
call void @__copy_.u(%closure* %6)
%funcptr12 = bitcast %closure* %6 to i8**
%loadtmp = load i8*, i8** %funcptr12, align 8
%casttmp = bitcast i8* %loadtmp to void (i8*)*
%envptr = getelementptr inbounds %closure, %closure* %4, i32 0, i32 1
%loadtmp2 = load i8*, i8** %envptr, align 8
call void %casttmp(i8* %loadtmp2)
call void @__free_.u(%closure* %4)
%envptr6 = getelementptr inbounds %closure, %closure* %6, i32 0, i32 1
%loadtmp7 = load i8*, i8** %envptr6, align 8
call void %casttmp(i8* %loadtmp7)
call void @__free_.u(%closure* %6)
call void @__free_.u(%closure* @schmu_c)
call void @__free_tup-.i(%tuple_fn_.int* %3)
call void @__free_tup-.i(%tuple_fn_.int* %0)
call void @__free_.i(%closure* %ret)
call void @__free_tup-..i-i(%tuple_fn_.fn_.int_int* %3)
call void @__free_tup-..i-i(%tuple_fn_.fn_.int_int* %0)
ret i64 0
}

define linkonce_odr void @__copy_.i(%closure* %0) {
define linkonce_odr void @__copy_..i(%closure* %0) {
entry:
%1 = getelementptr inbounds %closure, %closure* %0, i32 0, i32 1
%2 = load i8*, i8** %1, align 8
Expand Down Expand Up @@ -878,7 +898,7 @@ Copy closures
br label %ret
}

define linkonce_odr void @__free_.i(%closure* %0) {
define linkonce_odr void @__free_..i(%closure* %0) {
entry:
%envptr = getelementptr inbounds %closure, %closure* %0, i32 0, i32 1
%env = load i8*, i8** %envptr, align 8
Expand All @@ -905,10 +925,10 @@ Copy closures
br label %ret
}

define linkonce_odr void @__free_tup-.i(%tuple_fn_.int* %0) {
define linkonce_odr void @__free_tup-..i-i(%tuple_fn_.fn_.int_int* %0) {
entry:
%1 = bitcast %tuple_fn_.int* %0 to %closure*
call void @__free_.i(%closure* %1)
%1 = bitcast %tuple_fn_.fn_.int_int* %0 to %closure*
call void @__free_..i(%closure* %1)
ret void
}

Expand All @@ -929,7 +949,7 @@ Copy string literal on move

declare void @string_print(i8* %0)

declare void @string_modify-buf(i8** noalias %0, %closure* %1)
declare void @string_modify_buf(i8** noalias %0, %closure* %1)

define void @__fun_schmu0(i8** noalias %arr) {
entry:
Expand Down Expand Up @@ -966,7 +986,7 @@ Copy string literal on move
store i8* bitcast (void (i8**)* @__fun_schmu0 to i8*), i8** %funptr2, align 8
%envptr = getelementptr inbounds %closure, %closure* %clstmp, i32 0, i32 1
store i8* null, i8** %envptr, align 8
call void @string_modify-buf(i8** @schmu_b, %closure* %clstmp)
call void @string_modify_buf(i8** @schmu_b, %closure* %clstmp)
%8 = load i8*, i8** @schmu_b, align 8
call void @string_print(i8* %8)
call void @string_print(i8* bitcast ({ i64, i64, [5 x i8] }* @0 to i8*))
Expand Down
2 changes: 1 addition & 1 deletion test/autogen.t/string_lit.smu
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(print (fmt-str (copy "test ") 1))
print(fmt(copy("test "), 1))
8 changes: 4 additions & 4 deletions test/autogen.t/variants.smu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(def a (#some {"thing"}))
let a = Some(("thing", 0))

(match (copy a)
((#some {t}) (print t))
(#none ()))
match copy(a):
Some((t, _)): print(t)
None: ()
Loading

0 comments on commit 0a8c09f

Please sign in to comment.