-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,523 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Cpp Backend CI with Nix | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [ mlscript ] | ||
|
||
jobs: | ||
lints: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Nix | ||
uses: DeterminateSystems/nix-installer-action@main | ||
- name: Run Test | ||
run: nix develop --command sbt compilerJVM/test |
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,110 @@ | ||
:NewDefs | ||
:ParseOnly | ||
:UseIR | ||
:NoTailRec | ||
|
||
:prelude | ||
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) | ||
//│ |#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|)| | ||
//│ 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,) {}} | ||
//│ | ||
//│ Preluded. | ||
//│ | ||
|
||
:genCpp | ||
:runCpp | ||
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() | ||
//│ |#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|(||)| | ||
//│ 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()} | ||
//│ | ||
//│ | ||
//│ IR: | ||
//│ Program: | ||
//│ class Fn() extends Callable { | ||
//│ def apply1(x$11) = | ||
//│ let x$12 = Callable.apply2(builtin,println,x$11) in -- #64 | ||
//│ x$12 -- #63 | ||
//│ } | ||
//│ class Fn2(a) extends Callable { | ||
//│ def apply1(x$13) = | ||
//│ let x$14 = Callable.apply2(builtin,println,a) in -- #80 | ||
//│ let x$15 = Callable.apply2(builtin,println,x$13) in -- #79 | ||
//│ x$15 -- #78 | ||
//│ } | ||
//│ class Demo(n) { | ||
//│ def x() = | ||
//│ n -- #81 | ||
//│ } | ||
//│ def f(fn$0) = | ||
//│ let x$1 = Callable.apply1(fn$0,1) in -- #8 | ||
//│ x$1 -- #7 | ||
//│ def main() = | ||
//│ let x$2 = Demo(2) in -- #56 | ||
//│ let x$3 = Demo.x(x$2) in -- #55 | ||
//│ let x$4 = Fn() in -- #54 | ||
//│ let x$5 = Fn.apply1(x$4,3) in -- #53 | ||
//│ let* (x$6) = f(x$4) in -- #52 | ||
//│ let x$7 = Fn2(4) in -- #51 | ||
//│ let x$8 = Fn2.apply1(x$7,5) in -- #50 | ||
//│ let x$9 = Callable.apply1(x$7,6) in -- #49 | ||
//│ let* (x$10) = f(x$7) in -- #48 | ||
//│ x$10 -- #47 | ||
//│ let* (x$0) = main() in -- #2 | ||
//│ x$0 -- #1 | ||
//│ | ||
//│ | ||
//│ Execution succeeded: | ||
//│ 3 | ||
//│ 1 | ||
//│ 4 | ||
//│ 5 | ||
//│ 4 | ||
//│ 6 | ||
//│ 4 | ||
//│ 1 | ||
//│ Unit | ||
//│ |
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,95 @@ | ||
:NewDefs | ||
:ParseOnly | ||
:UseIR | ||
:NoTailRec | ||
|
||
:prelude | ||
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) | ||
//│ |#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|)| | ||
//│ 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,) {}} | ||
//│ | ||
//│ Preluded. | ||
//│ | ||
|
||
:interpIR | ||
:genCpp | ||
:runCpp | ||
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() | ||
//│ |#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|(||)| | ||
//│ 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()} | ||
//│ | ||
//│ | ||
//│ IR: | ||
//│ Program: | ||
//│ class Lambda$0(a) extends Callable { | ||
//│ def apply1(b$1) = | ||
//│ let x$12 = +(a,b$1) in -- #58 | ||
//│ x$12 -- #57 | ||
//│ } | ||
//│ class Lambda$1(a) extends Callable { | ||
//│ def apply1(b$2) = | ||
//│ let x$14 = Lambda$2(a,b$2) in -- #60 | ||
//│ x$14 -- #59 | ||
//│ } | ||
//│ class Lambda$2(a,b) extends Callable { | ||
//│ def apply1(c$0) = | ||
//│ let x$15 = +(a,b) in -- #73 | ||
//│ let x$16 = +(x$15,c$0) in -- #72 | ||
//│ x$16 -- #71 | ||
//│ } | ||
//│ def add2c(a$0) = | ||
//│ let x$2 = Lambda$0(a$0) in -- #4 | ||
//│ x$2 -- #3 | ||
//│ def add2(a$1,b$0) = | ||
//│ let x$3 = +(a$1,b$0) in -- #11 | ||
//│ x$3 -- #10 | ||
//│ def add3c(a$2) = | ||
//│ let x$5 = Lambda$1(a$2) in -- #13 | ||
//│ x$5 -- #12 | ||
//│ def main() = | ||
//│ let* (x$6) = add2c(1) in -- #45 | ||
//│ let x$7 = Callable.apply1(x$6,2) in -- #44 | ||
//│ let* (x$8) = add2(1,2) in -- #43 | ||
//│ let* (x$9) = add3c(1) in -- #42 | ||
//│ let x$10 = Callable.apply1(x$9,2) in -- #41 | ||
//│ let x$11 = Callable.apply1(x$10,3) in -- #40 | ||
//│ x$11 -- #39 | ||
//│ let* (x$0) = main() in -- #2 | ||
//│ x$0 -- #1 | ||
//│ | ||
//│ Interpreted: | ||
//│ 6 | ||
//│ | ||
//│ | ||
//│ Execution succeeded: | ||
//│ 6 | ||
//│ |
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,158 @@ | ||
:NewDefs | ||
:ParseOnly | ||
:UseIR | ||
:NoTailRec | ||
|
||
:prelude | ||
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) | ||
//│ |#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|)| | ||
//│ 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,) {}} | ||
//│ | ||
//│ Preluded. | ||
//│ | ||
|
||
:genCpp | ||
:runCpp | ||
:interpIR | ||
fun main(x) = | ||
class InnerClass(y) extends Callable { | ||
fun apply1(z) = x + y + z | ||
} | ||
let ic = InnerClass(1) | ||
ic(2) + ic(3) | ||
main(4) | ||
//│ |#fun| |main|(|x|)| |#=|→|#class| |InnerClass|(|y|)| |#extends| |Callable| |{|→|#fun| |apply1|(|z|)| |#=| |x| |+| |y| |+| |z|←|↵|}|↵|#let| |ic| |#=| |InnerClass|(|1|)|↵|ic|(|2|)| |+| |ic|(|3|)|←|↵|main|(|4|)| | ||
//│ Parsed: {fun main = (x,) => {class InnerClass(y,): Callable {fun apply1 = (z,) => +(+(x, y,), z,)}; let ic = InnerClass(1,); +(ic(2,), ic(3,),)}; main(4,)} | ||
//│ | ||
//│ | ||
//│ IR: | ||
//│ Program: | ||
//│ class InnerClass(y,x) extends Callable { | ||
//│ def apply1(z$0) = | ||
//│ let x$6 = +(x,y) in -- #45 | ||
//│ let x$7 = +(x$6,z$0) in -- #44 | ||
//│ x$7 -- #43 | ||
//│ } | ||
//│ def main(x$1) = | ||
//│ let x$2 = InnerClass(1,x$1) in -- #26 | ||
//│ let x$3 = Callable.apply1(x$2,2) in -- #25 | ||
//│ let x$4 = Callable.apply1(x$2,3) in -- #24 | ||
//│ let x$5 = +(x$3,x$4) in -- #23 | ||
//│ x$5 -- #22 | ||
//│ let* (x$0) = main(4) in -- #4 | ||
//│ x$0 -- #3 | ||
//│ | ||
//│ Interpreted: | ||
//│ 15 | ||
//│ | ||
//│ | ||
//│ Execution succeeded: | ||
//│ 15 | ||
//│ | ||
|
||
:genCpp | ||
:runCpp | ||
:interpIR | ||
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) | ||
//│ |#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|)| | ||
//│ 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,)} | ||
//│ | ||
//│ | ||
//│ IR: | ||
//│ Program: | ||
//│ class InnerClass(y) extends Callable { | ||
//│ def apply1(z$0) = | ||
//│ let x$8 = InnerClass2(z$0) in -- #44 | ||
//│ x$8 -- #43 | ||
//│ } | ||
//│ class InnerClass2(z) extends Callable { | ||
//│ def apply1(w$0) = | ||
//│ let x$9 = +(w$0,z) in -- #51 | ||
//│ x$9 -- #50 | ||
//│ } | ||
//│ def main(x$1) = | ||
//│ let x$2 = InnerClass(1) in -- #36 | ||
//│ let x$3 = Callable.apply1(x$2,2) in -- #35 | ||
//│ let x$4 = Callable.apply1(x$3,2) in -- #34 | ||
//│ let x$5 = Callable.apply1(x$2,3) in -- #33 | ||
//│ let x$6 = Callable.apply1(x$5,1) in -- #32 | ||
//│ let x$7 = +(x$4,x$6) in -- #31 | ||
//│ x$7 -- #30 | ||
//│ let* (x$0) = main(4) in -- #4 | ||
//│ x$0 -- #3 | ||
//│ | ||
//│ Interpreted: | ||
//│ 8 | ||
//│ | ||
//│ | ||
//│ Execution succeeded: | ||
//│ 8 | ||
//│ | ||
|
||
:genCpp | ||
:runCpp | ||
:interpIR | ||
fun main(x) = | ||
class InnerClass(y) extends Callable { | ||
fun f(x) = y | ||
} | ||
let ic = InnerClass(1) | ||
InnerClass.f(ic, Nil) | ||
main(2) | ||
//│ |#fun| |main|(|x|)| |#=|→|#class| |InnerClass|(|y|)| |#extends| |Callable| |{|→|#fun| |f|(|x|)| |#=| |y|←|↵|}|↵|#let| |ic| |#=| |InnerClass|(|1|)|↵|InnerClass|.f|(|ic|,| |Nil|)|←|↵|main|(|2|)| | ||
//│ Parsed: {fun main = (x,) => {class InnerClass(y,): Callable {fun f = (x,) => y}; let ic = InnerClass(1,); (InnerClass).f(ic, Nil,)}; main(2,)} | ||
//│ | ||
//│ | ||
//│ IR: | ||
//│ Program: | ||
//│ class InnerClass(y) extends Callable { | ||
//│ def f(x$5) = | ||
//│ y -- #24 | ||
//│ } | ||
//│ def main(x$1) = | ||
//│ let x$2 = InnerClass(1) in -- #17 | ||
//│ let x$3 = Nil() in -- #16 | ||
//│ let x$4 = InnerClass.f(x$2,x$3) in -- #15 | ||
//│ x$4 -- #14 | ||
//│ let* (x$0) = main(2) in -- #4 | ||
//│ x$0 -- #3 | ||
//│ | ||
//│ Interpreted: | ||
//│ 1 | ||
//│ | ||
//│ | ||
//│ Execution succeeded: | ||
//│ 1 | ||
//│ |
Oops, something went wrong.