-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTestList.scala
71 lines (59 loc) · 2.06 KB
/
TestList.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package scala.js
import scala.virtualization.lms.common._
import java.io.PrintWriter
import gen.js.{GenNumericOps, GenListOps, GenEffect}
class TestList extends FileDiffSuite {
trait MapAndFlatMap { this: ListOps with NumericOps =>
def test(xs: Rep[List[Int]]): Rep[List[Int]] = {
for {
x <- xs
y <- List(unit(1), unit(2), unit(3))
} yield x * y
}
}
trait Concat { this: ListOps =>
def test(xs: Rep[List[Int]]): Rep[List[Int]] =
xs ++ List(unit(1), unit(2), unit(3))
}
trait MkString { this: ListOps =>
def test(xs: Rep[List[Int]]): Rep[String] =
xs.mkString
}
trait Prepend { this: ListOps =>
def test(xs: Rep[List[Int]]): Rep[List[Int]] =
unit(42) :: xs
}
val prefix = "test-out/"
def testMapAndFlatMap() {
withOutFile(prefix+"map-flatmap") {
val prog = new MapAndFlatMap with ListOpsExp with NumericOpsExp with PrimitiveOpsExp
val codegen = new GenEffect with GenListOps with GenNumericOps { val IR: prog.type = prog }
codegen.emitSource(prog.test, "MapAndFlatMap", new PrintWriter(System.out))
}
assertFileEqualsCheck(prefix+"map-flatmap")
}
def testConcat() {
withOutFile(prefix+"concat") {
val prog = new Concat with ListOpsExp
val codegen = new GenEffect with GenListOps { val IR: prog.type = prog }
codegen.emitSource(prog.test, "Concat", new PrintWriter(System.out))
}
assertFileEqualsCheck(prefix+"concat")
}
def testMkString() {
withOutFile(prefix+"mkstring") {
val prog = new MkString with ListOpsExp
val codegen = new GenEffect with GenListOps { val IR: prog.type = prog }
codegen.emitSource(prog.test, "MkString", new PrintWriter(System.out))
}
assertFileEqualsCheck(prefix+"mkstring")
}
def testPrepend() {
withOutFile(prefix+"prepend") {
val prog = new Prepend with ListOpsExp
val codegen = new GenEffect with GenListOps { val IR: prog.type = prog }
codegen.emitSource(prog.test, "Prepend", new PrintWriter(System.out))
}
assertFileEqualsCheck(prefix+"prepend")
}
}