diff --git a/compiler/shared/main/scala/mlscript/compiler/ClassLifter.scala b/compiler/shared/main/scala/mlscript/compiler/ClassLifter.scala index 5124a31c5..559bc5957 100644 --- a/compiler/shared/main/scala/mlscript/compiler/ClassLifter.scala +++ b/compiler/shared/main/scala/mlscript/compiler/ClassLifter.scala @@ -7,7 +7,6 @@ import scala.collection.mutable.StringBuilder as StringBuilder import scala.collection.mutable.Map as MutMap import scala.collection.mutable.Set as MutSet import scala.collection.mutable.ArrayBuffer as ArrayBuffer -import mlscript.codegen.Helpers.inspect as showStructure import mlscript.codegen.CodeGenError import mlscript.compiler.mono.MonomorphError @@ -748,7 +747,7 @@ class ClassLifter(logDebugMsg: Boolean = false) { def liftTypingUnit(rawUnit: TypingUnit): TypingUnit = { log("=========================\n") - log(s"lifting: \n${showStructure(rawUnit)}\n") + log(s"lifting: \n$rawUnit\n") retSeq = Nil globalFunctions.clear() val re = liftEntities(rawUnit.entities)(using emptyCtx, Map(), Map(), None) diff --git a/compiler/shared/main/scala/mlscript/compiler/Helpers.scala b/compiler/shared/main/scala/mlscript/compiler/Helpers.scala index 5eb1a526d..41515a772 100644 --- a/compiler/shared/main/scala/mlscript/compiler/Helpers.scala +++ b/compiler/shared/main/scala/mlscript/compiler/Helpers.scala @@ -1,7 +1,6 @@ package mlscript package compiler -import mlscript.codegen.Helpers.inspect as showStructure import mlscript.compiler.mono.{Monomorph, MonomorphError} import scala.collection.mutable.ArrayBuffer @@ -16,7 +15,7 @@ object Helpers: case (None, Fld(FldFlags(_, spec, _), Var(name))) => Some((spec, Expr.Ref(name))) case (Some(Var(name)), Fld(FldFlags(_, spec, _), _)) => Some((spec, Expr.Ref(name))) case _ => throw new MonomorphError( - s"only `Var` can be parameters but we meet ${showStructure(term)}" + s"only `Var` can be parameters but we meet $term" ) } case _ => throw MonomorphError("expect the list of parameters to be a `Tup`") diff --git a/compiler/shared/main/scala/mlscript/compiler/PrettyPrinter.scala b/compiler/shared/main/scala/mlscript/compiler/PrettyPrinter.scala index 106748f96..14e91ccf4 100644 --- a/compiler/shared/main/scala/mlscript/compiler/PrettyPrinter.scala +++ b/compiler/shared/main/scala/mlscript/compiler/PrettyPrinter.scala @@ -5,7 +5,7 @@ import mlscript.compiler.debug.DebugOutput // For pretty printing terms in debug output. object PrettyPrinter: - def show(term: Term): DebugOutput = DebugOutput.Code(term.toString.linesIterator.toList) + def show(term: Term): DebugOutput = DebugOutput.Code(term.showDbg.linesIterator.toList) def show(unit: TypingUnit): DebugOutput = DebugOutput.Code(showTypingUnit(unit, 0).linesIterator.toList) def show(funDef: NuFunDef): DebugOutput = DebugOutput.Code(showFunDef(funDef).linesIterator.toList) def show(tyDef: NuTypeDef): DebugOutput = DebugOutput.Code(showTypeDef(tyDef, 0).linesIterator.toList) @@ -16,7 +16,7 @@ object PrettyPrinter: case term: Term => show(term) case tyDef: NuTypeDef => showTypeDef(tyDef) case funDef: NuFunDef => showFunDef(funDef) - case others => others.toString() + case others => others.showDbg }.mkString("{", "; ", "}") if (singleLine.length < 60) singleLine @@ -26,7 +26,7 @@ object PrettyPrinter: case term: Term => show(term) case tyDef: NuTypeDef => showTypeDef(tyDef) case funDef: NuFunDef => showFunDef(funDef) - case others => others.toString() + case others => others.showDbg }.map(indentStr + " " + _).mkString("{\n", "\n", s"\n$indentStr}") def showFunDef(funDef: NuFunDef): String = @@ -40,15 +40,15 @@ object PrettyPrinter: then "" else funDef.tparams.map(_.name).mkString("[", ", ", "]")) + " = " - + funDef.rhs.fold(_.toString, _.show(newDefs = true)) + + funDef.rhs.fold(_.showDbg, _.show(newDefs = true)) def showTypeDef(tyDef: NuTypeDef, indent: Int = 0): String = s"${tyDef.kind.str} ${tyDef.nme.name}" + (if tyDef.tparams.isEmpty then "" else tyDef.tparams.map(_._2.name).mkString("[", ",", "]")) - + tyDef.params.fold("")(params => s"($params)") + + tyDef.params.fold("")(params => s"(${params.showDbg})") + (if tyDef.parents.isEmpty then "" - else ": " + tyDef.parents.map(_.toString).mkString(", ")) + else ": " + tyDef.parents.map(_.showDbg).mkString(", ")) + showTypingUnit(tyDef.body, indent + 1) diff --git a/compiler/shared/test/diff/LambLift.mls b/compiler/shared/test/diff/LambLift.mls index c42974bf4..81fecb52d 100644 --- a/compiler/shared/test/diff/LambLift.mls +++ b/compiler/shared/test/diff/LambLift.mls @@ -9,8 +9,7 @@ fun foo() = (new Foo()).bar local(1) foo() -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(), Blk(...))), App(Var(foo), Tup())) +//│ //│ Lifted: //│ TypingUnit { //│ class Foo$1([x,]) {fun bar = () => +((this).x, foo$1(),)} @@ -27,8 +26,7 @@ foo() fun foo(f) = f(1) foo(x => x+1) -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(_: Var(f)), Blk(...))), App(Var(foo), Tup(_: Lam(Tup(_: Var(x)), App(Var(+), Tup(_: Var(x), _: IntLit(1))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class Lambda1$2$1([]) {fun apply = (x,) => +(x, 1,)} @@ -45,8 +43,7 @@ fun foo(x) = f(x) bar(y => y+x) foo(1) -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(_: Var(x)), Blk(...))), App(Var(foo), Tup(_: IntLit(1)))) +//│ //│ Lifted: //│ TypingUnit { //│ class Lambda1$3$1([x,]) {fun apply = (y,) => +(y, (this).x,)} @@ -67,8 +64,7 @@ class A(y: Int){ fun app(a) = foo(z => a.bar(z)) app(new A(1)) -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(_: Var(f)), Blk(...))), NuTypeDef(class, A, (), Tup(y: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, bar, None, [], Lam(Tup(_: Var(z)), App(Var(+), Tup(_: Var(y), _: Var(z))))))), NuFunDef(None, app, None, [], Lam(Tup(_: Var(a)), Blk(...))), App(Var(app), Tup(_: App(NuNew(Var(A)), Tup(_: IntLit(1)))))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1([y: Int,]) {fun bar = (z,) => +((this).y, z,)} diff --git a/compiler/shared/test/diff/LiftType.mls b/compiler/shared/test/diff/LiftType.mls index 773e24b1e..e8a5206b5 100644 --- a/compiler/shared/test/diff/LiftType.mls +++ b/compiler/shared/test/diff/LiftType.mls @@ -7,8 +7,7 @@ class CTX{ } //│ |#class| |CTX|{|→|#class| |A| |{||}|↵|#fun| |foo|(|f|#:| |A| |#=>| |A|)|#:| |(|A| |#=>| |A|)| |#=>| |A| |#=| |f|(|#new| |A|)|←|↵|}| //│ Parsed: {class CTX {class A {}; fun foo = (f: (A,) => A,) => f(new A,) : (A -> A) -> A}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, CTX, (), Tup(), (), None, None, TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit()), NuFunDef(None, foo, None, [], Lam(Tup(f: Lam(Tup(_: Var(A)), Var(A))), Asc(App(Var(f), Tup(_: NuNew(Var(A)))), Function(Tuple(List((None,Field(None,Function(Tuple(List((None,Field(None,TypeName(A))))),TypeName(A)))))),TypeName(A)))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class CTX$1_A$2([par$CTX$1,]) {} @@ -25,8 +24,7 @@ class CTX(x, y){ } //│ |#class| |CTX|(|x|,| |y|)|{|→|#class| |A|{| |#fun| |foo| |#=| |x|}|↵|#class| |B|#:| |A| |{| |#fun| |foo| |#=| |y|}|↵|#fun| |foo|(|any|#:| |[|A|,| |B|]|)|#:| |[|B|,| |A|]| |#=| |[|any|._2|,| |any|._1|]|←|↵|}| //│ Parsed: {class CTX(x, y,) {class A {fun foo = x}; class B: A {fun foo = y}; fun foo = (any: [A, B,],) => [(any)._2, (any)._1,] : [B, A]}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, CTX, (), Tup(_: Var(x), _: Var(y)), (), None, None, TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Var(x)))), NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Var(y)))), NuFunDef(None, foo, None, [], Lam(Tup(any: Tup(_: Var(A), _: Var(B))), Asc(Tup(_: Sel(Var(any), _2), _: Sel(Var(any), _1)), Tuple(List((None,Field(None,TypeName(B))), (None,Field(None,TypeName(A))))))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class CTX$1_A$2([par$CTX$1,]) {fun foo = () => ((this).par$CTX$1).x} @@ -44,8 +42,7 @@ class CTX(x, y){ } //│ |#class| |CTX|(|x|,| |y|)|{|→|#class| |A|{| |#fun| |foo| |#=| |x|}|↵|#class| |B|#:| |A| |{| |#fun| |foo| |#=| |y|}|↵|#fun| |foo|(|any|#:| |{|p1|#:| |A|,| |p2|#:| |B|}|)|#:| |[|B|,| |A|]| |#=| |[|any|.p2|,| |any|.p1|]|←|↵|}| //│ Parsed: {class CTX(x, y,) {class A {fun foo = x}; class B: A {fun foo = y}; fun foo = (any: '{' {p1: A, p2: B} '}',) => [(any).p2, (any).p1,] : [B, A]}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, CTX, (), Tup(_: Var(x), _: Var(y)), (), None, None, TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Var(x)))), NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Var(y)))), NuFunDef(None, foo, None, [], Lam(Tup(any: Bra(rcd = true, Rcd(Var(p1) = Var(A), Var(p2) = Var(B)))), Asc(Tup(_: Sel(Var(any), p2), _: Sel(Var(any), p1)), Tuple(List((None,Field(None,TypeName(B))), (None,Field(None,TypeName(A))))))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class CTX$1_A$2([par$CTX$1,]) {fun foo = () => ((this).par$CTX$1).x} @@ -63,8 +60,7 @@ class CTX(x, y){ } //│ |#class| |CTX|(|x|,| |y|)|{|→|#class| |A|{| |#fun| |foo| |#=| |x|}|↵|#class| |B|‹|T|›| |{| |#fun| |foo| |#=| |y|}|↵|#fun| |foo|(|any|#:| |[|A|,| |B|‹|A|›|]|)|#:| |[|[|B|‹|A|›|,| |A|]|,| |A|]| |#=| |[|any|,| |any|._1|]|←|↵|}| //│ Parsed: {class CTX(x, y,) {class A {fun foo = x}; class B‹T› {fun foo = y}; fun foo = (any: [A, B‹A›,],) => [any, (any)._1,] : [[B[A], A], A]}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, CTX, (), Tup(_: Var(x), _: Var(y)), (), None, None, TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Var(x)))), NuTypeDef(class, B, ((None,TypeName(T))), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Var(y)))), NuFunDef(None, foo, None, [], Lam(Tup(any: Tup(_: Var(A), _: TyApp(Var(B), List(TypeName(A))))), Asc(Tup(_: Var(any), _: Sel(Var(any), _1)), Tuple(List((None,Field(None,Tuple(List((None,Field(None,AppliedType(TypeName(B),List(TypeName(A))))), (None,Field(None,TypeName(A))))))), (None,Field(None,TypeName(A))))))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class CTX$1_A$2([par$CTX$1,]) {fun foo = () => ((this).par$CTX$1).x} @@ -85,8 +81,7 @@ class CTX{ } //│ |#class| |CTX|{|→|#fun| |ctx|(|x|,|y|)| |#=| |→|#class| |A|{| |#fun| |foo| |#=| |x| |}|↵|#fun| |bar|‹|T|›|(|any|#:| |T|)|#:| |A| |#=| |→|#let| |x| |#=| |#new| |T|↵|#new| |A|←|↵|(|#new| |CTX|)|.bar|‹|CTX|›|←|←|↵|}| //│ Parsed: {class CTX {fun ctx = (x, y,) => {class A {fun foo = x}; fun bar = (any: T,) => {let x = new T; new A} : A; ('(' new CTX ')').bar‹CTX›}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, CTX, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, ctx, None, [], Lam(Tup(_: Var(x), _: Var(y)), Blk(...)))))) +//│ //│ Lifted: //│ Lifting failed: mlscript.codegen.CodeGenError: Cannot find type T. Class values are not supported in lifter. //│ diff --git a/compiler/shared/test/diff/Lifter.mls b/compiler/shared/test/diff/Lifter.mls index fffb3d725..c0c0f3a68 100644 --- a/compiler/shared/test/diff/Lifter.mls +++ b/compiler/shared/test/diff/Lifter.mls @@ -27,8 +27,7 @@ class A(x) { } //│ |#class| |A|(|x|)| |{|→|#class| |B|(|y|)| |{|→|#fun| |getX| |#=| |x|↵|#fun| |getB1| |#=| |B1|(|y|)|↵|#class| |C|(|z|)| |{|→|#fun| |inc|(||)| |#=| |x| |+| |1|↵|#fun| |getY| |#=| |y|↵|#fun| |getA| |#=| |A|(|z|)|↵|#fun| |getB|(|w|)| |#=| |B|(|w|)|↵|#fun| |getC| |#=| |#new| |C|(|inc|(||)|)|↵|#fun| |getSelf| |#=| |this|←|↵|}|←|↵|}|↵|#class| |B1|(|y|)| |{|→|#fun| |getX| |#=| |x|↵|#fun| |getY| |#=| |y|↵|#fun| |getB| |#=| |#new| |B|(|y|)|↵|#fun| |getB1| |#=| |#new| |B1|(|y|)|←|↵|}|↵|#fun| |getB| |#=| |#new| |B|(|x|)|↵|#fun| |getB2|(|y|)| |#=| |B1|(|y|)|↵|#fun| |getB3|(|z|)| |#=| |getB2|(|z|)|↵|#fun| |getA| |#=| |A|(|x|)|←|↵|}| //│ Parsed: {class A(x,) {class B(y,) {fun getX = x; fun getB1 = B1(y,); class C(z,) {fun inc = () => +(x, 1,); fun getY = y; fun getA = A(z,); fun getB = (w,) => B(w,); fun getC = (new C)(inc(),); fun getSelf = this}}; class B1(y,) {fun getX = x; fun getY = y; fun getB = (new B)(y,); fun getB1 = (new B1)(y,)}; fun getB = (new B)(x,); fun getB2 = (y,) => B1(y,); fun getB3 = (z,) => getB2(z,); fun getA = A(x,)}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(_: Var(x)), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(_: Var(y)), (), None, None, TypingUnit(NuFunDef(None, getX, None, [], Var(x)), NuFunDef(None, getB1, None, [], App(Var(B1), Tup(_: Var(y)))), NuTypeDef(class, C, (), Tup(_: Var(z)), (), None, None, TypingUnit(NuFunDef(None, inc, None, [], Lam(Tup(), App(Var(+), Tup(_: Var(x), _: IntLit(1))))), NuFunDef(None, getY, None, [], Var(y)), NuFunDef(None, getA, None, [], App(Var(A), Tup(_: Var(z)))), NuFunDef(None, getB, None, [], Lam(Tup(_: Var(w)), App(Var(B), Tup(_: Var(w))))), NuFunDef(None, getC, None, [], App(NuNew(Var(C)), Tup(_: App(Var(inc), Tup())))), NuFunDef(None, getSelf, None, [], Var(this)))))), NuTypeDef(class, B1, (), Tup(_: Var(y)), (), None, None, TypingUnit(NuFunDef(None, getX, None, [], Var(x)), NuFunDef(None, getY, None, [], Var(y)), NuFunDef(None, getB, None, [], App(NuNew(Var(B)), Tup(_: Var(y)))), NuFunDef(None, getB1, None, [], App(NuNew(Var(B1)), Tup(_: Var(y)))))), NuFunDef(None, getB, None, [], App(NuNew(Var(B)), Tup(_: Var(x)))), NuFunDef(None, getB2, None, [], Lam(Tup(_: Var(y)), App(Var(B1), Tup(_: Var(y))))), NuFunDef(None, getB3, None, [], Lam(Tup(_: Var(z)), App(Var(getB2), Tup(_: Var(z))))), NuFunDef(None, getA, None, [], App(Var(A), Tup(_: Var(x))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2_C$4([par$A$1_B$2, z, x,]) { @@ -67,8 +66,7 @@ class A(x) { } //│ |#class| |A|(|x|)| |{|→|#class| |B|(|y|)| |{|→|#class| |C|(|z|)| |{|→|#fun| |sum| |#=| |x| |+| |y| |+| |z|←|↵|}|←|↵|}|←|↵|}| //│ Parsed: {class A(x,) {class B(y,) {class C(z,) {fun sum = +(+(x, y,), z,)}}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(_: Var(x)), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(_: Var(y)), (), None, None, TypingUnit(NuTypeDef(class, C, (), Tup(_: Var(z)), (), None, None, TypingUnit(NuFunDef(None, sum, None, [], App(Var(+), Tup(_: App(Var(+), Tup(_: Var(x), _: Var(y))), _: Var(z))))))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2_C$3([par$A$1_B$2, z, x,]) { @@ -106,9 +104,8 @@ new C{ fun bar = 17 } //│ |#class| |A|(|x|)| |{|→|#class| |B|{|→|#fun| |foo| |#=| |1|↵|#fun| |bar| |#=| |11|←|↵|}|↵|#fun| |getB| |#=| |#new| |B|{|→|#fun| |foo| |#=| |2|↵|#fun| |bar| |#=| |12|←|↵|}|↵|#fun| |bar| |#=| |13|←|↵|}|↵|#class| |C|#:| |A|{|→|#fun| |getB| |#=| |#new| |B|{|→|#fun| |foo| |#=| |3|↵|#fun| |bar| |#=| |14|←|↵|}|↵|#fun| |bar| |#=| |15|←|↵|}|↵|#new| |C|{|→|#fun| |getB| |#=| |#new| |B|{|→|#fun| |foo| |#=| |4|↵|#fun| |bar| |#=| |16|←|↵|}|↵|#fun| |bar| |#=| |17|←|↵|}| -//│ Parsed: {class A(x,) {class B {fun foo = 1; fun bar = 11}; fun getB = new B { ‹fun foo = 2; fun bar = 12› }; fun bar = 13}; class C: A {fun getB = new B { ‹fun foo = 3; fun bar = 14› }; fun bar = 15}; new C { ‹fun getB = new B { ‹fun foo = 4; fun bar = 16› }; fun bar = 17› }} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(_: Var(x)), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], IntLit(1)), NuFunDef(None, bar, None, [], IntLit(11)))), NuFunDef(None, getB, None, [], Rft(NuNew(Var(B)), ...)), NuFunDef(None, bar, None, [], IntLit(13)))), NuTypeDef(class, C, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, getB, None, [], Rft(NuNew(Var(B)), ...)), NuFunDef(None, bar, None, [], IntLit(15)))), Rft(NuNew(Var(C)), ...)) +//│ Parsed: {class A(x,) {class B {fun foo = 1; fun bar = 11}; fun getB = new B {fun foo = 2; fun bar = 12}; fun bar = 13}; class C: A {fun getB = new B {fun foo = 3; fun bar = 14}; fun bar = 15}; new C {fun getB = new B {fun foo = 4; fun bar = 16}; fun bar = 17}} +//│ //│ Lifted: //│ Lifting failed: mlscript.codegen.CodeGenError: Cannot find type B. Class values are not supported in lifter. //│ @@ -124,8 +121,7 @@ class Parent(x) { } //│ |#class| |Parent|‹|T|,| |U|,| |V|›|(|x|)| |{| |→|#fun| |foo|(|x|#:| |Int|)|#:| |T| |#=| |x|+|1|↵|#class| |Inner|‹|W|›|(|y|#:| |Int|)|{|→|#fun| |bar|(|z|#:| |U|)| |#=| |foo|(|y|)|↵|#fun| |boo|(|z|#:| |W|)| |#=| |z|←|↵|}|←|↵|}| //│ Parsed: {class Parent‹T, U, V›(x,) {fun foo = (x: Int,) => +(x, 1,) : T; class Inner‹W›(y: Int,) {fun bar = (z: U,) => foo(y,); fun boo = (z: W,) => z}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Parent, ((None,TypeName(T)), (None,TypeName(U)), (None,TypeName(V))), Tup(_: Var(x)), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(x: Var(Int)), Asc(App(Var(+), Tup(_: Var(x), _: IntLit(1))), TypeName(T)))), NuTypeDef(class, Inner, ((None,TypeName(W))), Tup(y: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, bar, None, [], Lam(Tup(z: Var(U)), App(Var(foo), Tup(_: Var(y))))), NuFunDef(None, boo, None, [], Lam(Tup(z: Var(W)), Var(z)))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class Parent$1_Inner$2[W,U]([par$Parent$1, y: Int,]) { @@ -146,9 +142,8 @@ class A(x: Int): ({a1: Int} & B & D(x)) { } } //│ |#class| |B|‹|T|›| |{||}|↵|#class| |C| |{||}|↵|#class| |D|(|y|#:| |Int|)| |{||}|↵|#class| |A|‹|T|,| |U|›|(|x|#:| |Int|)|#:| |(|{|a1|#:| |Int|}| |&| |B|‹|T|›| |&| |D|(|x|)|)| |{|→|#fun| |getA|(||)| |#=| |#new| |C|{|→|#fun| |foo|(|x|#:| |T|)| |#=| |x|←|↵|}|←|↵|}| -//│ Parsed: {class B‹T› {}; class C {}; class D(y: Int,) {}; class A‹T, U›(x: Int,): {a1: Int} & B[T] & D[x] {fun getA = () => new C { ‹fun foo = (x: T,) => x› }}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, B, ((None,TypeName(T))), Tup(), (), None, None, TypingUnit()), NuTypeDef(class, C, (), Tup(), (), None, None, TypingUnit()), NuTypeDef(class, D, (), Tup(y: Var(Int)), (), None, None, TypingUnit()), NuTypeDef(class, A, ((None,TypeName(T)), (None,TypeName(U))), Tup(x: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, getA, None, [], Lam(Tup(), Rft(NuNew(Var(C)), ...)))))) +//│ Parsed: {class B‹T› {}; class C {}; class D(y: Int,) {}; class A‹T, U›(x: Int,): {a1: Int} & B[T] & D[x] {fun getA = () => new C {fun foo = (x: T,) => x}}} +//│ //│ Lifted: //│ TypingUnit { //│ class B$1[T]([]) {} @@ -168,9 +163,8 @@ class A(x: Int) extends {a1: Int}, B, D(x){ } } //│ |#class| |B|‹|T|›| |{||}|↵|#class| |C| |{||}|↵|#class| |D|(|y|#:| |Int|)| |{||}|↵|#class| |A|‹|T|,| |U|›|(|x|#:| |Int|)| |#extends| |{|a1|#:| |Int|}|,| |B|‹|T|›|,| |D|(|x|)|{|→|#fun| |getA|(||)| |#=| |#new| |C|{|→|#fun| |foo|(|x|)| |#=| |x|←|↵|}|←|↵|}| -//│ Parsed: {class B‹T› {}; class C {}; class D(y: Int,) {}; class A‹T, U›(x: Int,): '{' {a1: Int} '}', B‹T›, D(x,) {fun getA = () => new C { ‹fun foo = (x,) => x› }}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, B, ((None,TypeName(T))), Tup(), (), None, None, TypingUnit()), NuTypeDef(class, C, (), Tup(), (), None, None, TypingUnit()), NuTypeDef(class, D, (), Tup(y: Var(Int)), (), None, None, TypingUnit()), NuTypeDef(class, A, ((None,TypeName(T)), (None,TypeName(U))), Tup(x: Var(Int)), (Bra(rcd = true, Rcd(Var(a1) = Var(Int))), TyApp(Var(B), List(TypeName(T))), App(Var(D), Tup(_: Var(x)))), None, None, TypingUnit(NuFunDef(None, getA, None, [], Lam(Tup(), Rft(NuNew(Var(C)), ...)))))) +//│ Parsed: {class B‹T› {}; class C {}; class D(y: Int,) {}; class A‹T, U›(x: Int,): '{' {a1: Int} '}', B‹T›, D(x,) {fun getA = () => new C {fun foo = (x,) => x}}} +//│ //│ Lifted: //│ TypingUnit { //│ class B$1[T]([]) {} @@ -189,8 +183,7 @@ class Child(x): ({ age: T } & { name: String}) { } //│ |#class| |Child|‹|T|,| |U|›|(|x|)|#:| |(|{| |age|#:| |T| |}| |&| |{| |name|#:| |String|}|)| |{|→|#class| |Inner|{|→|#fun| |foo| |#=| |age|←|↵|}|↵|#fun| |bar| |#=| |age|↵|#fun| |boo| |#=| |#new| |Inner|←|↵|}| //│ Parsed: {class Child‹T, U›(x,): {age: T} & {name: String} {class Inner {fun foo = age}; fun bar = age; fun boo = new Inner}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Child, ((None,TypeName(T)), (None,TypeName(U))), Tup(_: Var(x)), (), None, None, TypingUnit(NuTypeDef(class, Inner, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Var(age)))), NuFunDef(None, bar, None, [], Var(age)), NuFunDef(None, boo, None, [], NuNew(Var(Inner)))))) +//│ //│ Lifted: //│ TypingUnit { //│ class Child$1_Inner$2([par$Child$1, age,]) {fun foo = () => (this).age} @@ -211,9 +204,8 @@ new A(0) { fun getA2 = 2 } //│ |#class| |A|(|x|#:| |Int|)| |{|→|#fun| |getA|#:| |Int| |#=| |0|↵|#fun| |getA1| |#=| |1|←|↵|}|↵|#new| |A|(|0|)| |{|→|#fun| |getA| |#=| |3|↵|#fun| |getA2| |#=| |2|←|↵|}| -//│ Parsed: {class A(x: Int,) {fun getA = 0 : Int; fun getA1 = 1}; (new A)(0,) { ‹fun getA = 3; fun getA2 = 2› }} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(x: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, getA, None, [], Asc(IntLit(0), TypeName(Int))), NuFunDef(None, getA1, None, [], IntLit(1)))), Rft(App(NuNew(Var(A)), Tup(_: IntLit(0))), ...)) +//│ Parsed: {class A(x: Int,) {fun getA = 0 : Int; fun getA1 = 1}; (new A)(0,) {fun getA = 3; fun getA2 = 2}} +//│ //│ Lifted: //│ TypingUnit { //│ class A$1([x: Int,]) {fun getA = () => 0 : Int; fun getA1 = () => 1} @@ -232,9 +224,8 @@ new A(1) { } } //│ |#class| |A|(|x|)| |{|→|#class| |B|(|y|)| |{| |}|←|↵|}|↵|#new| |A|(|1|)| |{|→|#fun| |getB| |#=| |#new| |B|(|2|)|{|→|#fun| |getB| |#=| |#new| |B|(|3|)|←|↵|}|←|↵|}| -//│ Parsed: {class A(x,) {class B(y,) {}}; (new A)(1,) { ‹fun getB = (new B)(2,) { ‹fun getB = (new B)(3,)› }› }} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(_: Var(x)), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(_: Var(y)), (), None, None, TypingUnit()))), Rft(App(NuNew(Var(A)), Tup(_: IntLit(1))), ...)) +//│ Parsed: {class A(x,) {class B(y,) {}}; (new A)(1,) {fun getB = (new B)(2,) {fun getB = (new B)(3,)}}} +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2([par$A$1, y,]) {} @@ -265,9 +256,8 @@ new B{ fun getA = funcB } //│ |#class| |A| |{|→|#fun| |getA| |#=| |0|↵|#fun| |funcA| |#=| |10|←|↵|}|↵|#class| |B|#:| |A|{|→|#fun| |getA| |#=| |1|↵|#fun| |funcB| |#=| |11|←|↵|}|↵|#new| |A|↵|#new| |B|↵|#fun| |f|(|x|)| |#=| |#if| |x| |is| |A| |#then| |0| |#else| |1|↵|f|(|#new| |A|{|→|#fun| |getA| |#=| |2|←|↵|}|)|↵|#new| |B|{|→|#fun| |getA| |#=| |funcB|←|↵|}| -//│ Parsed: {class A {fun getA = 0; fun funcA = 10}; class B: A {fun getA = 1; fun funcB = 11}; new A; new B; fun f = (x,) => if (is(x, A,)) then 0 else 1; f(new A { ‹fun getA = 2› },); new B { ‹fun getA = funcB› }} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, getA, None, [], IntLit(0)), NuFunDef(None, funcA, None, [], IntLit(10)))), NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, getA, None, [], IntLit(1)), NuFunDef(None, funcB, None, [], IntLit(11)))), NuNew(Var(A)), NuNew(Var(B)), NuFunDef(None, f, None, [], Lam(Tup(_: Var(x)), If(IfThen(App(Var(is), Tup(_: Var(x), _: Var(A))), IntLit(0), Some(IntLit(1))))), App(Var(f), Tup(_: Rft(NuNew(Var(A)), ...))), Rft(NuNew(Var(B)), ...)) +//│ Parsed: {class A {fun getA = 0; fun funcA = 10}; class B: A {fun getA = 1; fun funcB = 11}; new A; new B; fun f = (x,) => if (is(x, A,)) then 0 else 1; f(new A {fun getA = 2},); new B {fun getA = funcB}} +//│ //│ Lifted: //│ TypingUnit { //│ class A$1([]) {fun getA = () => 0; fun funcA = () => 10} @@ -305,8 +295,7 @@ class A{ } //│ |#class| |A|{|→|#class| |B|{|→|#fun| |funB| |#=| |1|↵|#fun| |foo| |#=| |100|←|↵|}|↵|#class| |C|#:| |B|{|→|#fun| |funC| |#=| |2|↵|#fun| |foo| |#=| |1000|←|↵|}|↵|#class| |D|{|→|#fun| |funD| |#=| |3|↵|#fun| |foo| |#=| |10000| |↵|#class| |E|#:| |C|{|→|#fun| |funE| |#=| |4|↵|#fun| |foo| |#=| |100000|←|↵|}|↵|#class| |F|#:| |E|{|→|#fun| |funF| |#=| |5|↵|#fun| |foo| |#=| |1000000|←|↵|}|←|↵|}|←|↵|}| //│ Parsed: {class A {class B {fun funB = 1; fun foo = 100}; class C: B {fun funC = 2; fun foo = 1000}; class D {fun funD = 3; fun foo = 10000; class E: C {fun funE = 4; fun foo = 100000}; class F: E {fun funF = 5; fun foo = 1000000}}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funB, None, [], IntLit(1)), NuFunDef(None, foo, None, [], IntLit(100)))), NuTypeDef(class, C, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funC, None, [], IntLit(2)), NuFunDef(None, foo, None, [], IntLit(1000)))), NuTypeDef(class, D, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funD, None, [], IntLit(3)), NuFunDef(None, foo, None, [], IntLit(10000)), NuTypeDef(class, E, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funE, None, [], IntLit(4)), NuFunDef(None, foo, None, [], IntLit(100000)))), NuTypeDef(class, F, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funF, None, [], IntLit(5)), NuFunDef(None, foo, None, [], IntLit(1000000))))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2([par$A$1,]) {fun funB = () => 1; fun foo = () => 100} @@ -347,9 +336,8 @@ class A{ } } //│ |#class| |A|{|→|#class| |B|{|→|#fun| |funB| |#=| |1|↵|#fun| |foo| |#=| |100|←|↵|}|↵|#class| |C|#:| |B|{|→|#fun| |funC| |#=| |2|↵|#fun| |foo| |#=| |1000|↵|#fun| |getB| |#=| |#new| |B|←|↵|}|↵|#class| |D|{|→|#fun| |funD| |#=| |3|↵|#fun| |foo| |#=| |10000| |↵|#class| |E|#:| |C|{|→|#fun| |funE| |#=| |4|↵|#fun| |foo| |#=| |100000|↵|#fun| |getD| |#=| |#new| |D|←|↵|}|↵|#class| |F|#:| |E|{|→|#fun| |funF| |#=| |5|↵|#fun| |foo| |#=| |1000000|↵|#fun| |getE| |#=| |#new| |E|{|→|#fun| |foo| |#=| |0|←|↵|}|←|↵|}|←|↵|}|←|↵|}| -//│ Parsed: {class A {class B {fun funB = 1; fun foo = 100}; class C: B {fun funC = 2; fun foo = 1000; fun getB = new B}; class D {fun funD = 3; fun foo = 10000; class E: C {fun funE = 4; fun foo = 100000; fun getD = new D}; class F: E {fun funF = 5; fun foo = 1000000; fun getE = new E { ‹fun foo = 0› }}}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funB, None, [], IntLit(1)), NuFunDef(None, foo, None, [], IntLit(100)))), NuTypeDef(class, C, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funC, None, [], IntLit(2)), NuFunDef(None, foo, None, [], IntLit(1000)), NuFunDef(None, getB, None, [], NuNew(Var(B))))), NuTypeDef(class, D, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funD, None, [], IntLit(3)), NuFunDef(None, foo, None, [], IntLit(10000)), NuTypeDef(class, E, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funE, None, [], IntLit(4)), NuFunDef(None, foo, None, [], IntLit(100000)), NuFunDef(None, getD, None, [], NuNew(Var(D))))), NuTypeDef(class, F, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, funF, None, [], IntLit(5)), NuFunDef(None, foo, None, [], IntLit(1000000)), NuFunDef(None, getE, None, [], Rft(NuNew(Var(E)), ...))))))))) +//│ Parsed: {class A {class B {fun funB = 1; fun foo = 100}; class C: B {fun funC = 2; fun foo = 1000; fun getB = new B}; class D {fun funD = 3; fun foo = 10000; class E: C {fun funE = 4; fun foo = 100000; fun getD = new D}; class F: E {fun funF = 5; fun foo = 1000000; fun getE = new E {fun foo = 0}}}}} +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2([par$A$1,]) {fun funB = () => 1; fun foo = () => 100} @@ -383,8 +371,7 @@ class A{ new A //│ |#class| |A|{|→|#class| |B|{|→|#fun| |foo| |#=| |1|←|↵|}|↵|#fun| |bar| |#=| |#new| |B|←|↵|}|↵|#new| |A| //│ Parsed: {class A {class B {fun foo = 1}; fun bar = new B}; new A} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], IntLit(1)))), NuFunDef(None, bar, None, [], NuNew(Var(B))))), NuNew(Var(A))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2([par$A$1,]) {fun foo = () => 1} @@ -407,9 +394,8 @@ let x = new A{ } } //│ |#class| |A|(|x|)| |{|→|#fun| |foo| |#=| |0|↵|#fun| |bar| |#=| |x|←|↵|}|↵|#let| |x| |#=| |#new| |A|{|→|#fun| |foo| |#=| |1|↵|#fun| |newFun| |#=| |2|↵|#fun| |bar| |#=| |#new| |A|(|foo|)|{|→|#fun| |foo| |#=| |bar| |+| |1|↵|#fun| |bar2| |#=| |newFun| |+| |1|←|↵|}|←|↵|}| -//│ Parsed: {class A(x,) {fun foo = 0; fun bar = x}; let x = new A { ‹fun foo = 1; fun newFun = 2; fun bar = (new A)(foo,) { ‹fun foo = +(bar, 1,); fun bar2 = +(newFun, 1,)› }› }} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(_: Var(x)), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], IntLit(0)), NuFunDef(None, bar, None, [], Var(x)))), NuFunDef(Some(false), x, None, [], Rft(NuNew(Var(A)), ...))) +//│ Parsed: {class A(x,) {fun foo = 0; fun bar = x}; let x = new A {fun foo = 1; fun newFun = 2; fun bar = (new A)(foo,) {fun foo = +(bar, 1,); fun bar2 = +(newFun, 1,)}}} +//│ //│ Lifted: //│ TypingUnit { //│ class A$1([x,]) {fun foo = () => 0; fun bar = () => (this).x} @@ -435,9 +421,8 @@ new A{ } } //│ |#class| |A| |{||}|↵|#new| |A|{|→|#fun| |foo| |#=| |1|↵|#fun| |bar| |#=| |#new| |A|{|→|#fun| |foo1| |#=| |foo|↵|#fun| |bar1| |#=| |#new| |A|{|→|#fun| |foo2| |#=| |foo|↵|#fun| |bar2| |#=| |#new| |A|{|→|#fun| |foo3| |#=| |foo|↵|#fun| |bar3| |#=| |#new| |A|{|→|#fun| |foo4| |#=| |foo|↵|#fun| |bar4| |#=| |0|←|↵|}|←|↵|}|←|↵|}|←|↵|}|←|↵|}| -//│ Parsed: {class A {}; new A { ‹fun foo = 1; fun bar = new A { ‹fun foo1 = foo; fun bar1 = new A { ‹fun foo2 = foo; fun bar2 = new A { ‹fun foo3 = foo; fun bar3 = new A { ‹fun foo4 = foo; fun bar4 = 0› }› }› }› }› }} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit()), Rft(NuNew(Var(A)), ...)) +//│ Parsed: {class A {}; new A {fun foo = 1; fun bar = new A {fun foo1 = foo; fun bar1 = new A {fun foo2 = foo; fun bar2 = new A {fun foo3 = foo; fun bar3 = new A {fun foo4 = foo; fun bar4 = 0}}}}}} +//│ //│ Lifted: //│ TypingUnit {class A$1([]) {}; Code(List(new A$1([]) {}))} //│ diff --git a/compiler/shared/test/diff/LifterBlks.mls b/compiler/shared/test/diff/LifterBlks.mls index 414d4109b..61ac5eedf 100644 --- a/compiler/shared/test/diff/LifterBlks.mls +++ b/compiler/shared/test/diff/LifterBlks.mls @@ -6,8 +6,7 @@ fun foo = print("ko") //│ |#fun| |foo| |#=|→|print|(|"ok"|)|↵|print|(|"ko"|)|←| //│ Parsed: {fun foo = {print("ok",); print("ko",)}} -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Blk(...))) +//│ //│ Lifted: //│ TypingUnit {fun foo$1 = () => {print("ok",); print("ko",)}} //│ @@ -18,8 +17,7 @@ class A{ } //│ |#class| |A|{|→|#class| |B| |{||}|↵|#fun| |foo|(|x|#:| |B|)| |#=| |(|x| |#:| |B|)|←|↵|}| //│ Parsed: {class A {class B {}; fun foo = (x: B,) => '(' x : B ')'}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit()), NuFunDef(None, foo, None, [], Lam(Tup(x: Var(B)), Bra(rcd = false, Asc(Var(x), TypeName(B)))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2([par$A$1,]) {} @@ -40,8 +38,7 @@ fun foo = fun tmp = 2 //│ |#fun| |foo| |#=|→|#let| |local|(|x|)| |#=|→|#class| |Foo| |{|→|#fun| |bar| |#=| |x| |+| |1|←|↵|}|↵|Foo|(||)|.bar|←|↵|print| |#of| |local|(|0|)| |+| |local|(|1|)|↵|print| |#of| |(|local| |#of| |0|)| |+| |local| |#of| |1|↵|#fun| |tmp| |#=| |1|↵|print| |#of| |local| |#of| |0| |+| |local| |#of| |1|↵|#fun| |tmp| |#=| |2|←| //│ Parsed: {fun foo = {let local = (x,) => {class Foo {fun bar = +(x, 1,)}; (Foo()).bar}; print(+(local(0,), local(1,),),); print(+('(' local(0,) ')', local(1,),),); fun tmp = 1; print(local(+(0, local(1,),),),); fun tmp = 2}} -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Blk(...))) +//│ //│ Lifted: //│ TypingUnit { //│ class Foo$1([x,]) {fun bar = () => +((this).x, 1,)} @@ -55,9 +52,8 @@ class A(y){} let f = x => new A(0){fun bar = x+y} f(0) //│ |#class| |A|(|y|)|{||}|↵|#let| |f| |#=| |x| |#=>| |#new| |A|(|0|)|{|#fun| |bar| |#=| |x|+|y|}|↵|f|(|0|)| -//│ Parsed: {class A(y,) {}; let f = (x,) => (new A)(0,) { ‹fun bar = +(x, y,)› }; f(0,)} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(_: Var(y)), (), None, None, TypingUnit()), NuFunDef(Some(false), f, None, [], Lam(Tup(_: Var(x)), Rft(App(NuNew(Var(A)), Tup(_: IntLit(0))), ...))), App(Var(f), Tup(_: IntLit(0)))) +//│ Parsed: {class A(y,) {}; let f = (x,) => (new A)(0,) {fun bar = +(x, y,)}; f(0,)} +//│ //│ Lifted: //│ TypingUnit { //│ class A$1([y,]) {} @@ -78,9 +74,8 @@ class A(x){ } } //│ |#class| |A|(|x|)|{|→|#fun| |w| |#=| |x|↵|#fun| |foo|(|y|)| |#=| |→|#class| |B|(|z|)|{|→|#fun| |bar| |#=| |x|+|y|+|z|←|↵|}|↵|#new| |B|(|0|)|{|→|#fun| |bar| |#=| |w|+|y|+|z|←|↵|}|←|←|↵|}| -//│ Parsed: {class A(x,) {fun w = x; fun foo = (y,) => {class B(z,) {fun bar = +(+(x, y,), z,)}; (new B)(0,) { ‹fun bar = +(+(w, y,), z,)› }}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(_: Var(x)), (), None, None, TypingUnit(NuFunDef(None, w, None, [], Var(x)), NuFunDef(None, foo, None, [], Lam(Tup(_: Var(y)), Blk(...)))))) +//│ Parsed: {class A(x,) {fun w = x; fun foo = (y,) => {class B(z,) {fun bar = +(+(x, y,), z,)}; (new B)(0,) {fun bar = +(+(w, y,), z,)}}}} +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2([par$A$1, z, y,]) { @@ -110,8 +105,7 @@ fun f(x,y,z) = } //│ |#fun| |f|(|x|,|y|,|z|)| |#=| |→|#class| |A|{|→|#fun| |foo| |#=| |#new| |B|↵|#fun| |bar1| |#=| |x|←|↵|}|↵|#class| |B|{|→|#fun| |foo| |#=| |#new| |A|↵|#fun| |bar2| |#=| |y|←|↵|}|↵|#class| |C| |#extends| |A|,| |B| |{|→|#fun| |bar| |#=| |bar1| |+| |bar2|←|↵|}|←| //│ Parsed: {fun f = (x, y, z,) => {class A {fun foo = new B; fun bar1 = x}; class B {fun foo = new A; fun bar2 = y}; class C: A, B {fun bar = +(bar1, bar2,)}}} -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(x), _: Var(y), _: Var(z)), Blk(...)))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1([x, y,]) { @@ -141,8 +135,7 @@ fun f(x,y,z) = } //│ |#fun| |f|(|x|,|y|,|z|)| |#=| |→|#class| |C|{|→|#class| |A|{|→|#fun| |foo| |#=| |#new| |B|↵|#fun| |bar1| |#=| |x|←|↵|}|↵|#class| |B|{|→|#fun| |foo| |#=| |#new| |A|↵|#fun| |bar2| |#=| |y|←|↵|}|↵|#fun| |boo| |#=| |(|#new| |A|)|.bar1| |+| |B|(||)|.bar2| |+| |z|←|↵|}|←| //│ Parsed: {fun f = (x, y, z,) => {class C {class A {fun foo = new B; fun bar1 = x}; class B {fun foo = new A; fun bar2 = y}; fun boo = +(+(('(' new A ')').bar1, (B()).bar2,), z,)}}} -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(x), _: Var(y), _: Var(z)), Blk(...)))) +//│ //│ Lifted: //│ TypingUnit { //│ class C$1_A$2([par$C$1,]) { @@ -167,8 +160,7 @@ fun f(y) = } //│ |#fun| |f|(|y|)| |#=|→|#let| |g|(|x|)| |#=| |x| |+| |y| |+| |1|↵|#class| |Foo|(|x|)| |{|→|#fun| |h| |#=| |g|(|x|)|←|↵|}|←| //│ Parsed: {fun f = (y,) => {let g = (x,) => +(+(x, y,), 1,); class Foo(x,) {fun h = g(x,)}}} -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(y)), Blk(...)))) +//│ //│ Lifted: //│ TypingUnit { //│ class Foo$1([x, y,]) {fun h = () => g$2((this).x, y,)} @@ -179,16 +171,14 @@ fun f(y) = Foo(1).h //│ | |Foo|(|1|)|.h| //│ Parsed: {(Foo(1,)).h} -//│ Parsed: -//│ TypingUnit(Sel(App(Var(Foo), Tup(_: IntLit(1))), h)) +//│ //│ Lifted: //│ TypingUnit {Code(List((Foo(1,)).h))} //│ Foo(x).h //│ | |Foo|(|x|)|.h| //│ Parsed: {(Foo(x,)).h} -//│ Parsed: -//│ TypingUnit(Sel(App(Var(Foo), Tup(_: Var(x))), h)) +//│ //│ Lifted: //│ TypingUnit {Code(List((Foo(x,)).h))} //│ @@ -203,8 +193,7 @@ fun f(x) = Foo(x, x).bar //│ |#fun| |f|(|x|)| |#=|→|#let| |g|(|x|)| |#=| |→|#let| |h|(|x|)| |#=| |x| |+| |2|↵|Foo|(|h|(|x|)|,| |x|)|.bar|←|↵|#class| |Foo|(|x|,| |y|)| |{|→|#fun| |bar| |#=| |g|(|x|)|+|y|←|↵|}|↵|Foo|(|x|,| |x|)|.bar|←| //│ Parsed: {fun f = (x,) => {let g = (x,) => {let h = (x,) => +(x, 2,); (Foo(h(x,), x,)).bar}; class Foo(x, y,) {fun bar = +(g(x,), y,)}; (Foo(x, x,)).bar}} -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(x)), Blk(...)))) +//│ //│ Lifted: //│ TypingUnit { //│ class Foo$1([x, y,]) {fun bar = () => +(g$2((this).x,), (this).y,)} @@ -217,8 +206,7 @@ fun f(x) = class Foo(x, y) extends Bar(y, x), Baz(x + y) //│ |#class| |Foo|(|x|,| |y|)| |#extends| |Bar|(|y|,| |x|)|,| |Baz|(|x| |+| |y|)| //│ Parsed: {class Foo(x, y,): Bar(y, x,), Baz(+(x, y,),) {}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Foo, (), Tup(_: Var(x), _: Var(y)), (App(Var(Bar), Tup(_: Var(y), _: Var(x))), App(Var(Baz), Tup(_: App(Var(+), Tup(_: Var(x), _: Var(y)))))), None, None, TypingUnit())) +//│ //│ Lifted: //│ TypingUnit { //│ class Foo$1([x, y,]): Bar((this).y, (this).x,), Baz(+((this).x, (this).y,),) {} @@ -232,8 +220,7 @@ fun foo(x: T): string = "rua" //│ |#fun| |foo|‹|T|,| |U|›|(|x|#:| |T|)|#:| |string| |#=| |→|#class| |A|(|y|)| |#extends| |B|‹|T|›|,| |C|(|y|#:| |U|)| |{|→|#fun| |bar| |#=| |this|←|↵|}|↵|"rua"|←| //│ Parsed: {fun foo = (x: T,) => {class A(y,): B‹T›, C(y: U,) {fun bar = this}; "rua"} : string} -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [TypeName(T), TypeName(U)], Lam(Tup(x: Var(T)), Asc(Blk(...), TypeName(string))))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1[T,U]([y,]): B‹T›, C(y: U,) {fun bar = () => this} @@ -249,8 +236,7 @@ class A{ } //│ |#class| |A|‹|T|›|{|→|#class| |B|{|→|#fun| |f| |#=| |x| |#=>| |y| |#=>| |x|↵|#fun| |g|#:| |T| |#=>| |B| |#=>| |T|←|↵|}|←|↵|}| //│ Parsed: {class A‹T› {class B {fun f = (x,) => (y,) => x; fun g: T -> B -> T}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, ((None,TypeName(T))), Tup(), (), None, None, TypingUnit(NuTypeDef(class, B, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(x)), Lam(Tup(_: Var(y)), Var(x)))), NuFunDef(None, g, None, [], PolyType(List(),Function(Tuple(List((None,Field(None,TypeName(T))))),Function(Tuple(List((None,Field(None,TypeName(B))))),TypeName(T)))))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1_B$2_Lambda1$1$3([par$A$1_B$2, x,]) {fun apply = (y,) => (this).x} @@ -269,8 +255,7 @@ class Foo{ } //│ |#class| |Foo|‹|T|›|{|→|#class| |RectangleBox|#:| |Box|‹|T|›| |&| |{| |breadth|#:| |T| |}|↵|#class| |StackedRectangleBoxes|‹|N|›| |#:| |RectangleBox|‹|T|›| |&| |{| |size|#:| |N| |}|↵|#class| |Bar|#:| |{|any|#:| |RectangleBox| |#=>| |StackedRectangleBoxes|}|←|↵|}| //│ Parsed: {class Foo‹T› {class RectangleBox: Box[T] & {breadth: T} {}; class StackedRectangleBoxes‹N›: RectangleBox[T] & {size: N} {}; class Bar: {any: RectangleBox -> StackedRectangleBoxes} {}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Foo, ((None,TypeName(T))), Tup(), (), None, None, TypingUnit(NuTypeDef(class, RectangleBox, (), Tup(), (), None, None, TypingUnit()), NuTypeDef(class, StackedRectangleBoxes, ((None,TypeName(N))), Tup(), (), None, None, TypingUnit()), NuTypeDef(class, Bar, (), Tup(), (), None, None, TypingUnit())))) +//│ //│ Lifted: //│ TypingUnit { //│ class Foo$1_RectangleBox$2([par$Foo$1,]) {} @@ -291,9 +276,8 @@ fun ctx(a,b) = fun apply(x) = a+x }, b) //│ |#class| |Func|‹|T|,| |U|›| |{|→|#fun| |apply|#:| |T| |#=>| |U|←|↵|}|↵|#class| |Lambda|‹|T|,| |U|›| |#:| |Func|‹|T|,| |U|›| |{||}|↵|#fun| |ctx|(|a|,|b|)| |#=|→|#fun| |foo|(|f|#:| |Func|,| |x|)| |#=| |→|f|.apply|(|x|)|←|↵|foo|(|#new| |Lambda|{|→|#fun| |apply|(|x|)| |#=| |a|+|x|←|↵|}|,| |b|)|←| -//│ Parsed: {class Func‹T, U› {fun apply: T -> U}; class Lambda‹T, U›: Func[T, U] {}; fun ctx = (a, b,) => {fun foo = (f: Func, x,) => {(f).apply(x,)}; foo(new Lambda { ‹fun apply = (x,) => +(a, x,)› }, b,)}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Func, ((None,TypeName(T)), (None,TypeName(U))), Tup(), (), None, None, TypingUnit(NuFunDef(None, apply, None, [], PolyType(List(),Function(Tuple(List((None,Field(None,TypeName(T))))),TypeName(U)))))), NuTypeDef(class, Lambda, ((None,TypeName(T)), (None,TypeName(U))), Tup(), (), None, None, TypingUnit()), NuFunDef(None, ctx, None, [], Lam(Tup(_: Var(a), _: Var(b)), Blk(...)))) +//│ Parsed: {class Func‹T, U› {fun apply: T -> U}; class Lambda‹T, U›: Func[T, U] {}; fun ctx = (a, b,) => {fun foo = (f: Func, x,) => {(f).apply(x,)}; foo(new Lambda {fun apply = (x,) => +(a, x,)}, b,)}} +//│ //│ Lifted: //│ TypingUnit { //│ class Func$1[T,U]([]) {fun apply = T -> U} @@ -308,8 +292,7 @@ fun f(T) = f(MyClass) //│ |#fun| |f|(|T|)| |#=| |→|#new| |T|(||)|←|↵|f|(|MyClass|)| //│ Parsed: {fun f = (T,) => {(new T)()}; f(MyClass,)} -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(T)), Blk(...))), App(Var(f), Tup(_: Var(MyClass)))) +//│ //│ Lifted: //│ Lifting failed: mlscript.codegen.CodeGenError: Cannot find type T. Class values are not supported in lifter. //│ @@ -321,8 +304,7 @@ class A { } //│ |#class| |A| |{|→|#fun| |foo| |#=| |→|#fun| |bar| |#=| |foo|(||)|↵|bar|(||)|←|←|↵|}| //│ Parsed: {class A {fun foo = {fun bar = foo(); bar()}}} -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, A, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Blk(...))))) +//│ //│ Lifted: //│ TypingUnit { //│ class A$1([]) {fun foo = () => {bar$1(this,)}} diff --git a/compiler/shared/test/diff/mono.mls b/compiler/shared/test/diff/mono.mls index 780851b8a..a261d75d0 100644 --- a/compiler/shared/test/diff/mono.mls +++ b/compiler/shared/test/diff/mono.mls @@ -3,8 +3,7 @@ :mono fun f(x: Int) = if x then 42 else 1337 -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(x: Var(Int)), If(IfThen(Var(x), IntLit(42), Some(IntLit(1337)))))) +//│ //│ Lifted: //│ TypingUnit { //│ fun f$1 = (x: Int,) => if (x) then 42 else 1337 @@ -18,8 +17,7 @@ fun f(x: Int) = if x then 42 else 1337 :mono fun foo() = 42 -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(), IntLit(42)))) +//│ //│ Lifted: //│ TypingUnit {fun foo$1 = () => 42} //│ Mono: @@ -33,8 +31,7 @@ fun foo() = 42 fun foo(x, #b) = if b then x else 1337 let a = foo(42, true) let b = foo(23, false) -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(_: Var(x), _: Var(b)), If(IfThen(Var(b), Var(x), Some(IntLit(1337))))), NuFunDef(Some(false), a, None, [], App(Var(foo), Tup(_: IntLit(42), _: Var(true)))), NuFunDef(Some(false), b, None, [], App(Var(foo), Tup(_: IntLit(23), _: Var(false))))) +//│ //│ Lifted: //│ TypingUnit { //│ fun foo$3 = (x, #b,) => if (b) then x else 1337 @@ -60,8 +57,7 @@ let b = foo(23, false) :mono let x = 42 + 1337 -//│ Parsed: -//│ TypingUnit(NuFunDef(Some(false), x, None, [], App(Var(+), Tup(_: IntLit(42), _: IntLit(1337))))) +//│ //│ Lifted: //│ TypingUnit {let x$1 = () => +(42, 1337,)} //│ Mono: @@ -98,8 +94,7 @@ let x = 42 + 1337 :mono if true then 1 else 0 if 1+1 > 1 then 1 - 1 else 1*1 -//│ Parsed: -//│ TypingUnit(If(IfThen(Var(true), IntLit(1), Some(IntLit(0))), If(IfThen(App(Var(>), Tup(_: App(Var(+), Tup(_: IntLit(1), _: IntLit(1))), _: IntLit(1))), App(Var(-), Tup(_: IntLit(1), _: IntLit(1))), Some(App(Var(*), Tup(_: IntLit(1), _: IntLit(1)))))) +//│ //│ Lifted: //│ TypingUnit { //│ Code(List(if (true) then 1 else 0)) @@ -122,8 +117,7 @@ if 1+1 > 1 then 1 - 1 else 1*1 :mono if(b) then 1 else 2 -//│ Parsed: -//│ TypingUnit(If(IfThen(Bra(rcd = false, Var(b)), IntLit(1), Some(IntLit(2)))) +//│ //│ Lifted: //│ TypingUnit {Code(List(if ('(' b ')') then 1 else 2))} //│ Mono: @@ -138,8 +132,7 @@ if(b) then 1 else 2 :mono ((f, g) => f(g))(f => f, true) -//│ Parsed: -//│ TypingUnit(App(Bra(rcd = false, Lam(Tup(_: Var(f), _: Var(g)), App(Var(f), Tup(_: Var(g))))), Tup(_: Lam(Tup(_: Var(f)), Var(f)), _: Var(true)))) +//│ //│ Lifted: //│ TypingUnit { //│ class Lambda2$1$1([]) {fun apply = (f, g,) => f(g,)} @@ -167,8 +160,7 @@ if(b) then 1 else 2 :mono (b => if b then true else false) (true) -//│ Parsed: -//│ TypingUnit(App(Bra(rcd = false, Lam(Tup(_: Var(b)), If(IfThen(Var(b), Var(true), Some(Var(false))))), Tup(_: Var(true)))) +//│ //│ Lifted: //│ TypingUnit { //│ class Lambda1$1$1([]) {fun apply = (b,) => if (b) then true else false} @@ -192,8 +184,7 @@ if(b) then 1 else 2 fun f(x) = if(x > 0) then x+1 else x - 1 f(2)+3 -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(x)), Blk(...))), App(Var(+), Tup(_: App(Var(f), Tup(_: IntLit(2))), _: IntLit(3)))) +//│ //│ Lifted: //│ TypingUnit { //│ fun f$1 = (x,) => {if ('(' >(x, 0,) ')') then +(x, 1,) else -(x, 1,)} @@ -216,8 +207,7 @@ f(2)+3 fun fac(n) = if (n > 1) then fac(n - 1) * n else 1 fac(2) -//│ Parsed: -//│ TypingUnit(NuFunDef(None, fac, None, [], Lam(Tup(_: Var(n)), Blk(...))), App(Var(fac), Tup(_: IntLit(2)))) +//│ //│ Lifted: //│ TypingUnit { //│ fun fac$1 = (n,) => {if ('(' >(n, 1,) ')') then *(fac$1(-(n, 1,),), n,) else 1} @@ -245,8 +235,7 @@ fun count(lst) = if l is undefined then 1 else count(l)+1 else 0 count(new List(new List(new Nil(undefined, false), true), true)) -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, List, (), Tup(l: App(Var(|), Tup(_: App(Var(|), Tup(_: Var(List), _: Var(Nil))), _: UnitLit(true))), hasTail: Var(Bool)), (), None, None, TypingUnit()), NuTypeDef(class, Nil, (), Tup(l: App(Var(|), Tup(_: App(Var(|), Tup(_: Var(List), _: Var(Nil))), _: UnitLit(true))), hasTail: Var(Bool)), (), None, None, TypingUnit()), NuFunDef(None, count, None, [], Lam(Tup(_: Var(lst)), Blk(...))), App(Var(count), Tup(_: App(NuNew(Var(List)), Tup(_: App(NuNew(Var(List)), Tup(_: App(NuNew(Var(Nil)), Tup(_: UnitLit(true), _: Var(false))), _: Var(true))), _: Var(true)))))) +//│ //│ Lifted: //│ TypingUnit { //│ class List$1([val l: |(|(List, Nil,), undefined,), val hasTail: Bool,]) {} @@ -302,8 +291,7 @@ class Nil() { } fun add2(x) = x+2 (new List(1, new List(2, new Nil()))).map(x => x+1).map(x => add2(x)) -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, List, (), Tup(e: Var(Int), tail: App(Var(|), Tup(_: Var(List), _: Var(Nil)))), (), None, None, TypingUnit(NuFunDef(None, map, None, [], PolyType(List(),Function(Tuple(List((None,Field(None,Function(Tuple(List((None,Field(None,TypeName(Int))))),TypeName(Int)))))),TypeName(List)))), NuFunDef(None, map, None, [], Lam(Tup(_: Var(f)), App(NuNew(Var(List)), Tup(_: App(Var(f), Tup(_: Var(e))), _: App(Sel(Var(tail), map), Tup(_: Var(f))))))), NuFunDef(None, count, None, [], PolyType(List(),Function(Tuple(List()),TypeName(Int)))), NuFunDef(None, count, None, [], Lam(Tup(), App(Var(+), Tup(_: IntLit(1), _: App(Sel(Var(tail), count), Tup()))))))), NuTypeDef(class, Nil, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, map, None, [], Lam(Tup(_: Var(f)), Var(this))), NuFunDef(None, count, None, [], Lam(Tup(), IntLit(0))))), NuFunDef(None, add2, None, [], Lam(Tup(_: Var(x)), App(Var(+), Tup(_: Var(x), _: IntLit(2))))), App(Sel(App(Sel(Bra(rcd = false, App(NuNew(Var(List)), Tup(_: IntLit(1), _: App(NuNew(Var(List)), Tup(_: IntLit(2), _: App(NuNew(Var(Nil)), Tup())))))), map), Tup(_: Lam(Tup(_: Var(x)), App(Var(+), Tup(_: Var(x), _: IntLit(1)))))), map), Tup(_: Lam(Tup(_: Var(x)), App(Var(add2), Tup(_: Var(x))))))) +//│ //│ Lifted: //│ TypingUnit { //│ class List$1([e: Int, tail: |(List, Nil,),]) { @@ -369,8 +357,7 @@ fun generate(x) = if x > 0 then new List(x, generate(x+1)) else new Nil() foo(new List(1, new List(2, new Nil()))) foo(generate(1)) -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, List, (), Tup(e: Var(Int), tail: App(Var(|), Tup(_: Var(List), _: Var(Nil)))), (), None, None, TypingUnit(NuFunDef(None, count, None, [], PolyType(List(),Function(Tuple(List()),TypeName(Int)))), NuFunDef(None, count, None, [], Lam(Tup(), App(Var(+), Tup(_: IntLit(1), _: App(Sel(Var(tail), count), Tup()))))))), NuTypeDef(class, Nil, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, count, None, [], Lam(Tup(), IntLit(0))))), NuFunDef(None, foo, None, [], Lam(Tup(_: Var(x)), App(Sel(Var(x), count), Tup()))), NuFunDef(None, generate, None, [], Lam(Tup(_: Var(x)), Blk(...))), App(Var(foo), Tup(_: App(NuNew(Var(List)), Tup(_: IntLit(1), _: App(NuNew(Var(List)), Tup(_: IntLit(2), _: App(NuNew(Var(Nil)), Tup()))))))), App(Var(foo), Tup(_: App(Var(generate), Tup(_: IntLit(1)))))) +//│ //│ Lifted: //│ TypingUnit { //│ class List$1([e: Int, tail: |(List, Nil,),]) { @@ -423,8 +410,7 @@ foo(generate(1)) fun foo(x) = (f => f(x))(z => z+1) foo(2) -//│ Parsed: -//│ TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(_: Var(x)), Blk(...))), App(Var(foo), Tup(_: IntLit(2)))) +//│ //│ Lifted: //│ TypingUnit { //│ class Lambda1$2$1([x,]) {fun apply = (f,) => f((this).x,)} @@ -457,8 +443,7 @@ foo(2) fun f(x) = (y => f(x+y))(x+1) f(1) -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(x)), Blk(...))), App(Var(f), Tup(_: IntLit(1)))) +//│ //│ Lifted: //│ TypingUnit { //│ class Lambda1$2$1([x,]) {fun apply = (y,) => f$1(+((this).x, y,),)} @@ -488,8 +473,7 @@ f(1) fun f(x) = f(x) f(0) f(1) -//│ Parsed: -//│ TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(x)), App(Var(f), Tup(_: Var(x))))), App(Var(f), Tup(_: IntLit(0))), App(Var(f), Tup(_: IntLit(1)))) +//│ //│ Lifted: //│ TypingUnit { //│ fun f$1 = (x,) => f$1(x,) @@ -536,8 +520,7 @@ fun foo(x) = x.apply(new Cons(1, new Nil())) + x.apply(new Nil()) foo(new Lambda()) foo(new Lambda2(2)) -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Cons, (), Tup(e: Var('A), tail: App(Var(|), Tup(_: Var(Cons), _: Var(Nil)))), (), None, None, TypingUnit(NuFunDef(None, count, None, [], PolyType(List(),Function(Tuple(List()),TypeName(Int)))), NuFunDef(None, count, None, [], Lam(Tup(), App(Var(+), Tup(_: IntLit(1), _: App(Sel(Var(tail), count), Tup()))))))), NuTypeDef(class, Nil, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, count, None, [], Lam(Tup(), IntLit(0))))), NuTypeDef(class, Lambda, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, apply, None, [], Lam(Tup(_: Var(l)), Blk(...))))), NuTypeDef(class, Lambda2, (), Tup(a: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, apply, None, [], Lam(Tup(_: Var(l)), Blk(...))))), NuFunDef(None, foo, None, [], Lam(Tup(_: Var(x)), Blk(...))), App(Var(foo), Tup(_: App(NuNew(Var(Lambda)), Tup()))), App(Var(foo), Tup(_: App(NuNew(Var(Lambda2)), Tup(_: IntLit(2)))))) +//│ //│ Lifted: //│ TypingUnit { //│ class Cons$1([e: 'A, tail: |(Cons, Nil,),]) { @@ -611,8 +594,7 @@ fun foo(x) = x(new Cons(1, new Nil())) + x(new Nil()) foo(l => l.count()) foo(l => (new Cons(2, l)).count()) -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Cons, (), Tup(e: Var(Int), tail: App(Var(|), Tup(_: Var(Cons), _: Var(Nil)))), (), None, None, TypingUnit(NuFunDef(None, count, None, [], PolyType(List(),Function(Tuple(List()),TypeName(Int)))), NuFunDef(None, count, None, [], Lam(Tup(), App(Var(+), Tup(_: IntLit(1), _: App(Sel(Var(tail), count), Tup()))))))), NuTypeDef(class, Nil, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, count, None, [], Lam(Tup(), IntLit(0))))), NuFunDef(None, foo, None, [], Lam(Tup(_: Var(x)), Blk(...))), App(Var(foo), Tup(_: Lam(Tup(_: Var(l)), App(Sel(Var(l), count), Tup())))), App(Var(foo), Tup(_: Lam(Tup(_: Var(l)), App(Sel(Bra(rcd = false, App(NuNew(Var(Cons)), Tup(_: IntLit(2), _: Var(l)))), count), Tup()))))) +//│ //│ Lifted: //│ TypingUnit { //│ class Cons$1([e: Int, tail: |(Cons, Nil,),]) { @@ -706,8 +688,7 @@ class C(e1: Exp, e2: Exp) extends Exp { e1.isEmpty() && e2.isEmpty() } (new C(new Ch(1), new A(new Ch(2), new Ch(3)))).derive(0).isEmpty() -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Exp, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, derive, None, [], PolyType(List(),Function(Tuple(List((Some(x),Field(None,TypeName(Int))))),TypeName(Exp)))), NuFunDef(None, derive, None, [], Lam(Tup(x: Var(Int)), App(Var(Exp), Tup()))), NuFunDef(None, isEmpty, None, [], PolyType(List(),Function(Tuple(List()),TypeName(Bool)))), NuFunDef(None, isEmpty, None, [], Lam(Tup(), Var(false))))), NuTypeDef(class, E, (), Tup(), (Var(Exp)), None, None, TypingUnit(NuFunDef(None, derive, None, [], Lam(Tup(_: Var(x)), Blk(...))), NuFunDef(None, isEmpty, None, [], Lam(Tup(), Blk(...))))), NuTypeDef(class, Ep, (), Tup(), (Var(Exp)), None, None, TypingUnit(NuFunDef(None, derive, None, [], Lam(Tup(_: Var(x)), Blk(...))), NuFunDef(None, isEmpty, None, [], Lam(Tup(), Blk(...))))), NuTypeDef(class, Ch, (), Tup(i: Var(Int)), (Var(Exp)), None, None, TypingUnit(NuFunDef(None, derive, None, [], Lam(Tup(_: Var(x)), Blk(...))), NuFunDef(None, isEmpty, None, [], Lam(Tup(), Blk(...))))), NuTypeDef(class, A, (), Tup(e1: Var(Exp), e2: Var(Exp)), (Var(Exp)), None, None, TypingUnit(NuFunDef(None, derive, None, [], Lam(Tup(_: Var(x)), Blk(...))), NuFunDef(None, isEmpty, None, [], Lam(Tup(), Blk(...))))), NuTypeDef(class, C, (), Tup(e1: Var(Exp), e2: Var(Exp)), (Var(Exp)), None, None, TypingUnit(NuFunDef(None, derive, None, [], Lam(Tup(_: Var(x)), Blk(...))), NuFunDef(None, isEmpty, None, [], Lam(Tup(), Blk(...))))), App(Sel(App(Sel(Bra(rcd = false, App(NuNew(Var(C)), Tup(_: App(NuNew(Var(Ch)), Tup(_: IntLit(1))), _: App(NuNew(Var(A)), Tup(_: App(NuNew(Var(Ch)), Tup(_: IntLit(2))), _: App(NuNew(Var(Ch)), Tup(_: IntLit(3)))))))), derive), Tup(_: IntLit(0))), isEmpty), Tup())) +//│ //│ Lifted: //│ TypingUnit { //│ class Exp$1([]) { @@ -808,8 +789,7 @@ class Nil(hasTail: Bool) {} fun gen() = if anyUnknown then new List(gen(), true) else new Nil(false) gen() -//│ Parsed: -//│ TypingUnit(NuFunDef(Some(false), anyUnknown, None, [], Var(false)), NuTypeDef(class, List, (), Tup(l: App(Var(|), Tup(_: Var(List), _: Var(Nil))), hasTail: Var(Bool)), (), None, None, TypingUnit()), NuTypeDef(class, Nil, (), Tup(hasTail: Var(Bool)), (), None, None, TypingUnit()), NuFunDef(None, gen, None, [], Lam(Tup(), Blk(...))), App(Var(gen), Tup())) +//│ //│ Lifted: //│ TypingUnit { //│ class List$1([l: |(List, Nil,), hasTail: Bool,]) {} @@ -850,8 +830,7 @@ class Foo(x: Int){ fun boo(z) = bar(z)+x } (new Foo(1)).boo(2) -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Foo, (), Tup(x: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, bar, None, [], Lam(Tup(_: Var(y)), App(Var(+), Tup(_: Var(x), _: Var(y))))), NuFunDef(None, boo, None, [], Lam(Tup(_: Var(z)), App(Var(+), Tup(_: App(Var(bar), Tup(_: Var(z))), _: Var(x))))))), App(Sel(Bra(rcd = false, App(NuNew(Var(Foo)), Tup(_: IntLit(1)))), boo), Tup(_: IntLit(2)))) +//│ //│ Lifted: //│ TypingUnit { //│ class Foo$1([x: Int,]) { @@ -887,8 +866,7 @@ class OneInt(a: Int){ if(a > 0) then (new OneInt(a - 1)).fac() else 1 } (new OneInt(10)).fac() -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, OneInt, (), Tup(a: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, fac, None, [], PolyType(List(),Function(Tuple(List()),TypeName(Int)))), NuFunDef(None, fac, None, [], Lam(Tup(), Blk(...))))), App(Sel(Bra(rcd = false, App(NuNew(Var(OneInt)), Tup(_: IntLit(10)))), fac), Tup())) +//│ //│ Lifted: //│ TypingUnit { //│ class OneInt$1([a: Int,]) { @@ -937,8 +915,7 @@ fun g(x) = if x > any then g(x - 1) else f(x - 2) g(1) -//│ Parsed: -//│ TypingUnit(NuFunDef(Some(false), any, None, [], IntLit(-20)), NuFunDef(None, f, None, [], Lam(Tup(_: Var(x)), Blk(...))), NuFunDef(None, g, None, [], Lam(Tup(_: Var(x)), Blk(...))), App(Var(g), Tup(_: IntLit(1)))) +//│ //│ Lifted: //│ TypingUnit { //│ let any$3 = () => -20 @@ -976,8 +953,7 @@ class OneBool(b: Bool){ fun get = () -> b } (if b then new OneInt(1) else new OneBool(true)).get() -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, OneInt, (), Tup(a: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, get, None, [], Lam(Tup(), Var(a))))), NuTypeDef(class, OneBool, (), Tup(b: Var(Bool)), (), None, None, TypingUnit(NuFunDef(None, get, None, [], Lam(Tup(), Var(b))))), App(Sel(Bra(rcd = false, If(IfThen(Var(b), App(NuNew(Var(OneInt)), Tup(_: IntLit(1))), Some(App(NuNew(Var(OneBool)), Tup(_: Var(true)))))), get), Tup())) +//│ //│ Lifted: //│ TypingUnit { //│ class OneInt$1([a: Int,]) {fun get = () => (this).a} @@ -1022,8 +998,7 @@ let bar = Bar(42) baz(bar) (new Car()).da(Bar(1337)) bar.car -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Bar, (), Tup(x: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(_: Var(x)), Var(x))), NuFunDef(None, FooMinus, None, [], Lam(Tup(y: Var(Int)), App(Var(+), Tup(_: Var(x), _: Var(y))))), NuFunDef(None, car, None, [], App(Var(foo), Tup(_: IntLit(2)))))), NuTypeDef(class, Car, (), Tup(), (), None, None, TypingUnit(NuFunDef(None, da, None, [], Lam(Tup(b: Var(Bar)), App(Sel(Var(b), foo), Tup(_: IntLit(2))))))), NuFunDef(None, baz, None, [], Lam(Tup(b: Var(Bar)), App(Sel(Var(b), foo), Tup(_: IntLit(2))))), NuFunDef(Some(false), bar, None, [], App(Var(Bar), Tup(_: IntLit(42)))), App(Var(baz), Tup(_: Var(bar))), App(Sel(Bra(rcd = false, App(NuNew(Var(Car)), Tup())), da), Tup(_: App(Var(Bar), Tup(_: IntLit(1337))))), Sel(Var(bar), car)) +//│ //│ Lifted: //│ TypingUnit { //│ class Bar$1([x: Int,]) { @@ -1093,8 +1068,7 @@ class Sub2(c: Int) extends Sub(c+c){ } (new Sub(10)).foo() (new Sub2(c)).foo() -//│ Parsed: -//│ TypingUnit(NuFunDef(Some(false), c, None, [], IntLit(5)), NuTypeDef(class, Sup, (), Tup(a: Var(Int)), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(), Var(a))))), NuTypeDef(class, Sub, (), Tup(b: Var(Int)), (App(Var(Sup), Tup(_: App(Var(+), Tup(_: Var(b), _: Var(b)))))), None, None, TypingUnit()), NuTypeDef(class, Sub2, (), Tup(c: Var(Int)), (App(Var(Sub), Tup(_: App(Var(+), Tup(_: Var(c), _: Var(c)))))), None, None, TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(), App(Var(+), Tup(_: Var(a), _: Var(c))))))), App(Sel(Bra(rcd = false, App(NuNew(Var(Sub)), Tup(_: IntLit(10)))), foo), Tup()), App(Sel(Bra(rcd = false, App(NuNew(Var(Sub2)), Tup(_: Var(c)))), foo), Tup())) +//│ //│ Lifted: //│ TypingUnit { //│ class Sup$1([a: Int,]) {fun foo = () => (this).a} @@ -1151,8 +1125,7 @@ class F1() extends Foo(x => x+1){} class F2() extends Foo(x => x+2){} (new F1()).foo() (new F2()).foo() -//│ Parsed: -//│ TypingUnit(NuTypeDef(class, Foo, (), Tup(f: App(Var(->), Tup(_: Var(Int), _: Var(Int)))), (), None, None, TypingUnit(NuFunDef(None, foo, None, [], Lam(Tup(), App(Var(f), Tup(_: IntLit(1))))))), NuTypeDef(class, F1, (), Tup(), (App(Var(Foo), Tup(_: Lam(Tup(_: Var(x)), App(Var(+), Tup(_: Var(x), _: IntLit(1))))))), None, None, TypingUnit()), NuTypeDef(class, F2, (), Tup(), (App(Var(Foo), Tup(_: Lam(Tup(_: Var(x)), App(Var(+), Tup(_: Var(x), _: IntLit(2))))))), None, None, TypingUnit()), App(Sel(Bra(rcd = false, App(NuNew(Var(F1)), Tup())), foo), Tup()), App(Sel(Bra(rcd = false, App(NuNew(Var(F2)), Tup())), foo), Tup())) +//│ //│ Lifted: //│ TypingUnit { //│ class Foo$1([f: ->(Int, Int,),]) {fun foo = () => (this).f(1,)} diff --git a/compiler/shared/test/scala/mlscript/compiler/Test.scala b/compiler/shared/test/scala/mlscript/compiler/Test.scala index e0df0d8f0..7f4c81698 100644 --- a/compiler/shared/test/scala/mlscript/compiler/Test.scala +++ b/compiler/shared/test/scala/mlscript/compiler/Test.scala @@ -3,7 +3,6 @@ package mlscript.compiler import mlscript.utils.shorthands.* import scala.util.control.NonFatal import scala.collection.mutable.StringBuilder -import mlscript.codegen.Helpers.inspect as showStructure import mlscript.{DiffTests, ModeType, TypingUnit} import mlscript.compiler.debug.TreeDebug import mlscript.compiler.mono.Monomorph @@ -14,8 +13,6 @@ class DiffTestCompiler extends DiffTests { import DiffTestCompiler.* override def postProcess(mode: ModeType, basePath: List[Str], testName: Str, unit: TypingUnit): List[Str] = val outputBuilder = StringBuilder() - outputBuilder ++= "Parsed:\n" - outputBuilder ++= showStructure(unit) outputBuilder ++= "\nLifted:\n" var rstUnit = unit; diff --git a/shared/src/main/scala/mlscript/JSBackend.scala b/shared/src/main/scala/mlscript/JSBackend.scala index 9c8b3d34f..d745e8f3c 100644 --- a/shared/src/main/scala/mlscript/JSBackend.scala +++ b/shared/src/main/scala/mlscript/JSBackend.scala @@ -1,7 +1,6 @@ package mlscript import mlscript.utils._, shorthands._, algorithms._ -import mlscript.codegen.Helpers._ import mlscript.codegen._ import scala.collection.mutable.{ListBuffer, HashMap, HashSet} import mlscript.{JSField, JSLit} @@ -69,7 +68,7 @@ abstract class JSBackend(allowUnresolvedSymbols: Bool) { case Inst(bod) => translatePattern(bod) case _: Lam | _: App | _: Sel | _: Let | _: Blk | _: Bind | _: Test | _: With | _: CaseOf | _: Subs | _: Assign | If(_, _) | New(_, _) | NuNew(_) | _: Splc | _: Forall | _: Where | _: Super | _: Eqn | _: AdtMatchWith | _: Rft => - throw CodeGenError(s"term ${inspect(t)} is not a valid pattern") + throw CodeGenError(s"term $t is not a valid pattern") } private def translateParams(t: Term)(implicit scope: Scope): Ls[JSPattern] = t match { @@ -172,7 +171,7 @@ abstract class JSBackend(allowUnresolvedSymbols: Bool) { } callee(args map { case (_, Fld(_, arg)) => translateTerm(arg) }: _*) case App(trm, splice) => ??? // TODO represents `trm(...splice)` - case _ => throw CodeGenError(s"ill-formed application ${inspect(term)}") + case _ => throw CodeGenError(s"ill-formed application $term") } /** @@ -297,7 +296,7 @@ abstract class JSBackend(allowUnresolvedSymbols: Bool) { case _: Subs | _: Sel | _: Var => JSCommaExpr(JSAssignExpr(translateTerm(lhs), translateTerm(value)) :: JSArray(Nil) :: Nil) case _ => - throw CodeGenError(s"illegal assignemnt left-hand side: ${inspect(lhs)}") + throw CodeGenError(s"illegal assignemnt left-hand side: $lhs") } case Inst(bod) => translateTerm(bod) case iff: If => @@ -310,7 +309,7 @@ abstract class JSBackend(allowUnresolvedSymbols: Bool) { case n: JSNew => n case t => JSNew(t) } - case _ => throw CodeGenError(s"Unsupported `new` class term: ${inspect(cls)}") + case _ => throw CodeGenError(s"Unsupported `new` class term: $cls") } // * Would not be quite correct: // JSNew(translateTerm(cls)) @@ -328,7 +327,7 @@ abstract class JSBackend(allowUnresolvedSymbols: Bool) { case Eqn(Var(name), _) => throw CodeGenError(s"assignment of $name is not supported outside a constructor") case _: Bind | _: Test | If(_, _) | _: Splc | _: Where | _: AdtMatchWith | _: Rft => - throw CodeGenError(s"cannot generate code for term ${inspect(term)}") + throw CodeGenError(s"cannot generate code for term $term") } private def translateCaseBranch(scrut: JSExpr, branch: CaseBranches)(implicit @@ -369,7 +368,7 @@ abstract class JSBackend(allowUnresolvedSymbols: Bool) { } } case lit: Lit => - JSBinary("===", scrut, JSLit(lit.idStr)) + JSBinary("===", scrut, translateTerm(lit)) }, _, _ diff --git a/shared/src/main/scala/mlscript/NuTypeDefs.scala b/shared/src/main/scala/mlscript/NuTypeDefs.scala index 8eb2bdf2d..8d97dc000 100644 --- a/shared/src/main/scala/mlscript/NuTypeDefs.scala +++ b/shared/src/main/scala/mlscript/NuTypeDefs.scala @@ -560,7 +560,7 @@ class NuTypeDefs extends ConstraintSolver { self: Typer => case fd @ NuFunDef(_, nme, snme, tparams, R(rhs)) => funSigs.updateWith(nme.name) { case S(s) => - err(s"A type signature for '$nme' was already given", fd.toLoc) + err(s"A type signature for '${nme.name}' was already given", fd.toLoc) S(s) case N => S(fd) } diff --git a/shared/src/main/scala/mlscript/Typer.scala b/shared/src/main/scala/mlscript/Typer.scala index 1ba890989..3a3e5d15d 100644 --- a/shared/src/main/scala/mlscript/Typer.scala +++ b/shared/src/main/scala/mlscript/Typer.scala @@ -1380,7 +1380,7 @@ class Typer(var dbg: Boolean, var verbose: Bool, var explainErrors: Bool, val ne // () // and others case pat => - lastWords(s"Cannot handle pattern ${pat}") + lastWords(s"Cannot handle pattern ${pat.showDbg}") } handlePat(pat, cond_ty) diff --git a/shared/src/main/scala/mlscript/TyperDatatypes.scala b/shared/src/main/scala/mlscript/TyperDatatypes.scala index 121184b93..5fc80392a 100644 --- a/shared/src/main/scala/mlscript/TyperDatatypes.scala +++ b/shared/src/main/scala/mlscript/TyperDatatypes.scala @@ -240,7 +240,7 @@ abstract class TyperDatatypes extends TyperHelpers { Typer: Typer => RecordType(fields.filterNot(f => shadowing(f._1)) ++ fs)(prov) } def sorted: RecordType = RecordType(fields.sortBy(_._1))(prov) - override def toString = s"{${fields.map(f => s"${f._1}: ${f._2}").mkString(", ")}}" + override def toString = s"{${fields.map(f => s"${f._1.name}: ${f._2}").mkString(", ")}}" } object RecordType { def empty: RecordType = RecordType(Nil)(noProv) diff --git a/shared/src/main/scala/mlscript/codegen/Helpers.scala b/shared/src/main/scala/mlscript/codegen/Helpers.scala deleted file mode 100644 index 5bade531b..000000000 --- a/shared/src/main/scala/mlscript/codegen/Helpers.scala +++ /dev/null @@ -1,100 +0,0 @@ -package mlscript.codegen - -import mlscript._, mlscript.utils.shorthands._ -import scala.collection.immutable.{Map, Set} - -object Helpers { - /** - * Show how a term is actually structured. - */ - def inspect(t: Terms): Str = t match { - case Var(name) => s"Var($name)" - case Lam(lhs, rhs) => s"Lam(${inspect(lhs)}, ${inspect(rhs)})" - case App(lhs, rhs) => s"App(${inspect(lhs)}, ${inspect(rhs)})" - case Tup(fields) => - val entries = fields map { - case (S(name), Fld(_, value)) => s"$name: ${inspect(value)}" - case (N, Fld(_, value)) => s"_: ${inspect(value)}" - } - s"Tup(${entries mkString ", "})" - case Rcd(fields) => - val entries = fields.iterator - .map { case k -> Fld(_, v) => s"${inspect(k)} = ${inspect(v)}" } - .mkString(", ") - s"Rcd($entries)" - case Sel(receiver, fieldName) => s"Sel(${inspect(receiver)}, $fieldName)" - case Let(isRec, name, rhs, body) => s"Let($isRec, $name, ${inspect(rhs)}, ${inspect(body)})" - case Blk(stmts) => s"Blk(...)" - case Bra(rcd, trm) => s"Bra(rcd = $rcd, ${inspect(trm)})" - case Asc(trm, ty) => s"Asc(${inspect(trm)}, $ty)" - case Bind(lhs, rhs) => s"Bind(${inspect(lhs)}, ${inspect(rhs)})" - case Test(trm, ty) => s"Test(${inspect(trm)}, ${inspect(ty)})" - case With(trm, fields) => - s"With(${inspect(trm)}, ${inspect(fields)})" - case CaseOf(trm, cases) => - def inspectCaseBranches(br: CaseBranches): Str = br match { - case Case(clsNme, body, rest) => - s"Case($clsNme, ${inspect(body)}, ${inspectCaseBranches(rest)})" - case Wildcard(body) => s"Wildcard(${inspect(body)})" - case NoCases => "NoCases" - } - s"CaseOf(${inspect(trm)}, ${inspectCaseBranches(cases)}" - case IntLit(value) => s"IntLit($value)" - case DecLit(value) => s"DecLit($value)" - case StrLit(value) => s"StrLit($value)" - case UnitLit(value) => s"UnitLit($value)" - case Subs(arr, idx) => s"Subs(${inspect(arr)}, ${inspect(idx)})" - case Assign(f, v) => s"Assign(${inspect(f)}, ${inspect(v)})" - case Splc(fs) => - val elems = fs.map{case L(l) => s"...${inspect(l)}" case R(Fld(_, r)) => inspect(r)}.mkString(", ") - s"Splc($elems)" - case If(bod, els) => s"If(${inspect(bod)}, ${els.map(inspect)})" - case New(base, body) => s"New(${base}, ${inspect(body)})" - case NuNew(base) => s"NuNew(${inspect(base)})" - case TyApp(base, targs) => s"TyApp(${inspect(base)}, ${targs})" - case Def(rec, nme, rhs, isByname) => - s"Def($rec, $nme, ${rhs.fold(inspect, "" + _)}, $isByname)" - case Where(bod, sts) => s"Where(${inspect(bod)}, ...)" - case Forall(ps, bod) => s"Forall($ps, ${inspect(bod)})" - case Inst(bod) => s"Inst(${inspect(bod)})" - case Eqn(lhs, rhs) => s"Eqn(${inspect(lhs)}, ${inspect(rhs)})" - case Super() => "Super()" - case AdtMatchWith(cond, arms) => - s"match ${inspect(cond)} with ${arms.map(patmat => s"${inspect(patmat.pat)} -> ${inspect(patmat.rhs)}").mkString(" | ")}" - case Rft(bse, tu) => s"Rft(${inspect(bse)}, ...)" - } - - def inspect(body: IfBody): Str = body match { - case IfElse(expr) => s"IfElse(${inspect(expr)}" - case IfThen(expr, rhs) => s"IfThen(${inspect(expr)}, ${inspect(rhs)}" - case IfBlock(lines) => s"IfBlock(${ - lines.iterator.map { - case L(body) => inspect(body) - case R(NuFunDef(S(isRec), nme, _, _, L(rhs))) => - s"Let($isRec, ${nme.name}, ${inspect(rhs)})" - case R(_) => ??? - }.mkString(";") - })" - case IfOpsApp(lhs, opsRhss) => s"IfOpsApp(${inspect(lhs)}, ${ - opsRhss.iterator.map { case (op, body) => - s"$op -> ${inspect(body)}" - } - }".mkString("; ") - case IfLet(isRec, name, rhs, body) => ??? - case IfOpApp(lhs, op, rhs) => - s"IfOpApp(${inspect(lhs)}, ${inspect(op)}, ${inspect(rhs)}" - } - def inspect(t: TypingUnit): Str = t.entities.iterator - .map { - case term: Term => inspect(term) - case NuFunDef(lt, nme, symNme, targs, L(term)) => - s"NuFunDef(${lt}, ${nme.name}, $symNme, ${targs.mkString("[", ", ", "]")}, ${inspect(term)})" - case NuFunDef(lt, nme, symNme, targs, R(ty)) => - s"NuFunDef(${lt}, ${nme.name}, $symNme, ${targs.mkString("[", ", ", "]")}, $ty)" - case NuTypeDef(kind, nme, tparams, params, ctor, sig, parents, sup, ths, body) => - s"NuTypeDef(${kind.str}, ${nme.name}, ${tparams.mkString("(", ", ", ")")}, ${ - inspect(params.getOrElse(Tup(Nil)))}, ${parents.map(inspect).mkString("(", ", ", ")")}, $sup, $ths, ${inspect(body)})" - case others => others.toString() - } - .mkString("TypingUnit(", ", ", ")") -} diff --git a/shared/src/main/scala/mlscript/helpers.scala b/shared/src/main/scala/mlscript/helpers.scala index cb069e47c..b6154bd40 100644 --- a/shared/src/main/scala/mlscript/helpers.scala +++ b/shared/src/main/scala/mlscript/helpers.scala @@ -101,7 +101,7 @@ trait TypeLikeImpl extends Located { self: TypeLike => case AppliedType(n, args) => s"${n.name}${args.map(_.showIn(ctx, 0)).mkString(ctx.<, ", ", ctx.>)}" case Selection(b, n) => b.showIn(ctx, 100) + "." + n.name - case Rem(b, ns) => s"${b.showIn(ctx, 90)}${ns.map("\\"+_).mkString}" + case Rem(b, ns) => s"${b.showIn(ctx, 90)}${ns.map("\\"+_.name).mkString}" case Literal(IntLit(n)) => n.toString case Literal(DecLit(n)) => n.toString case Literal(StrLit(s)) => "\"" + s + "\"" @@ -173,7 +173,7 @@ trait TypeLikeImpl extends Located { self: TypeLike => case _ => "" }}${sig.fold("")(": " + _.showIn(bodyCtx, 0))}${parents match { case Nil => "" - case ps => " extends " + ps.mkString(", ") // TODO pp parent terms... + case ps => " extends " + ps.iterator.map(_.print(false)).mkString(", ") // TODO pp parent terms... }}${if (body.entities.isEmpty && sup.isEmpty && ths.isEmpty) "" else " {\n" + sup.fold("")(s"${bodyCtx.indStr}super: " + _.showIn(bodyCtx, 0) + "\n") + ths.fold("")(s"${bodyCtx.indStr}this: " + _.showIn(bodyCtx, 0) + "\n") + @@ -386,7 +386,8 @@ trait PgrmImpl { self: Pgrm => } diags.toList -> res } - override def toString = tops.map("" + _ + ";").mkString(" ") + + def showDbg: Str = tops.iterator.map("" + _.showDbg + ";").mkString(" ") } object OpApp { @@ -401,18 +402,16 @@ object OpApp { trait DeclImpl extends Located { self: Decl => val body: Located def showBody: Str = this match { - case Def(_, _, rhs, isByname) => rhs.fold(_.toString, _.showDbg2) + case d: Def => d.rhs.fold(_.showDbg, _.showDbg2) case td: TypeDef => td.body.showDbg2 } def describe: Str = this match { case _: Def => "definition" case _: TypeDef => "type declaration" } - def showDbg: Str = showHead + (this match { - case TypeDef(Als, _, _, _, _, _, _, _) => " = "; case _ => ": " }) + showBody def showHead: Str = this match { - case Def(true, n, b, isByname) => s"rec def $n" - case Def(false, n, b, isByname) => s"def $n" + case Def(true, n, b, isByname) => s"rec def ${n.showDbg}" + case Def(false, n, b, isByname) => s"def ${n.showDbg}" case TypeDef(k, n, tps, b, _, _, pos, _) => s"${k.str} ${n.name}${if (tps.isEmpty) "" else tps.map(_.name).mkString("[", ", ", "]")}${ if (pos.isEmpty) "" else pos.mkString("(", ", ", ")") @@ -434,27 +433,22 @@ trait NuDeclImpl extends Located { self: NuDecl => } def name: Str = nameVar.name def showBody: Str = this match { - case NuFunDef(_, _, _, _, rhs) => rhs.fold(_.toString, _.showDbg2) + case fd: NuFunDef => fd.rhs.fold(_.print(false), _.showDbg2) case td: NuTypeDef => td.body.showDbg } def describe: Str = this match { case _: NuFunDef => "definition" case _: NuTypeDef => "type declaration" } - def showDbg: Str = showHead + (this match { - case NuFunDef(_, _, _, _, L(_)) => " = " - case NuFunDef(_, _, _, _, R(_)) => ": " - case _: NuTypeDef => " " - }) + showBody def showHead: Str = this match { - case NuFunDef(N, n, snme, _, b) => s"fun${snme.fold("")(" ("+_+")")} $n" - case NuFunDef(S(false), n, snme, _, b) => s"let${snme.fold("")(" "+_+")")} $n" - case NuFunDef(S(true), n, snme, _, b) => s"let rec${snme.fold("")(" "+_+")")} $n" + case NuFunDef(N, n, snme, _, b) => s"fun${snme.fold("")(" ("+_.name+")")} ${n.name}" + case NuFunDef(S(false), n, snme, _, b) => s"let${snme.fold("")(" "+_.name+")")} ${n.name}" + case NuFunDef(S(true), n, snme, _, b) => s"let rec${snme.fold("")(" "+_.name+")")} ${n.name}" case NuTypeDef(k, n, tps, sps, ctor, sig, parents, sup, ths, bod) => s"${k.str} ${n.name}${if (tps.isEmpty) "" else tps.map(_._2.name).mkString("‹", ", ", "›")}${ sps.fold("")("(" + _.showElems + ")") }${sig.fold("")(": " + _.showDbg2)}${ - if (parents.isEmpty) "" else if (k === Als) " = " else ": "}${parents.mkString(", ")}" + if (parents.isEmpty) "" else if (k === Als) " = " else ": "}${parents.iterator.map(_.showDbg).mkString(", ")}" } lazy val genUnapply: Opt[NuFunDef] = this match { case td: NuTypeDef if td.kind is Cls => td.params.map { tup => @@ -472,13 +466,13 @@ trait NuDeclImpl extends Located { self: NuDecl => } trait TypingUnitImpl extends Located { self: TypingUnit => - def showDbg: Str = entities.map { - case t: Term => t.toString + def showDbg: Str = entities.iterator.map { + case t: Term => t.print(false) case d: NuDecl => d.showDbg - case c: Constructor => c.toString + case c: Constructor => c.showDbg case e => lastWords(s"Unexpected typing unit entity: $e") }.mkString("{", "; ", "}") - override def toString: String = s"‹${entities.mkString("; ")}›" + lazy val children: List[Located] = entities } @@ -495,6 +489,15 @@ trait TypeNameImpl extends Ordered[TypeName] { self: TypeName => lazy val toVar: Var = Var(name).withLocOf(this) } +trait FldFlagsImpl extends Located { self: FldFlags => + def children: Ls[Located] = Nil + override def toString(): String = { + val FldFlags(m, s, g) = this + val res = (if (m) "m" else "") + (if (s) "s" else "") + (if (g) "g" else "") + if (res.isEmpty) "_" else res + } +} + trait FldImpl extends Located { self: Fld => def children: Ls[Located] = self.value :: Nil def describe: Str = @@ -561,31 +564,31 @@ trait TermImpl extends StatementImpl { self: Term => case AdtMatchWith(cond, arms) => "ADT pattern matching" } } - - override def toString: Str = print(false) + + override def showDbg: Str = print(false) def print(brackets: Bool): Str = { def bra(str: Str): Str = if (brackets) s"($str)" else str this match { - case Bra(true, trm) => s"'{' $trm '}'" - case Bra(false, trm) => s"'(' $trm ')'" - case Blk(stmts) => stmts.mkString("{", "; ", "}") + case Bra(true, trm) => s"'{' ${trm.showDbg} '}'" + case Bra(false, trm) => s"'(' ${trm.showDbg} ')'" + case Blk(stmts) => stmts.iterator.map(_.showDbg).mkString("{", "; ", "}") case IntLit(value) => value.toString case DecLit(value) => value.toString case StrLit(value) => '"'.toString + value + '"' case UnitLit(value) => if (value) "undefined" else "null" case v @ Var(name) => name + v.uid.fold("")("::"+_.toString) - case Asc(trm, ty) => s"$trm : ${ty.showDbg2}" |> bra - case Lam(pat: Tup, rhs) => s"(${pat.showElems}) => $rhs" |> bra - case Lam(pat, rhs) => s"(...$pat) => $rhs" |> bra + case Asc(trm, ty) => s"${trm.showDbg} : ${ty.showDbg2}" |> bra + case Lam(pat: Tup, rhs) => s"(${pat.showElems}) => ${rhs.showDbg}" |> bra + case Lam(pat, rhs) => s"(...${pat.showDbg}) => ${rhs.showDbg}" |> bra case App(lhs, rhs: Tup) => s"${lhs.print(!lhs.isInstanceOf[App])}(${rhs.showElems})" |> bra case App(lhs, rhs) => s"${lhs.print(!lhs.isInstanceOf[App])}(...${rhs.print(true)})" |> bra case Rcd(fields) => fields.iterator.map(nv => - (if (nv._2.flags.mut) "mut " else "") + nv._1.name + ": " + nv._2.value).mkString("{", ", ", "}") - case Sel(receiver, fieldName) => "(" + receiver.toString + ")." + fieldName - case Let(isRec, name, rhs, body) => - s"let${if (isRec) " rec" else ""} $name = $rhs in $body" |> bra + (if (nv._2.flags.mut) "mut " else "") + nv._1.name + ": " + nv._2.value.showDbg).mkString("{", ", ", "}") + case Sel(receiver, fieldName) => "(" + receiver.showDbg + ")." + fieldName.showDbg + case Let(isRec, Var(name), rhs, body) => + s"let${if (isRec) " rec" else ""} $name = ${rhs.showDbg} in ${body.showDbg}" |> bra case tup: Tup => "[" + tup.showElems + "]" case Splc(fields) => fields.map{ case L(l) => s"...$l" @@ -596,26 +599,26 @@ trait TermImpl extends StatementImpl { self: Term => + r ) }.mkString("(", ", ", ")") - case Bind(l, r) => s"$l as $r" |> bra - case Test(l, r) => s"$l is $r" |> bra - case With(t, fs) => s"$t with $fs" |> bra + case Bind(l, r) => s"${l.showDbg} as ${r.showDbg}" |> bra + case Test(l, r) => s"${l.showDbg} is ${r.showDbg}" |> bra + case With(t, fs) => s"${t.showDbg} with ${fs.showDbg}" |> bra case CaseOf(s, c) => - s"case $s of { ${c.print(true)} }" |> bra - case Subs(a, i) => s"($a)[$i]" - case Assign(lhs, rhs) => s" $lhs <- $rhs" |> bra - case New(S((at, ar)), bod) => s"new ${at.showDbg2}($ar) ${bod.showDbg}" |> bra + s"case ${s.showDbg} of { ${c.print(true)} }" |> bra + case Subs(a, i) => s"(${a.showDbg})[${i.showDbg}]" + case Assign(lhs, rhs) => s" ${lhs.showDbg} <- ${rhs.showDbg}" |> bra + case New(S((at, ar)), bod) => s"new ${at.showDbg2}(${ar.showDbg}) ${bod.showDbg}" |> bra case New(N, bod) => s"new ${bod.showDbg}" |> bra - case NuNew(cls) => s"new ${cls.print(false)}" |> bra - case If(body, els) => s"if $body" + els.fold("")(" else " + _) |> bra - case TyApp(lhs, targs) => s"$lhs‹${targs.map(_.showDbg2).mkString(", ")}›" - case Where(bod, wh) => s"${bod} where {${wh.mkString("; ")}}" - case Forall(ps, bod) => s"forall ${ps.mkString(", ")}. ${bod}" + case NuNew(cls) => s"new ${cls.showDbg}" |> bra + case If(body, els) => s"if ${body.showDbg}" + els.fold("")(" else " + _.showDbg) |> bra + case TyApp(lhs, targs) => s"${lhs.showDbg}‹${targs.iterator.map(_.showDbg2).mkString(", ")}›" + case Where(bod, wh) => s"${bod.showDbg} where {${wh.iterator.map(_.showDbg).mkString("; ")}}" + case Forall(ps, bod) => s"forall ${ps.mkString(", ")}. ${bod.showDbg}" case Inst(bod) => s"${bod.print(true)}!" case Super() => "super" - case Eqn(lhs, rhs) => s"${lhs} = ${rhs}" + case Eqn(lhs, rhs) => s"${lhs.showDbg} = ${rhs.showDbg}" case AdtMatchWith(cond, arms) => - s"match ${cond} with ${arms.map (patmat => s"${patmat.pat} -> ${patmat.rhs}").mkString (" | ") }" - case Rft(bse, tu) => s"${bse} { ${tu} }" + s"match ${cond.showDbg} with ${arms.map (patmat => s"${patmat.pat.showDbg} -> ${patmat.rhs.showDbg}").mkString (" | ") }" + case Rft(bse, tu) => s"${bse.showDbg} ${tu.showDbg}" }} def toTypeRaise(implicit raise: Raise): Type = toType match { @@ -739,7 +742,7 @@ trait TupImpl { self: Tup => (if (t.flags.mut) "mut " else "") + (if (t.flags.genGetter) "val " else "") + (if (t.flags.spec) "#" else "") - + n.fold("")(_.name + ": ") + t.value + "," + + n.fold("")(_.name + ": ") + t.value.print(false) + "," )}.mkString(" ") } @@ -747,7 +750,7 @@ trait SimpleTermImpl extends Ordered[SimpleTerm] { self: SimpleTerm => def compare(that: SimpleTerm): Int = this.idStr compare that.idStr val idStr: Str = this match { case Var(name) => name - case lit: Lit => lit.toString + case lit: Lit => lit.showDbg } } @@ -817,6 +820,8 @@ trait Located { trait DesugaredStatementImpl extends Located { self: DesugaredStatement => def describe: Str + + def showDbg: Str } trait StatementImpl extends Located { self: Statement => @@ -836,7 +841,7 @@ trait StatementImpl extends Located { self: Statement => case v @ Var(nme) => R(TypeName(nme).withLocOf(v)) case t => import Message._ - L(ErrorReport(msg"illegal datatype type parameter shape: ${t.toString}" -> t.toLoc :: Nil, newDefs=false)) + L(ErrorReport(msg"illegal datatype type parameter shape: ${t.showDbg}" -> t.toLoc :: Nil, newDefs=false)) } val (diags2, cs) = desugarCases(bod, targs) val dataDefs = cs.collect{case td: TypeDef => td} @@ -1000,15 +1005,20 @@ trait StatementImpl extends Located { self: Statement => case AdtMatchWith(cond, _) => cond :: Nil // FIXME discards branches... } - - override def toString: Str = this match { - case LetS(isRec, name, rhs) => s"let${if (isRec) " rec" else ""} $name = $rhs" - case DatatypeDefn(head, body) => s"data type $head of $body" - case DataDefn(head) => s"data $head" - case Constructor(params, bod) => s"constructor(${params.showElems}) $bod" - case _: Term => super.toString - case d: Decl => d.showDbg - case d: NuDecl => d.showDbg + def showDbg: Str = this match { + case LetS(isRec, name, rhs) => s"let${if (isRec) " rec" else ""} ${name.showDbg} = ${rhs.showDbg}" + case DatatypeDefn(head, body) => s"data type ${head.showDbg} of ${body.showDbg}" + case DataDefn(head) => s"data ${head.showDbg}" + case Constructor(params, body) => s"constructor(${params.showElems}) ${body.showDbg}" + case t: Term => t.print(false) + case d: Decl => d.showHead + (d match { + case n: TypeDef if n.kind is Als => " = " + case _ => ": " + }) + d.showBody + case n: NuDecl => n.showHead + (n match { + case n: NuFunDef => if (n.rhs.isLeft) " = " else ": " + case _: NuTypeDef => " " + }) + n.showBody } } @@ -1058,13 +1068,13 @@ trait IfBodyImpl extends Located { self: IfBody => case IfOpsApp(t, ops) => t :: ops.flatMap(x => x._1 :: x._2 :: Nil) } - override def toString: String = this match { - case IfThen(lhs, rhs) => s"($lhs) then $rhs" - case IfElse(trm) => s"else $trm" - case IfBlock(ts) => s"‹${ts.map(_.fold(identity, identity)).mkString("; ")}›" - case IfOpApp(lhs, op, ib) => s"$lhs $op $ib" - case IfOpsApp(lhs, ops) => s"$lhs ‹${ops.iterator.map{case(v, r) => s"· $v $r"}.mkString("; ")}›" - case IfLet(isRec, v, r, b) => s"${if (isRec) "rec " else ""}let $v = $r in $b" + def showDbg: String = this match { + case IfThen(lhs, rhs) => s"(${lhs.showDbg}) then ${rhs.showDbg}" + case IfElse(trm) => s"else ${trm.showDbg}" + case IfBlock(ts) => s"‹${ts.iterator.map(_.fold(_.showDbg, _.showDbg)).mkString("; ")}›" + case IfOpApp(lhs, op, ib) => s"${lhs.showDbg} ${op.showDbg} ${ib.showDbg}" + case IfOpsApp(lhs, ops) => s"${lhs.showDbg} ‹${ops.iterator.map{case(v, r) => s"· ${v.showDbg} ${r.showDbg}"}.mkString("; ")}›" + case IfLet(isRec, v, r, b) => s"${if (isRec) "rec " else ""}let ${v.showDbg} = ${r.showDbg} in ${b.showDbg}" } } diff --git a/shared/src/main/scala/mlscript/syntax.scala b/shared/src/main/scala/mlscript/syntax.scala index e899ff582..d3d3b05c4 100644 --- a/shared/src/main/scala/mlscript/syntax.scala +++ b/shared/src/main/scala/mlscript/syntax.scala @@ -104,7 +104,7 @@ final case class IfOpsApp(lhs: Term, opsRhss: Ls[Var -> IfBody]) extends IfBody final case class IfBlock(lines: Ls[IfBody \/ Statement]) extends IfBody // final case class IfApp(fun: Term, opsRhss: Ls[Var -> IfBody]) extends IfBody -final case class FldFlags(mut: Bool, spec: Bool, genGetter: Bool) +final case class FldFlags(mut: Bool, spec: Bool, genGetter: Bool) extends FldFlagsImpl final case class Fld(flags: FldFlags, value: Term) extends FldImpl object FldFlags { val empty: FldFlags = FldFlags(false, false, false) } diff --git a/shared/src/main/scala/mlscript/ucs/Desugarer.scala b/shared/src/main/scala/mlscript/ucs/Desugarer.scala index 6358f1892..6e49e61ef 100644 --- a/shared/src/main/scala/mlscript/ucs/Desugarer.scala +++ b/shared/src/main/scala/mlscript/ucs/Desugarer.scala @@ -379,7 +379,7 @@ class Desugarer extends TypeDefs { self: Typer => patternMap.foreachEntry { (pattern, locations) => val first = pattern match { case Left(tupleArity) => s"()^$tupleArity" - case Right(litOrCls) => litOrCls.toString() + case Right(litOrCls) => litOrCls.showDbg } val second = locations.mkString("[", ", ", "]") printlnUCS(s" + $first -> $second") @@ -689,7 +689,7 @@ class Desugarer extends TypeDefs { self: Typer => parentOpt match { case S(IfThenElse(test, whenTrue, whenFalse)) => if (whenFalse === t) - throw new DesugaringException(msg"The case when this is false is not handled: ${test.toString}", test.toLoc) + throw new DesugaringException(msg"The case when this is false is not handled: ${test.showDbg}", test.toLoc) else lastWords("`MissingCase` are not supposed to be the true branch of `IfThenElse`") case S(Match(_, _, _)) => @@ -755,7 +755,7 @@ class Desugarer extends TypeDefs { self: Typer => missingCases.iterator.zipWithIndex.flatMap { case ((pattern, locations), index) => val patternName = pattern match { case L(tupleArity) => s"$tupleArity-ary tuple" - case R(litOrCls) => litOrCls.toString() + case R(litOrCls) => litOrCls.showDbg } val progress = s"[Missing Case ${index + 1}/$numMissingCases]" (msg"$progress `$patternName`" -> N) :: diff --git a/shared/src/main/scala/mlscript/ucs/MutCaseOf.scala b/shared/src/main/scala/mlscript/ucs/MutCaseOf.scala index 199d5619a..8472e8b31 100644 --- a/shared/src/main/scala/mlscript/ucs/MutCaseOf.scala +++ b/shared/src/main/scala/mlscript/ucs/MutCaseOf.scala @@ -62,7 +62,7 @@ sealed abstract class MutCaseOf extends WithBindings { object MutCaseOf { def showScrutinee(scrutinee: Scrutinee): Str = - s"«${scrutinee.term}»" + (scrutinee.local match { + s"«${scrutinee.term.showDbg}»" + (scrutinee.local match { case N => "" case S(Var(alias)) => s" as $alias" }) @@ -72,15 +72,15 @@ object MutCaseOf { def rec(t: MutCaseOf, indent: Int): Unit = { val baseIndent = " " * indent lazy val bindingLines = t.getBindings.iterator.map { - case LetBinding(_, recursive, name, term) => + case LetBinding(_, recursive, Var(name), term) => // Show bindings - s"[binding $name = $term]" + s"[binding $name = ${term.showDbg}]" }.toList t match { case IfThenElse(condition, whenTrue, whenFalse) => // Output the `whenTrue` with the prefix "if". bindingLines.foreach { lines += baseIndent + _ } - lines += baseIndent + s"if «$condition»" + lines += baseIndent + s"if «${condition.showDbg}»" rec(whenTrue, indent + 1) // Output the `whenFalse` case with the prefix "else". lines += s"${baseIndent}else" @@ -90,13 +90,13 @@ object MutCaseOf { lines += baseIndent + showScrutinee(scrutinee) + " match" branches.foreach { case MutCase.Literal(literal, consequent) => - lines += s"$baseIndent case $literal =>" + lines += s"$baseIndent case ${literal.showDbg} =>" rec(consequent, indent + 1) case MutCase.Constructor(Var(className) -> fields, consequent) => lines += s"$baseIndent case $className =>" fields.foreach { case (field, Var(alias)) => // Show pattern bindings. - lines += s"$baseIndent [pattern $alias = ${scrutinee.reference}.$field]" + lines += s"$baseIndent [pattern $alias = ${scrutinee.reference.showDbg}.$field]" } rec(consequent, indent + 2) } @@ -106,7 +106,7 @@ object MutCaseOf { } case Consequent(term) => bindingLines.foreach { lines += baseIndent + _ } - lines += s"$baseIndent«$term»" + lines += s"$baseIndent«${term.showDbg}»" case MissingCase => bindingLines.foreach { lines += baseIndent + _ } lines += s"$baseIndent" @@ -210,7 +210,7 @@ object MutCaseOf { // A short-hand for pattern matchings with only true and false branches. final case class IfThenElse(condition: Term, var whenTrue: MutCaseOf, var whenFalse: MutCaseOf) extends MutCaseOf { def describe: Str = - s"IfThenElse($condition, whenTrue = ${whenTrue.kind}, whenFalse = ${whenFalse.kind})" + s"IfThenElse(${condition.showDbg}, whenTrue = ${whenTrue.kind}, whenFalse = ${whenFalse.kind})" def duplicate(): MutCaseOf = IfThenElse(condition, whenTrue.duplicate(), whenFalse.duplicate()) @@ -469,7 +469,7 @@ object MutCaseOf { } } final case class Consequent(term: Term) extends MutCaseOf { - def describe: Str = s"Consequent($term)" + def describe: Str = s"Consequent(${term.showDbg})" override def fill(subTree: MutCaseOf): Unit = () diff --git a/shared/src/main/scala/mlscript/ucs/Scrutinee.scala b/shared/src/main/scala/mlscript/ucs/Scrutinee.scala index a0ce56d3e..899c5629a 100644 --- a/shared/src/main/scala/mlscript/ucs/Scrutinee.scala +++ b/shared/src/main/scala/mlscript/ucs/Scrutinee.scala @@ -26,5 +26,5 @@ final case class Scrutinee(var local: Opt[Var], term: Term)(val matchRootLoc: Op (local match { case N => "" case S(Var(alias)) => s"$alias @ " - }) + s"$term" + }) + s"${term.showDbg}" } diff --git a/shared/src/test/diff/basics/Blocks.fun b/shared/src/test/diff/basics/Blocks.fun index 65d88924e..059b5e80d 100644 --- a/shared/src/test/diff/basics/Blocks.fun +++ b/shared/src/test/diff/basics/Blocks.fun @@ -44,7 +44,7 @@ discard / foo 1 //│ Parsed: discard(...(foo(...{1}))); //│ Desugared: discard(...(foo(...{1}))) -//│ AST: App(Var(discard), App(Var(foo), Blk(...))) +//│ AST: App(Var(discard),App(Var(foo),Blk(List(IntLit(1))))) :e discard foo @@ -81,7 +81,7 @@ id id id //│ Parsed: id(...id)(...{id}); //│ Desugared: id(...id)(...{id}) -//│ AST: App(App(Var(id), Var(id)), Blk(...)) +//│ AST: App(App(Var(id),Var(id)),Blk(List(Var(id)))) //│ res: 'a -> 'a :p @@ -91,7 +91,7 @@ id id id id id id //│ Parsed: id(...id)(...id)(...{id(...id)(...id)(...{id(...id)(...id)(...{id(...id)(...id)})})}); //│ Desugared: id(...id)(...id)(...{id(...id)(...id)(...{id(...id)(...id)(...{id(...id)(...id)})})}) -//│ AST: App(App(App(Var(id), Var(id)), Var(id)), Blk(...)) +//│ AST: App(App(App(Var(id),Var(id)),Var(id)),Blk(List(App(App(App(Var(id),Var(id)),Var(id)),Blk(List(App(App(App(Var(id),Var(id)),Var(id)),Blk(List(App(App(Var(id),Var(id)),Var(id))))))))))) //│ res: 'a -> 'a :p @@ -100,7 +100,7 @@ id id / id id //│ Parsed: id(...id)(...{id(...id)(...{id(...id)})}); //│ Desugared: id(...id)(...{id(...id)(...{id(...id)})}) -//│ AST: App(App(Var(id), Var(id)), Blk(...)) +//│ AST: App(App(Var(id),Var(id)),Blk(List(App(App(Var(id),Var(id)),Blk(List(App(Var(id),Var(id)))))))) //│ res: 'a -> 'a :p @@ -109,7 +109,7 @@ id id id id //│ Parsed: id(...id)(...{id(...id)})(...{id(...id)}); //│ Desugared: id(...id)(...{id(...id)})(...{id(...id)}) -//│ AST: App(App(App(Var(id), Var(id)), Blk(...)), Blk(...)) +//│ AST: App(App(App(Var(id),Var(id)),Blk(List(App(Var(id),Var(id))))),Blk(List(App(Var(id),Var(id))))) //│ res: 'a -> 'a let foo = diff --git a/shared/src/test/diff/basics/Data.fun b/shared/src/test/diff/basics/Data.fun index f155732ee..551c3b1c0 100644 --- a/shared/src/test/diff/basics/Data.fun +++ b/shared/src/test/diff/basics/Data.fun @@ -4,7 +4,7 @@ data Test a b //│ Parsed: data Test(...a)(...b); //│ Desugared: class Test[a, b]: {a: a, b: b} //│ Desugared: def Test: forall a b. (...a) -> (...b) -> Test[a, b] -//│ AST: Def(false, Test, PolyType(List(Left(TypeName(a)), Left(TypeName(b))),Function(TypeName(a),Function(TypeName(b),AppliedType(TypeName(Test),List(TypeName(a), TypeName(b)))))), true) +//│ AST: Def(false,Var(Test),Right(PolyType(List(Left(TypeName(a)), Left(TypeName(b))),Function(TypeName(a),Function(TypeName(b),AppliedType(TypeName(Test),List(TypeName(a), TypeName(b))))))),true) //│ Defined class Test[+a, +b] //│ Test: 'a -> 'b -> Test['a, 'b] @@ -13,7 +13,7 @@ data Person(name: string, age: int) //│ Parsed: data Person(...'(' {[name: string, age: int,]} ')'); //│ Desugared: class Person: {age: int, name: string} //│ Desugared: def Person: (name: string, age: int) -> Person[] -//│ AST: Def(false, Person, PolyType(List(),Function(Tuple(List((Some(name),Field(None,TypeName(string))), (Some(age),Field(None,TypeName(int))))),AppliedType(TypeName(Person),List()))), true) +//│ AST: Def(false,Var(Person),Right(PolyType(List(),Function(Tuple(List((Some(Var(name)),Field(None,TypeName(string))), (Some(Var(age)),Field(None,TypeName(int))))),AppliedType(TypeName(Person),List())))),true) //│ Defined class Person //│ Person: (name: string, age: int,) -> Person diff --git a/shared/src/test/diff/basics/Datatypes.fun b/shared/src/test/diff/basics/Datatypes.fun index 2b2b0e737..02cad3d2c 100644 --- a/shared/src/test/diff/basics/Datatypes.fun +++ b/shared/src/test/diff/basics/Datatypes.fun @@ -6,9 +6,9 @@ data type Boolean of Tru, Fals //│ Desugared: class Tru: {} //│ Desugared: class Fals: {} //│ Desugared: def Tru: Tru[] -//│ AST: Def(false, Tru, PolyType(List(),AppliedType(TypeName(Tru),List())), true) +//│ AST: Def(false,Var(Tru),Right(PolyType(List(),AppliedType(TypeName(Tru),List()))),true) //│ Desugared: def Fals: Fals[] -//│ AST: Def(false, Fals, PolyType(List(),AppliedType(TypeName(Fals),List())), true) +//│ AST: Def(false,Var(Fals),Right(PolyType(List(),AppliedType(TypeName(Fals),List()))),true) //│ Defined type alias Boolean //│ Defined class Tru //│ Defined class Fals @@ -29,7 +29,7 @@ data type Bool2 of True2 & False2 //│ Desugared: type alias Bool2 = &[True2, False2] //│ Desugared: class &[True2, False2]: {False2 <: False2, True2 <: True2} //│ Desugared: def &: forall True2 False2. (...True2) -> (...False2) -> &[True2, False2] -//│ AST: Def(false, &, PolyType(List(Left(TypeName(True2)), Left(TypeName(False2))),Function(TypeName(True2),Function(TypeName(False2),AppliedType(TypeName(&),List(TypeName(True2), TypeName(False2)))))), true) +//│ AST: Def(false,Var(&),Right(PolyType(List(Left(TypeName(True2)), Left(TypeName(False2))),Function(TypeName(True2),Function(TypeName(False2),AppliedType(TypeName(&),List(TypeName(True2), TypeName(False2))))))),true) //│ ╔══[ERROR] type identifier not found: True2 //│ ║ l.27: data type Bool2 of True2 & False2 //│ ╙── ^^^^^ @@ -122,9 +122,9 @@ data type List a of //│ Desugared: class Nil[a]: {} //│ Desugared: class Cons[a]: {head: a, tail: anything} //│ Desugared: def Nil: forall a. Nil[a] -//│ AST: Def(false, Nil, PolyType(List(Left(TypeName(a))),AppliedType(TypeName(Nil),List(TypeName(a)))), true) +//│ AST: Def(false,Var(Nil),Right(PolyType(List(Left(TypeName(a))),AppliedType(TypeName(Nil),List(TypeName(a))))),true) //│ Desugared: def Cons: forall a. (head: a) -> (tail: anything) -> Cons[a] -//│ AST: Def(false, Cons, PolyType(List(Left(TypeName(a))),Function(Tuple(List((Some(head),Field(None,TypeName(a))))),Function(Tuple(List((Some(tail),Field(None,Top)))),AppliedType(TypeName(Cons),List(TypeName(a)))))), true) +//│ AST: Def(false,Var(Cons),Right(PolyType(List(Left(TypeName(a))),Function(Tuple(List((Some(Var(head)),Field(None,TypeName(a))))),Function(Tuple(List((Some(Var(tail)),Field(None,Top)))),AppliedType(TypeName(Cons),List(TypeName(a))))))),true) //│ Defined type alias List[+a] //│ Defined class Nil[±a] //│ Defined class Cons[+a] @@ -144,7 +144,7 @@ data type Ls of LsA a //│ Desugared: type alias Ls = LsA[a] //│ Desugared: class LsA[a]: {a: a} //│ Desugared: def LsA: forall a. (...a) -> LsA[a] -//│ AST: Def(false, LsA, PolyType(List(Left(TypeName(a))),Function(TypeName(a),AppliedType(TypeName(LsA),List(TypeName(a))))), true) +//│ AST: Def(false,Var(LsA),Right(PolyType(List(Left(TypeName(a))),Function(TypeName(a),AppliedType(TypeName(LsA),List(TypeName(a)))))),true) //│ ╔══[ERROR] type identifier not found: a //│ ║ l.142: data type Ls of LsA a //│ ╙── ^ @@ -159,7 +159,7 @@ data type Ls2 of LsA2 `a //│ Desugared: type alias Ls2 = LsA2[] //│ Desugared: class LsA2: {`a: 'a} //│ Desugared: def LsA2: (...'a) -> LsA2[] -//│ AST: Def(false, LsA2, PolyType(List(),Function(a,AppliedType(TypeName(LsA2),List()))), true) +//│ AST: Def(false,Var(LsA2),Right(PolyType(List(),Function(a,AppliedType(TypeName(LsA2),List())))),true) //│ ╔══[ERROR] cannot inherit from a polymorphic type //│ ║ l.157: data type Ls2 of LsA2 `a //│ ╙── ^^^^^^^ diff --git a/shared/src/test/diff/basics/Either.fun b/shared/src/test/diff/basics/Either.fun index 7ea04bae6..a9a49120a 100644 --- a/shared/src/test/diff/basics/Either.fun +++ b/shared/src/test/diff/basics/Either.fun @@ -9,9 +9,9 @@ data type Either l r of //│ Desugared: class Left[l, r]: {l: l} //│ Desugared: class Right[l, r]: {r: r} //│ Desugared: def Left: forall l r. (...l) -> Left[l, r] -//│ AST: Def(false, Left, PolyType(List(Left(TypeName(l)), Left(TypeName(r))),Function(TypeName(l),AppliedType(TypeName(Left),List(TypeName(l), TypeName(r))))), true) +//│ AST: Def(false,Var(Left),Right(PolyType(List(Left(TypeName(l)), Left(TypeName(r))),Function(TypeName(l),AppliedType(TypeName(Left),List(TypeName(l), TypeName(r)))))),true) //│ Desugared: def Right: forall l r. (...r) -> Right[l, r] -//│ AST: Def(false, Right, PolyType(List(Left(TypeName(l)), Left(TypeName(r))),Function(TypeName(r),AppliedType(TypeName(Right),List(TypeName(l), TypeName(r))))), true) +//│ AST: Def(false,Var(Right),Right(PolyType(List(Left(TypeName(l)), Left(TypeName(r))),Function(TypeName(r),AppliedType(TypeName(Right),List(TypeName(l), TypeName(r)))))),true) //│ Defined type alias Either[+l, +r] //│ Defined class Left[+l, ±r] //│ Defined class Right[±l, +r] diff --git a/shared/src/test/diff/basics/Flow.fun b/shared/src/test/diff/basics/Flow.fun index 5005f8a42..8c363a2cb 100644 --- a/shared/src/test/diff/basics/Flow.fun +++ b/shared/src/test/diff/basics/Flow.fun @@ -6,9 +6,9 @@ data R x //│ Desugared: class L[x]: {x: x} //│ Desugared: class R[x]: {x: x} //│ Desugared: def L: forall x. (...x) -> L[x] -//│ AST: Def(false, L, PolyType(List(Left(TypeName(x))),Function(TypeName(x),AppliedType(TypeName(L),List(TypeName(x))))), true) +//│ AST: Def(false,Var(L),Right(PolyType(List(Left(TypeName(x))),Function(TypeName(x),AppliedType(TypeName(L),List(TypeName(x)))))),true) //│ Desugared: def R: forall x. (...x) -> R[x] -//│ AST: Def(false, R, PolyType(List(Left(TypeName(x))),Function(TypeName(x),AppliedType(TypeName(R),List(TypeName(x))))), true) +//│ AST: Def(false,Var(R),Right(PolyType(List(Left(TypeName(x))),Function(TypeName(x),AppliedType(TypeName(R),List(TypeName(x)))))),true) //│ Defined class L[+x] //│ Defined class R[+x] //│ L: 'a -> L['a] diff --git a/shared/src/test/diff/basics/Operators.fun b/shared/src/test/diff/basics/Operators.fun index bbf5eff5c..895e9dd48 100644 --- a/shared/src/test/diff/basics/Operators.fun +++ b/shared/src/test/diff/basics/Operators.fun @@ -16,7 +16,7 @@ a + b //│ Parsed: +(...a)(...{b}); //│ Desugared: +(...a)(...{b}) -//│ AST: App(App(Var(+), Var(a)), Blk(...)) +//│ AST: App(App(Var(+),Var(a)),Blk(List(Var(b)))) //│ res: int :pe @@ -31,7 +31,7 @@ succ a + c //│ Parsed: +(...(succ(...a)))(...{+(...b)(...{c})}); //│ Desugared: +(...(succ(...a)))(...{+(...b)(...{c})}) -//│ AST: App(App(Var(+), App(Var(succ), Var(a))), Blk(...)) +//│ AST: App(App(Var(+),App(Var(succ),Var(a))),Blk(List(App(App(Var(+),Var(b)),Blk(List(Var(c))))))) //│ res: int :p @@ -40,7 +40,7 @@ succ / a + c //│ Parsed: succ(...(+(...a)(...{+(...b)(...{c})}))); //│ Desugared: succ(...(+(...a)(...{+(...b)(...{c})}))) -//│ AST: App(Var(succ), App(App(Var(+), Var(a)), Blk(...))) +//│ AST: App(Var(succ),App(App(Var(+),Var(a)),Blk(List(App(App(Var(+),Var(b)),Blk(List(Var(c)))))))) //│ res: int :p @@ -55,11 +55,11 @@ a + d //│ Parsed: +(...a)(...b); +(...(+(...a)(...b)))(...c); +(...(+(...(+(...a)(...b)))(...c)))(...d); //│ Desugared: +(...a)(...b) -//│ AST: App(App(Var(+), Var(a)), Var(b)) +//│ AST: App(App(Var(+),Var(a)),Var(b)) //│ Desugared: +(...(+(...a)(...b)))(...c) -//│ AST: App(App(Var(+), App(App(Var(+), Var(a)), Var(b))), Var(c)) +//│ AST: App(App(Var(+),App(App(Var(+),Var(a)),Var(b))),Var(c)) //│ Desugared: +(...(+(...(+(...a)(...b)))(...c)))(...d) -//│ AST: App(App(Var(+), App(App(Var(+), App(App(Var(+), Var(a)), Var(b))), Var(c))), Var(d)) +//│ AST: App(App(Var(+),App(App(Var(+),App(App(Var(+),Var(a)),Var(b))),Var(c))),Var(d)) //│ res: int //│ res: int //│ res: int @@ -74,7 +74,7 @@ a + d //│ Parsed: +(...(+(...(+(...a)(...b)))(...(+(...(+(...c)(...1)))(...(+(...2)(...3)))))))(...d); //│ Desugared: +(...(+(...(+(...a)(...b)))(...(+(...(+(...c)(...1)))(...(+(...2)(...3)))))))(...d) -//│ AST: App(App(Var(+), App(App(Var(+), App(App(Var(+), Var(a)), Var(b))), App(App(Var(+), App(App(Var(+), Var(c)), IntLit(1))), App(App(Var(+), IntLit(2)), IntLit(3))))), Var(d)) +//│ AST: App(App(Var(+),App(App(Var(+),App(App(Var(+),Var(a)),Var(b))),App(App(Var(+),App(App(Var(+),Var(c)),IntLit(1))),App(App(Var(+),IntLit(2)),IntLit(3))))),Var(d)) //│ res: int :pe @@ -112,7 +112,7 @@ succ + c //│ Parsed: +(...(succ(...{+(...a)(...b)})))(...c); //│ Desugared: +(...(succ(...{+(...a)(...b)})))(...c) -//│ AST: App(App(Var(+), App(Var(succ), Blk(...))), Var(c)) +//│ AST: App(App(Var(+),App(Var(succ),Blk(List(App(App(Var(+),Var(a)),Var(b)))))),Var(c)) //│ res: int // Maybe allow this as it lets us nicely align the operands? diff --git a/shared/src/test/diff/basics/Slashes.fun b/shared/src/test/diff/basics/Slashes.fun index ef7aef704..d4c331609 100644 --- a/shared/src/test/diff/basics/Slashes.fun +++ b/shared/src/test/diff/basics/Slashes.fun @@ -23,7 +23,7 @@ x => succ / succ / x + 1 foo / x => succ / succ / x //│ Parsed: foo(...((...x) => succ(...(succ(...x))))); //│ Desugared: foo(...((...x) => succ(...(succ(...x))))) -//│ AST: App(Var(foo), Lam(Var(x), App(Var(succ), App(Var(succ), Var(x))))) +//│ AST: App(Var(foo),Lam(Var(x),App(Var(succ),App(Var(succ),Var(x))))) //│ res: int :e diff --git a/shared/src/test/diff/mlscript/Basics.mls b/shared/src/test/diff/mlscript/Basics.mls index 2af98bf08..7ecdfea0f 100644 --- a/shared/src/test/diff/mlscript/Basics.mls +++ b/shared/src/test/diff/mlscript/Basics.mls @@ -96,7 +96,7 @@ def f (x y z) = add x y //│ ╙── ^^^^^ //│ f: error -> int //│ Code generation encountered an error: -//│ term App(App(Var(x), Tup(_: Var(y))), Tup(_: Var(z))) is not a valid pattern +//│ term App(App(Var(x),Tup(List((None,Fld(_,Var(y)))))),Tup(List((None,Fld(_,Var(z)))))) is not a valid pattern f 1 //│ res: int diff --git a/shared/src/test/diff/mlscript/ByNameByValue.mls b/shared/src/test/diff/mlscript/ByNameByValue.mls index 3e8764077..a9b9b9b18 100644 --- a/shared/src/test/diff/mlscript/ByNameByValue.mls +++ b/shared/src/test/diff/mlscript/ByNameByValue.mls @@ -16,7 +16,7 @@ def incr x = x.a <- x.a + 1 def gensym = let n = { mut a = 0 } in fun () -> (incr n, n) //│ Parsed: def gensym: let n = {mut a: 0} in () => [incr(n,), n,]; //│ Desugared: def gensym: let n = {mut a: 0} in () => [incr(n,), n,] -//│ AST: Def(false, gensym, Let(false, n, Rcd(Var(a) = IntLit(0)), Lam(Tup(), Tup(_: App(Var(incr), Tup(_: Var(n))), _: Var(n)))), true) +//│ AST: Def(false,Var(gensym),Left(Let(false,Var(n),Rcd(List((Var(a),Fld(m,IntLit(0))))),Lam(Tup(List()),Tup(List((None,Fld(_,App(Var(incr),Tup(List((None,Fld(_,Var(n)))))))), (None,Fld(_,Var(n)))))))),true) //│ // Query 1 //│ globalThis.gensym = function gensym() { //│ return (((n) => () => [ @@ -35,7 +35,7 @@ def gensym = let n = { mut a = 0 } in fun () -> (incr n, n) gensym1 = let n = { mut a = 0 } in fun () -> (incr n, n) //│ Parsed: let gensym1 = let n = {mut a: 0} in () => [incr(n,), n,]; //│ Desugared: def gensym1: let n = {mut a: 0} in () => [incr(n,), n,] -//│ AST: Def(false, gensym1, Let(false, n, Rcd(Var(a) = IntLit(0)), Lam(Tup(), Tup(_: App(Var(incr), Tup(_: Var(n))), _: Var(n)))), false) +//│ AST: Def(false,Var(gensym1),Left(Let(false,Var(n),Rcd(List((Var(a),Fld(m,IntLit(0))))),Lam(Tup(List()),Tup(List((None,Fld(_,App(Var(incr),Tup(List((None,Fld(_,Var(n)))))))), (None,Fld(_,Var(n)))))))),false) //│ // Query 1 //│ globalThis.gensym1 = ((n) => () => [ //│ incr(n), diff --git a/shared/src/test/diff/mlscript/MultiArgs.mls b/shared/src/test/diff/mlscript/MultiArgs.mls index 62e7a8090..9f04e7f15 100644 --- a/shared/src/test/diff/mlscript/MultiArgs.mls +++ b/shared/src/test/diff/mlscript/MultiArgs.mls @@ -75,9 +75,9 @@ f = fun (x, y) -> add x y f(1, 2) //│ Parsed: let f = (x, y,) => add(x,)(y,); f(1, 2,); //│ Desugared: def f: (x, y,) => add(x,)(y,) -//│ AST: Def(false, f, Lam(Tup(_: Var(x), _: Var(y)), App(App(Var(add), Tup(_: Var(x))), Tup(_: Var(y)))), false) +//│ AST: Def(false,Var(f),Left(Lam(Tup(List((None,Fld(_,Var(x))), (None,Fld(_,Var(y))))),App(App(Var(add),Tup(List((None,Fld(_,Var(x)))))),Tup(List((None,Fld(_,Var(y)))))))),false) //│ Desugared: f(1, 2,) -//│ AST: App(Var(f), Tup(_: IntLit(1), _: IntLit(2))) +//│ AST: App(Var(f),Tup(List((None,Fld(_,IntLit(1))), (None,Fld(_,IntLit(2)))))) //│ f: (int, int,) -> int //│ = [Function: f] //│ res: int @@ -119,9 +119,9 @@ f = fun ((x, y)) -> add x y f((1, 2)) //│ Parsed: let f = ('(' [x, y,] ')',) => add(x,)(y,); f('(' [1, 2,] ')',); //│ Desugared: def f: ('(' [x, y,] ')',) => add(x,)(y,) -//│ AST: Def(false, f, Lam(Tup(_: Bra(rcd = false, Tup(_: Var(x), _: Var(y)))), App(App(Var(add), Tup(_: Var(x))), Tup(_: Var(y)))), false) +//│ AST: Def(false,Var(f),Left(Lam(Tup(List((None,Fld(_,Bra(false,Tup(List((None,Fld(_,Var(x))), (None,Fld(_,Var(y)))))))))),App(App(Var(add),Tup(List((None,Fld(_,Var(x)))))),Tup(List((None,Fld(_,Var(y)))))))),false) //│ Desugared: f('(' [1, 2,] ')',) -//│ AST: App(Var(f), Tup(_: Bra(rcd = false, Tup(_: IntLit(1), _: IntLit(2))))) +//│ AST: App(Var(f),Tup(List((None,Fld(_,Bra(false,Tup(List((None,Fld(_,IntLit(1))), (None,Fld(_,IntLit(2))))))))))) //│ f: ((int, int,),) -> int //│ = [Function: f1] //│ res: int diff --git a/shared/src/test/diff/mlscript/Mut.mls b/shared/src/test/diff/mlscript/Mut.mls index 5abffdda4..7cbd3ed19 100644 --- a/shared/src/test/diff/mlscript/Mut.mls +++ b/shared/src/test/diff/mlscript/Mut.mls @@ -613,7 +613,7 @@ b1.x <- 1 + 2 <- 4 //│ ║ l.550: b1.x <- 1 + 2 <- 4 //│ ╙── ^ //│ Code generation encountered an error: -//│ illegal assignemnt left-hand side: Bra(rcd = false, Assign(Sel(Var(mt1), 0), Sel(Var(b1), t))) +//│ illegal assignemnt left-hand side: Bra(false,Assign(Sel(Var(mt1),Var(0)),Sel(Var(b1),Var(t)))) def f : {mut 0 : int} -> int -> unit def g : (mut int, bool) -> int -> unit diff --git a/shared/src/test/diff/mlscript/Ops.mls b/shared/src/test/diff/mlscript/Ops.mls index 837b2c09e..fb99294cf 100644 --- a/shared/src/test/diff/mlscript/Ops.mls +++ b/shared/src/test/diff/mlscript/Ops.mls @@ -3,7 +3,7 @@ 2 + 2 //│ Parsed: +(2,)(2,); //│ Desugared: +(2,)(2,) -//│ AST: App(App(Var(+), Tup(_: IntLit(2))), Tup(_: IntLit(2))) +//│ AST: App(App(Var(+),Tup(List((None,Fld(_,IntLit(2)))))),Tup(List((None,Fld(_,IntLit(2)))))) //│ res: int //│ = 4 @@ -11,7 +11,7 @@ 1 + 2 * 2 + 3 //│ Parsed: +(+(1,)(*(2,)(2,),),)(3,); //│ Desugared: +(+(1,)(*(2,)(2,),),)(3,) -//│ AST: App(App(Var(+), Tup(_: App(App(Var(+), Tup(_: IntLit(1))), Tup(_: App(App(Var(*), Tup(_: IntLit(2))), Tup(_: IntLit(2))))))), Tup(_: IntLit(3))) +//│ AST: App(App(Var(+),Tup(List((None,Fld(_,App(App(Var(+),Tup(List((None,Fld(_,IntLit(1)))))),Tup(List((None,Fld(_,App(App(Var(*),Tup(List((None,Fld(_,IntLit(2)))))),Tup(List((None,Fld(_,IntLit(2)))))))))))))))),Tup(List((None,Fld(_,IntLit(3)))))) //│ res: int //│ = 8 @@ -20,7 +20,7 @@ 1 + 2 / 2 + 3 //│ Parsed: +(+(1,)(/(2,)(2,),),)(3,); //│ Desugared: +(+(1,)(/(2,)(2,),),)(3,) -//│ AST: App(App(Var(+), Tup(_: App(App(Var(+), Tup(_: IntLit(1))), Tup(_: App(App(Var(/), Tup(_: IntLit(2))), Tup(_: IntLit(2))))))), Tup(_: IntLit(3))) +//│ AST: App(App(Var(+),Tup(List((None,Fld(_,App(App(Var(+),Tup(List((None,Fld(_,IntLit(1)))))),Tup(List((None,Fld(_,App(App(Var(/),Tup(List((None,Fld(_,IntLit(2)))))),Tup(List((None,Fld(_,IntLit(2)))))))))))))))),Tup(List((None,Fld(_,IntLit(3)))))) //│ ╔══[ERROR] Type mismatch in operator application: //│ ║ l.20: 1 + 2 / 2 + 3 //│ ║ ^^^^^^^^^ @@ -36,7 +36,7 @@ 1 |> 2 || 3 //│ Parsed: ||(|>(1,)(2,),)(3,); //│ Desugared: ||(|>(1,)(2,),)(3,) -//│ AST: App(App(Var(||), Tup(_: App(App(Var(|>), Tup(_: IntLit(1))), Tup(_: IntLit(2))))), Tup(_: IntLit(3))) +//│ AST: App(App(Var(||),Tup(List((None,Fld(_,App(App(Var(|>),Tup(List((None,Fld(_,IntLit(1)))))),Tup(List((None,Fld(_,IntLit(2))))))))))),Tup(List((None,Fld(_,IntLit(3)))))) //│ ╔══[ERROR] identifier not found: |> //│ ║ l.36: 1 |> 2 || 3 //│ ╙── ^^ @@ -54,7 +54,7 @@ true || false && true || false //│ Parsed: ||(||(true,)(&&(false,)(true,),),)(false,); //│ Desugared: ||(||(true,)(&&(false,)(true,),),)(false,) -//│ AST: App(App(Var(||), Tup(_: App(App(Var(||), Tup(_: Var(true))), Tup(_: App(App(Var(&&), Tup(_: Var(false))), Tup(_: Var(true))))))), Tup(_: Var(false))) +//│ AST: App(App(Var(||),Tup(List((None,Fld(_,App(App(Var(||),Tup(List((None,Fld(_,Var(true)))))),Tup(List((None,Fld(_,App(App(Var(&&),Tup(List((None,Fld(_,Var(false)))))),Tup(List((None,Fld(_,Var(true)))))))))))))))),Tup(List((None,Fld(_,Var(false)))))) //│ res: bool //│ = true diff --git a/shared/src/test/diff/mlscript/Weird.mls b/shared/src/test/diff/mlscript/Weird.mls index 9aa518f72..2b658ed4e 100644 --- a/shared/src/test/diff/mlscript/Weird.mls +++ b/shared/src/test/diff/mlscript/Weird.mls @@ -41,9 +41,9 @@ class C def n: C{} //│ Parsed: rec def n: C; {}; //│ Desugared: rec def n: C -//│ AST: Def(true, n, PolyType(List(),TypeName(C)), true) +//│ AST: Def(true,Var(n),Right(PolyType(List(),TypeName(C))),true) //│ Desugared: {} -//│ AST: Rcd() +//│ AST: Rcd(List()) //│ n: C //│ = //│ res: anything diff --git a/shared/src/test/diff/nu/AbstractClasses.mls b/shared/src/test/diff/nu/AbstractClasses.mls index ab09dd59b..540f361d7 100644 --- a/shared/src/test/diff/nu/AbstractClasses.mls +++ b/shared/src/test/diff/nu/AbstractClasses.mls @@ -51,7 +51,7 @@ new Foo(1) { fun f = id } //│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^^^ //│ error //│ Code generation encountered an error: -//│ cannot generate code for term Rft(App(NuNew(Var(Foo)), Tup(_: IntLit(1))), ...) +//│ cannot generate code for term Rft(App(NuNew(Var(Foo)),Tup(List((None,Fld(_,IntLit(1)))))),TypingUnit(List(NuFunDef(None,Var(f),None,List(),Left(Var(id)))))) abstract class Bar extends Foo(1) diff --git a/shared/src/test/diff/nu/BadBlocks.mls b/shared/src/test/diff/nu/BadBlocks.mls index eedcd08df..b76b35c08 100644 --- a/shared/src/test/diff/nu/BadBlocks.mls +++ b/shared/src/test/diff/nu/BadBlocks.mls @@ -176,5 +176,5 @@ fun test = (new { //│ ╙── ^ //│ fun test: error //│ Code generation encountered an error: -//│ Unsupported `new` class term: Bra(rcd = true, Rcd(Var(res) = Var(res))) +//│ Unsupported `new` class term: Bra(true,Rcd(List((Var(res),Fld(g,Var(res)))))) diff --git a/shared/src/test/diff/nu/LamPatterns.mls b/shared/src/test/diff/nu/LamPatterns.mls index cb78cf349..7458108e6 100644 --- a/shared/src/test/diff/nu/LamPatterns.mls +++ b/shared/src/test/diff/nu/LamPatterns.mls @@ -14,7 +14,7 @@ Some(x) => x //│ ╙── ^ //│ error -> error //│ Code generation encountered an error: -//│ term App(Var(Some), Tup(_: Var(x))) is not a valid pattern +//│ term App(Var(Some),Tup(List((None,Fld(_,Var(x)))))) is not a valid pattern :js // FIXME type diff --git a/shared/src/test/diff/nu/LetRec.mls b/shared/src/test/diff/nu/LetRec.mls index 74f8a3f58..f990934e2 100644 --- a/shared/src/test/diff/nu/LetRec.mls +++ b/shared/src/test/diff/nu/LetRec.mls @@ -129,7 +129,7 @@ let rec lol = () => lol :p let rec f = 1 //│ |#let| |#rec| |f| |#=| |1| -//│ AST: TypingUnit(NuFunDef(Some(true), f, None, [], IntLit(1))) +//│ AST: TypingUnit(List(NuFunDef(Some(true),Var(f),None,List(),Left(IntLit(1))))) //│ Parsed: let rec f = 1; //│ let rec f: 1 //│ f diff --git a/shared/src/test/diff/nu/NewNew.mls b/shared/src/test/diff/nu/NewNew.mls index 8ab334a69..b043836ce 100644 --- a/shared/src/test/diff/nu/NewNew.mls +++ b/shared/src/test/diff/nu/NewNew.mls @@ -167,7 +167,7 @@ new PoInt['_] //│ ╙── ^ //│ PoInt[nothing] | error //│ Code generation encountered an error: -//│ Unsupported `new` class term: TyApp(Var(PoInt), List('_)) +//│ Unsupported `new` class term: TyApp(Var(PoInt),List('_)) :e new PoInt[Str](0, 0) @@ -176,7 +176,7 @@ new PoInt[Str](0, 0) //│ ╙── ^^^^^^^^^^^^^^^^^^^^ //│ PoInt[0] //│ Code generation encountered an error: -//│ Unsupported `new` class term: TyApp(Var(PoInt), List(TypeName(Str))) +//│ Unsupported `new` class term: TyApp(Var(PoInt),List(TypeName(Str))) type T = PoInt[Str] //│ type T = PoInt[Str] @@ -211,7 +211,7 @@ let origin = new PoInt[Int](0, 0) //│ ╙── ^^^^^^^^^^^^^^^^^^^^ //│ let origin: PoInt[0] //│ Code generation encountered an error: -//│ Unsupported `new` class term: TyApp(Var(PoInt), List(TypeName(Int))) +//│ Unsupported `new` class term: TyApp(Var(PoInt),List(TypeName(Int))) :e // TODO support @@ -221,7 +221,7 @@ new {} //│ ╙── ^^ //│ error //│ Code generation encountered an error: -//│ Unsupported `new` class term: Bra(rcd = true, Rcd()) +//│ Unsupported `new` class term: Bra(true,Rcd(List())) :pe :e @@ -247,7 +247,7 @@ new //│ ╙── ^ //│ error //│ Code generation encountered an error: -//│ Unsupported `new` class term: Blk(...) +//│ Unsupported `new` class term: Blk(List(Asc(Var(x),Literal(IntLit(0))))) @@ -302,6 +302,6 @@ module A { class B } new A.B //│ B //│ Code generation encountered an error: -//│ Unsupported `new` class term: Sel(Var(A), B) +//│ Unsupported `new` class term: Sel(Var(A),Var(B)) diff --git a/shared/src/test/diff/nu/OpLam.mls b/shared/src/test/diff/nu/OpLam.mls index 15b57dbca..b7eb786b5 100644 --- a/shared/src/test/diff/nu/OpLam.mls +++ b/shared/src/test/diff/nu/OpLam.mls @@ -107,6 +107,6 @@ x => x.y => y //│ ╙── ^ //│ anything -> error -> error //│ Code generation encountered an error: -//│ term Sel(Var(x), y) is not a valid pattern +//│ term Sel(Var(x),Var(y)) is not a valid pattern diff --git a/shared/src/test/diff/nu/OverrideShorthand.mls b/shared/src/test/diff/nu/OverrideShorthand.mls index 25db2319d..2bd823530 100644 --- a/shared/src/test/diff/nu/OverrideShorthand.mls +++ b/shared/src/test/diff/nu/OverrideShorthand.mls @@ -10,7 +10,7 @@ class Pair(lhs: Int, rhs: Int) :e fun f(override Pair(x, y)) = x + y //│ |#fun| |f|(|#override| |Pair|(|x|,| |y|)|)| |#=| |x| |+| |y| -//│ AST: TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(_$0)), If(IfOpApp(Var(_$0), Var(is), IfThen(App(Var(Pair), Tup(_: Var(x), _: Var(y))), App(Var(+), Tup(_: Var(x), _: Var(y))), Some(App(Sel(Super(), f), Tup(_: Var(_$0)))))))) +//│ AST: TypingUnit(List(NuFunDef(None,Var(f),None,List(),Left(Lam(Tup(List((None,Fld(_,Var(_$0))))),If(IfOpApp(Var(_$0),Var(is),IfThen(App(Var(Pair),Tup(List((None,Fld(_,Var(x))), (None,Fld(_,Var(y)))))),App(Var(+),Tup(List((None,Fld(_,Var(x))), (None,Fld(_,Var(y)))))))),Some(App(Sel(Super(),Var(f)),Tup(List((None,Fld(_,Var(_$0))))))))))))) //│ Parsed: fun f = (_$0,) => if _$0 is (Pair(x, y,)) then +(x, y,) else (super).f(_$0,); //│ ╔══[ERROR] identifier not found: super //│ ║ l.11: fun f(override Pair(x, y)) = x + y @@ -46,7 +46,7 @@ fun f(override Pair(x, y), z) = x + y //│ ╙── ^ //│ fun f: (error, anything) -> Int //│ Code generation encountered an error: -//│ term App(Var(Pair), Tup(_: Var(x), _: Var(y))) is not a valid pattern +//│ term App(Var(Pair),Tup(List((None,Fld(_,Var(x))), (None,Fld(_,Var(y)))))) is not a valid pattern // TODO diff --git a/shared/src/test/diff/nu/Refinements.mls b/shared/src/test/diff/nu/Refinements.mls index 2311c3c10..62a2a6790 100644 --- a/shared/src/test/diff/nu/Refinements.mls +++ b/shared/src/test/diff/nu/Refinements.mls @@ -83,7 +83,7 @@ let r = new {} //│ ╙── ^^ //│ let r: error //│ Code generation encountered an error: -//│ Unsupported `new` class term: Bra(rcd = true, Rcd()) +//│ Unsupported `new` class term: Bra(true,Rcd(List())) :ge r : Object diff --git a/shared/src/test/diff/nu/RightAssocOps.mls b/shared/src/test/diff/nu/RightAssocOps.mls index 15a34aaad..b692e7fb0 100644 --- a/shared/src/test/diff/nu/RightAssocOps.mls +++ b/shared/src/test/diff/nu/RightAssocOps.mls @@ -30,7 +30,7 @@ fun (++) conc(xs, ys) = [xs, ys] :p 1 +: "a" ++ "b" :+ 2 //│ |1| |+:| |"a"| |++| |"b"| |:+| |2| -//│ AST: TypingUnit(App(Var(+:), Tup(_: IntLit(1), _: App(Var(:+), Tup(_: App(Var(++), Tup(_: StrLit(a), _: StrLit(b))), _: IntLit(2)))))) +//│ AST: TypingUnit(List(App(Var(+:),Tup(List((None,Fld(_,IntLit(1))), (None,Fld(_,App(Var(:+),Tup(List((None,Fld(_,App(Var(++),Tup(List((None,Fld(_,StrLit(a))), (None,Fld(_,StrLit(b)))))))), (None,Fld(_,IntLit(2))))))))))))) //│ Parsed: +:(1, :+(++("a", "b",), 2,),); //│ [[Int], [["a", "b"], [Int]]] //│ res @@ -39,7 +39,7 @@ fun (++) conc(xs, ys) = [xs, ys] :p 1 +: "a" :+ 2 ++ "b" //│ |1| |+:| |"a"| |:+| |2| |++| |"b"| -//│ AST: TypingUnit(App(Var(+:), Tup(_: IntLit(1), _: App(Var(++), Tup(_: App(Var(:+), Tup(_: StrLit(a), _: IntLit(2))), _: StrLit(b)))))) +//│ AST: TypingUnit(List(App(Var(+:),Tup(List((None,Fld(_,IntLit(1))), (None,Fld(_,App(Var(++),Tup(List((None,Fld(_,App(Var(:+),Tup(List((None,Fld(_,StrLit(a))), (None,Fld(_,IntLit(2)))))))), (None,Fld(_,StrLit(b))))))))))))) //│ Parsed: +:(1, ++(:+("a", 2,), "b",),); //│ [[Int], [["a", [Int]], "b"]] //│ res @@ -49,7 +49,7 @@ fun (++) conc(xs, ys) = [xs, ys] :e 1 +: "a" ++ 2 +: "b" //│ |1| |+:| |"a"| |++| |2| |+:| |"b"| -//│ AST: TypingUnit(App(Var(+:), Tup(_: IntLit(1), _: App(Var(+:), Tup(_: App(Var(++), Tup(_: StrLit(a), _: IntLit(2))), _: StrLit(b)))))) +//│ AST: TypingUnit(List(App(Var(+:),Tup(List((None,Fld(_,IntLit(1))), (None,Fld(_,App(Var(+:),Tup(List((None,Fld(_,App(Var(++),Tup(List((None,Fld(_,StrLit(a))), (None,Fld(_,IntLit(2)))))))), (None,Fld(_,StrLit(b))))))))))))) //│ Parsed: +:(1, +:(++("a", 2,), "b",),); //│ ╔══[ERROR] Type mismatch in operator application: //│ ║ l.50: 1 +: "a" ++ 2 +: "b" diff --git a/shared/src/test/diff/nu/TODO_Classes.mls b/shared/src/test/diff/nu/TODO_Classes.mls index bc37f00a7..dec21bdd1 100644 --- a/shared/src/test/diff/nu/TODO_Classes.mls +++ b/shared/src/test/diff/nu/TODO_Classes.mls @@ -80,7 +80,7 @@ new C { val x = 1 } //│ ╙── ^^^^^^^^^^^^^^^^^^^ //│ error //│ Code generation encountered an error: -//│ cannot generate code for term Rft(NuNew(Var(C)), ...) +//│ cannot generate code for term Rft(NuNew(Var(C)),TypingUnit(List(NuFunDef(Some(false),Var(x),None,List(),Left(IntLit(1)))))) diff --git a/shared/src/test/diff/parser/BasicSyntax.mls b/shared/src/test/diff/parser/BasicSyntax.mls index 5c4c9b09d..f525ad016 100644 --- a/shared/src/test/diff/parser/BasicSyntax.mls +++ b/shared/src/test/diff/parser/BasicSyntax.mls @@ -319,18 +319,18 @@ f[1, 2, 3] f{} //│ |f|{||}| -//│ Parsed: {f { ‹› }} +//│ Parsed: {f {}} f{1} //│ |f|{|1|}| -//│ Parsed: {f { ‹1› }} +//│ Parsed: {f {1}} f{1, 2, 3} //│ |f|{|1|,| |2|,| |3|}| //│ ╔══[PARSE ERROR] Unexpected comma here //│ ║ l.328: f{1, 2, 3} //│ ╙── ^ -//│ Parsed: {f { ‹1› }} +//│ Parsed: {f {1}} f 1,, 2 diff --git a/shared/src/test/diff/parser/New.mls b/shared/src/test/diff/parser/New.mls index 2ce52058d..f10a90908 100644 --- a/shared/src/test/diff/parser/New.mls +++ b/shared/src/test/diff/parser/New.mls @@ -38,19 +38,19 @@ new A of 1, 2, 3 new A { fun x = 1 } //│ |#new| |A| |{| |#fun| |x| |#=| |1| |}| -//│ Parsed: {new A { ‹fun x = 1› }} +//│ Parsed: {new A {fun x = 1}} new A() { fun x = 1 } //│ |#new| |A|(||)| |{| |#fun| |x| |#=| |1| |}| -//│ Parsed: {(new A)() { ‹fun x = 1› }} +//│ Parsed: {(new A)() {fun x = 1}} new A(1, 2, 3) { fun x = 1 } //│ |#new| |A|(|1|,| |2|,| |3|)| |{| |#fun| |x| |#=| |1| |}| -//│ Parsed: {(new A)(1, 2, 3,) { ‹fun x = 1› }} +//│ Parsed: {(new A)(1, 2, 3,) {fun x = 1}} new A of 1, 2, 3 { fun x = 1 } //│ |#new| |A| |#of| |1|,| |2|,| |3| |{| |#fun| |x| |#=| |1| |}| -//│ Parsed: {new A(1, 2, 3 { ‹fun x = 1› },)} +//│ Parsed: {new A(1, 2, 3 {fun x = 1},)} :pe diff --git a/shared/src/test/diff/ucs/LeadingAnd.mls b/shared/src/test/diff/ucs/LeadingAnd.mls index faa751e46..2303e4ebb 100644 --- a/shared/src/test/diff/ucs/LeadingAnd.mls +++ b/shared/src/test/diff/ucs/LeadingAnd.mls @@ -23,7 +23,7 @@ fun f(a, b) = if a is Some(av) and b is Some(bv) then av + bv //│ |#fun| |f|(|a|,| |b|)| |#=| |#if| |a| |is| |Some|(|av|)|→|and| |b| |is| |Some|(|bv|)|↵|#then| |av| |+| |bv|←| -//│ AST: TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(a), _: Var(b)), If(IfOpApp(Var(a), Var(is), I; f; O; p; s; A; p; p; (; A; p; p; (; V; a; r; (; S; o; m; e; ); ,; ; T; u; p; (; _; :; ; V; a; r; (; a; v; ); ); ); ,; ; <; i; t; e; r; a; t; o; r; >, None)))) +//│ AST: TypingUnit(List(NuFunDef(None,Var(f),None,List(),Left(Lam(Tup(List((None,Fld(_,Var(a))), (None,Fld(_,Var(b))))),If(IfOpApp(Var(a),Var(is),IfOpsApp(App(Var(Some),Tup(List((None,Fld(_,Var(av)))))),List((Var(and),IfThen(App(Var(is),Tup(List((None,Fld(_,Var(b))), (None,Fld(_,App(Var(Some),Tup(List((None,Fld(_,Var(bv))))))))))),App(Var(+),Tup(List((None,Fld(_,Var(av))), (None,Fld(_,Var(bv))))))))))),None)))))) //│ Parsed: fun f = (a, b,) => if a is Some(av,) ‹· and (is(b, Some(bv,),)) then +(av, bv,)›; //│ fun f: (Some[Int], Some[Int]) -> Int @@ -34,7 +34,7 @@ fun f(a, b) = if a is and b is Some(bv) then av + bv //│ |#fun| |f|(|a|,| |b|)| |#=| |#if| |a| |is|→|Some|(|av|)|→|and| |b| |is| |Some|(|bv|)|↵|#then| |av| |+| |bv|←|←| -//│ AST: TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(a), _: Var(b)), If(IfOpApp(Var(a), Var(is), IfBlock(I; f; O; p; s; A; p; p; (; A; p; p; (; V; a; r; (; S; o; m; e; ); ,; ; T; u; p; (; _; :; ; V; a; r; (; a; v; ); ); ); ,; ; <; i; t; e; r; a; t; o; r; >), None)))) +//│ AST: TypingUnit(List(NuFunDef(None,Var(f),None,List(),Left(Lam(Tup(List((None,Fld(_,Var(a))), (None,Fld(_,Var(b))))),If(IfOpApp(Var(a),Var(is),IfBlock(List(Left(IfOpsApp(App(Var(Some),Tup(List((None,Fld(_,Var(av)))))),List((Var(and),IfThen(App(Var(is),Tup(List((None,Fld(_,Var(b))), (None,Fld(_,App(Var(Some),Tup(List((None,Fld(_,Var(bv))))))))))),App(Var(+),Tup(List((None,Fld(_,Var(av))), (None,Fld(_,Var(bv)))))))))))))),None)))))) //│ Parsed: fun f = (a, b,) => if a is ‹Some(av,) ‹· and (is(b, Some(bv,),)) then +(av, bv,)››; //│ ╔══[ERROR] Illegal pattern `and` //│ ║ l.34: and b is Some(bv) diff --git a/shared/src/test/diff/ucs/SplitOps.mls b/shared/src/test/diff/ucs/SplitOps.mls index 03ee227f5..c966e4b0a 100644 --- a/shared/src/test/diff/ucs/SplitOps.mls +++ b/shared/src/test/diff/ucs/SplitOps.mls @@ -93,10 +93,10 @@ fun f(a, b, c) = if a == 0 and b is B() and c is C() then 0 //│ |#fun| |f|(|a|,| |b|,| |c|)| |#=|→|#if| |a|→|==| |0| |and| |b| |is| |B|(||)| |and| |c| |is| |C|(||)| |#then| |0|←|←| -//│ AST: TypingUnit(NuFunDef(None, f, None, [], Lam(Tup(_: Var(a), _: Var(b), _: Var(c)), Blk(...)))) +//│ AST: TypingUnit(List(NuFunDef(None,Var(f),None,List(),Left(Lam(Tup(List((None,Fld(_,Var(a))), (None,Fld(_,Var(b))), (None,Fld(_,Var(c))))),Blk(List(If(IfOpsApp(Var(a),List((Var(==),IfThen(App(App(Var(and),Tup(List((None,Fld(_,App(App(Var(and),Tup(List((None,Fld(_,IntLit(0)))))),Tup(List((None,Fld(_,App(App(Var(is),Tup(List((None,Fld(_,Var(b)))))),Tup(List((None,Fld(_,App(Var(B),Tup(List()))))))))))))))))),Tup(List((None,Fld(_,App(App(Var(is),Tup(List((None,Fld(_,Var(c)))))),Tup(List((None,Fld(_,App(Var(C),Tup(List())))))))))))),IntLit(0))))),None)))))))) //│ Parsed: fun f = (a, b, c,) => {if a ‹· == (and(and(0,)(is(b,)(B(),),),)(is(c,)(C(),),)) then 0›}; //│ Desugared: rec def f: (a, b, c,) => {if a ‹· == (and(and(0,)(is(b,)(B(),),),)(is(c,)(C(),),)) then 0›} -//│ AST: Def(true, f, Lam(Tup(_: Var(a), _: Var(b), _: Var(c)), Blk(...)), true) +//│ AST: Def(true,Var(f),Left(Lam(Tup(List((None,Fld(_,Var(a))), (None,Fld(_,Var(b))), (None,Fld(_,Var(c))))),Blk(List(If(IfOpsApp(Var(a),List((Var(==),IfThen(App(App(Var(and),Tup(List((None,Fld(_,App(App(Var(and),Tup(List((None,Fld(_,IntLit(0)))))),Tup(List((None,Fld(_,App(App(Var(is),Tup(List((None,Fld(_,Var(b)))))),Tup(List((None,Fld(_,App(Var(B),Tup(List()))))))))))))))))),Tup(List((None,Fld(_,App(App(Var(is),Tup(List((None,Fld(_,Var(c)))))),Tup(List((None,Fld(_,App(Var(C),Tup(List())))))))))))),IntLit(0))))),None))))),true) //│ ╔══[ERROR] The case when this is false is not handled: ==(a,)(0,) //│ ║ l.93: if a //│ ║ ^ diff --git a/shared/src/test/scala/mlscript/DiffTests.scala b/shared/src/test/scala/mlscript/DiffTests.scala index 2edc36dfc..b5772437f 100644 --- a/shared/src/test/scala/mlscript/DiffTests.scala +++ b/shared/src/test/scala/mlscript/DiffTests.scala @@ -427,10 +427,10 @@ class DiffTests val res = p.parseAll(p.typingUnit) if (parseOnly) - output("Parsed: " + res.showDbg) + output(s"Parsed: ${res.showDbg}") if (mode.showParse) - output("AST: " + mlscript.codegen.Helpers.inspect(res)) + output(s"AST: $res") postProcess(mode, basePath, testName, res).foreach(output) @@ -459,7 +459,7 @@ class DiffTests case Success(p, index) => if (mode.expectParseErrors && !newParser) failures += blockLineNum - if (mode.showParse || mode.dbgParsing) output("Parsed: " + p) + if (mode.showParse || mode.dbgParsing) output("Parsed: " + p.showDbg) // if (mode.isDebugging) typer.resetState() if (mode.stats) typer.resetStats() typer.dbg = mode.dbg @@ -619,10 +619,10 @@ class DiffTests report(diags) if (mode.showParse) { - typeDefs.foreach(td => output("Desugared: " + td)) + typeDefs.foreach(td => output("Desugared: " + td.showDbg)) stmts.foreach { s => - output("Desugared: " + s) - output("AST: " + mlscript.codegen.Helpers.inspect(s)) + output("Desugared: " + s.showDbg) + output(s"AST: $s") } } @@ -769,7 +769,7 @@ class DiffTests declared += nme.name -> ty_sch val exp = getType(ty_sch, N) if (mode.generateTsDeclarations) tsTypegenCodeBuilder.addTypeGenTermDefinition(exp, Some(nme.name)) - S(nme.name -> (s"$nme: ${exp.show(newDefs)}" :: Nil)) + S(nme.name -> (s"${nme.name}: ${exp.show(newDefs)}" :: Nil)) // statement is defined and has a body/definition case d @ Def(isrec, nme, L(rhs), isByname) => @@ -784,7 +784,7 @@ class DiffTests case N => ctx += nme.name -> typer.VarSymbol(ty_sch, nme) if (mode.generateTsDeclarations) tsTypegenCodeBuilder.addTypeGenTermDefinition(exp, Some(nme.name)) - s"$nme: ${exp.show(newDefs)}" :: Nil + s"${nme.name}: ${exp.show(newDefs)}" :: Nil // statement has a body and a declared type // both are used to compute a subsumption (What is this??) @@ -796,7 +796,7 @@ class DiffTests typer.subsume(ty_sch, sign)(ctx, raiseToBuffer, typer.TypeProvenance(d.toLoc, "def definition")) if (mode.generateTsDeclarations) tsTypegenCodeBuilder.addTypeGenTermDefinition(exp, Some(nme.name)) typeBeforeDiags = true - exp.show(newDefs) :: s" <: $nme:" :: sign_exp.show(newDefs) :: Nil + exp.show(newDefs) :: s" <: ${nme.name}:" :: sign_exp.show(newDefs) :: Nil })) case desug: DesugaredStatement => typer.dbg = mode.dbg