Skip to content

Commit 4fb5424

Browse files
read a dummy node to avoid lambda lifting
it seems that the lambda lifting is unsound
1 parent d5ed20d commit 4fb5424

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/main/scala/wasm/StagedMiniWasm.scala

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,38 @@ trait StagedWasmEvaluator extends SAIOps {
8888
// no need to modify the stack when entering a block
8989
// the type system guarantees that we will never take more than the input size from the stack
9090
val funcTy = ty.funcType
91+
val dummy = "dummy".reflectCtrlWith[Unit]()
9192
// TODO: somehow the type of exitSize in residual program is nothing
9293
def restK: Rep[Cont[Unit]] = fun((_: Rep[Unit]) => {
94+
info(s"Exiting the block, stackSize =", Stack.size)
95+
"dummy-op".reflectCtrlWith[Unit](dummy)
9396
eval(rest, kont, trail)
9497
})
9598
eval(inner, restK, restK :: trail)
9699
case Loop(ty, inner) =>
97100
val funcTy = ty.funcType
98101
val exitSize = Stack.size - funcTy.inps.size + funcTy.out.size
102+
val dummy = "dummy".reflectCtrlWith[Unit]()
99103
def restK = fun((_: Rep[Unit]) => {
104+
"dummy-op".reflectCtrlWith[Unit](dummy)
105+
info(s"Exiting the loop, stackSize =", Stack.size)
100106
eval(rest, kont, trail)
101107
})
102108
def loop : Rep[Unit => Unit] = fun((_u: Rep[Unit]) => {
109+
"dummy-op".reflectCtrlWith[Unit](dummy)
110+
info(s"Entered the loop, stackSize =", Stack.size)
103111
eval(inner, restK, loop :: trail)
104112
})
105113
loop(())
106114
case If(ty, thn, els) =>
107115
val funcTy = ty.funcType
108116
val exitSize = Stack.size - funcTy.inps.size + funcTy.out.size
109117
val cond = Stack.pop()
118+
val dummy = "dummy".reflectCtrlWith[Unit]()
110119
// TODO: can we avoid code duplication here?
111120
def restK = fun((_: Rep[Unit]) => {
121+
"dummy-op".reflectCtrlWith[Unit](dummy)
122+
info(s"Exiting the if, stackSize =", Stack.size)
112123
eval(rest, kont, trail)
113124
})
114125
if (cond != Values.I32(0)) {
@@ -121,7 +132,7 @@ trait StagedWasmEvaluator extends SAIOps {
121132
trail(label)(())
122133
case BrIf(label) =>
123134
val cond = Stack.pop()
124-
info(s"The br_if(${label})'s condition is ", cond)
135+
info(s"The br_if(${label})'s condition is ", cond.toInt)
125136
if (cond != Values.I32(0)) {
126137
info(s"Jump to $label")
127138
trail(label)(())
@@ -157,14 +168,14 @@ trait StagedWasmEvaluator extends SAIOps {
157168
case FuncDef(_, FuncBodyDef(ty, _, locals, body)) =>
158169
val returnSize = Stack.size - ty.inps.size + ty.out.size
159170
val args = Stack.take(ty.inps.size)
160-
info("New frame:", Frames.top)
171+
// info("New frame:", Frames.top)
161172
val callee =
162173
if (compileCache.contains(funcIndex)) {
163174
compileCache(funcIndex)
164175
} else {
165176
val callee = topFun(
166177
(kont: Rep[Cont[Unit]]) => {
167-
info(s"Entered the function at $funcIndex, stackSize =", Stack.size, ", frame =", Frames.top)
178+
info(s"Entered the function at $funcIndex, stackSize =", Stack.size)
168179
eval(body, kont, kont::Nil): Rep[Unit]
169180
}
170181
)
@@ -180,6 +191,7 @@ trait StagedWasmEvaluator extends SAIOps {
180191
callee(trail.last)
181192
} else {
182193
val restK: Rep[Cont[Unit]] = fun((_: Rep[Unit]) => {
194+
info(s"Exiting the function at $funcIndex, stackSize =", Stack.size)
183195
Frames.popFrame()
184196
eval(rest, kont, trail)
185197
})
@@ -269,6 +281,7 @@ trait StagedWasmEvaluator extends SAIOps {
269281

270282
def evalTop(main: Option[String], printRes: Boolean = false): Rep[Unit] = {
271283
val haltK: Rep[Unit] => Rep[Unit] = (_) => {
284+
info("Exiting the program...")
272285
if (printRes) {
273286
Stack.print()
274287
}
@@ -773,6 +786,8 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
773786
shallow(lhs); emit(" >= "); shallow(rhs)
774787
case Node(_, "num-to-int", List(num), _) =>
775788
shallow(num); emit(".toInt()")
789+
case Node(_, "dummy", _, _) => emit("std::monostate()")
790+
case Node(_, "dummy-op", _, _) => emit("std::monostate()")
776791
case Node(_, "no-op", _, _) =>
777792
emit("std::monostate()")
778793
case _ => super.shallow(n)
@@ -833,7 +848,19 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
833848
#include <variant>
834849
#include <vector>
835850
836-
#define info(x, ...)
851+
void info() {
852+
#ifdef DEBUG
853+
std::cout << std::endl;
854+
#endif
855+
}
856+
857+
template <typename T, typename... Args>
858+
void info(const T &first, const Args &...args) {
859+
#ifdef DEBUG
860+
std::cout << first << " ";
861+
info(args...);
862+
#endif
863+
}
837864
838865
class Num_t {
839866
public:

0 commit comments

Comments
 (0)