-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Construct trees for HOAS patterns respecting eta expansion
- Loading branch information
1 parent
209d763
commit c7a88fa
Showing
3 changed files
with
51 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import scala.quoted.* | ||
|
||
inline def test1: String = ${ testExpr1 } | ||
def testExpr1(using Quotes): Expr[String] = | ||
'{ def f(x: Int) = 1; val n = 2; f(n) } match | ||
case '{ def g(y: Int) = 1; val n = 2; $a(g, n): Int } => Expr(a.show) | ||
inline def testExpr(inline body: Any) = ${ testExprImpl('body) } | ||
def testExprImpl(body: Expr[Any])(using Quotes): Expr[String] = | ||
body match | ||
case '{ def g(y: Int) = "hello" * y; $a(g): String } => | ||
'{ $a((z:Int) => "this is " + z.toString()) } | ||
case _ => Expr("not matched") | ||
|
||
inline def test2: String = ${ testExpr2 } | ||
def testExpr2(using Quotes): Expr[String] = | ||
'{ def f(x: Int, y:Int) = 1; f(1, 2) } match | ||
case '{ def g(y: Int, z:Int) = 1; $a(g): Int } => Expr(a.show) | ||
case _ => Expr("not matched") | ||
// TODO issue-17105: Clean this up if not neccessary | ||
// inline def test1: String = ${ testExpr1 } | ||
// def testExpr1(using Quotes): Expr[String] = | ||
// '{ def f(x: Int) = 1; val n = 2; f(n) } match | ||
// case '{ def g(y: Int) = 1; val n = 2; $a(g, n): Int } => Expr(a.show) | ||
// case _ => Expr("not matched") | ||
|
||
inline def test3: String = ${ testExpr3 } | ||
def testExpr3(using Quotes): Expr[String] = | ||
'{ | ||
def f1(using Ordered[Int]) = | ||
def f2(using Ordered[Int]) = | ||
1 < 2 | ||
f2 || 2 < 3: Boolean | ||
} match | ||
case '{ | ||
def g1(using ord: Ordered[Int]) = | ||
def g2(using Ordered[Int]) = | ||
1 < 2 | ||
$a(g2, ord): Boolean | ||
} => Expr(a.show) | ||
case _ => Expr("not matched") | ||
// inline def test2: String = ${ testExpr2 } | ||
// def testExpr2(using Quotes): Expr[String] = | ||
// '{ def f(x: Int, y:Int) = 1; f(1, 2) } match | ||
// case '{ def g(y: Int, z:Int) = 1; $a(g): Int } => Expr(a.show) | ||
// case _ => Expr("not matched") | ||
|
||
// inline def test3: String = ${ testExpr3 } | ||
// def testExpr3(using Quotes): Expr[String] = | ||
// '{ | ||
// def f1(using Ordered[Int]) = | ||
// def f2(using Ordered[Int]) = | ||
// 1 < 2 | ||
// f2 || 2 < 3: Boolean | ||
// } match | ||
// case '{ | ||
// def g1(using ord: Ordered[Int]) = | ||
// def g2(using Ordered[Int]) = | ||
// 1 < 2 | ||
// $a(g2, ord): Boolean | ||
// } => Expr(a.show) | ||
// case _ => Expr("not matched") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
@main def Test: Unit = | ||
println(test1) | ||
println(test2) | ||
println(test3) | ||
@main def app: Unit = | ||
testExpr { def f(x: Int) = "hello" * x; f(0) + "bye" } |