Skip to content

Commit 437533b

Browse files
author
Chris Van Vranken
committed
update versions
1 parent 24de1ae commit 437533b

File tree

7 files changed

+26
-37
lines changed

7 files changed

+26
-37
lines changed

.dotty-ide.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
*.log
44

55
target/
6+
7+
.dotty-ide-artifact
8+
.dotty-ide.json

build.sbt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
val dottyVersion = "0.10.0-RC1"
1+
val dottyVersion = "0.25.0-RC2"
22

33
lazy val root = project
44
.in(file("."))
@@ -9,8 +9,9 @@ lazy val root = project
99
scalaVersion := dottyVersion,
1010

1111
libraryDependencies ++= Seq(
12-
"ch.epfl.lamp" % "dotty_0.10" % dottyVersion,
13-
"ch.epfl.lamp" % "dotty_0.10" % dottyVersion % "test->runtime",
12+
"ch.epfl.lamp" % "dotty_0.25" % dottyVersion,
13+
"ch.epfl.lamp" % "dotty_0.25" % dottyVersion % "test->runtime",
14+
"ch.epfl.lamp" %% "dotty-staging" % dottyVersion,
1415
"com.novocode" % "junit-interface" % "0.11" % "test"
1516
)
1617
)

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.2.3
1+
sbt.version=1.3.13

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.4")
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.1")

src/main/scala/Vectors.scala

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
11
// Import Expr and some extension methods
22
import scala.quoted._
3+
import scala.quoted.staging._
34
import scala.tasty._
45

56
object Vectors {
67

78
// Needed to show quotes
8-
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make
9+
given Toolbox = Toolbox.make(getClass.getClassLoader)
910

1011
/** Compute the dot product of the vectors (represented as arrays)
1112
* Returns (v1(0) * v2(0)) + (v1(1) * v2(1)) + ... + (v1(v1.length - 1) * v2(v2.length - 1))
1213
* Or throws an exception if v1.length != v2.length
1314
* Both arrays are assumed to be immutable.
1415
*/
15-
inline def dot(v1: => Array[Int], v2: => Array[Int]): Int = ~dotImpl('(v1), '(v2))(Tasty.macroContext)
16+
inline def dot(v1: => Array[Int], v2: => Array[Int]): Int = ${dotImpl('{v1}, '{v2})}
1617

1718
/** Generates code to compute the dot product.
1819
* Will try to partially evaluate any statically available data.
1920
*/
20-
def dotImpl(v1: Expr[Array[Int]], v2: Expr[Array[Int]])(reflect: Tasty): Expr[Int] = {
21-
import reflect._
21+
def dotImpl(v1: Expr[Array[Int]], v2: Expr[Array[Int]])(using qctx: QuoteContext): Expr[Int] = {
22+
import qctx.tasty.{_}
2223

2324
object EmptyArray {
2425
def unapply(arg: Tree): Boolean = arg match {
25-
case Term.Apply(Term.Apply(Term.TypeApply(Term.Select(Term.Ident("Array"), "apply", _), List(TypeTree.Synthetic())), List(Term.Typed(Term.Repeated(Nil), TypeTree.Synthetic()))), _) => true
26+
case Apply(Apply(TypeApply(Select(Ident("Array"), "apply"),List(Inferred())),List(Typed(Repeated(Nil,Inferred()),Inferred()))),_) => true
2627
case _ => false
2728
}
2829
}
2930

3031
// Useful methods
3132
// Use i.toExpr to lift an i:Int into an quoted.Expr[Int]
32-
// Use q.toTasty to transform a q:quoted.Expr[_] to a Tasty.Tree
33+
// Use q.unseal to transform a q:quoted.Expr[_] to a Tasty.Tree
3334
// Use tree.toExpr[Int] to transform a tree:Tasty.Tree to a quoted.Expr[Int]
3435
// Use q.show to show the code of a q:quoted.Expr[_]
35-
// Use tree.show to show the extractors needed to pattern match a tree:Tasty.Tree
36+
// Use tree.showExtractors to show the extractors needed to pattern match a tree:Tasty.Tree
3637

37-
val generatedCode = (v1.toTasty.underlyingArgument, v2.toTasty.underlyingArgument) match {
38-
case (EmptyArray(), EmptyArray()) => '(0)
38+
val generatedCode = (v1.unseal.underlyingArgument, v2.unseal.underlyingArgument) match {
39+
case (EmptyArray(), EmptyArray()) => '{0}
3940
// TODO Exercise: optimize more cases
40-
// case (EmptyArray(), _) => '()
41+
// case (EmptyArray(), _) => '{0}
4142
// ...
4243
case (tv1, tv2) =>
4344
// Print the extractors of tv1 and tv2
@@ -61,10 +62,10 @@ object Vectors {
6162
generatedCode
6263
}
6364

64-
/** Staged code that computes the the dot product with a while loop */
65-
def dynamicDot(v1: Expr[Array[Int]], v2: Expr[Array[Int]]): Expr[Int] = '{
66-
val vv1 = ~v1
67-
val vv2 = ~v2
65+
/** Staged code that computes the dot product with a while loop */
66+
def dynamicDot(v1: Expr[Array[Int]], v2: Expr[Array[Int]])(using qctx: QuoteContext): Expr[Int] = '{
67+
val vv1 = $v1
68+
val vv2 = $v2
6869
val len = vv1.length
6970
if (vv2.length != len)
7071
throw new Exception(s"Vectors must have the same sizes ($len, ${vv2.length}")

src/test/scala/VectorTests.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.junit.Test
22
import org.junit.Assert._
3-
43
import Vectors._
4+
import scala.language.implicitConversions
55

66
class VectorTests {
77

@@ -10,7 +10,7 @@ class VectorTests {
1010
val empty: Array[Int] = Array()
1111
assertEquals(dot(empty, Array()), 0)
1212
}
13-
13+
1414
@Test def zeroVector(): Unit = {
1515
assertEquals(dot(Array(1, 2, 3, 4, 5), Array(0, 0, 0, 0, 0)), 0)
1616
val zeros: Array[Int] = Array(0, 0, 0, 0, 0)
@@ -39,7 +39,6 @@ class VectorTests {
3939
assertEquals(dot(vec, Array(10, 20, 30, 40, 50)), 550)
4040
}
4141

42-
4342
@Test def mixedVector(): Unit = {
4443
val v1 = 1
4544
val z = 0

0 commit comments

Comments
 (0)