From 6e9ae187a05b1ca4fe748d8a7b45440a55ceb589 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 5 Dec 2011 17:00:55 +0100 Subject: Another test pack for reflection Also see https://github.com/scala/scala/pull/25. --- test/pending/run/reify_addressbook.check | 30 +++++++ test/pending/run/reify_addressbook.scala | 71 ++++++++++++++++ test/pending/run/reify_brainf_ck.check | 4 + test/pending/run/reify_brainf_ck.scala | 85 ++++++++++++++++++++ test/pending/run/reify_callccinterpreter.check | 3 + test/pending/run/reify_callccinterpreter.scala | 94 ++++++++++++++++++++++ test/pending/run/reify_complex.check | 1 + test/pending/run/reify_complex.scala | 31 +++++++ test/pending/run/reify_extendbuiltins.check | 1 + test/pending/run/reify_extendbuiltins.scala | 21 +++++ test/pending/run/reify_fors.check | 5 ++ test/pending/run/reify_fors.scala | 107 +++++++++++++++++++++++++ test/pending/run/reify_gadts.check | 1 + test/pending/run/reify_gadts.scala | 45 +++++++++++ test/pending/run/reify_implicits.check | 1 + test/pending/run/reify_implicits.scala | 21 +++++ test/pending/run/reify_lazyevaluation.check | 8 ++ test/pending/run/reify_lazyevaluation.scala | 65 +++++++++++++++ test/pending/run/reify_maps.check | 4 + test/pending/run/reify_maps.scala | 26 ++++++ test/pending/run/reify_properties.check | 2 + test/pending/run/reify_properties.scala | 63 +++++++++++++++ test/pending/run/reify_simpleinterpreter.check | 2 + test/pending/run/reify_simpleinterpreter.scala | 82 +++++++++++++++++++ test/pending/run/reify_sort.check | 2 + test/pending/run/reify_sort.scala | 57 +++++++++++++ test/pending/run/reify_sort1.check | 2 + test/pending/run/reify_sort1.scala | 27 +++++++ test/pending/run/reify_timeofday.check | 1 + test/pending/run/reify_timeofday.scala | 48 +++++++++++ test/pending/run/t5229_1_nolift.scala | 1 + test/pending/run/t5271_1.check | 0 test/pending/run/t5271_1.scala | 14 ++++ test/pending/run/t5271_2.check | 1 + test/pending/run/t5271_2.scala | 16 ++++ test/pending/run/t5272.check | 1 + test/pending/run/t5272.scala | 17 ++++ test/pending/run/t5273_1.check | 1 + test/pending/run/t5273_1.scala | 16 ++++ test/pending/run/t5273_2.check | 1 + test/pending/run/t5273_2.scala | 17 ++++ test/pending/run/t5274_1.check | 3 + test/pending/run/t5274_1.scala | 20 +++++ test/pending/run/t5274_2.check | 2 + test/pending/run/t5274_2.scala | 57 +++++++++++++ test/pending/run/t5275.check | 1 + test/pending/run/t5275.scala | 15 ++++ test/pending/run/t5276.check | 1 + test/pending/run/t5276.scala | 15 ++++ test/pending/run/t5277_1.check | 1 + test/pending/run/t5277_1.scala | 21 +++++ test/pending/run/t5277_2.check | 2 + test/pending/run/t5277_2.scala | 18 +++++ test/pending/run/t5279.check | 1 + test/pending/run/t5279.scala | 14 ++++ 55 files changed, 1166 insertions(+) create mode 100644 test/pending/run/reify_addressbook.check create mode 100644 test/pending/run/reify_addressbook.scala create mode 100644 test/pending/run/reify_brainf_ck.check create mode 100644 test/pending/run/reify_brainf_ck.scala create mode 100644 test/pending/run/reify_callccinterpreter.check create mode 100644 test/pending/run/reify_callccinterpreter.scala create mode 100644 test/pending/run/reify_complex.check create mode 100644 test/pending/run/reify_complex.scala create mode 100644 test/pending/run/reify_extendbuiltins.check create mode 100644 test/pending/run/reify_extendbuiltins.scala create mode 100644 test/pending/run/reify_fors.check create mode 100644 test/pending/run/reify_fors.scala create mode 100644 test/pending/run/reify_gadts.check create mode 100644 test/pending/run/reify_gadts.scala create mode 100644 test/pending/run/reify_implicits.check create mode 100644 test/pending/run/reify_implicits.scala create mode 100644 test/pending/run/reify_lazyevaluation.check create mode 100644 test/pending/run/reify_lazyevaluation.scala create mode 100644 test/pending/run/reify_maps.check create mode 100644 test/pending/run/reify_maps.scala create mode 100644 test/pending/run/reify_properties.check create mode 100644 test/pending/run/reify_properties.scala create mode 100644 test/pending/run/reify_simpleinterpreter.check create mode 100644 test/pending/run/reify_simpleinterpreter.scala create mode 100644 test/pending/run/reify_sort.check create mode 100644 test/pending/run/reify_sort.scala create mode 100644 test/pending/run/reify_sort1.check create mode 100644 test/pending/run/reify_sort1.scala create mode 100644 test/pending/run/reify_timeofday.check create mode 100644 test/pending/run/reify_timeofday.scala create mode 100644 test/pending/run/t5229_1_nolift.scala create mode 100644 test/pending/run/t5271_1.check create mode 100644 test/pending/run/t5271_1.scala create mode 100644 test/pending/run/t5271_2.check create mode 100644 test/pending/run/t5271_2.scala create mode 100644 test/pending/run/t5272.check create mode 100644 test/pending/run/t5272.scala create mode 100644 test/pending/run/t5273_1.check create mode 100644 test/pending/run/t5273_1.scala create mode 100644 test/pending/run/t5273_2.check create mode 100644 test/pending/run/t5273_2.scala create mode 100644 test/pending/run/t5274_1.check create mode 100644 test/pending/run/t5274_1.scala create mode 100644 test/pending/run/t5274_2.check create mode 100644 test/pending/run/t5274_2.scala create mode 100644 test/pending/run/t5275.check create mode 100644 test/pending/run/t5275.scala create mode 100644 test/pending/run/t5276.check create mode 100644 test/pending/run/t5276.scala create mode 100644 test/pending/run/t5277_1.check create mode 100644 test/pending/run/t5277_1.scala create mode 100644 test/pending/run/t5277_2.check create mode 100644 test/pending/run/t5277_2.scala create mode 100644 test/pending/run/t5279.check create mode 100644 test/pending/run/t5279.scala (limited to 'test/pending') diff --git a/test/pending/run/reify_addressbook.check b/test/pending/run/reify_addressbook.check new file mode 100644 index 0000000000..4e12f87bdc --- /dev/null +++ b/test/pending/run/reify_addressbook.check @@ -0,0 +1,30 @@ + + + + My Address Book + + + + + + + + + + + + + + + + + + + +
NameAge
Tom 20
Bob 22
James 19
+ + diff --git a/test/pending/run/reify_addressbook.scala b/test/pending/run/reify_addressbook.scala new file mode 100644 index 0000000000..225f26b75e --- /dev/null +++ b/test/pending/run/reify_addressbook.scala @@ -0,0 +1,71 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + case class Person(name: String, age: Int) + + /** An AddressBook takes a variable number of arguments + * which are accessed as a Sequence + */ + class AddressBook(a: Person*) { + private val people: List[Person] = a.toList + + /** Serialize to XHTML. Scala supports XML literals + * which may contain Scala expressions between braces, + * which are replaced by their evaluation + */ + def toXHTML = + + + + + + { for (p <- people) yield + + + + + } +
NameAge
{ p.name } { p.age.toString() }
; + } + + /** We introduce CSS using raw strings (between triple + * quotes). Raw strings may contain newlines and special + * characters (like \) are not interpreted. + */ + val header = + + + { "My Address Book" } + + + ; + + val people = new AddressBook( + Person("Tom", 20), + Person("Bob", 22), + Person("James", 19)); + + val page = + + { header } + + { people.toXHTML } + + ; + + println(page) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_brainf_ck.check b/test/pending/run/reify_brainf_ck.check new file mode 100644 index 0000000000..702bb18394 --- /dev/null +++ b/test/pending/run/reify_brainf_ck.check @@ -0,0 +1,4 @@ +---running--- +Hello World! + +---done--- diff --git a/test/pending/run/reify_brainf_ck.scala b/test/pending/run/reify_brainf_ck.scala new file mode 100644 index 0000000000..3bfb76c9ea --- /dev/null +++ b/test/pending/run/reify_brainf_ck.scala @@ -0,0 +1,85 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + import scala.annotation._ + + trait Func[T] { + val zero: T + def inc(t: T): T + def dec(t: T): T + def in: T + def out(t: T): Unit + } + + object ByteFunc extends Func[Byte] { + override val zero: Byte = 0 + override def inc(t: Byte) = ((t + 1) & 0xFF).toByte + override def dec(t: Byte) = ((t - 1) & 0xFF).toByte + override def in: Byte = readByte + override def out(t: Byte) { print(t.toChar) } + } + + case class Tape[T](left: List[T], cell: T, right: List[T])(implicit func: Func[T]) { + private def headOf(list:List[T]) = if (list.isEmpty) func.zero else list.head + private def tailOf(list:List[T]) = if (list.isEmpty) Nil else list.tail + def isZero = cell == func.zero + def execute(ch: Char) = (ch: @switch) match { + case '+' => copy(cell = func.inc(cell)) + case '-' => copy(cell = func.dec(cell)) + case '<' => Tape(tailOf(left), headOf(left), cell :: right) + case '>' => Tape(cell :: left, headOf(right), tailOf(right)) + case '.' => func.out(cell); this + case ',' => copy(cell = func.in) + case '[' | ']' => this + case _ => error("Unexpected token: " + ch) + } + } + + object Tape { + def empty[T](func: Func[T]) = Tape(Nil, func.zero, Nil)(func) + } + + class Brainfuck[T](func:Func[T]) { + + def execute(p: String) { + val prog = p.replaceAll("[^\\+\\-\\[\\]\\.\\,\\>\\<]", "") + + @tailrec def braceMatcher(pos: Int, stack: List[Int], o2c: Map[Int, Int]): Map[Int,Int] = + if(pos == prog.length) o2c else (prog(pos): @switch) match { + case '[' => braceMatcher(pos + 1, pos :: stack, o2c) + case ']' => braceMatcher(pos + 1, stack.tail, o2c + (stack.head -> pos)) + case _ => braceMatcher(pos + 1, stack, o2c) + } + + val open2close = braceMatcher(0, Nil, Map()) + val close2open = open2close.map(_.swap) + + @tailrec def ex(pos:Int, tape:Tape[T]): Unit = + if(pos < prog.length) ex((prog(pos): @switch) match { + case '[' if tape.isZero => open2close(pos) + case ']' if ! tape.isZero => close2open(pos) + case _ => pos + 1 + }, tape.execute(prog(pos))) + + println("---running---") + ex(0, Tape.empty(func)) + println("\n---done---") + } + } + + val bf = new Brainfuck(ByteFunc) + bf.execute(""">+++++++++[<++++++++>-]<.>+++++++[<++ + ++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] + <.#>+++++++++++[<+++++>-]<.>++++++++[<++ + +>-]<.+++.------.--------.[-]>++++++++[<++++> + -]<+.[-]++++++++++.""") + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_callccinterpreter.check b/test/pending/run/reify_callccinterpreter.check new file mode 100644 index 0000000000..ef8fc121df --- /dev/null +++ b/test/pending/run/reify_callccinterpreter.check @@ -0,0 +1,3 @@ +42 +wrong +5 diff --git a/test/pending/run/reify_callccinterpreter.scala b/test/pending/run/reify_callccinterpreter.scala new file mode 100644 index 0000000000..c10f4f0b4e --- /dev/null +++ b/test/pending/run/reify_callccinterpreter.scala @@ -0,0 +1,94 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + type Answer = Value; + + /** + * A continuation monad. + */ + case class M[A](in: (A => Answer) => Answer) { + def bind[B](k: A => M[B]) = M[B](c => in (a => k(a) in c)) + def map[B](f: A => B): M[B] = bind(x => unitM(f(x))) + def flatMap[B](f: A => M[B]): M[B] = bind(f) + } + + def unitM[A](a: A) = M[A](c => c(a)) + + def id[A] = (x: A) => x + def showM(m: M[Value]): String = (m in id).toString() + + def callCC[A](h: (A => M[A]) => M[A]) = + M[A](c => h(a => M[A](d => c(a))) in c) + + type Name = String + + trait Term + case class Var(x: Name) extends Term + case class Con(n: Int) extends Term + case class Add(l: Term, r: Term) extends Term + case class Lam(x: Name, body: Term) extends Term + case class App(fun: Term, arg: Term) extends Term + case class Ccc(x: Name, t: Term) extends Term + + trait Value + case object Wrong extends Value { + override def toString() = "wrong" + } + case class Num(n: Int) extends Value { + override def toString() = n.toString() + } + case class Fun(f: Value => M[Value]) extends Value { + override def toString() = "" + } + + type Environment = List[Pair[Name, Value]]; + + def lookup(x: Name, e: Environment): M[Value] = e match { + case List() => unitM(Wrong) + case Pair(y, b) :: e1 => if (x == y) unitM(b) else lookup(x, e1) + } + + def add(a: Value, b: Value): M[Value] = Pair(a, b) match { + case Pair(Num(m), Num(n)) => unitM(Num(m + n)) + case _ => unitM(Wrong) + } + + def apply(a: Value, b: Value): M[Value] = a match { + case Fun(k) => k(b) + case _ => unitM(Wrong) + } + + def interp(t: Term, e: Environment): M[Value] = t match { + case Var(x) => lookup(x, e) + case Con(n) => unitM(Num(n)) + case Add(l, r) => for (a <- interp(l, e); + b <- interp(r, e); + c <- add(a, b)) + yield c + case Lam(x, t) => unitM(Fun(a => interp(t, Pair(x, a) :: e))) + case App(f, t) => for (a <- interp(f, e); + b <- interp(t, e); + c <- apply(a, b)) + yield c + case Ccc(x, t) => callCC(k => interp(t, Pair(x, Fun(k)) :: e)) + } + + def test(t: Term): String = showM(interp(t, List())) + + val term0 = App(Lam("x", Add(Var("x"), Var("x"))), Add(Con(10), Con(11))) + val term1 = App(Con(1), Con(2)) + val term2 = Add(Con(1), Ccc("k", Add(Con(2), App(Var("k"), Con(4))))) + + println(test(term0)) + println(test(term1)) + println(test(term2)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_complex.check b/test/pending/run/reify_complex.check new file mode 100644 index 0000000000..7df35e33a0 --- /dev/null +++ b/test/pending/run/reify_complex.check @@ -0,0 +1 @@ +3.0+4.0*i diff --git a/test/pending/run/reify_complex.scala b/test/pending/run/reify_complex.scala new file mode 100644 index 0000000000..aae4d558cf --- /dev/null +++ b/test/pending/run/reify_complex.scala @@ -0,0 +1,31 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + class Complex(val re: Double, val im: Double) { + def + (that: Complex) = + new Complex(re + that.re, im + that.im) + def - (that: Complex) = + new Complex(re - that.re, im - that.im) + def * (that: Complex) = + new Complex(re * that.re - im * that.im, + re * that.im + im * that.re) + def / (that: Complex) = { + val denom = that.re * that.re + that.im * that.im + new Complex((re * that.re + im * that.im) / denom, + (im * that.re - re * that.im) / denom) + } + override def toString = + re + (if (im < 0) "-" + (-im) else "+" + im) + "*i" + } + val x = new Complex(2, 1); val y = new Complex(1, 3) + println(x + y) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_extendbuiltins.check b/test/pending/run/reify_extendbuiltins.check new file mode 100644 index 0000000000..a48033a30d --- /dev/null +++ b/test/pending/run/reify_extendbuiltins.check @@ -0,0 +1 @@ +10! = 3628800 diff --git a/test/pending/run/reify_extendbuiltins.scala b/test/pending/run/reify_extendbuiltins.scala new file mode 100644 index 0000000000..57acd699ff --- /dev/null +++ b/test/pending/run/reify_extendbuiltins.scala @@ -0,0 +1,21 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + def fact(n: Int): BigInt = + if (n == 0) 1 else fact(n-1) * n + class Factorizer(n: Int) { + def ! = fact(n) + } + implicit def int2fact(n: Int) = new Factorizer(n) + + println("10! = " + (10!)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_fors.check b/test/pending/run/reify_fors.check new file mode 100644 index 0000000000..eefddedc20 --- /dev/null +++ b/test/pending/run/reify_fors.check @@ -0,0 +1,5 @@ +Persons over 20: John Richard +divisors(34) = List(1, 2, 17, 34) +findNums(15) = (4,1) (5,2) (6,1) (7,4) (8,3) (8,5) (9,2) (9,4) (10,1) (10,3) (10,7) (11,2) (11,6) (11,8) (12,1) (12,5) (12,7) (13,4) (13,6) (13,10) (14,3) (14,5) (14,9) +average(List(3.5, 5.0, 4.5)) = 4.333333333333333 +scalProd(List(3.5, 5.0, 4.5), List(2.0, 1.0, 3.0)) = 25.5 diff --git a/test/pending/run/reify_fors.scala b/test/pending/run/reify_fors.scala new file mode 100644 index 0000000000..f3556514a9 --- /dev/null +++ b/test/pending/run/reify_fors.scala @@ -0,0 +1,107 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + object Persons { + /** A list of persons. To create a list, we use Predef.List + * which takes a variable number of arguments and constructs + * a list out of them. + */ + val persons = List( + new Person("Bob", 17), + new Person("John", 40), + new Person("Richard", 68) + ) + + /** A Person class. 'val' constructor parameters become + * public members of the class. + */ + class Person(val name: String, val age: Int) + + /** Return an iterator over persons that are older than 20. + */ + def olderThan20(xs: Seq[Person]): Iterator[String] = + olderThan20(xs.elements) + + /** Return an iterator over persons older than 20, given + * an iterator over persons. + */ + def olderThan20(xs: Iterator[Person]): Iterator[String] = { + + // The first expression is called a 'generator' and makes + // 'p' take values from 'xs'. The second expression is + // called a 'filter' and it is a boolean expression which + // selects only persons older than 20. There can be more than + // one generator and filter. The 'yield' expression is evaluated + // for each 'p' which satisfies the filters and used to assemble + // the resulting iterator + for (p <- xs if p.age > 20) yield p.name + } + } + + /** Some functions over lists of numbers which demonstrate + * the use of for comprehensions. + */ + object Numeric { + + /** Return the divisors of n. */ + def divisors(n: Int): List[Int] = + for (i <- List.range(1, n+1) if n % i == 0) yield i + + /** Is 'n' a prime number? */ + def isPrime(n: Int) = divisors(n).length == 2 + + /** Return pairs of numbers whose sum is prime. */ + def findNums(n: Int): Iterable[(Int, Int)] = { + + // a for comprehension using two generators + for (i <- 1 until n; + j <- 1 until (i-1); + if isPrime(i + j)) yield (i, j) + } + + /** Return the sum of the elements of 'xs'. */ + def sum(xs: List[Double]): Double = + xs.foldLeft(0.0) { (x, y) => x + y } + + /** Return the sum of pairwise product of the two lists. */ + def scalProd(xs: List[Double], ys: List[Double]) = + sum(for((x, y) <- xs zip ys) yield x * y); + + /** Remove duplicate elements in 'xs'. */ + def removeDuplicates[A](xs: List[A]): List[A] = + if (xs.isEmpty) + xs + else + xs.head :: removeDuplicates(for (x <- xs.tail if x != xs.head) yield x) + } + + // import all members of object 'persons' in the current scope + import Persons._ + + print("Persons over 20:") + olderThan20(persons) foreach { x => print(" " + x) } + println + + import Numeric._ + + println("divisors(34) = " + divisors(34)) + + print("findNums(15) =") + findNums(15) foreach { x => print(" " + x) } + println + + val xs = List(3.5, 5.0, 4.5) + println("average(" + xs + ") = " + sum(xs) / xs.length) + + val ys = List(2.0, 1.0, 3.0) + println("scalProd(" + xs + ", " + ys +") = " + scalProd(xs, ys)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_gadts.check b/test/pending/run/reify_gadts.check new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/test/pending/run/reify_gadts.check @@ -0,0 +1 @@ +42 diff --git a/test/pending/run/reify_gadts.scala b/test/pending/run/reify_gadts.scala new file mode 100644 index 0000000000..7077de735c --- /dev/null +++ b/test/pending/run/reify_gadts.scala @@ -0,0 +1,45 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + /* The syntax tree of a toy language */ + abstract class Term[T] + + /* An integer literal */ + case class Lit(x: Int) extends Term[Int] + + /* Successor of a number */ + case class Succ(t: Term[Int]) extends Term[Int] + + /* Is 't' equal to zero? */ + case class IsZero(t: Term[Int]) extends Term[Boolean] + + /* An 'if' expression. */ + case class If[T](c: Term[Boolean], + t1: Term[T], + t2: Term[T]) extends Term[T] + + /** A type-safe eval function. The right-hand sides can + * make use of the fact that 'T' is a more precise type, + * constraint by the pattern type. + */ + def eval[T](t: Term[T]): T = t match { + case Lit(n) => n + + // the right hand side makes use of the fact + // that T = Int and so it can use '+' + case Succ(u) => eval(u) + 1 + case IsZero(u) => eval(u) == 0 + case If(c, u1, u2) => eval(if (eval(c)) u1 else u2) + } + println( + eval(If(IsZero(Lit(1)), Lit(41), Succ(Lit(41))))) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_implicits.check b/test/pending/run/reify_implicits.check new file mode 100644 index 0000000000..e3aeb20f6b --- /dev/null +++ b/test/pending/run/reify_implicits.check @@ -0,0 +1 @@ +x = List(1, 2, 3, 4) diff --git a/test/pending/run/reify_implicits.scala b/test/pending/run/reify_implicits.scala new file mode 100644 index 0000000000..a15cef9c97 --- /dev/null +++ b/test/pending/run/reify_implicits.scala @@ -0,0 +1,21 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + implicit def arrayWrapper[A : ClassManifest](x: Array[A]) = + new { + def sort(p: (A, A) => Boolean) = { + util.Sorting.stableSort(x, p); x + } + } + val x = Array(2, 3, 1, 4) + println("x = "+ x.sort((x: Int, y: Int) => x < y).toList) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_lazyevaluation.check b/test/pending/run/reify_lazyevaluation.check new file mode 100644 index 0000000000..1c7f96cd96 --- /dev/null +++ b/test/pending/run/reify_lazyevaluation.check @@ -0,0 +1,8 @@ +s = Susp(?) +evaluating... +s() = 3 +s = Susp(3) +2 + s = 5 +sl2 = Susp(?) +sl2() = Some(3) +sl2 = Susp(Some(3)) diff --git a/test/pending/run/reify_lazyevaluation.scala b/test/pending/run/reify_lazyevaluation.scala new file mode 100644 index 0000000000..f38af76751 --- /dev/null +++ b/test/pending/run/reify_lazyevaluation.scala @@ -0,0 +1,65 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + object lazyLib { + + /** Delay the evaluation of an expression until it is needed. */ + def delay[A](value: => A): Susp[A] = new SuspImpl[A](value) + + /** Get the value of a delayed expression. */ + implicit def force[A](s: Susp[A]): A = s() + + /** + * Data type of suspended computations. (The name froms from ML.) + */ + abstract class Susp[+A] extends Function0[A] + + /** + * Implementation of suspended computations, separated from the + * abstract class so that the type parameter can be invariant. + */ + class SuspImpl[A](lazyValue: => A) extends Susp[A] { + private var maybeValue: Option[A] = None + + override def apply() = maybeValue match { + case None => + val value = lazyValue + maybeValue = Some(value) + value + case Some(value) => + value + } + + override def toString() = maybeValue match { + case None => "Susp(?)" + case Some(value) => "Susp(" + value + ")" + } + } + } + + import lazyLib._ + + val s: Susp[Int] = delay { println("evaluating..."); 3 } + + println("s = " + s) // show that s is unevaluated + println("s() = " + s()) // evaluate s + println("s = " + s) // show that the value is saved + println("2 + s = " + (2 + s)) // implicit call to force() + + val sl = delay { Some(3) } + val sl1: Susp[Some[Int]] = sl + val sl2: Susp[Option[Int]] = sl1 // the type is covariant + + println("sl2 = " + sl2) + println("sl2() = " + sl2()) + println("sl2 = " + sl2) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_maps.check b/test/pending/run/reify_maps.check new file mode 100644 index 0000000000..08cbbb1359 --- /dev/null +++ b/test/pending/run/reify_maps.check @@ -0,0 +1,4 @@ +red has code: 16711680 +Unknown color: green +Unknown color: blue +turquoise has code: 65535 diff --git a/test/pending/run/reify_maps.scala b/test/pending/run/reify_maps.scala new file mode 100644 index 0000000000..589b28d049 --- /dev/null +++ b/test/pending/run/reify_maps.scala @@ -0,0 +1,26 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + val colors = Map("red" -> 0xFF0000, + "turquoise" -> 0x00FFFF, + "black" -> 0x000000, + "orange" -> 0xFF8040, + "brown" -> 0x804000) + for (name <- List("red", "green", "blue", "turquoise")) println( + colors.get(name) match { + case Some(code) => + name + " has code: " + code + case None => + "Unknown color: " + name + } + ) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_properties.check b/test/pending/run/reify_properties.check new file mode 100644 index 0000000000..d769bea4b0 --- /dev/null +++ b/test/pending/run/reify_properties.check @@ -0,0 +1,2 @@ +user1: MR. ROBERT +user2: MR. BOB KUZ diff --git a/test/pending/run/reify_properties.scala b/test/pending/run/reify_properties.scala new file mode 100644 index 0000000000..2115a96715 --- /dev/null +++ b/test/pending/run/reify_properties.scala @@ -0,0 +1,63 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + /** A mutable property whose getter and setter may be customized. */ + case class Property[T](init: T) { + private var value: T = init + + /** The getter function, defaults to identity. */ + private var setter: T => T = identity[T] + + /** The setter function, defaults to identity. */ + private var getter: T => T = identity[T] + + /** Retrive the value held in this property. */ + def apply(): T = getter(value) + + /** Update the value held in this property, through the setter. */ + def update(newValue: T) = value = setter(newValue) + + /** Change the getter. */ + def get(newGetter: T => T) = { getter = newGetter; this } + + /** Change the setter */ + def set(newSetter: T => T) = { setter = newSetter; this } + } + + class User { + // Create a property with custom getter and setter + val firstname = Property("") + .get { v => v.toUpperCase() } + .set { v => "Mr. " + v } + val lastname = Property("") + + /** Scala provides syntactic sugar for calling 'apply'. Simply + * adding a list of arguments between parenthesis (in this case, + * an empty list) is translated to a call to 'apply' with those + * arguments. + */ + override def toString() = firstname() + " " + lastname() + } + + val user1 = new User + + // Syntactic sugar for 'update': an assignment is translated to a + // call to method 'update' + user1.firstname() = "Robert" + + val user2 = new User + user2.firstname() = "bob" + user2.lastname() = "KUZ" + + println("user1: " + user1) + println("user2: " + user2) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_simpleinterpreter.check b/test/pending/run/reify_simpleinterpreter.check new file mode 100644 index 0000000000..4344dc9009 --- /dev/null +++ b/test/pending/run/reify_simpleinterpreter.check @@ -0,0 +1,2 @@ +42 +wrong diff --git a/test/pending/run/reify_simpleinterpreter.scala b/test/pending/run/reify_simpleinterpreter.scala new file mode 100644 index 0000000000..b39f5583bb --- /dev/null +++ b/test/pending/run/reify_simpleinterpreter.scala @@ -0,0 +1,82 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + case class M[A](value: A) { + def bind[B](k: A => M[B]): M[B] = k(value) + def map[B](f: A => B): M[B] = bind(x => unitM(f(x))) + def flatMap[B](f: A => M[B]): M[B] = bind(f) + } + + def unitM[A](a: A): M[A] = M(a) + + def showM(m: M[Value]): String = m.value.toString(); + + type Name = String + + trait Term; + case class Var(x: Name) extends Term + case class Con(n: Int) extends Term + case class Add(l: Term, r: Term) extends Term + case class Lam(x: Name, body: Term) extends Term + case class App(fun: Term, arg: Term) extends Term + + trait Value + case object Wrong extends Value { + override def toString() = "wrong" + } + case class Num(n: Int) extends Value { + override def toString() = n.toString() + } + case class Fun(f: Value => M[Value]) extends Value { + override def toString() = "" + } + + type Environment = List[Pair[Name, Value]] + + def lookup(x: Name, e: Environment): M[Value] = e match { + case List() => unitM(Wrong) + case Pair(y, b) :: e1 => if (x == y) unitM(b) else lookup(x, e1) + } + + def add(a: Value, b: Value): M[Value] = Pair(a, b) match { + case Pair(Num(m), Num(n)) => unitM(Num(m + n)) + case _ => unitM(Wrong) + } + + def apply(a: Value, b: Value): M[Value] = a match { + case Fun(k) => k(b) + case _ => unitM(Wrong) + } + + def interp(t: Term, e: Environment): M[Value] = t match { + case Var(x) => lookup(x, e) + case Con(n) => unitM(Num(n)) + case Add(l, r) => for (a <- interp(l, e); + b <- interp(r, e); + c <- add(a, b)) + yield c + case Lam(x, t) => unitM(Fun(a => interp(t, Pair(x, a) :: e))) + case App(f, t) => for (a <- interp(f, e); + b <- interp(t, e); + c <- apply(a, b)) + yield c + } + + def test(t: Term): String = + showM(interp(t, List())) + + val term0 = App(Lam("x", Add(Var("x"), Var("x"))), Add(Con(10), Con(11))) + val term1 = App(Con(1), Con(2)) + + println(test(term0)) + println(test(term1)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_sort.check b/test/pending/run/reify_sort.check new file mode 100644 index 0000000000..375536cc29 --- /dev/null +++ b/test/pending/run/reify_sort.check @@ -0,0 +1,2 @@ +[6,2,8,5,1] +[1,2,5,6,8] diff --git a/test/pending/run/reify_sort.scala b/test/pending/run/reify_sort.scala new file mode 100644 index 0000000000..42991fe5d2 --- /dev/null +++ b/test/pending/run/reify_sort.scala @@ -0,0 +1,57 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + /** Nested methods can use and even update everything + * visible in their scope (including local variables or + * arguments of enclosing methods). + */ + def sort(a: Array[Int]) { + + def swap(i: Int, j: Int) { + val t = a(i); a(i) = a(j); a(j) = t + } + + def sort1(l: Int, r: Int) { + val pivot = a((l + r) / 2) + var i = l + var j = r + while (i <= j) { + while (a(i) < pivot) i += 1 + while (a(j) > pivot) j -= 1 + if (i <= j) { + swap(i, j) + i += 1 + j -= 1 + } + } + if (l < j) sort1(l, j) + if (j < r) sort1(i, r) + } + + if (a.length > 0) + sort1(0, a.length - 1) + } + + def println(ar: Array[Int]) { + def print1 = { + def iter(i: Int): String = + ar(i) + (if (i < ar.length-1) "," + iter(i+1) else "") + if (ar.length == 0) "" else iter(0) + } + Console.println("[" + print1 + "]") + } + + val ar = Array(6, 2, 8, 5, 1) + println(ar) + sort(ar) + println(ar) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_sort1.check b/test/pending/run/reify_sort1.check new file mode 100644 index 0000000000..0d30805141 --- /dev/null +++ b/test/pending/run/reify_sort1.check @@ -0,0 +1,2 @@ +List(6, 2, 8, 5, 1) +List(1, 2, 5, 6, 8) diff --git a/test/pending/run/reify_sort1.scala b/test/pending/run/reify_sort1.scala new file mode 100644 index 0000000000..42f4c824a5 --- /dev/null +++ b/test/pending/run/reify_sort1.scala @@ -0,0 +1,27 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + def sort(a: List[Int]): List[Int] = { + if (a.length < 2) + a + else { + val pivot = a(a.length / 2) + sort(a.filter(_ < pivot)) ::: + a.filter(_ == pivot) ::: + sort(a.filter(_ > pivot)) + } + } + + val xs = List(6, 2, 8, 5, 1) + println(xs) + println(sort(xs)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/reify_timeofday.check b/test/pending/run/reify_timeofday.check new file mode 100644 index 0000000000..3fd3b76a62 --- /dev/null +++ b/test/pending/run/reify_timeofday.check @@ -0,0 +1 @@ +DateError diff --git a/test/pending/run/reify_timeofday.scala b/test/pending/run/reify_timeofday.scala new file mode 100644 index 0000000000..6bd11b0d30 --- /dev/null +++ b/test/pending/run/reify_timeofday.scala @@ -0,0 +1,48 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + class DateError extends Exception + + /** Simulating properties in Scala + * (example 4.2.1 in ScalaReference.pdf) + */ + class TimeOfDayVar { + private var h, m, s: Int = 0 + + def hours = h + + /** A method 'ident_=' is a setter for 'ident'. 'code.ident = ...' will + * be translated to a call to 'ident_=' + */ + def hours_= (h: Int) = + if (0 <= h && h < 24) this.h = h + else throw new DateError() + + def minutes = m + def minutes_= (m: Int) = + if (0 <= m && m < 60) this.m = m + else throw new DateError() + + def seconds = s + def seconds_= (s: Int) = + if (0 <= s && s < 60) this.s = s + else throw new DateError() + } + + val d = new TimeOfDayVar + d.hours = 8; d.minutes = 30; d.seconds = 0 + try { d.hours = 25 // throws a DateError exception + } catch { + case de: DateError => println("DateError") + case e: Exception => println("Exception") + } + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5229_1_nolift.scala b/test/pending/run/t5229_1_nolift.scala new file mode 100644 index 0000000000..33855d2e4f --- /dev/null +++ b/test/pending/run/t5229_1_nolift.scala @@ -0,0 +1 @@ +object C diff --git a/test/pending/run/t5271_1.check b/test/pending/run/t5271_1.check new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/pending/run/t5271_1.scala b/test/pending/run/t5271_1.scala new file mode 100644 index 0000000000..5f10e64528 --- /dev/null +++ b/test/pending/run/t5271_1.scala @@ -0,0 +1,14 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + case class C(foo: Int, bar: Int) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5271_2.check b/test/pending/run/t5271_2.check new file mode 100644 index 0000000000..b8626c4cff --- /dev/null +++ b/test/pending/run/t5271_2.check @@ -0,0 +1 @@ +4 diff --git a/test/pending/run/t5271_2.scala b/test/pending/run/t5271_2.scala new file mode 100644 index 0000000000..71967c04ed --- /dev/null +++ b/test/pending/run/t5271_2.scala @@ -0,0 +1,16 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + case class C(foo: Int, bar: Int) + val c = C(2, 2) + println(c.foo * c.bar) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5272.check b/test/pending/run/t5272.check new file mode 100644 index 0000000000..dcf02b2fb6 --- /dev/null +++ b/test/pending/run/t5272.check @@ -0,0 +1 @@ +okay diff --git a/test/pending/run/t5272.scala b/test/pending/run/t5272.scala new file mode 100644 index 0000000000..3f44d05fb3 --- /dev/null +++ b/test/pending/run/t5272.scala @@ -0,0 +1,17 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + 2 match { + case 2 => println("okay") + case _ => println("not okay") + } + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5273_1.check b/test/pending/run/t5273_1.check new file mode 100644 index 0000000000..c551774ca5 --- /dev/null +++ b/test/pending/run/t5273_1.check @@ -0,0 +1 @@ +name = American Dollar, shortname = USD, value = 2,8567 diff --git a/test/pending/run/t5273_1.scala b/test/pending/run/t5273_1.scala new file mode 100644 index 0000000000..8b75084463 --- /dev/null +++ b/test/pending/run/t5273_1.scala @@ -0,0 +1,16 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + val RegexParser = """(.*) \d+([A-Z]+) \| (.*) \|.*""".r + val RegexParser(name, shortname, value) = "American Dollar 1USD | 2,8567 | sometext" + println("name = %s, shortname = %s, value = %s".format(name, shortname, value)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5273_2.check b/test/pending/run/t5273_2.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/pending/run/t5273_2.check @@ -0,0 +1 @@ +2 diff --git a/test/pending/run/t5273_2.scala b/test/pending/run/t5273_2.scala new file mode 100644 index 0000000000..1175881c9f --- /dev/null +++ b/test/pending/run/t5273_2.scala @@ -0,0 +1,17 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + List(1, 2, 3) match { + case foo :: bar :: _ => println(foo * bar) + case _ => println("this is getting out of hand!") + } + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5274_1.check b/test/pending/run/t5274_1.check new file mode 100644 index 0000000000..fca8bc3d3e --- /dev/null +++ b/test/pending/run/t5274_1.check @@ -0,0 +1,3 @@ +50! = 30414093201713378043612608166064768844377641568960512000000000000 +49! = 608281864034267560872252163321295376887552831379210240000000000 +50!/49! = 50 diff --git a/test/pending/run/t5274_1.scala b/test/pending/run/t5274_1.scala new file mode 100644 index 0000000000..c501172518 --- /dev/null +++ b/test/pending/run/t5274_1.scala @@ -0,0 +1,20 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + def factorial(n: BigInt): BigInt = + if (n == 0) 1 else n * factorial(n-1) + + val f50 = factorial(50); val f49 = factorial(49) + println("50! = " + f50) + println("49! = " + f49) + println("50!/49! = " + (f50 / f49)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5274_2.check b/test/pending/run/t5274_2.check new file mode 100644 index 0000000000..375536cc29 --- /dev/null +++ b/test/pending/run/t5274_2.check @@ -0,0 +1,2 @@ +[6,2,8,5,1] +[1,2,5,6,8] diff --git a/test/pending/run/t5274_2.scala b/test/pending/run/t5274_2.scala new file mode 100644 index 0000000000..42991fe5d2 --- /dev/null +++ b/test/pending/run/t5274_2.scala @@ -0,0 +1,57 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + /** Nested methods can use and even update everything + * visible in their scope (including local variables or + * arguments of enclosing methods). + */ + def sort(a: Array[Int]) { + + def swap(i: Int, j: Int) { + val t = a(i); a(i) = a(j); a(j) = t + } + + def sort1(l: Int, r: Int) { + val pivot = a((l + r) / 2) + var i = l + var j = r + while (i <= j) { + while (a(i) < pivot) i += 1 + while (a(j) > pivot) j -= 1 + if (i <= j) { + swap(i, j) + i += 1 + j -= 1 + } + } + if (l < j) sort1(l, j) + if (j < r) sort1(i, r) + } + + if (a.length > 0) + sort1(0, a.length - 1) + } + + def println(ar: Array[Int]) { + def print1 = { + def iter(i: Int): String = + ar(i) + (if (i < ar.length-1) "," + iter(i+1) else "") + if (ar.length == 0) "" else iter(0) + } + Console.println("[" + print1 + "]") + } + + val ar = Array(6, 2, 8, 5, 1) + println(ar) + sort(ar) + println(ar) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5275.check b/test/pending/run/t5275.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/pending/run/t5275.check @@ -0,0 +1 @@ +2 diff --git a/test/pending/run/t5275.scala b/test/pending/run/t5275.scala new file mode 100644 index 0000000000..d419834ded --- /dev/null +++ b/test/pending/run/t5275.scala @@ -0,0 +1,15 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + class C(val foo: Int) + println(new C(2).foo) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5276.check b/test/pending/run/t5276.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/pending/run/t5276.check @@ -0,0 +1 @@ +2 diff --git a/test/pending/run/t5276.scala b/test/pending/run/t5276.scala new file mode 100644 index 0000000000..432fdb91e4 --- /dev/null +++ b/test/pending/run/t5276.scala @@ -0,0 +1,15 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + lazy x = 2 + println(x) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5277_1.check b/test/pending/run/t5277_1.check new file mode 100644 index 0000000000..a48033a30d --- /dev/null +++ b/test/pending/run/t5277_1.check @@ -0,0 +1 @@ +10! = 3628800 diff --git a/test/pending/run/t5277_1.scala b/test/pending/run/t5277_1.scala new file mode 100644 index 0000000000..57acd699ff --- /dev/null +++ b/test/pending/run/t5277_1.scala @@ -0,0 +1,21 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + def fact(n: Int): BigInt = + if (n == 0) 1 else fact(n-1) * n + class Factorizer(n: Int) { + def ! = fact(n) + } + implicit def int2fact(n: Int) = new Factorizer(n) + + println("10! = " + (10!)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5277_2.check b/test/pending/run/t5277_2.check new file mode 100644 index 0000000000..5f1d0ecea5 --- /dev/null +++ b/test/pending/run/t5277_2.check @@ -0,0 +1,2 @@ +2 +1 diff --git a/test/pending/run/t5277_2.scala b/test/pending/run/t5277_2.scala new file mode 100644 index 0000000000..67b6b000bc --- /dev/null +++ b/test/pending/run/t5277_2.scala @@ -0,0 +1,18 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + def p(implicit i: Int) = print(i) + implicit val v = 2 + + println(p) + println(p(1)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} diff --git a/test/pending/run/t5279.check b/test/pending/run/t5279.check new file mode 100644 index 0000000000..f599e28b8a --- /dev/null +++ b/test/pending/run/t5279.check @@ -0,0 +1 @@ +10 diff --git a/test/pending/run/t5279.scala b/test/pending/run/t5279.scala new file mode 100644 index 0000000000..39e7dd2c66 --- /dev/null +++ b/test/pending/run/t5279.scala @@ -0,0 +1,14 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + println(new Integer(10)) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} -- cgit v1.2.3