Skip to content

Commit 3baabab

Browse files
committed
micro-truffle on lms using stable vars
1 parent b360871 commit 3baabab

9 files changed

+2267
-137
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ more seamless.
2020
### How to build:
2121

2222
1. Install the simple build tool ([SBT](http://www.scala-sbt.org/)).
23-
You will need a version 0.12.0 of the [sbt-launch.jar](http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.12.0/sbt-launch.jar).
23+
You will need version 0.12.0 of [sbt-launch.jar](http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.12.0/sbt-launch.jar).
2424
Follow the [installation instructions](http://www.scala-sbt.org/download.html#manual) on the SBT website.
2525

2626
2. Run `sbt test` to run the test suite.

test-out/epfl/test13-interpret1.check

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spec-add-int: AddN(LookupN(n),ConstN(-1))
2+
spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n)))
3+
65280

test-out/epfl/test13-interpret2.check

+1,033
Large diffs are not rendered by default.

test-out/epfl/test13-interpret3.check

+237
Large diffs are not rendered by default.

test-out/epfl/test13-stable1.check

+14-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ free vars: List(Sym(1), Sym(2))
22
/*****************************************
33
Emitting Generated Code
44
*******************************************/
5-
class staged$0(px3:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px4:Object,px6:scala.virtualization.lms.epfl.test13.SCell[Int]) extends ((Int)=>(Int)) {
5+
class staged$0(px3:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px4:Object,px6:scala.virtualization.lms.epfl.test13.RCell[Int]) extends ((Int)=>(Int)) {
66
def apply(x0:Int): Int = {
77
val x1 = x0 + 1
88
val x2 = x0 * 2
9-
val x3 = px3 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable1$1$$anon$1
9+
val x3 = px3 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable1$1$$anon$2
1010
val x4 = px4 // static data: <function1>
1111
val x5 = {import x3._;
12-
val s1 = infix_lhs(findDefinition(Sym(1)).get).head;
13-
val s2 = infix_lhs(findDefinition(Sym(2)).get).head;
14-
reset;x3.nVars=3;compile{(x:Rep[Int]) =>
12+
val s1 = findDefinition(Sym(1)).map(infix_lhs(_).head).getOrElse(Sym(1));
13+
val s2 = findDefinition(Sym(2)).map(infix_lhs(_).head).getOrElse(Sym(2));
14+
x3.reset;x3.nVars=3
15+
compile{(x:Rep[Int]) =>
1516
createDefinition(s1,StaticData(x1));
1617
createDefinition(s2,StaticData(x2));
17-
val r = x4.asInstanceOf[Rep[Int]=>Rep[Int]](x)
18-
println(globalDefs); r}}//List(Sym(1), Sym(2))
19-
val x6 = px6 // static data: SCell(stable)
18+
val y = x4.asInstanceOf[Rep[Int]=>Rep[Int]](x)
19+
println("freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable1$1$Prog$2$$anonfun$6$$anonfun$7: List(Sym(1), Sym(2))")
20+
println(globalDefs)
21+
y}}//List(Sym(1), Sym(2))
22+
val x6 = px6 // static data: RCell(stable)
2023
val x7 = x6.value
2124
val x8 = x5(x7)
2225
x8
@@ -27,6 +30,7 @@ x8
2730
*******************************************/
2831

2932
compilation: ok
33+
freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable1$1$Prog$2$$anonfun$6$$anonfun$7: List(Sym(1), Sym(2))
3034
List(TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(4),NumericPlus(Sym(1),Sym(2))), TP(Sym(5),NumericTimes(Sym(3),Sym(4))))
3135
/*****************************************
3236
Emitting Generated Code
@@ -46,6 +50,7 @@ x5
4650

4751
compilation: ok
4852
28
53+
freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable1$1$Prog$2$$anonfun$6$$anonfun$7: List(Sym(1), Sym(2))
4954
List(TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(4),NumericPlus(Sym(1),Sym(2))), TP(Sym(5),NumericTimes(Sym(3),Sym(4))))
5055
/*****************************************
5156
Emitting Generated Code
@@ -65,6 +70,7 @@ x5
6570

6671
compilation: ok
6772
140
73+
freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable1$1$Prog$2$$anonfun$6$$anonfun$7: List(Sym(1), Sym(2))
6874
List(TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(4),NumericPlus(Sym(1),Sym(2))), TP(Sym(5),NumericTimes(Sym(3),Sym(4))))
6975
/*****************************************
7076
Emitting Generated Code

test-out/epfl/test13-stable2.check

+57-51
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
call with arg 9
22
(re) compiling
33
free vars: List(Sym(1), Sym(2))
4-
read value SCell(stable) sym Sym(3)
5-
compiled Sym(12)
4+
read value RCell(stable) sym Sym(3)
65
/*****************************************
76
Emitting Generated Code
87
*******************************************/
9-
class staged$0(px3:scala.virtualization.lms.epfl.test13.SCell[Int],px8:scala.virtualization.lms.epfl.test13.SCell[scala.Function1[Int, Int]],px10:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px11:Object) extends ((Int)=>(Int)) {
8+
class staged$0(px3:scala.virtualization.lms.epfl.test13.RCell[Int],px5:Int,px9:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px11:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px12:Object) extends ((Int)=>(Int)) {
109
def apply(x0:Int): Int = {
11-
val x3 = px3 // static data: SCell(stable)
10+
val x3 = px3 // static data: RCell(stable)
1211
val x4 = x3.value
13-
val x5 = x4 == 1
14-
val x15 = if (x5) {
12+
val x5 = px5 // static data: 1
13+
val x6 = x4 == x5
14+
val x16 = if (x6) {
1515
val x1 = x0 + 1
1616
val x2 = x0 * 2
17-
val x6 = x1 + x2
18-
val x7 = 1 * x6
19-
x7
17+
val x7 = x1 + x2
18+
val x8 = 1 * x7
19+
x8
2020
} else {
21-
val x8 = px8 // static data: SCell(code)
22-
val x9 = x8.set(null)
21+
val x9 = px9 // static data: RCell(code)
22+
val x10 = x9.set(null)
2323
val x1 = x0 + 1
2424
val x2 = x0 * 2
25-
val x10 = px10 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable2$1$$anon$2
26-
val x11 = px11 // static data: <function1>
27-
val x12 = {import x10._;
28-
val s4 = infix_lhs(findDefinition(Sym(4)).get).head;
29-
val s1 = infix_lhs(findDefinition(Sym(1)).get).head;
30-
val s2 = infix_lhs(findDefinition(Sym(2)).get).head;
31-
reset;x10.nVars=5;compile{(x:Rep[Int]) =>
25+
val x11 = px11 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable2$1$$anon$3
26+
val x12 = px12 // static data: <function1>
27+
val x13 = {import x11._;
28+
val s4 = findDefinition(Sym(4)).map(infix_lhs(_).head).getOrElse(Sym(4));
29+
val s1 = findDefinition(Sym(1)).map(infix_lhs(_).head).getOrElse(Sym(1));
30+
val s2 = findDefinition(Sym(2)).map(infix_lhs(_).head).getOrElse(Sym(2));
31+
x11.reset;x11.nVars=5
32+
compile{(x:Rep[Unit]) =>
3233
createDefinition(s4,StaticData(x4));
3334
createDefinition(s1,StaticData(x1));
3435
createDefinition(s2,StaticData(x2));
35-
val r = x11.asInstanceOf[Rep[Int]=>Rep[Int]](x)
36-
println(globalDefs); r}}//List(Sym(4), Sym(1), Sym(2))
37-
val x13 = x12(x4)
38-
x13
36+
val y = x12.asInstanceOf[Int=>Rep[Int]](x4)
37+
println("freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.StableVarsExp$$anonfun$compPart$1$2$$anonfun$apply$4: List(Sym(4), Sym(1), Sym(2))")
38+
println(globalDefs)
39+
y}}//List(Sym(4), Sym(1), Sym(2))
40+
val x14 = x13.apply(())
41+
x14
3942
}
40-
x15
43+
x16
4144
}
4245
}
4346
/*****************************************
@@ -47,17 +50,17 @@ x15
4750
compilation: ok
4851
28
4952
call with arg 9
50-
List(TP(Sym(4),StaticData(5)), TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(6),NumericPlus(Sym(1),Sym(2))), TP(Sym(7),NumericTimes(Sym(4),Sym(6))))
53+
freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.StableVarsExp$$anonfun$compPart$1$2$$anonfun$apply$4: List(Sym(4), Sym(1), Sym(2))
54+
List(TP(Sym(4),StaticData(5)), TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(6),NumericPlus(Sym(1),Sym(2))), TP(Sym(7),NumericTimes(Const(5),Sym(6))))
5155
/*****************************************
5256
Emitting Generated Code
5357
*******************************************/
54-
class staged$1(px4:Int,px1:Int,px2:Int) extends ((Int)=>(Int)) {
55-
def apply(x5:Int): Int = {
56-
val x4 = px4 // static data: 5
58+
class staged$1(px1:Int,px2:Int) extends ((Unit)=>(Int)) {
59+
def apply(x5:Unit): Int = {
5760
val x1 = px1 // static data: 10
5861
val x2 = px2 // static data: 18
5962
val x6 = x1 + x2
60-
val x7 = x4 * x6
63+
val x7 = 5 * x6
6164
x7
6265
}
6366
}
@@ -70,43 +73,46 @@ compilation: ok
7073
call with arg 9
7174
(re) compiling
7275
free vars: List(Sym(9), Sym(10))
73-
read value SCell(stable) sym Sym(11)
74-
compiled Sym(20)
76+
read value RCell(stable) sym Sym(11)
7577
/*****************************************
7678
Emitting Generated Code
7779
*******************************************/
78-
class staged$2(px11:scala.virtualization.lms.epfl.test13.SCell[Int],px16:scala.virtualization.lms.epfl.test13.SCell[scala.Function1[Int, Int]],px18:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px19:Object) extends ((Int)=>(Int)) {
80+
class staged$2(px11:scala.virtualization.lms.epfl.test13.RCell[Int],px13:Int,px17:scala.virtualization.lms.epfl.test13.RCell[scala.Function1[Int, Int]],px19:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px20:Object) extends ((Int)=>(Int)) {
7981
def apply(x8:Int): Int = {
80-
val x11 = px11 // static data: SCell(stable)
82+
val x11 = px11 // static data: RCell(stable)
8183
val x12 = x11.value
82-
val x13 = x12 == 2
83-
val x23 = if (x13) {
84+
val x13 = px13 // static data: 2
85+
val x14 = x12 == x13
86+
val x24 = if (x14) {
8487
val x9 = x8 + 1
8588
val x10 = x8 * 2
86-
val x14 = x9 + x10
87-
val x15 = 2 * x14
88-
x15
89+
val x15 = x9 + x10
90+
val x16 = 2 * x15
91+
x16
8992
} else {
90-
val x16 = px16 // static data: SCell(code)
91-
val x17 = x16.set(null)
93+
val x17 = px17 // static data: RCell(code)
94+
val x18 = x17.set(null)
9295
val x9 = x8 + 1
9396
val x10 = x8 * 2
94-
val x18 = px18 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable2$1$$anon$2
95-
val x19 = px19 // static data: <function1>
96-
val x20 = {import x18._;
97-
val s12 = infix_lhs(findDefinition(Sym(12)).get).head;
98-
val s9 = infix_lhs(findDefinition(Sym(9)).get).head;
99-
val s10 = infix_lhs(findDefinition(Sym(10)).get).head;
100-
reset;x18.nVars=13;compile{(x:Rep[Int]) =>
97+
val x19 = px19 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable2$1$$anon$3
98+
val x20 = px20 // static data: <function1>
99+
val x21 = {import x19._;
100+
val s12 = findDefinition(Sym(12)).map(infix_lhs(_).head).getOrElse(Sym(12));
101+
val s9 = findDefinition(Sym(9)).map(infix_lhs(_).head).getOrElse(Sym(9));
102+
val s10 = findDefinition(Sym(10)).map(infix_lhs(_).head).getOrElse(Sym(10));
103+
x19.reset;x19.nVars=13
104+
compile{(x:Rep[Unit]) =>
101105
createDefinition(s12,StaticData(x12));
102106
createDefinition(s9,StaticData(x9));
103107
createDefinition(s10,StaticData(x10));
104-
val r = x19.asInstanceOf[Rep[Int]=>Rep[Int]](x)
105-
println(globalDefs); r}}//List(Sym(12), Sym(9), Sym(10))
106-
val x21 = x20(x12)
107-
x21
108+
val y = x20.asInstanceOf[Int=>Rep[Int]](x12)
109+
println("freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.StableVarsExp$$anonfun$compPart$1$2$$anonfun$apply$4: List(Sym(12), Sym(9), Sym(10))")
110+
println(globalDefs)
111+
y}}//List(Sym(12), Sym(9), Sym(10))
112+
val x22 = x21.apply(())
113+
x22
108114
}
109-
x23
115+
x24
110116
}
111117
}
112118
/*****************************************

test-out/epfl/test13-unstage1.check

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
free vars: List(Sym(1), Sym(2))
2+
/*****************************************
3+
Emitting Generated Code
4+
*******************************************/
5+
class staged$0(px4:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px5:Object) extends ((Int)=>(Int)) {
6+
def apply(x0:Int): Int = {
7+
val x1 = x0 + 1
8+
val x2 = x0 * 2
9+
val x3 = x1 + x2
10+
val x4 = px4 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testUnstage$1$$anon$1
11+
val x5 = px5 // static data: <function1>
12+
val x6 = {import x4._;
13+
val s3 = findDefinition(Sym(3)).map(infix_lhs(_).head).getOrElse(Sym(3));
14+
val s1 = findDefinition(Sym(1)).map(infix_lhs(_).head).getOrElse(Sym(1));
15+
val s2 = findDefinition(Sym(2)).map(infix_lhs(_).head).getOrElse(Sym(2));
16+
x4.reset;x4.nVars=4
17+
compile{(x:Rep[Unit]) =>
18+
createDefinition(s3,StaticData(x3));
19+
createDefinition(s1,StaticData(x1));
20+
createDefinition(s2,StaticData(x2));
21+
val y = x5.asInstanceOf[Int=>Rep[Int]](x3)
22+
println("freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testUnstage$1$Prog$1$$anonfun$5$$anonfun$apply$5: List(Sym(3), Sym(1), Sym(2))")
23+
println(globalDefs)
24+
y}}//List(Sym(3), Sym(1), Sym(2))
25+
val x7 = x6.apply(())
26+
x7
27+
}
28+
}
29+
/*****************************************
30+
End of Generated Code
31+
*******************************************/
32+
33+
compilation: ok
34+
freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testUnstage$1$Prog$1$$anonfun$5$$anonfun$apply$5: List(Sym(3), Sym(1), Sym(2))
35+
List(TP(Sym(3),StaticData(28)), TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(5),NumericPlus(Sym(1),Sym(2))), TP(Sym(6),NumericTimes(Const(28),Sym(5))))
36+
/*****************************************
37+
Emitting Generated Code
38+
*******************************************/
39+
class staged$1(px1:Int,px2:Int) extends ((Unit)=>(Int)) {
40+
def apply(x4:Unit): Int = {
41+
val x1 = px1 // static data: 10
42+
val x2 = px2 // static data: 18
43+
val x5 = x1 + x2
44+
val x6 = 28 * x5
45+
x6
46+
}
47+
}
48+
/*****************************************
49+
End of Generated Code
50+
*******************************************/
51+
52+
compilation: ok
53+
784
54+
freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testUnstage$1$Prog$1$$anonfun$5$$anonfun$apply$5: List(Sym(3), Sym(1), Sym(2))
55+
List(TP(Sym(3),StaticData(10)), TP(Sym(1),StaticData(4)), TP(Sym(2),StaticData(6)), TP(Sym(5),NumericPlus(Sym(1),Sym(2))), TP(Sym(6),NumericTimes(Const(10),Sym(5))))
56+
/*****************************************
57+
Emitting Generated Code
58+
*******************************************/
59+
class staged$2(px1:Int,px2:Int) extends ((Unit)=>(Int)) {
60+
def apply(x4:Unit): Int = {
61+
val x1 = px1 // static data: 4
62+
val x2 = px2 // static data: 6
63+
val x5 = x1 + x2
64+
val x6 = 10 * x5
65+
x6
66+
}
67+
}
68+
/*****************************************
69+
End of Generated Code
70+
*******************************************/
71+
72+
compilation: ok
73+
100
74+
freeVars/globalDefs for function of type scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testUnstage$1$Prog$1$$anonfun$5$$anonfun$apply$5: List(Sym(3), Sym(1), Sym(2))
75+
List(TP(Sym(3),StaticData(4)), TP(Sym(1),StaticData(2)), TP(Sym(2),StaticData(2)), TP(Sym(5),NumericPlus(Sym(1),Sym(2))), TP(Sym(6),NumericTimes(Const(4),Sym(5))))
76+
/*****************************************
77+
Emitting Generated Code
78+
*******************************************/
79+
class staged$3(px1:Int,px2:Int) extends ((Unit)=>(Int)) {
80+
def apply(x4:Unit): Int = {
81+
val x1 = px1 // static data: 2
82+
val x2 = px2 // static data: 2
83+
val x5 = x1 + x2
84+
val x6 = 4 * x5
85+
x6
86+
}
87+
}
88+
/*****************************************
89+
End of Generated Code
90+
*******************************************/
91+
92+
compilation: ok
93+
16

0 commit comments

Comments
 (0)