Skip to content

Commit 4c574a6

Browse files
Merge pull request #1 from lampepfl/fix-eof-bug
Fix EOF bug and upgrade
2 parents 083f03f + fbc1dd1 commit 4c574a6

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/main/g8/build.sbt

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

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

1111
libraryDependencies ++= Seq(
12-
"ch.epfl.lamp" % "dotty_0.8" % dottyVersion,
13-
"ch.epfl.lamp" % "dotty_0.8" % dottyVersion % "test->runtime",
12+
"ch.epfl.lamp" % "dotty_0.9" % dottyVersion,
13+
"ch.epfl.lamp" % "dotty_0.9" % dottyVersion % "test->runtime",
1414
"com.novocode" % "junit-interface" % "0.11" % "test"
1515
)
1616
)

src/main/g8/src/main/scala/Main.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ object Main {
99

1010
def main(args: Array[String]): Unit = {
1111
val square = stagedPower(2)
12-
println(s"3^2 = " + square(3))
13-
println(s"4.1^2 = " + square(4.1))
12+
println("3^2 = " + square(3))
13+
println("4.1^2 = " + square(4.1))
1414
println()
1515
val cube = stagedPower(3)
16-
println(s"2.4^3 = " + cube(2.4))
16+
println("2.4^3 = " + cube(2.4))
1717
println()
1818

1919
val toTheFourth = stagedPower(4)
20-
println(s"3^4 = " + toTheFourth(3))
20+
println("3^4 = " + toTheFourth(3))
2121
println()
2222
}
2323

2424
def stagedPower(n: Int): Double => Double = {
2525
// Code representing the labmda where the recursion is unrolled based on the value of n
2626
val code = '{ (x: Double) => ~powerCode(n, '(x)) }
2727

28-
println(s"staged power for n=$n:")
28+
println(s"staged power for n=" + n + ":")
2929
println(code.show)
3030

3131
// Evaluate the contents of the code and return it's value
@@ -35,6 +35,7 @@ object Main {
3535
def powerCode(n: Int, x: Expr[Double]): Expr[Double] =
3636
if (n == 0) 1.0.toExpr // toExpr lifts 1.0 to '(1.0)
3737
else if (n == 1) x // optimization to not generate x * 1
38+
else if (n < 0) throw new Exception("Negative powers not implemented. Left as a small exercise. Dont be shy, try it out.")
3839
else if (n == 2) '(~x * ~x) // optimization to not generate { val y = x; y * y }
3940
else if (n % 2 == 1) '{ ~x * ~powerCode(n - 1, x) }
4041
else '{ val y = ~x * ~x; ~powerCode(n / 2, '(y)) }

src/main/g8/src/test/scala/Test1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import org.junit.Assert._
88
class Test1 {
99
@Test def t1(): Unit = {
1010
val code = '(println("foo"))
11-
assertEquals("println(\"foo\")", code.show)
11+
assertEquals("scala.Predef.println(\"foo\")", code.show)
1212
}
1313
}

0 commit comments

Comments
 (0)