Commit 0702c852 authored by Kunshan Wang's avatar Kunshan Wang

Implementing SwapStack...

parent d62078d8
......@@ -699,7 +699,7 @@ class InterpreterThread(val id: Int, microVM: MicroVM, initialStack: Interpreter
branchAndMovePC(dis)
}
}
case i @ InstNewStack(sig, callee, argList, excClause) => {
val calleeFunc = boxOf(callee).asInstanceOf[BoxFunc].func.getOrElse {
throw new UvmRuntimeException(ctx + "Stack-bottom function must not be NULL")
......@@ -708,7 +708,7 @@ class InterpreterThread(val id: Int, microVM: MicroVM, initialStack: Interpreter
val funcVer = getFuncDefOrTriggerCallback(calleeFunc)
val argBoxes = argList.map(boxOf)
val ib = boxOf(i).asInstanceOf[BoxStack]
handleOutOfMemory(excClause) {
......@@ -717,11 +717,34 @@ class InterpreterThread(val id: Int, microVM: MicroVM, initialStack: Interpreter
continueNormally()
}
}
case i @ InstSwapStack(swappee, curStackAction, newStackAction, excClause, keepAlives) => {
val oldStack = curStack
val newStack = boxOf(swappee).asInstanceOf[BoxStack].stack.getOrElse {
throw new UvmRuntimeException(ctx + "Swappee must not be NULL.")
}
curStackAction match {
case RetWith(retTy) => {
oldStack.state = StackState.Ready(retTy)
}
case KillOld() => {
oldStack.state = StackState.Dead
}
}
newStackAction match {
case PassValue(argTy, arg) => {
val argBox = boxOf(arg) // The current stack is still the swapper's stack.
rebindPassValue(Some(newStack), boxOf(arg))
}
case PassVoid() => {
rebindPassVoid(Some(newStack))
}
}
}
// Indentation guide: Insert more instructions (after TRAP) here.
case i @ InstCommInst(ci, typeList, argList, excClause, keepAlives) => {
......@@ -800,6 +823,11 @@ class InterpreterThread(val id: Int, microVM: MicroVM, initialStack: Interpreter
curStack.state = StackState.Ready(readyType)
stack = None
}
def unbindAndKillStack(): Unit = {
curStack.state = StackState.Dead
stack = None
}
def rebind(newStack: Option[InterpreterStack]): Unit = {
if (newStack == None) throw new UvmRuntimeException(ctx + "Rebinding to NULL stack. This does not make sense.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment