Skip to content

Commit

Permalink
A handful of tests for closures under reification
Browse files Browse the repository at this point in the history
  • Loading branch information
xeno-by committed Dec 26, 2011
1 parent f737e35 commit 8f2d318
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure1.check
@@ -0,0 +1,2 @@
10
10
20 changes: 20 additions & 0 deletions test/pending/run/reify_closure1.scala
@@ -0,0 +1,20 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo[T](ys: List[T]): Int => Int = {
val fun: reflect.Code[Int => Int] = x => {
x
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(List(1, 2, 3))(10))
println(foo(List(1, 2, 3, 4))(10))
}
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure2a.check
@@ -0,0 +1,2 @@
11
12
20 changes: 20 additions & 0 deletions test/pending/run/reify_closure2a.scala
@@ -0,0 +1,20 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo(y: Int): Int => Int = {
val fun: reflect.Code[Int => Int] = x => {
x + y
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(1)(10))
println(foo(2)(10))
}
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure2b.check
@@ -0,0 +1,2 @@
11
12
22 changes: 22 additions & 0 deletions test/pending/run/reify_closure2b.scala
@@ -0,0 +1,22 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo(y: Int): Int => Int = {
class Foo(y: Int) {
val fun: reflect.Code[Int => Int] = x => {
x + y
}
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(new Foo(y).fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(1)(10))
println(foo(2)(10))
}
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure3a.check
@@ -0,0 +1,2 @@
11
12
22 changes: 22 additions & 0 deletions test/pending/run/reify_closure3a.scala
@@ -0,0 +1,22 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo(y: Int): Int => Int = {
def y1 = y

val fun: reflect.Code[Int => Int] = x => {
x + y1
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(1)(10))
println(foo(2)(10))
}
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure3b.check
@@ -0,0 +1,2 @@
11
12
24 changes: 24 additions & 0 deletions test/pending/run/reify_closure3b.scala
@@ -0,0 +1,24 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo(y: Int): Int => Int = {
class Foo(y: Int) {
def y1 = y

val fun: reflect.Code[Int => Int] = x => {
x + y1
}
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(new Foo(y).fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(1)(10))
println(foo(2)(10))
}
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure4a.check
@@ -0,0 +1,2 @@
11
12
22 changes: 22 additions & 0 deletions test/pending/run/reify_closure4a.scala
@@ -0,0 +1,22 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo(y: Int): Int => Int = {
val y1 = y

val fun: reflect.Code[Int => Int] = x => {
x + y1
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(1)(10))
println(foo(2)(10))
}
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure4b.check
@@ -0,0 +1,2 @@
11
12
24 changes: 24 additions & 0 deletions test/pending/run/reify_closure4b.scala
@@ -0,0 +1,24 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo(y: Int): Int => Int = {
class Foo(y: Int) {
val y1 = y

val fun: reflect.Code[Int => Int] = x => {
x + y1
}
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(new Foo(y).fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(1)(10))
println(foo(2)(10))
}
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure5a.check
@@ -0,0 +1,2 @@
13
14
20 changes: 20 additions & 0 deletions test/pending/run/reify_closure5a.scala
@@ -0,0 +1,20 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo[T](ys: List[T]): Int => Int = {
val fun: reflect.Code[Int => Int] = x => {
x + ys.length
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(List(1, 2, 3))(10))
println(foo(List(1, 2, 3, 4))(10))
}
2 changes: 2 additions & 0 deletions test/pending/run/reify_closure5b.check
@@ -0,0 +1,2 @@
13
14
22 changes: 22 additions & 0 deletions test/pending/run/reify_closure5b.scala
@@ -0,0 +1,22 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
def foo[T](ys: List[T]): Int => Int = {
class Foo[T](ys: List[T]) {
val fun: reflect.Code[Int => Int] = x => {
x + ys.length
}
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(new Foo(ys).fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println(foo(List(1, 2, 3))(10))
println(foo(List(1, 2, 3, 4))(10))
}
3 changes: 3 additions & 0 deletions test/pending/run/reify_closure6.check
@@ -0,0 +1,3 @@
first invocation = 15
second invocation = 18
q after second invocation = 2
26 changes: 26 additions & 0 deletions test/pending/run/reify_closure6.scala
@@ -0,0 +1,26 @@
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
import reflect.runtime.Mirror.ToolBox

object Test extends App {
var q = 0
def foo[T](ys: List[T]): Int => Int = {
val z = 1
var y = 0
val fun: reflect.Code[Int => Int] = x => {
y += 1
q += 1
x + ys.length * z + q + y
}

val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter)
val ttree = toolbox.typeCheck(fun.tree)
val dyn = toolbox.runExpr(ttree)
dyn.asInstanceOf[Int => Int]
}

println("first invocation = " + foo(List(1, 2, 3))(10))
println("second invocation = " + foo(List(1, 2, 3, 4))(10))
println("q after second invocation = " + q)
}

0 comments on commit 8f2d318

Please sign in to comment.