Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A handful of tests for closures under reification
- Loading branch information
Showing
20 changed files
with
243 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
10 | ||
10 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
11 | ||
12 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
11 | ||
12 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
11 | ||
12 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
11 | ||
12 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
11 | ||
12 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
11 | ||
12 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
13 | ||
14 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
13 | ||
14 |
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 |
---|---|---|
@@ -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)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
first invocation = 15 | ||
second invocation = 18 | ||
q after second invocation = 2 |
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 |
---|---|---|
@@ -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) | ||
} |