Skip to content

Commit a3a3565

Browse files
committed
Add tests for Cpp backend
1 parent 43cc4f0 commit a3a3565

File tree

8 files changed

+1523
-0
lines changed

8 files changed

+1523
-0
lines changed

.github/workflows/nix.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Cpp Backend CI with Nix
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ mlscript ]
7+
8+
jobs:
9+
lints:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Install Nix
14+
uses: DeterminateSystems/nix-installer-action@main
15+
- name: Run Test
16+
run: nix develop --command sbt compilerJVM/test
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
:NewDefs
2+
:ParseOnly
3+
:UseIR
4+
:NoTailRec
5+
6+
:prelude
7+
module True
8+
module False
9+
module Callable {
10+
fun apply0() = 0
11+
fun apply1(x0) = 0
12+
fun apply2(x0,x1) = 0
13+
fun apply3(x0,x1,x2) = 0
14+
fun apply4(x0,x1,x2,x3) = 0
15+
fun apply5(x0,x1,x2,x3,x4) = 0
16+
}
17+
module List[A, B]
18+
class Cons[A, B](h: A, t: Cons[A, B]) extends List[A, B]
19+
module Nil[A, B] extends List[A, B]
20+
module Option[A]
21+
class Some[A](x: A) extends Option[A]
22+
module None[A] extends Option[A]
23+
class Pair[A, B](x: A, y: B)
24+
class Tuple2[A, B](x: A, y: B)
25+
class Tuple3[A, B, C](x: A, y: B, z: C)
26+
module Nat
27+
class S(s: Nat) extends Nat
28+
module O extends Nat
29+
class HiddenTheseEntities(_0: HiddenTheseEntities, _1: True, _2: False, _3: Callable, _4: List, _5: Cons, _6: Nil, _7: Option, _8: Some, _9: None, _10: Pair, _11: Tuple2, _12: Tuple3, _13: Nat, _14: S, _15: O)
30+
//│ |#module| |True|↵|#module| |False|↵|#module| |Callable| |{|→|#fun| |apply0|(||)| |#=| |0|↵|#fun| |apply1|(|x0|)| |#=| |0|↵|#fun| |apply2|(|x0|,|x1|)| |#=| |0|↵|#fun| |apply3|(|x0|,|x1|,|x2|)| |#=| |0|↵|#fun| |apply4|(|x0|,|x1|,|x2|,|x3|)| |#=| |0|↵|#fun| |apply5|(|x0|,|x1|,|x2|,|x3|,|x4|)| |#=| |0|←|↵|}|↵|#module| |List|[|A|,| |B|]|↵|#class| |Cons|[|A|,| |B|]|(|h|#:| |A|,| |t|#:| |Cons|[|A|,| |B|]|)| |#extends| |List|[|A|,| |B|]|↵|#module| |Nil|[|A|,| |B|]| |#extends| |List|[|A|,| |B|]|↵|#module| |Option|[|A|]|↵|#class| |Some|[|A|]|(|x|#:| |A|)| |#extends| |Option|[|A|]|↵|#module| |None|[|A|]| |#extends| |Option|[|A|]|↵|#class| |Pair|[|A|,| |B|]|(|x|#:| |A|,| |y|#:| |B|)|↵|#class| |Tuple2|[|A|,| |B|]|(|x|#:| |A|,| |y|#:| |B|)|↵|#class| |Tuple3|[|A|,| |B|,| |C|]|(|x|#:| |A|,| |y|#:| |B|,| |z|#:| |C|)|↵|#module| |Nat|↵|#class| |S|(|s|#:| |Nat|)| |#extends| |Nat|↵|#module| |O| |#extends| |Nat|↵|#class| |HiddenTheseEntities|(|_0|#:| |HiddenTheseEntities|,| |_1|#:| |True|,| |_2|#:| |False|,| |_3|#:| |Callable|,| |_4|#:| |List|,| |_5|#:| |Cons|,| |_6|#:| |Nil|,| |_7|#:| |Option|,| |_8|#:| |Some|,| |_9|#:| |None|,| |_10|#:| |Pair|,| |_11|#:| |Tuple2|,| |_12|#:| |Tuple3|,| |_13|#:| |Nat|,| |_14|#:| |S|,| |_15|#:| |O|)|
31+
//│ Parsed: {module True {}; module False {}; module Callable {fun apply0 = () => 0; fun apply1 = (x0,) => 0; fun apply2 = (x0, x1,) => 0; fun apply3 = (x0, x1, x2,) => 0; fun apply4 = (x0, x1, x2, x3,) => 0; fun apply5 = (x0, x1, x2, x3, x4,) => 0}; module List‹A, B› {}; class Cons‹A, B›(h: A, t: Cons‹A, B›,): List‹A, B› {}; module Nil‹A, B›: List‹A, B› {}; module Option‹A› {}; class Some‹A›(x: A,): Option‹A› {}; module None‹A›: Option‹A› {}; class Pair‹A, B›(x: A, y: B,) {}; class Tuple2‹A, B›(x: A, y: B,) {}; class Tuple3‹A, B, C›(x: A, y: B, z: C,) {}; module Nat {}; class S(s: Nat,): Nat {}; module O: Nat {}; class HiddenTheseEntities(_0: HiddenTheseEntities, _1: True, _2: False, _3: Callable, _4: List, _5: Cons, _6: Nil, _7: Option, _8: Some, _9: None, _10: Pair, _11: Tuple2, _12: Tuple3, _13: Nat, _14: S, _15: O,) {}}
32+
//│
33+
//│ Preluded.
34+
//│
35+
36+
:genCpp
37+
:runCpp
38+
module Fn extends Callable {
39+
fun apply1(x) = builtin("println", x)
40+
}
41+
class Fn2(a) extends Callable {
42+
fun apply1(x) =
43+
builtin("println", a)
44+
builtin("println", x)
45+
}
46+
class Demo(n) {
47+
fun x() = n
48+
}
49+
fun f(fn) = fn(1)
50+
fun main() =
51+
let d1 = Demo(2)
52+
Demo.x(d1)
53+
let print = Fn()
54+
Fn.apply1(print, 3)
55+
f(print)
56+
let print2 = Fn2(4)
57+
Fn2.apply1(print2, 5)
58+
print2(6)
59+
f(print2)
60+
main()
61+
//│ |#module| |Fn| |#extends| |Callable| |{|→|#fun| |apply1|(|x|)| |#=| |builtin|(|"println"|,| |x|)|←|↵|}|↵|#class| |Fn2|(|a|)| |#extends| |Callable| |{|→|#fun| |apply1|(|x|)| |#=|→|builtin|(|"println"|,| |a|)|↵|builtin|(|"println"|,| |x|)|←|←|↵|}|↵|#class| |Demo|(|n|)| |{|→|#fun| |x|(||)| |#=| |n|←|↵|}|↵|#fun| |f|(|fn|)| |#=| |fn|(|1|)|↵|#fun| |main|(||)| |#=|→|#let| |d1| |#=| |Demo|(|2|)|↵|Demo|.x|(|d1|)|↵|#let| |print| |#=| |Fn|(||)|↵|Fn|.apply1|(|print|,| |3|)|↵|f|(|print|)|↵|#let| |print2| |#=| |Fn2|(|4|)|↵|Fn2|.apply1|(|print2|,| |5|)|↵|print2|(|6|)|↵|f|(|print2|)|←|↵|main|(||)|
62+
//│ Parsed: {module Fn: Callable {fun apply1 = (x,) => builtin("println", x,)}; class Fn2(a,): Callable {fun apply1 = (x,) => {builtin("println", a,); builtin("println", x,)}}; class Demo(n,) {fun x = () => n}; fun f = (fn,) => fn(1,); fun main = () => {let d1 = Demo(2,); (Demo).x(d1,); let print = Fn(); (Fn).apply1(print, 3,); f(print,); let print2 = Fn2(4,); (Fn2).apply1(print2, 5,); print2(6,); f(print2,)}; main()}
63+
//│
64+
//│
65+
//│ IR:
66+
//│ Program:
67+
//│ class Fn() extends Callable {
68+
//│ def apply1(x$11) =
69+
//│ let x$12 = Callable.apply2(builtin,println,x$11) in -- #64
70+
//│ x$12 -- #63
71+
//│ }
72+
//│ class Fn2(a) extends Callable {
73+
//│ def apply1(x$13) =
74+
//│ let x$14 = Callable.apply2(builtin,println,a) in -- #80
75+
//│ let x$15 = Callable.apply2(builtin,println,x$13) in -- #79
76+
//│ x$15 -- #78
77+
//│ }
78+
//│ class Demo(n) {
79+
//│ def x() =
80+
//│ n -- #81
81+
//│ }
82+
//│ def f(fn$0) =
83+
//│ let x$1 = Callable.apply1(fn$0,1) in -- #8
84+
//│ x$1 -- #7
85+
//│ def main() =
86+
//│ let x$2 = Demo(2) in -- #56
87+
//│ let x$3 = Demo.x(x$2) in -- #55
88+
//│ let x$4 = Fn() in -- #54
89+
//│ let x$5 = Fn.apply1(x$4,3) in -- #53
90+
//│ let* (x$6) = f(x$4) in -- #52
91+
//│ let x$7 = Fn2(4) in -- #51
92+
//│ let x$8 = Fn2.apply1(x$7,5) in -- #50
93+
//│ let x$9 = Callable.apply1(x$7,6) in -- #49
94+
//│ let* (x$10) = f(x$7) in -- #48
95+
//│ x$10 -- #47
96+
//│ let* (x$0) = main() in -- #2
97+
//│ x$0 -- #1
98+
//│
99+
//│
100+
//│ Execution succeeded:
101+
//│ 3
102+
//│ 1
103+
//│ 4
104+
//│ 5
105+
//│ 4
106+
//│ 6
107+
//│ 4
108+
//│ 1
109+
//│ Unit
110+
//│
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
:NewDefs
2+
:ParseOnly
3+
:UseIR
4+
:NoTailRec
5+
6+
:prelude
7+
module True
8+
module False
9+
module Callable {
10+
fun apply0() = 0
11+
fun apply1(x0) = 0
12+
fun apply2(x0,x1) = 0
13+
fun apply3(x0,x1,x2) = 0
14+
fun apply4(x0,x1,x2,x3) = 0
15+
fun apply5(x0,x1,x2,x3,x4) = 0
16+
}
17+
module List[A, B]
18+
class Cons[A, B](h: A, t: Cons[A, B]) extends List[A, B]
19+
module Nil[A, B] extends List[A, B]
20+
module Option[A]
21+
class Some[A](x: A) extends Option[A]
22+
module None[A] extends Option[A]
23+
class Pair[A, B](x: A, y: B)
24+
class Tuple2[A, B](x: A, y: B)
25+
class Tuple3[A, B, C](x: A, y: B, z: C)
26+
module Nat
27+
class S(s: Nat) extends Nat
28+
module O extends Nat
29+
class HiddenTheseEntities(_0: HiddenTheseEntities, _1: True, _2: False, _3: Callable, _4: List, _5: Cons, _6: Nil, _7: Option, _8: Some, _9: None, _10: Pair, _11: Tuple2, _12: Tuple3, _13: Nat, _14: S, _15: O)
30+
//│ |#module| |True|↵|#module| |False|↵|#module| |Callable| |{|→|#fun| |apply0|(||)| |#=| |0|↵|#fun| |apply1|(|x0|)| |#=| |0|↵|#fun| |apply2|(|x0|,|x1|)| |#=| |0|↵|#fun| |apply3|(|x0|,|x1|,|x2|)| |#=| |0|↵|#fun| |apply4|(|x0|,|x1|,|x2|,|x3|)| |#=| |0|↵|#fun| |apply5|(|x0|,|x1|,|x2|,|x3|,|x4|)| |#=| |0|←|↵|}|↵|#module| |List|[|A|,| |B|]|↵|#class| |Cons|[|A|,| |B|]|(|h|#:| |A|,| |t|#:| |Cons|[|A|,| |B|]|)| |#extends| |List|[|A|,| |B|]|↵|#module| |Nil|[|A|,| |B|]| |#extends| |List|[|A|,| |B|]|↵|#module| |Option|[|A|]|↵|#class| |Some|[|A|]|(|x|#:| |A|)| |#extends| |Option|[|A|]|↵|#module| |None|[|A|]| |#extends| |Option|[|A|]|↵|#class| |Pair|[|A|,| |B|]|(|x|#:| |A|,| |y|#:| |B|)|↵|#class| |Tuple2|[|A|,| |B|]|(|x|#:| |A|,| |y|#:| |B|)|↵|#class| |Tuple3|[|A|,| |B|,| |C|]|(|x|#:| |A|,| |y|#:| |B|,| |z|#:| |C|)|↵|#module| |Nat|↵|#class| |S|(|s|#:| |Nat|)| |#extends| |Nat|↵|#module| |O| |#extends| |Nat|↵|#class| |HiddenTheseEntities|(|_0|#:| |HiddenTheseEntities|,| |_1|#:| |True|,| |_2|#:| |False|,| |_3|#:| |Callable|,| |_4|#:| |List|,| |_5|#:| |Cons|,| |_6|#:| |Nil|,| |_7|#:| |Option|,| |_8|#:| |Some|,| |_9|#:| |None|,| |_10|#:| |Pair|,| |_11|#:| |Tuple2|,| |_12|#:| |Tuple3|,| |_13|#:| |Nat|,| |_14|#:| |S|,| |_15|#:| |O|)|
31+
//│ Parsed: {module True {}; module False {}; module Callable {fun apply0 = () => 0; fun apply1 = (x0,) => 0; fun apply2 = (x0, x1,) => 0; fun apply3 = (x0, x1, x2,) => 0; fun apply4 = (x0, x1, x2, x3,) => 0; fun apply5 = (x0, x1, x2, x3, x4,) => 0}; module List‹A, B› {}; class Cons‹A, B›(h: A, t: Cons‹A, B›,): List‹A, B› {}; module Nil‹A, B›: List‹A, B› {}; module Option‹A› {}; class Some‹A›(x: A,): Option‹A› {}; module None‹A›: Option‹A› {}; class Pair‹A, B›(x: A, y: B,) {}; class Tuple2‹A, B›(x: A, y: B,) {}; class Tuple3‹A, B, C›(x: A, y: B, z: C,) {}; module Nat {}; class S(s: Nat,): Nat {}; module O: Nat {}; class HiddenTheseEntities(_0: HiddenTheseEntities, _1: True, _2: False, _3: Callable, _4: List, _5: Cons, _6: Nil, _7: Option, _8: Some, _9: None, _10: Pair, _11: Tuple2, _12: Tuple3, _13: Nat, _14: S, _15: O,) {}}
32+
//│
33+
//│ Preluded.
34+
//│
35+
36+
:interpIR
37+
:genCpp
38+
:runCpp
39+
fun add2c(a)(b) = a + b
40+
fun add2(a, b) = a + b
41+
fun add3c(a)(b)(c) = a + b + c
42+
fun main() =
43+
add2c(1)(2)
44+
add2(1, 2)
45+
add3c(1)(2)(3)
46+
main()
47+
//│ |#fun| |add2c|(|a|)|(|b|)| |#=| |a| |+| |b|↵|#fun| |add2|(|a|,| |b|)| |#=| |a| |+| |b|↵|#fun| |add3c|(|a|)|(|b|)|(|c|)| |#=| |a| |+| |b| |+| |c|↵|#fun| |main|(||)| |#=|→|add2c|(|1|)|(|2|)|↵|add2|(|1|,| |2|)|↵|add3c|(|1|)|(|2|)|(|3|)|←|↵|main|(||)|
48+
//│ Parsed: {fun add2c = (a,) => (b,) => +(a, b,); fun add2 = (a, b,) => +(a, b,); fun add3c = (a,) => (b,) => (c,) => +(+(a, b,), c,); fun main = () => {add2c(1,)(2,); add2(1, 2,); add3c(1,)(2,)(3,)}; main()}
49+
//│
50+
//│
51+
//│ IR:
52+
//│ Program:
53+
//│ class Lambda$0(a) extends Callable {
54+
//│ def apply1(b$1) =
55+
//│ let x$12 = +(a,b$1) in -- #58
56+
//│ x$12 -- #57
57+
//│ }
58+
//│ class Lambda$1(a) extends Callable {
59+
//│ def apply1(b$2) =
60+
//│ let x$14 = Lambda$2(a,b$2) in -- #60
61+
//│ x$14 -- #59
62+
//│ }
63+
//│ class Lambda$2(a,b) extends Callable {
64+
//│ def apply1(c$0) =
65+
//│ let x$15 = +(a,b) in -- #73
66+
//│ let x$16 = +(x$15,c$0) in -- #72
67+
//│ x$16 -- #71
68+
//│ }
69+
//│ def add2c(a$0) =
70+
//│ let x$2 = Lambda$0(a$0) in -- #4
71+
//│ x$2 -- #3
72+
//│ def add2(a$1,b$0) =
73+
//│ let x$3 = +(a$1,b$0) in -- #11
74+
//│ x$3 -- #10
75+
//│ def add3c(a$2) =
76+
//│ let x$5 = Lambda$1(a$2) in -- #13
77+
//│ x$5 -- #12
78+
//│ def main() =
79+
//│ let* (x$6) = add2c(1) in -- #45
80+
//│ let x$7 = Callable.apply1(x$6,2) in -- #44
81+
//│ let* (x$8) = add2(1,2) in -- #43
82+
//│ let* (x$9) = add3c(1) in -- #42
83+
//│ let x$10 = Callable.apply1(x$9,2) in -- #41
84+
//│ let x$11 = Callable.apply1(x$10,3) in -- #40
85+
//│ x$11 -- #39
86+
//│ let* (x$0) = main() in -- #2
87+
//│ x$0 -- #1
88+
//│
89+
//│ Interpreted:
90+
//│ 6
91+
//│
92+
//│
93+
//│ Execution succeeded:
94+
//│ 6
95+
//│
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
:NewDefs
2+
:ParseOnly
3+
:UseIR
4+
:NoTailRec
5+
6+
:prelude
7+
module True
8+
module False
9+
module Callable {
10+
fun apply0() = 0
11+
fun apply1(x0) = 0
12+
fun apply2(x0,x1) = 0
13+
fun apply3(x0,x1,x2) = 0
14+
fun apply4(x0,x1,x2,x3) = 0
15+
fun apply5(x0,x1,x2,x3,x4) = 0
16+
}
17+
module List[A, B]
18+
class Cons[A, B](h: A, t: Cons[A, B]) extends List[A, B]
19+
module Nil[A, B] extends List[A, B]
20+
module Option[A]
21+
class Some[A](x: A) extends Option[A]
22+
module None[A] extends Option[A]
23+
class Pair[A, B](x: A, y: B)
24+
class Tuple2[A, B](x: A, y: B)
25+
class Tuple3[A, B, C](x: A, y: B, z: C)
26+
module Nat
27+
class S(s: Nat) extends Nat
28+
module O extends Nat
29+
class HiddenTheseEntities(_0: HiddenTheseEntities, _1: True, _2: False, _3: Callable, _4: List, _5: Cons, _6: Nil, _7: Option, _8: Some, _9: None, _10: Pair, _11: Tuple2, _12: Tuple3, _13: Nat, _14: S, _15: O)
30+
//│ |#module| |True|↵|#module| |False|↵|#module| |Callable| |{|→|#fun| |apply0|(||)| |#=| |0|↵|#fun| |apply1|(|x0|)| |#=| |0|↵|#fun| |apply2|(|x0|,|x1|)| |#=| |0|↵|#fun| |apply3|(|x0|,|x1|,|x2|)| |#=| |0|↵|#fun| |apply4|(|x0|,|x1|,|x2|,|x3|)| |#=| |0|↵|#fun| |apply5|(|x0|,|x1|,|x2|,|x3|,|x4|)| |#=| |0|←|↵|}|↵|#module| |List|[|A|,| |B|]|↵|#class| |Cons|[|A|,| |B|]|(|h|#:| |A|,| |t|#:| |Cons|[|A|,| |B|]|)| |#extends| |List|[|A|,| |B|]|↵|#module| |Nil|[|A|,| |B|]| |#extends| |List|[|A|,| |B|]|↵|#module| |Option|[|A|]|↵|#class| |Some|[|A|]|(|x|#:| |A|)| |#extends| |Option|[|A|]|↵|#module| |None|[|A|]| |#extends| |Option|[|A|]|↵|#class| |Pair|[|A|,| |B|]|(|x|#:| |A|,| |y|#:| |B|)|↵|#class| |Tuple2|[|A|,| |B|]|(|x|#:| |A|,| |y|#:| |B|)|↵|#class| |Tuple3|[|A|,| |B|,| |C|]|(|x|#:| |A|,| |y|#:| |B|,| |z|#:| |C|)|↵|#module| |Nat|↵|#class| |S|(|s|#:| |Nat|)| |#extends| |Nat|↵|#module| |O| |#extends| |Nat|↵|#class| |HiddenTheseEntities|(|_0|#:| |HiddenTheseEntities|,| |_1|#:| |True|,| |_2|#:| |False|,| |_3|#:| |Callable|,| |_4|#:| |List|,| |_5|#:| |Cons|,| |_6|#:| |Nil|,| |_7|#:| |Option|,| |_8|#:| |Some|,| |_9|#:| |None|,| |_10|#:| |Pair|,| |_11|#:| |Tuple2|,| |_12|#:| |Tuple3|,| |_13|#:| |Nat|,| |_14|#:| |S|,| |_15|#:| |O|)|
31+
//│ Parsed: {module True {}; module False {}; module Callable {fun apply0 = () => 0; fun apply1 = (x0,) => 0; fun apply2 = (x0, x1,) => 0; fun apply3 = (x0, x1, x2,) => 0; fun apply4 = (x0, x1, x2, x3,) => 0; fun apply5 = (x0, x1, x2, x3, x4,) => 0}; module List‹A, B› {}; class Cons‹A, B›(h: A, t: Cons‹A, B›,): List‹A, B› {}; module Nil‹A, B›: List‹A, B› {}; module Option‹A› {}; class Some‹A›(x: A,): Option‹A› {}; module None‹A›: Option‹A› {}; class Pair‹A, B›(x: A, y: B,) {}; class Tuple2‹A, B›(x: A, y: B,) {}; class Tuple3‹A, B, C›(x: A, y: B, z: C,) {}; module Nat {}; class S(s: Nat,): Nat {}; module O: Nat {}; class HiddenTheseEntities(_0: HiddenTheseEntities, _1: True, _2: False, _3: Callable, _4: List, _5: Cons, _6: Nil, _7: Option, _8: Some, _9: None, _10: Pair, _11: Tuple2, _12: Tuple3, _13: Nat, _14: S, _15: O,) {}}
32+
//│
33+
//│ Preluded.
34+
//│
35+
36+
:genCpp
37+
:runCpp
38+
:interpIR
39+
fun main(x) =
40+
class InnerClass(y) extends Callable {
41+
fun apply1(z) = x + y + z
42+
}
43+
let ic = InnerClass(1)
44+
ic(2) + ic(3)
45+
main(4)
46+
//│ |#fun| |main|(|x|)| |#=|→|#class| |InnerClass|(|y|)| |#extends| |Callable| |{|→|#fun| |apply1|(|z|)| |#=| |x| |+| |y| |+| |z|←|↵|}|↵|#let| |ic| |#=| |InnerClass|(|1|)|↵|ic|(|2|)| |+| |ic|(|3|)|←|↵|main|(|4|)|
47+
//│ Parsed: {fun main = (x,) => {class InnerClass(y,): Callable {fun apply1 = (z,) => +(+(x, y,), z,)}; let ic = InnerClass(1,); +(ic(2,), ic(3,),)}; main(4,)}
48+
//│
49+
//│
50+
//│ IR:
51+
//│ Program:
52+
//│ class InnerClass(y,x) extends Callable {
53+
//│ def apply1(z$0) =
54+
//│ let x$6 = +(x,y) in -- #45
55+
//│ let x$7 = +(x$6,z$0) in -- #44
56+
//│ x$7 -- #43
57+
//│ }
58+
//│ def main(x$1) =
59+
//│ let x$2 = InnerClass(1,x$1) in -- #26
60+
//│ let x$3 = Callable.apply1(x$2,2) in -- #25
61+
//│ let x$4 = Callable.apply1(x$2,3) in -- #24
62+
//│ let x$5 = +(x$3,x$4) in -- #23
63+
//│ x$5 -- #22
64+
//│ let* (x$0) = main(4) in -- #4
65+
//│ x$0 -- #3
66+
//│
67+
//│ Interpreted:
68+
//│ 15
69+
//│
70+
//│
71+
//│ Execution succeeded:
72+
//│ 15
73+
//│
74+
75+
:genCpp
76+
:runCpp
77+
:interpIR
78+
fun main(x) =
79+
class InnerClass(y) extends Callable {
80+
fun apply1(z) =
81+
module InnerClass2 extends Callable {
82+
fun apply1(w) = w + z
83+
}
84+
InnerClass2
85+
}
86+
let ic = InnerClass(1)
87+
ic(2)(2) + ic(3)(1)
88+
main(4)
89+
//│ |#fun| |main|(|x|)| |#=|→|#class| |InnerClass|(|y|)| |#extends| |Callable| |{|→|#fun| |apply1|(|z|)| |#=|→|#module| |InnerClass2| |#extends| |Callable| |{|→|#fun| |apply1|(|w|)| |#=| |w| |+| |z|←|↵|}|↵|InnerClass2|←|←|↵|}|↵|#let| |ic| |#=| |InnerClass|(|1|)|↵|ic|(|2|)|(|2|)| |+| |ic|(|3|)|(|1|)|←|↵|main|(|4|)|
90+
//│ Parsed: {fun main = (x,) => {class InnerClass(y,): Callable {fun apply1 = (z,) => {module InnerClass2: Callable {fun apply1 = (w,) => +(w, z,)}; InnerClass2}}; let ic = InnerClass(1,); +(ic(2,)(2,), ic(3,)(1,),)}; main(4,)}
91+
//│
92+
//│
93+
//│ IR:
94+
//│ Program:
95+
//│ class InnerClass(y) extends Callable {
96+
//│ def apply1(z$0) =
97+
//│ let x$8 = InnerClass2(z$0) in -- #44
98+
//│ x$8 -- #43
99+
//│ }
100+
//│ class InnerClass2(z) extends Callable {
101+
//│ def apply1(w$0) =
102+
//│ let x$9 = +(w$0,z) in -- #51
103+
//│ x$9 -- #50
104+
//│ }
105+
//│ def main(x$1) =
106+
//│ let x$2 = InnerClass(1) in -- #36
107+
//│ let x$3 = Callable.apply1(x$2,2) in -- #35
108+
//│ let x$4 = Callable.apply1(x$3,2) in -- #34
109+
//│ let x$5 = Callable.apply1(x$2,3) in -- #33
110+
//│ let x$6 = Callable.apply1(x$5,1) in -- #32
111+
//│ let x$7 = +(x$4,x$6) in -- #31
112+
//│ x$7 -- #30
113+
//│ let* (x$0) = main(4) in -- #4
114+
//│ x$0 -- #3
115+
//│
116+
//│ Interpreted:
117+
//│ 8
118+
//│
119+
//│
120+
//│ Execution succeeded:
121+
//│ 8
122+
//│
123+
124+
:genCpp
125+
:runCpp
126+
:interpIR
127+
fun main(x) =
128+
class InnerClass(y) extends Callable {
129+
fun f(x) = y
130+
}
131+
let ic = InnerClass(1)
132+
InnerClass.f(ic, Nil)
133+
main(2)
134+
//│ |#fun| |main|(|x|)| |#=|→|#class| |InnerClass|(|y|)| |#extends| |Callable| |{|→|#fun| |f|(|x|)| |#=| |y|←|↵|}|↵|#let| |ic| |#=| |InnerClass|(|1|)|↵|InnerClass|.f|(|ic|,| |Nil|)|←|↵|main|(|2|)|
135+
//│ Parsed: {fun main = (x,) => {class InnerClass(y,): Callable {fun f = (x,) => y}; let ic = InnerClass(1,); (InnerClass).f(ic, Nil,)}; main(2,)}
136+
//│
137+
//│
138+
//│ IR:
139+
//│ Program:
140+
//│ class InnerClass(y) extends Callable {
141+
//│ def f(x$5) =
142+
//│ y -- #24
143+
//│ }
144+
//│ def main(x$1) =
145+
//│ let x$2 = InnerClass(1) in -- #17
146+
//│ let x$3 = Nil() in -- #16
147+
//│ let x$4 = InnerClass.f(x$2,x$3) in -- #15
148+
//│ x$4 -- #14
149+
//│ let* (x$0) = main(2) in -- #4
150+
//│ x$0 -- #3
151+
//│
152+
//│ Interpreted:
153+
//│ 1
154+
//│
155+
//│
156+
//│ Execution succeeded:
157+
//│ 1
158+
//│

0 commit comments

Comments
 (0)