Commit d62078d8 authored by Kunshan Wang's avatar Kunshan Wang

TheadStackManager.newStack now takes FuncVer.

It will no longer raise exception for undefined functions.
parent 63a689c6
......@@ -290,14 +290,18 @@ class ClientAgent(microVM: MicroVM) {
}
def newStack(func: Handle, args: Seq[Handle]): Handle = {
val fv = func.vb.asInstanceOf[BoxFunc].func match {
val funcVal = func.vb.asInstanceOf[BoxFunc].func match {
case None => throw new UvmRuntimeException("Stack-bottom function must not be NULL")
case Some(v) => v
}
val funcVer = funcVal.versions.headOption.getOrElse {
throw new UvmRuntimeException("Stack-bottom function %s is not defined.".format(funcVal.repr))
}
val argBoxes = args.map(_.vb)
val sta = microVM.threadStackManager.newStack(fv, argBoxes, mutator)
val sta = microVM.threadStackManager.newStack(funcVer, argBoxes, mutator)
val nb = BoxStack(Some(sta))
newHandle(InternalTypes.STACK, nb)
......
......@@ -699,6 +699,29 @@ 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")
}
val funcVer = getFuncDefOrTriggerCallback(calleeFunc)
val argBoxes = argList.map(boxOf)
val ib = boxOf(i).asInstanceOf[BoxStack]
handleOutOfMemory(excClause) {
val sta = microVM.threadStackManager.newStack(funcVer, argBoxes, mutator)
ib.stack = Some(sta)
continueNormally()
}
}
case i @ InstSwapStack(swappee, curStackAction, newStackAction, excClause, keepAlives) => {
}
// Indentation guide: Insert more instructions (after TRAP) here.
case i @ InstCommInst(ci, typeList, argList, excClause, keepAlives) => {
......
package uvm.refimpl.itpr
import uvm.Function
import uvm.FuncVer
import uvm.refimpl.MicroVM
import uvm.refimpl.mem._
import scala.collection.mutable.HashMap
......@@ -34,10 +34,10 @@ class ThreadStackManager(microVM: MicroVM) {
* via the "new_stack" message or µVM threads (the InterpreterThread class) which can execute the NEWSTACK
* instruction.
*/
def newStack(function: Function, args: Seq[ValueBox], mutator: Mutator): InterpreterStack = {
def newStack(funcVer: FuncVer, args: Seq[ValueBox], mutator: Mutator): InterpreterStack = {
val stackMemory = microVM.memoryManager.makeStackMemory(mutator)
val id = makeStackID()
val sta = new InterpreterStack(id, stackMemory, function.versions.head, args)
val sta = new InterpreterStack(id, stackMemory, funcVer, args)
stackRegistry.put(id, sta)
sta
}
......
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