-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from AnyDSL/feature/fun
Feature/fun
- Loading branch information
Showing
19 changed files
with
467 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// once this works, replace old malloc.thorin with this one | ||
// RUN: rm -f %t.ll ; \ | ||
// RUN: %thorin -p clos %s --output-ll %t.ll -o - | ||
|
||
.plugin core; | ||
|
||
.let I32 = .Idx 4294967296; | ||
.lam Ptr T: * = %mem.Ptr (T, 0); | ||
|
||
.fun f(mem: %mem.M, x: I32) -> [%mem.M, I32] = return (mem, %core.wrap.add 0 (x, 42:I32)); | ||
.fun g(mem: %mem.M, x: I32) -> [%mem.M, I32] = return (mem, 1:I32); | ||
|
||
.fun .extern main(mem: %mem.M, argc: I32, argv: Ptr «⊤:.Nat; Ptr «⊤:.Nat; .Idx 256»») -> [%mem.M, I32] = { | ||
.fun h(mem: %mem.M, x: I32) -> [%mem.M, I32] = return (mem, %core.wrap.add 0 (x, argc)); | ||
|
||
.let pb_type = .Fn [%mem.M, I32] -> [%mem.M, I32]; | ||
.let Tas = (pb_type, 0); | ||
.let arr_size = ⊤:.Nat; | ||
|
||
.let ('mem, pb_ptr) = %mem.malloc Tas (mem, 32); | ||
.let pb_arr = %core.bitcast (Ptr «⊤:.Nat; .Fn [%mem.M, I32] -> [%mem.M, I32]») pb_ptr; | ||
.let ('mem, a_arr) = %mem.alloc («4; I32», 0) (mem); | ||
|
||
.let 'lea = %mem.lea (arr_size, ‹arr_size; pb_type›, 0) (pb_arr, 0:I32); | ||
.let 'mem = %mem.store (mem, lea, f); | ||
.let 'lea = %mem.lea (arr_size, ‹arr_size; pb_type›, 0) (pb_arr, 1:I32); | ||
.let 'mem = %mem.store (mem, lea, g); | ||
.let 'lea = %mem.lea (arr_size, ‹arr_size; pb_type›, 0) (pb_arr, 2:I32); | ||
.let 'mem = %mem.store (mem, lea, h); | ||
.let 'lea = %mem.lea (arr_size, ‹arr_size; I32›, 0) (a_arr, 0:I32); | ||
.let 'mem = %mem.store (mem, lea, 10:I32); | ||
.let 'lea = %mem.lea (arr_size, ‹arr_size; pb_type›, 0) (pb_arr, 2:I32); | ||
.let ('mem, func) = %mem.load (mem, lea); | ||
.let ('mem, val) = %mem.load (mem, lea); | ||
|
||
.ret ('mem, x) = func : (mem, 1:I32); | ||
return (mem, x)) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// RUN: rm -f %t.ll ; \ | ||
// RUN: %thorin %s -o - | FileCheck %s | ||
|
||
.plugin core; | ||
|
||
.let _32 = 4294967296; | ||
.let I32 = .Idx _32; | ||
.let I64 = .Idx 0; | ||
.lam Ptr(T: *) -> * = %mem.Ptr (T, 0); | ||
|
||
.fun foo(mem: %mem.M, x: I32)@(%core.icmp.e (x, 23:I32)) -> [%mem.M, I32] = return (mem, %core.wrap.add 0 (x, 1:I32)); | ||
|
||
.fun .extern main(mem: %mem.M, argc: I32, argv: Ptr (Ptr (.Idx 256))) -> [%mem.M, I32] = { | ||
.ret (`mem, x) = foo $ (mem, 23:I32); | ||
.ret (`mem, y) = foo $ (mem, 23:I32); | ||
return (mem, %core.wrap.add 0 (x, y)) | ||
}; | ||
|
||
.lam f1(T: *)((x y: T), return: T -> ⊥) -> ⊥ = return x; | ||
.con f2(T: *)((x y: T), return: .Cn T) = return x; | ||
.fun f3(T: *) (x y: T) = return x; | ||
|
||
.let g1 = .lm (T: *)((x y: T), return: T -> ⊥) -> ⊥ = return x; | ||
.let g2 = .cn (T: *)((x y: T), return: .Cn T) = return x; | ||
.let g3 = .fn (T: *) (x y: T) = return x; | ||
|
||
.let F1 = Π [T:*][T, T][T -> ⊥] -> ⊥; | ||
.let F2 =.Cn[T:*][T, T][.Cn T]; | ||
.let F3 =.Fn[T:*][T, T] -> T; | ||
|
||
|
||
.let _ = .ret res = f1 .Nat $ (23, 42); res; | ||
.let _ = f1 .Nat ((23, 42), .cn res: .Nat = res); | ||
|
||
// CHECK-DAG: return{{.*}}48 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.