-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTestDynamic.scala
100 lines (86 loc) · 2.62 KB
/
TestDynamic.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package scala.js
import scala.virtualization.lms.common._
import java.io.PrintWriter
import java.io.FileOutputStream
import language.{JS, Dynamics}
import exp.{JSExp, DynamicsExp}
import gen.js.{GenJS, GenDynamics}
trait DynamicProg { this: Dynamics =>
def test(x: Rep[Any]): Rep[Any] = {
dynamic(x).foo.bar(x).baz()
}
}
trait AllocProg { this: JS =>
def test(x: Rep[Any]): Rep[Any] = {
val f = fun { (y : Rep[Any]) => new Record { val a = (newDynamic("Foo")(): Rep[Any]) } }
f.apply(x)
}
}
trait NewDynamicInFunProg { this: JS =>
def test(x: Rep[Any]): Rep[Any] = {
val f = fun { y : Rep[Any] => newDynamic("Foo")() }
f.apply(x)
}
}
trait DynamicUpdateProg { this: Dynamics =>
def test(x: Rep[Any]): Rep[Any] = {
val x_ = dynamic(x)
x_.foo = x
x_.foo
}
}
trait DynamicInlineProg { this: Dynamics =>
def test(x: Rep[Any]): Rep[Any] = {
val self = inlineDynamic("this")
val obj = inlineDynamic("foo.bar")
obj.call(self)
}
}
class TestDynamic extends FileDiffSuite {
val prefix = "test-out/"
def testDynamic = {
withOutFile(prefix+"dynamic") {
new DynamicProg with DynamicsExp { self =>
val codegen = new GenDynamics { val IR: self.type = self }
codegen.emitSource(test _, "main", new PrintWriter(System.out))
}
}
assertFileEqualsCheck(prefix+"dynamic")
}
def testAlloc = {
withOutFile(prefix+"dynamic_alloc") {
new AllocProg with JSExp { self =>
val codegen = new GenJS { val IR: self.type = self }
codegen.emitSource(test _, "main", new PrintWriter(System.out))
}
}
assertFileEqualsCheck(prefix+"dynamic_alloc")
}
def testNewDynamicInFun = {
withOutFile(prefix+"dynamic_newinfun") {
new NewDynamicInFunProg with JSExp { self =>
val codegen = new GenJS { val IR: self.type = self }
codegen.emitSource(test _, "main", new PrintWriter(System.out))
}
}
assertFileEqualsCheck(prefix+"dynamic_newinfun")
}
def testDynamicUpdate = {
withOutFile(prefix+"dynamicupdate") {
new DynamicUpdateProg with DynamicsExp { self =>
val codegen = new GenDynamics { val IR: self.type = self }
codegen.emitSource(test _, "main", new PrintWriter(System.out))
}
}
assertFileEqualsCheck(prefix+"dynamicupdate")
}
def testDynamicInline = {
withOutFile(prefix+"dynamicinline") {
new DynamicInlineProg with DynamicsExp { self =>
val codegen = new GenDynamics { val IR: self.type = self }
codegen.emitSource(test _, "main", new PrintWriter(System.out))
}
}
assertFileEqualsCheck(prefix+"dynamicinline")
}
}