Commit 1d8bf3c1 authored by Kunshan Wang's avatar Kunshan Wang

Cookie.

parent 059a77ba
......@@ -1127,6 +1127,21 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
continueNormally()
}
case "@uvm.native.expose" => {
???
}
case "@uvm.native.unexpose" => {
???
}
case "@uvm.native.get_cookie" => {
val cookie = topMu.cookie
boxOf(i).asInstanceOf[BoxInt].value = OpHelper.trunc(cookie, 64)
continueNormally()
}
// Insert more CommInsts here.
case ciName => {
......@@ -1280,7 +1295,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
val funcVer = getFuncDefOrTriggerCallback(func)
curInstHalfExecuted = true
curStack.pushMuFrame(funcVer, args)
curStack.pushMuFrameForCallBack(funcVer, cookie, args)
}
case NativeCallResult.Return() => {
continueNormally()
......
......@@ -28,7 +28,7 @@ class InterpreterStack(val id: Int, val stackMemory: StackMemory, stackBottomFun
def state = _state
private def state_=(s: StackState) = _state = s
private var _top: InterpreterFrame = InterpreterFrame.forMuFunc(stackBottomFunc, args, None)
private var _top: InterpreterFrame = InterpreterFrame.forMuFunc(stackBottomFunc, 0L, args, None)
def top = _top
private def top_=(f: InterpreterFrame) = _top = f
......@@ -54,13 +54,19 @@ class InterpreterStack(val id: Int, val stackMemory: StackMemory, stackBottomFun
def muFrames: Iterator[MuFrame] = frames.filter(_.isInstanceOf[MuFrame]).map(_.asInstanceOf[MuFrame])
def pushMuFrame(funcVer: FuncVer, args: Seq[ValueBox]): Unit = {
val newFrame = InterpreterFrame.forMuFunc(funcVer, args, Some(top))
val newFrame = InterpreterFrame.forMuFunc(funcVer, 0L, args, Some(top))
top = newFrame
top.savedStackPointer = stackMemory.top
}
def pushMuFrameForCallBack(funcVer: FuncVer, cookie: Long, args: Seq[ValueBox]): Unit = {
val newFrame = InterpreterFrame.forMuFunc(funcVer, cookie, args, Some(top))
top = newFrame
top.savedStackPointer = stackMemory.top
}
def replaceTopMuFrame(funcVer: FuncVer, args: Seq[ValueBox]): Unit = {
val newFrame = InterpreterFrame.forMuFunc(funcVer, args, top.prev)
val newFrame = InterpreterFrame.forMuFunc(funcVer, 0L, args, top.prev)
stackMemory.rewind(top.savedStackPointer)
top = newFrame
top.savedStackPointer = stackMemory.top
......@@ -137,8 +143,8 @@ abstract class InterpreterFrame(val prev: Option[InterpreterFrame]) {
}
object InterpreterFrame {
def forMuFunc(funcVer: FuncVer, args: Seq[ValueBox], prev: Option[InterpreterFrame]): MuFrame = {
val frm = new MuFrame(funcVer, prev) // Bottom frame
def forMuFunc(funcVer: FuncVer, cookie: Long, args: Seq[ValueBox], prev: Option[InterpreterFrame]): MuFrame = {
val frm = new MuFrame(funcVer, cookie, prev) // Bottom frame
for ((p, a) <- (funcVer.params zip args)) {
frm.boxes(p).copyFrom(a)
......@@ -153,7 +159,12 @@ object InterpreterFrame {
}
}
class MuFrame(val funcVer: FuncVer, prev: Option[InterpreterFrame]) extends InterpreterFrame(prev) {
/**
* A Mu frame
*
* @param cookie: The cookie in the native interface. When called by another Mu function, cookie can be any value.
*/
class MuFrame(val funcVer: FuncVer, val cookie: Long, prev: Option[InterpreterFrame]) extends InterpreterFrame(prev) {
val boxes = new HashMap[LocalVariable, ValueBox]()
/** Edge-assigned instructions take values determined at look backedges */
......
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