Commit e250d63a authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Rewritten interpreter with syntax sugars.

parent d584994d
......@@ -29,18 +29,18 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
case "@uvm.new_stack" => {
val Seq(sig) = sigList
val Seq(func) = argList
val funcVal = boxOf(func).asInstanceOf[BoxFunc].func.getOrElse {
val funcVal = func.asFunc.getOrElse {
throw new UvmRuntimeException(ctx + "Attempt to create new thread for NULL Mu function.")
}
val sta = microVM.threadStackManager.newStack(funcVal, mutator)
resultBox(0).asInstanceOf[BoxStack].stack = Some(sta)
resultBox(0).asStack = Some(sta)
continueNormally()
}
case "@uvm.kill_stack" => {
val Seq(s) = argList
val sta = boxOf(s).asInstanceOf[BoxStack].stack.getOrElse {
val sta = s.asStack.getOrElse {
throw new UvmRuntimeException(ctx + "Attempt to kill NULL stack.")
}
sta.kill()
......@@ -52,8 +52,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
}
case "@uvm.current_stack" => {
val bi = resultBox(0)
bi.asInstanceOf[BoxStack].stack = stack
results(0).asStack = Some(curStack)
continueNormally()
}
......@@ -61,59 +60,48 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
case "@uvm.tr64.is_fp" => {
val Seq(tr) = argList
val raw = boxOf(tr).asInstanceOf[BoxTagRef64].raw
val result = OpHelper.tr64IsFp(raw)
writeBooleanResult(result, resultBox(0))
results(0).asBoolean = OpHelper.tr64IsFp(tr.asTR64Raw)
continueNormally()
}
case "@uvm.tr64.is_int" => {
val Seq(tr) = argList
val raw = boxOf(tr).asInstanceOf[BoxTagRef64].raw
val result = OpHelper.tr64IsInt(raw)
writeBooleanResult(result, resultBox(0))
results(0).asBoolean = OpHelper.tr64IsInt(tr.asTR64Raw)
continueNormally()
}
case "@uvm.tr64.is_ref" => {
val Seq(tr) = argList
val raw = boxOf(tr).asInstanceOf[BoxTagRef64].raw
val result = OpHelper.tr64IsRef(raw)
writeBooleanResult(result, resultBox(0))
results(0).asBoolean = OpHelper.tr64IsRef(tr.asTR64Raw)
continueNormally()
}
case "@uvm.tr64.from_fp" => {
val Seq(v) = argList
val vFP = boxOf(v).asInstanceOf[BoxDouble].value
val raw = OpHelper.fpToTr64(vFP)
resultBox(0).asInstanceOf[BoxTagRef64].raw = raw
results(0).asTR64Raw = OpHelper.fpToTr64(v.asDouble)
continueNormally()
}
case "@uvm.tr64.from_int" => {
val Seq(v) = argList
val vInt = OpHelper.prepareUnsigned(boxOf(v).asInstanceOf[BoxInt].value, 52)
val raw = OpHelper.intToTr64(vInt.longValue())
resultBox(0).asInstanceOf[BoxTagRef64].raw = raw
results(0).asTR64Raw = OpHelper.intToTr64(v.getUInt(52).longValue)
continueNormally()
}
case "@uvm.tr64.from_ref" => {
val Seq(ref, tag) = argList
val vRef = boxOf(ref).asInstanceOf[BoxRef].objRef
val vTag = OpHelper.prepareUnsigned(boxOf(tag).asInstanceOf[BoxInt].value, 6)
val raw = OpHelper.refToTr64(vRef, vTag.longValue())
resultBox(0).asInstanceOf[BoxTagRef64].raw = raw
val vRef = ref.asRef
val vTag = tag.getSInt(6).longValue
resultBox(0).asTR64Raw = OpHelper.refToTr64(vRef, vTag)
continueNormally()
}
case "@uvm.tr64.to_fp" => {
val Seq(tr) = argList
val raw = boxOf(tr).asInstanceOf[BoxTagRef64].raw
val raw = tr.asTR64Raw
if (OpHelper.tr64IsFp(raw)) {
val result = OpHelper.tr64ToFp(raw)
resultBox(0).asInstanceOf[BoxDouble].value = result
results(0).asDouble = result
continueNormally()
} else {
throw new UvmRuntimeException(ctx + "Attempt to extract double from a tagref64 which is not holding a double")
......@@ -122,10 +110,10 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
case "@uvm.tr64.to_int" => {
val Seq(tr) = argList
val raw = boxOf(tr).asInstanceOf[BoxTagRef64].raw
val raw = tr.asTR64Raw
if (OpHelper.tr64IsInt(raw)) {
val result = OpHelper.tr64ToInt(raw)
resultBox(0).asInstanceOf[BoxInt].value = OpHelper.unprepare(result, 52)
results(0).setInt(result, 52)
continueNormally()
} else {
throw new UvmRuntimeException(ctx + "Attempt to extract int from a tagref64 which is not holding a int")
......@@ -134,10 +122,10 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
case "@uvm.tr64.to_ref" => {
val Seq(tr) = argList
val raw = boxOf(tr).asInstanceOf[BoxTagRef64].raw
val raw = tr.asTR64Raw
if (OpHelper.tr64IsRef(raw)) {
val result = OpHelper.tr64ToRef(raw)
resultBox(0).asInstanceOf[BoxRef].objRef = result
results(0).asRef = result
continueNormally()
} else {
throw new UvmRuntimeException(ctx + "Attempt to extract ref from a tagref64 which is not holding a ref")
......@@ -146,10 +134,10 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
case "@uvm.tr64.to_tag" => {
val Seq(tr) = argList
val raw = boxOf(tr).asInstanceOf[BoxTagRef64].raw
val raw = tr.asTR64Raw
if (OpHelper.tr64IsRef(raw)) {
val result = OpHelper.tr64ToTag(raw)
resultBox(0).asInstanceOf[BoxInt].value = OpHelper.unprepare(result, 6)
results(0).setInt(result, 6)
continueNormally()
} else {
throw new UvmRuntimeException(ctx + "Attempt to extract tag from a tagref64 which is not holding a ref")
......@@ -157,17 +145,15 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
}
case "@uvm.futex.wait" => {
val Seq(ty) = typeList
val Seq(ty: TypeInt) = typeList
val Seq(loc, v) = argList
val len = ty.asInstanceOf[TypeInt].length
val bLoc = boxOf(loc).asInstanceOf[BoxIRef]
val objRef = bLoc.objRef
val offset = bLoc.offset
val len = ty.length
val (objRef, offset) = loc.asIRef
val locWord = objRef + offset
val bv = boxOf(v).asInstanceOf[BoxInt]
val exp = v.asIntRaw
val equal = MemoryOperations.cmpInt(len, locWord, bv)
val equal = MemoryOperations.cmpInt(len, locWord, exp)
if (equal) {
microVM.threadStackManager.futexManager.futexWaitNoCheck(objRef, offset, curThread, None)
......@@ -179,21 +165,18 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
}
case "@uvm.futex.wait_timeout" => {
val Seq(ty) = typeList
val Seq(ty: TypeInt) = typeList
val Seq(loc, v, timeout) = argList
val len = ty.asInstanceOf[TypeInt].length
val bLoc = boxOf(loc).asInstanceOf[BoxIRef]
val objRef = bLoc.objRef
val offset = bLoc.offset
val len = ty.length
val (objRef, offset) = loc.asIRef
val locWord = objRef + offset
val bv = boxOf(v).asInstanceOf[BoxInt]
val bto = boxOf(timeout).asInstanceOf[BoxInt]
val toVal = OpHelper.prepareSigned(bto.value, 64).longValue
val toVal = timeout.asSInt64.longValue
val exp = v.asIntRaw
if (toVal < 0L) throw new UvmRefImplException(ctx + "This refimpl treats timeout as signed due to restriction of Java.")
val equal = MemoryOperations.cmpInt(len, locWord, bv)
val equal = MemoryOperations.cmpInt(len, locWord, exp)
if (equal) {
microVM.threadStackManager.futexManager.futexWaitNoCheck(objRef, offset, curThread, Some(toVal))
......@@ -205,15 +188,13 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
}
case "@uvm.futex.wake" => {
val Seq(ty) = typeList
val Seq(ty: TypeInt) = typeList
val Seq(loc, nthread) = argList
val len = ty.asInstanceOf[TypeInt].length
val bLoc = boxOf(loc).asInstanceOf[BoxIRef]
val objRef = bLoc.objRef
val offset = bLoc.offset
val len = ty.length
val (objRef, offset) = loc.asIRef
val locWord = objRef + offset
val nth = OpHelper.prepareSigned(boxOf(nthread).asInstanceOf[BoxInt].value, 32).intValue
val nth = nthread.asSInt32.intValue
if (nth < 0) throw new UvmRuntimeException(ctx + "nthread must not be negative")
......@@ -226,14 +207,14 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
val Seq(locSrc, locDst, expected, nthread) = argList
val len = ty.asInstanceOf[TypeInt].length
val (objRefSrc, offsetSrc) = boxOf(locSrc).asInstanceOf[BoxIRef].oo
val (objRefDst, offsetDst) = boxOf(locDst).asInstanceOf[BoxIRef].oo
val bExp = boxOf(expected).asInstanceOf[BoxInt]
val nth = OpHelper.prepareSigned(boxOf(nthread).asInstanceOf[BoxInt].value, 32).intValue
val (objRefSrc, offsetSrc) = locSrc.asIRef
val (objRefDst, offsetDst) = locDst.asIRef
val exp = expected.asIntRaw
val nth = nthread.asSInt32.intValue
if (nth < 0) throw new UvmRuntimeException(ctx + "nthread must not be negative")
val equal = MemoryOperations.cmpInt(len, objRefSrc + offsetSrc, bExp)
val equal = MemoryOperations.cmpInt(len, objRefSrc + offsetSrc, exp)
if (equal) {
val nWoken = microVM.threadStackManager.futexManager.futexRequeue(objRefSrc, offsetSrc, objRefDst, offsetDst, nth)
......@@ -255,8 +236,8 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
val Seq(r) = argList
val (addr, offset) = ty match {
case TypeRef(_) => (boxOf(r).asInstanceOf[BoxRef].objRef, 0L)
case TypeIRef(_) => boxOf(r).asInstanceOf[BoxIRef].oo
case TypeRef(_) => (r.asRef, 0L)
case TypeIRef(_) => r.asIRef
}
pin(addr)
......@@ -270,8 +251,8 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
val Seq(r) = argList
val addr = ty match {
case TypeRef(_) => boxOf(r).asInstanceOf[BoxRef].objRef
case TypeIRef(_) => boxOf(r).asInstanceOf[BoxIRef].objRef
case TypeRef(_) => r.asRef
case TypeIRef(_) => r.asIRef._1
}
unpin(addr)
......@@ -284,11 +265,11 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
val Seq(sig) = sigList
val Seq(func, cookie) = argList
val f = boxOf(func).asInstanceOf[BoxFunc].func.getOrElse {
val f = func.asFunc.getOrElse {
throw new UvmRuntimeException(ctx + "Attempt to expose NULL Mu function")
}
val c = boxOf(cookie).asInstanceOf[BoxInt].value.toLong
val c = boxOf(cookie).asSInt64.longValue
val addr = microVM.nativeCallHelper.exposeFuncDynamic(f, c)
......@@ -301,7 +282,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
val Seq(callConv) = flagList
val Seq(addr) = argList
val a = boxOf(addr).asInstanceOf[BoxPointer].addr
val a = addr.asPtr
microVM.nativeCallHelper.unexposeFunc(a)
......@@ -310,34 +291,34 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
case "@uvm.native.get_cookie" => {
val cookie = topDefMu.cookie
resultBox(0).asInstanceOf[BoxInt].value = OpHelper.trunc(cookie, 64)
results(0).asInt64 = cookie
continueNormally()
}
case "@uvm.meta.id_of" => {
val Seq(name) = argList
val nameStr = MemoryOperations.bytesToStr(boxOf(name).asInstanceOf[BoxRef].objRef)
val nameStr = MemoryOperations.bytesToStr(name.asRef)
val theID = microVM.idOf(nameStr)
resultBox(0).asInstanceOf[BoxInt].value = OpHelper.unprepare(theID, 32)
results(0).asInt32 = theID
continueNormally()
}
case "@uvm.meta.name_of" => {
val Seq(theID) = argList
val idInt = boxOf(theID).asInstanceOf[BoxInt].value.toInt
val idInt = theID.asSInt32.toInt
val name = microVM.nameOf(idInt)
val bytesRef = MemoryOperations.strToBytes(name)
resultBox(0).asInstanceOf[BoxRef].objRef = bytesRef
results(0).asRef = bytesRef
continueNormally()
}
case "@uvm.meta.load_bundle" => {
val Seq(bundle) = argList
val bundleStr = MemoryOperations.bytesToStr(boxOf(bundle).asInstanceOf[BoxRef].objRef)
val bundleStr = MemoryOperations.bytesToStr(bundle.asRef)
MetaOperations.loadBundle(bundleStr)
......@@ -346,7 +327,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
case "@uvm.meta.load_hail" => {
val Seq(hailScript) = argList
val hailStr = MemoryOperations.bytesToStr(boxOf(hailScript).asInstanceOf[BoxRef].objRef)
val hailStr = MemoryOperations.bytesToStr(hailScript.asRef)
MetaOperations.loadHail(hailStr)
......@@ -358,17 +339,17 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
???
}
case "@uvm.meta.cur_func_ver" => ???
case "@uvm.meta.cur_inst" => ???
case "@uvm.meta.dump_keepalives" => ???
case "@uvm.meta.cur_func_ver" => ???
case "@uvm.meta.cur_inst" => ???
case "@uvm.meta.dump_keepalives" => ???
case "@uvm.meta.pop_frame" => ???
case "@uvm.meta.push_frame" => ???
case "@uvm.meta.pop_frame" => ???
case "@uvm.meta.push_frame" => ???
case "@uvm.meta.enable_watchpoint" => ???
case "@uvm.meta.enable_watchpoint" => ???
case "@uvm.meta.disable_watchpoint" => ???
case "@uvm.meta.set_trap_handler" => ???
case "@uvm.meta.set_trap_handler" => ???
// Insert more CommInsts here.
......
......@@ -40,7 +40,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
htr match {
case HowToResume.PassValues(values) => rebindPassValues(initialStack, values)
case HowToResume.ThrowExc(exc) => catchException(exc)
case HowToResume.ThrowExc(exc) => catchException(exc)
}
}
......@@ -87,7 +87,7 @@ trait InterpreterThreadState {
protected def ctx = stack match {
case None => "(Thred not bound to stack): "
case Some(s) => s.top match {
case f: NativeFrame => "TID %d, Native frame for function 0x%x: ".format(id, f.func)
case f: NativeFrame => "TID %d, Native frame for function 0x%x: ".format(id, f.func)
case f: UndefinedMuFrame => "TID %d, Function %s (not defined): ".format(id, f.func.repr)
case f: DefinedMuFrame => {
val ix = f.curInstIndex
......@@ -96,7 +96,7 @@ trait InterpreterThreadState {
} else {
"TID %d, FuncVer %s, BB %s, Inst(%d): %s (%s): ".format(id, f.funcVer.repr, curBB.repr, ix, curInst.repr, curInst match {
case ci: InstCommInst => ci.inst.name.get
case _ => curInst.getClass.getSimpleName()
case _ => curInst.getClass.getSimpleName()
})
}
}
......@@ -106,12 +106,15 @@ trait InterpreterThreadState {
/** Get the value box of an SSA variable in the current stack. */
protected def boxOf(v: SSAVariable): ValueBox = v match {
case g: GlobalVariable => microVM.constantPool.getGlobalVarBox(g)
case l: LocalVariable => topDefMu.boxes(l)
case l: LocalVariable => topDefMu.boxes(l)
}
/** Get the edge-assigned value box of an edge-assigned instruction in the current stack. */
protected def edgeAssignedBoxOf(p: Parameter): ValueBox = topDefMu.edgeAssignedBoxes(p)
/** Results (SSA Variables) of the current instruction. */
protected def results = curInst.results
/** Get the result boxes of the current instruction. */
protected def resultBoxes: Seq[ValueBox] = curInst.results.map(boxOf)
......@@ -154,7 +157,7 @@ trait InterpreterActions extends InterpreterThreadState {
curInst.asInstanceOf[InstCommInst].inst.name.get)
logger.debug(ctx + "Setting futex return value")
writeIntResult(32, rv, resultBoxes(0))
results(0).asInt32 = rv
continueNormally()
}
......@@ -165,7 +168,7 @@ trait InterpreterActions extends InterpreterThreadState {
topMu.justCreated = false
topMu match {
case f: DefinedMuFrame => interpretCurrentInstruction()
case f: DefinedMuFrame => interpretCurrentInstruction()
case f: UndefinedMuFrame => executeUndefinedMuFrame()
}
}
......@@ -281,7 +284,7 @@ trait InterpreterActions extends InterpreterThreadState {
maybeDestClause match {
case Some(dc) => (f, dc)
case None => f.prev match {
case None => throw new UvmRuntimeException(ctx + "Exception is thrown out of the bottom frame.")
case None => throw new UvmRuntimeException(ctx + "Exception is thrown out of the bottom frame.")
case Some(prev) => unwindUntilCatchable(prev)
}
......@@ -312,10 +315,10 @@ trait InterpreterActions extends InterpreterThreadState {
*/
protected def maybeFindExceptionHandler(inst: Instruction): Option[DestClause] = {
inst match {
case i: InstCall => i.excClause.map(_.exc)
case i: InstTrap => i.excClause.map(_.exc)
case i: InstCall => i.excClause.map(_.exc)
case i: InstTrap => i.excClause.map(_.exc)
case i: InstWatchPoint => i.exc
case i: InstSwapStack => i.excClause.map(_.exc)
case i: InstSwapStack => i.excClause.map(_.exc)
case _ => {
throw new UvmRefImplException(ctx + "Non-OSR point instruction %s (%s) is in a stack frame when an exception is thrown.".format(inst.repr, inst.getClass.getName))
}
......@@ -323,25 +326,12 @@ trait InterpreterActions extends InterpreterThreadState {
}
// Misc helper
protected def writeBooleanResult(result: Boolean, box: ValueBox): Unit = {
box.asInstanceOf[BoxInt].value = if (result) 1 else 0
}
protected def writeIntResult(len: Int, result: BigInt, box: ValueBox): Unit = {
box.asInstanceOf[BoxInt].value = OpHelper.unprepare(result, len)
}
protected def incrementBoxIRefOrPointer(ptr: Boolean, src: SSAVariable, dst: SSAVariable, addrIncr: Word): Unit = {
if (ptr) {
val sb = boxOf(src).asInstanceOf[BoxPointer]
val db = boxOf(dst).asInstanceOf[BoxPointer]
db.addr = sb.addr + addrIncr
dst.asPtr = src.asPtr + addrIncr
} else {
val sb = boxOf(src).asInstanceOf[BoxIRef]
val db = boxOf(dst).asInstanceOf[BoxIRef]
db.objRef = sb.objRef
db.offset = sb.offset + addrIncr
val (sb,so) = src.asIRef
dst.asIRef = (sb, so + addrIncr)
}
}
......@@ -389,12 +379,10 @@ trait InterpreterActions extends InterpreterThreadState {
}
/** Rebind to a stack and throw an exception on that stack. */
protected def rebindThrowExc(newStack: InterpreterStack, exc: ValueBox): Unit = {
protected def rebindThrowExc(newStack: InterpreterStack, exc: Word): Unit = {
rebind(newStack)
val excObjRef = exc.asInstanceOf[BoxRef].objRef
catchException(excObjRef)
catchException(exc)
}
// Trap and watchpoint handling
......@@ -426,7 +414,7 @@ trait InterpreterActions extends InterpreterThreadState {
rebindPassValues(ns, values.map(_.vb))
}
case ClientHowToResume.ThrowExc(exc) => {
rebindThrowExc(ns, exc.vb)
rebindThrowExc(ns, exc.vb.objRef)
}
}
}
......@@ -447,7 +435,7 @@ trait InterpreterActions extends InterpreterThreadState {
*/
protected def branchToExcDestOr(excClause: Option[ExcClause])(f: => Unit): Unit = {
excClause match {
case None => f
case None => f
case Some(ExcClause(_, excBB)) => branchTo(excBB)
}
}
......@@ -488,18 +476,61 @@ trait InterpreterActions extends InterpreterThreadState {
}
import MagicalBox.MagicalBox
implicit protected def ssaVariableToMagicalBox(v: SSAVariable) = new MagicalBox(boxOf(v))
implicit protected def boxToMagicalBox(b: ValueBox) = new MagicalBox(b)
implicit protected def ssaVariableToValueBox(v: SSAVariable): ValueBox = boxOf(v)
implicit protected def ssaVariableToMagicalBox(v: SSAVariable): MagicalBox = new MagicalBox(boxOf(v))
implicit protected def boxToMagicalBox(b: ValueBox): MagicalBox = new MagicalBox(b)
}
object MagicalBox {
implicit class MagicalBox(val box: ValueBox) extends AnyVal {
def getIntRaw(): BigInt = box.asInstanceOf[BoxInt].value
def setIntRaw(v: BigInt): Unit = box.asInstanceOf[BoxInt].value = v
def asIntRaw: BigInt = box.asInstanceOf[BoxInt].value
def asInt32: BigInt = OpHelper.prepareUnsigned(box.asIntRaw, 32)
def asInt64: BigInt = OpHelper.prepareUnsigned(box.asIntRaw, 64)
def asUInt32: BigInt = OpHelper.prepareUnsigned(box.asIntRaw, 32)
def asUInt64: BigInt = OpHelper.prepareUnsigned(box.asIntRaw, 64)
def asSInt32: BigInt = OpHelper.prepareSigned(box.asIntRaw, 32)
def asSInt64: BigInt = OpHelper.prepareSigned(box.asIntRaw, 64)
def asInt1: BigInt = OpHelper.prepareUnsigned(box.asIntRaw, 1)
def asBoolean: Boolean = OpHelper.prepareUnsigned(box.asIntRaw, 1) == 1
def asFloat: Float = box.asInstanceOf[BoxFloat].value
def asDouble: Double = box.asInstanceOf[BoxDouble].value
def asRef: Word = box.asInstanceOf[BoxRef].objRef
def asIRef: (Word, Word) = box.asInstanceOf[BoxIRef].oo
def asFunc: Option[Function] = box.asInstanceOf[BoxFunc].func
def asThread: Option[InterpreterThread] = box.asInstanceOf[BoxThread].thread
def asStack: Option[InterpreterStack] = box.asInstanceOf[BoxStack].stack
def asTR64Raw: Long = box.asInstanceOf[BoxTagRef64].raw
def asPtr: Word = box.asInstanceOf[BoxPointer].addr
def asSeq: Seq[ValueBox] = box.asInstanceOf[BoxSeq].values
def asIntRaw_=(v: BigInt): Unit = box.asInstanceOf[BoxInt].value = v
def asInt1_=(v: BigInt): Unit = box.setInt(v, 1)
def asInt32_=(v: BigInt): Unit = box.setInt(v, 32)
def asInt64_=(v: BigInt): Unit = box.setInt(v, 64)
def asUInt32_=(v: BigInt): Unit = box.setInt(v, 32)
def asUInt64_=(v: BigInt): Unit = box.setInt(v, 64)
def asSInt32_=(v: BigInt): Unit = box.setInt(v, 32)
def asSInt64_=(v: BigInt): Unit = box.setInt(v, 64)
def asBoolean_=(v: Boolean): Unit = box.setInt(if (v) 1 else 0, 1)
def asFloat_=(v: Float): Unit = box.asInstanceOf[BoxFloat].value = v
def asDouble_=(v: Double): Unit = box.asInstanceOf[BoxDouble].value = v
def asRef_=(v: Word): Unit = box.asInstanceOf[BoxRef].objRef = v
def asIRef_=(oo: (Word, Word)): Unit = box.asInstanceOf[BoxIRef].oo = oo
def asFunc_=(v: Option[Function]): Unit = box.asInstanceOf[BoxFunc].func = v
def asThread_=(v: Option[InterpreterThread]): Unit = box.asInstanceOf[BoxThread].thread = v
def asStack_=(v: Option[InterpreterStack]): Unit = box.asInstanceOf[BoxStack].stack = v
def asTR64Raw_=(v: Long): Unit = box.asInstanceOf[BoxTagRef64].raw = v
def asPtr_=(v: Word): Unit = box.asInstanceOf[BoxPointer].addr = v
def asSeq_=(vs: Seq[ValueBox]): Unit = {
for ((dst, src) <- box.asSeq zip vs) {
dst copyFrom src
}
}
def getSInt(len: Int): BigInt = OpHelper.prepareSigned(box.asIntRaw, len)
def getUInt(len: Int): BigInt = OpHelper.prepareUnsigned(box.asIntRaw, len)
def setInt(v: BigInt, len: Int): Unit = box.asIntRaw = OpHelper.unprepare(v, len)
def getSInt(len: Int): BigInt = OpHelper.prepareSigned(box.getIntRaw(), len)
def getUInt(len: Int): BigInt = OpHelper.prepareUnsigned(box.getIntRaw(), len)
def setInt(v: BigInt, len: Int): Unit = box.setIntRaw(OpHelper.unprepare(v, len))
}
}
\ No newline at end of file
......@@ -289,6 +289,41 @@ object PrimOpHelpers {
case _ => throw new UvmRuntimeException(ctx + "Comparison operator %s is not suitable for double.".format(op))
}
}
def refCmp(op: CmpOptr.CmpOptr, op1v: Word, op2v: Word, ctx: => String): Boolean = {
op match {
case CmpOptr.EQ => op1v == op2v
case CmpOptr.NE => op1v != op2v
case _ => throw new UvmRuntimeException(ctx + "Comparison operator %s is not suitable for ref.".format(op))
}
<