WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

Commit 694684b2 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Use AnyVal for all implicit classes.

parent 5c2d1c03
...@@ -68,18 +68,18 @@ class GlobalBundle extends Bundle { ...@@ -68,18 +68,18 @@ class GlobalBundle extends Bundle {
for (cand <- newNs.all) { for (cand <- newNs.all) {
try { try {
oldNs.add(cand) oldNs.add(cand)
def assertPresent[T <: Identified](ns: NestedNamespace[T], obj: T): Unit = { // def assertPresent[T <: Identified](ns: NestedNamespace[T], obj: T): Unit = {
assert(ns.get(obj.id) == Some(obj)) // assert(ns.get(obj.id) == Some(obj))
if (obj.id == 65731) { // if (obj.id == 65731) {
printf("Obj[65731] found in ns " + ns) // printf("Obj[65731] found in ns " + ns)
} // }
ns.maybeParent match { // ns.maybeParent match {
case None => // case None =>
case Some(ns2) => // case Some(ns2) =>
assertPresent(ns2, obj) // assertPresent(ns2, obj)
} // }
} // }
assertPresent(oldNs.asInstanceOf[NestedNamespace[T]], cand) // assertPresent(oldNs.asInstanceOf[NestedNamespace[T]], cand)
} catch { } catch {
case e: NameConflictException => case e: NameConflictException =>
throw new IllegalRedefinitionException( throw new IllegalRedefinitionException(
......
...@@ -21,7 +21,7 @@ trait IdentifiedSettable extends Identified { ...@@ -21,7 +21,7 @@ trait IdentifiedSettable extends Identified {
} }
object RichIdentifiedSettable { object RichIdentifiedSettable {
implicit class RichIdentifiedSettable[T <: IdentifiedSettable](val is: T) { implicit class RichIdentifiedSettable[T <: IdentifiedSettable](val is: T) extends AnyVal {
def :=(p: Int): T = { def :=(p: Int): T = {
is.id = p is.id = p
is is
......
...@@ -24,7 +24,7 @@ class Later { ...@@ -24,7 +24,7 @@ class Later {
} }
object Later { object Later {
implicit class Laterable[T](val anything: T) { implicit class Laterable[T](val anything: T) extends AnyVal {
def later(lat: Later)(job: T => Unit): T = { def later(lat: Later)(job: T => Unit): T = {
lat(() => job(anything)) lat(() => job(anything))
anything anything
......
...@@ -716,8 +716,21 @@ class MuCtx(_mutator: Mutator)( ...@@ -716,8 +716,21 @@ class MuCtx(_mutator: Mutator)(
} }
object RichMuCtx { object RichMuCtx {
/** Allow you to use the `val h = x << ctx.makeSomeHandle()` or `val h = x(ctx.makeSomeHandle())`
* syntax to dispose it later*/
class DelayedDisposer(garbageList: Buffer[MuValue]) {
def apply[T <: MuValue](v: T): T = {
garbageList += v
v
}
def <<[T <: MuValue](v: T): T = {
garbageList += v
v
}
}
/** Extensions to the MuCtx interface. Not officially part of the client API. */ /** Extensions to the MuCtx interface. Not officially part of the client API. */
implicit class RichMuCtx(ctx: MuCtx) { implicit class RichMuCtx(val ctx: MuCtx) extends AnyVal {
def handleFromBoolean(b: Boolean) = ctx.handleFromInt(if (b) 1 else 0, 1) def handleFromBoolean(b: Boolean) = ctx.handleFromInt(if (b) 1 else 0, 1)
def handleFromInt1(num: BigInt) = ctx.handleFromInt(num, 1) def handleFromInt1(num: BigInt) = ctx.handleFromInt(num, 1)
def handleFromInt6(num: BigInt) = ctx.handleFromInt(num, 6) def handleFromInt6(num: BigInt) = ctx.handleFromInt(num, 6)
...@@ -728,17 +741,6 @@ object RichMuCtx { ...@@ -728,17 +741,6 @@ object RichMuCtx {
def handleFromInt64(num: BigInt) = ctx.handleFromInt(num, 64) def handleFromInt64(num: BigInt) = ctx.handleFromInt(num, 64)
def deleteValue(vs: MuValue*) = vs.foreach(ctx.deleteValue) def deleteValue(vs: MuValue*) = vs.foreach(ctx.deleteValue)
class DelayedDisposer(garbageList: Buffer[MuValue]) {
def apply[T <: MuValue](v: T): T = {
garbageList += v
v
}
def <<[T <: MuValue](v: T): T = {
garbageList += v
v
}
}
def autoDispose[T](f: DelayedDisposer => T) = { def autoDispose[T](f: DelayedDisposer => T) = {
val garbages = ArrayBuffer[MuValue]() val garbages = ArrayBuffer[MuValue]()
val dd = new DelayedDisposer(garbages) val dd = new DelayedDisposer(garbages)
......
...@@ -12,23 +12,14 @@ import uvm.IdentifiedSettable ...@@ -12,23 +12,14 @@ import uvm.IdentifiedSettable
object InternalIDFactory extends IDFactory(32768) // IDs from 32768-65535 are for implementation internal use. object InternalIDFactory extends IDFactory(32768) // IDs from 32768-65535 are for implementation internal use.
object InternalTypes { object InternalTypes {
private implicit class IdentifiedSettableAssignable[T <: IdentifiedSettable](i: T) { import uvm.RichIdentifiedSettable._
def :=(name: String): T = {
i.id = InternalIDFactory.getID()
i.name = Some(name)
i
}
def :=(idName: (Int, String)): T = { def internal(name: String): (Int, String) = {
val (id, name) = idName val id = InternalIDFactory.getID()
i.id = id val n = "@uvm.internal.types." + name
i.name = Some(name) (id, n)
i
}
} }
def internal(name: String) = "@uvm.internal.types." + name
val I1 = TypeInt(1) := internal("i1") val I1 = TypeInt(1) := internal("i1")
val I6 = TypeInt(6) := internal("i6") val I6 = TypeInt(6) := internal("i6")
val I8 = TypeInt(6) := internal("i8") val I8 = TypeInt(6) := internal("i8")
...@@ -65,7 +56,7 @@ object InternalTypePool { ...@@ -65,7 +56,7 @@ object InternalTypePool {
val vecOf = LazyPool[(Type, Long), TypeVector] { case (t, l) => TypeVector(t, l) } val vecOf = LazyPool[(Type, Long), TypeVector] { case (t, l) => TypeVector(t, l) }
def unmarkedOf(t: Type): Type = t match { def unmarkedOf(t: Type): Type = t match {
case TypeWeakRef(r) => refOf(r) case TypeWeakRef(r) => refOf(r)
case _ => t case _ => t
} }
} }
...@@ -78,11 +69,11 @@ object TypeInferer { ...@@ -78,11 +69,11 @@ object TypeInferer {
} }
def inferType(v: SSAVariable): Type = v match { def inferType(v: SSAVariable): Type = v match {
case c: Constant => c.constTy case c: Constant => c.constTy
case g: GlobalCell => irefOf(g.cellTy) case g: GlobalCell => irefOf(g.cellTy)
case f: Function => funcOf(f.sig) case f: Function => funcOf(f.sig)
case p: NorParam => p.ty case p: NorParam => p.ty
case p: ExcParam => REF_VOID case p: ExcParam => REF_VOID
case r: InstResult => { case r: InstResult => {
val resTys = inferInstResultTypes(r.inst) val resTys = inferInstResultTypes(r.inst)
try { try {
...@@ -98,90 +89,90 @@ object TypeInferer { ...@@ -98,90 +89,90 @@ object TypeInferer {
case i: InstBinOp => Seq(i.opndTy) case i: InstBinOp => Seq(i.opndTy)
case i: InstCmp => i.opndTy match { case i: InstCmp => i.opndTy match {
case TypeVector(_, l) => Seq(vecOf(I1, l)) case TypeVector(_, l) => Seq(vecOf(I1, l))
case _ => Seq(I1) case _ => Seq(I1)
} }
case i: InstConv => Seq(i.toTy) case i: InstConv => Seq(i.toTy)
case i: InstSelect => Seq(i.opndTy) case i: InstSelect => Seq(i.opndTy)
case i: InstBranch => Seq() case i: InstBranch => Seq()
case i: InstBranch2 => Seq() case i: InstBranch2 => Seq()
case i: InstSwitch => Seq() case i: InstSwitch => Seq()
case i: InstCall => i.sig.retTys case i: InstCall => i.sig.retTys
case i: InstTailCall => Seq() case i: InstTailCall => Seq()
case i: InstRet => Seq() case i: InstRet => Seq()
case i: InstThrow => Seq() case i: InstThrow => Seq()
case i: InstExtractValue => Seq(i.strTy.fieldTys(i.index)) case i: InstExtractValue => Seq(i.strTy.fieldTys(i.index))
case i: InstInsertValue => Seq(i.strTy) case i: InstInsertValue => Seq(i.strTy)
case i: InstExtractElement => Seq(i.seqTy.elemTy) case i: InstExtractElement => Seq(i.seqTy.elemTy)
case i: InstInsertElement => Seq(i.seqTy) case i: InstInsertElement => Seq(i.seqTy)
case i: InstShuffleVector => Seq(vecOf((i.vecTy.elemTy, i.maskTy.len))) case i: InstShuffleVector => Seq(vecOf((i.vecTy.elemTy, i.maskTy.len)))
case i: InstNew => Seq(refOf(i.allocTy)) case i: InstNew => Seq(refOf(i.allocTy))
case i: InstNewHybrid => Seq(refOf(i.allocTy)) case i: InstNewHybrid => Seq(refOf(i.allocTy))
case i: InstAlloca => Seq(irefOf(i.allocTy)) case i: InstAlloca => Seq(irefOf(i.allocTy))
case i: InstAllocaHybrid => Seq(irefOf(i.allocTy)) case i: InstAllocaHybrid => Seq(irefOf(i.allocTy))
case i: InstGetIRef => Seq(irefOf(i.referentTy)) case i: InstGetIRef => Seq(irefOf(i.referentTy))
case i: InstGetFieldIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.fieldTys(i.index))) case i: InstGetFieldIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.fieldTys(i.index)))
case i: InstGetElemIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.elemTy)) case i: InstGetElemIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.elemTy))
case i: InstShiftIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy)) case i: InstShiftIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy))
case i: InstGetVarPartIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.varTy)) case i: InstGetVarPartIRef => Seq(ptrOrIRefOf(i.ptr, i.referentTy.varTy))
case i: InstLoad => Seq(unmarkedOf(i.referentTy)) case i: InstLoad => Seq(unmarkedOf(i.referentTy))
case i: InstStore => Seq() case i: InstStore => Seq()
case i: InstCmpXchg => Seq(unmarkedOf(i.referentTy), I1) case i: InstCmpXchg => Seq(unmarkedOf(i.referentTy), I1)
case i: InstAtomicRMW => Seq(unmarkedOf(i.referentTy)) case i: InstAtomicRMW => Seq(unmarkedOf(i.referentTy))
case i: InstFence => Seq() case i: InstFence => Seq()
case i: InstTrap => i.retTys case i: InstTrap => i.retTys
case i: InstWatchPoint => i.retTys case i: InstWatchPoint => i.retTys
case i: InstCCall => i.sig.retTys case i: InstCCall => i.sig.retTys
case i: InstNewThread => Seq(THREAD) case i: InstNewThread => Seq(THREAD)
case i: InstSwapStack => i.curStackAction match { case i: InstSwapStack => i.curStackAction match {
case RetWith(t) => t case RetWith(t) => t
case _: KillOld => Seq() case _: KillOld => Seq()
} }
case i: InstCommInst => i.inst.name.get match { case i: InstCommInst => i.inst.name.get match {
case "@uvm.new_stack" => Seq(STACK) case "@uvm.new_stack" => Seq(STACK)
case "@uvm.kill_stack" => Seq() case "@uvm.kill_stack" => Seq()
case "@uvm.thread_exit" => Seq() case "@uvm.thread_exit" => Seq()
case "@uvm.current_stack" => Seq(STACK) case "@uvm.current_stack" => Seq(STACK)
case "@uvm.tr64.is_fp" => Seq(I1) case "@uvm.tr64.is_fp" => Seq(I1)
case "@uvm.tr64.is_int" => Seq(I1) case "@uvm.tr64.is_int" => Seq(I1)
case "@uvm.tr64.is_ref" => Seq(I1) case "@uvm.tr64.is_ref" => Seq(I1)
case "@uvm.tr64.from_fp" => Seq(TAGREF64) case "@uvm.tr64.from_fp" => Seq(TAGREF64)
case "@uvm.tr64.from_int" => Seq(TAGREF64) case "@uvm.tr64.from_int" => Seq(TAGREF64)
case "@uvm.tr64.from_ref" => Seq(TAGREF64) case "@uvm.tr64.from_ref" => Seq(TAGREF64)
case "@uvm.tr64.to_fp" => Seq(DOUBLE) case "@uvm.tr64.to_fp" => Seq(DOUBLE)
case "@uvm.tr64.to_int" => Seq(I52) case "@uvm.tr64.to_int" => Seq(I52)
case "@uvm.tr64.to_ref" => Seq(REF_VOID) case "@uvm.tr64.to_ref" => Seq(REF_VOID)
case "@uvm.tr64.to_tag" => Seq(I6) case "@uvm.tr64.to_tag" => Seq(I6)
case "@uvm.futex.wait" => Seq(I32) case "@uvm.futex.wait" => Seq(I32)
case "@uvm.futex.wait_timeout" => Seq(I32) case "@uvm.futex.wait_timeout" => Seq(I32)
case "@uvm.futex.wake" => Seq(I32) case "@uvm.futex.wake" => Seq(I32)
case "@uvm.futex.cmp_requeue" => Seq(I32) case "@uvm.futex.cmp_requeue" => Seq(I32)
case "@uvm.kill_dependency" => Seq(i.typeList(0)) case "@uvm.kill_dependency" => Seq(i.typeList(0))
case "@uvm.native.pin" => i.typeList(0) match { case "@uvm.native.pin" => i.typeList(0) match {
case TypeRef(t) => Seq(ptrOf(t)) case TypeRef(t) => Seq(ptrOf(t))
case TypeIRef(t) => Seq(ptrOf(t)) case TypeIRef(t) => Seq(ptrOf(t))
} }
case "@uvm.native.unpin" => Seq() case "@uvm.native.unpin" => Seq()
case "@uvm.native.expose" => Seq(funcPtrOf(i.funcSigList(0))) case "@uvm.native.expose" => Seq(funcPtrOf(i.funcSigList(0)))
case "@uvm.native.unexpose" => Seq() case "@uvm.native.unexpose" => Seq()
case "@uvm.native.get_cookie" => Seq(I64) case "@uvm.native.get_cookie" => Seq(I64)
case "@uvm.meta.id_of" => Seq(I32) case "@uvm.meta.id_of" => Seq(I32)
case "@uvm.meta.name_of" => Seq(BYTES_R) case "@uvm.meta.name_of" => Seq(BYTES_R)
case "@uvm.meta.load_bundle" => Seq(BYTES_R) case "@uvm.meta.load_bundle" => Seq(BYTES_R)
case "@uvm.meta.load_hail" => Seq(BYTES_R) case "@uvm.meta.load_hail" => Seq(BYTES_R)
case "@uvm.meta.cur_func" => Seq(I32) case "@uvm.meta.cur_func" => Seq(I32)
case "@uvm.meta.cur_func_ver" => Seq(I32) case "@uvm.meta.cur_func_ver" => Seq(I32)
case "@uvm.meta.cur_inst" => Seq(I32) case "@uvm.meta.cur_inst" => Seq(I32)
case "@uvm.meta.dump_keepalives" => Seq(REFS_R) case "@uvm.meta.dump_keepalives" => Seq(REFS_R)
case "@uvm.meta.pop_frame" => Seq() case "@uvm.meta.pop_frame" => Seq()
case "@uvm.meta.push_frame" => Seq() case "@uvm.meta.push_frame" => Seq()
case "@uvm.meta.enable_watchpoint" => Seq() case "@uvm.meta.enable_watchpoint" => Seq()
case "@uvm.meta.disable_watchpoint" => Seq() case "@uvm.meta.disable_watchpoint" => Seq()
case "@uvm.meta.set_trap_handler" => Seq() case "@uvm.meta.set_trap_handler" => Seq()
} }
} }
} }
\ No newline at end of file
...@@ -255,7 +255,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner { ...@@ -255,7 +255,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
val Seq(r) = argList val Seq(r) = argList
val (addr, offset) = ty match { val (addr, offset) = ty match {
case TypeRef(_) => (boxOf(r).asInstanceOf[BoxRef].objRef, 0L) case TypeRef(_) => (boxOf(r).asInstanceOf[BoxRef].objRef, 0L)
case TypeIRef(_) => boxOf(r).asInstanceOf[BoxIRef].oo case TypeIRef(_) => boxOf(r).asInstanceOf[BoxIRef].oo
} }
...@@ -270,7 +270,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner { ...@@ -270,7 +270,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
val Seq(r) = argList val Seq(r) = argList
val addr = ty match { val addr = ty match {
case TypeRef(_) => boxOf(r).asInstanceOf[BoxRef].objRef case TypeRef(_) => boxOf(r).asInstanceOf[BoxRef].objRef
case TypeIRef(_) => boxOf(r).asInstanceOf[BoxIRef].objRef case TypeIRef(_) => boxOf(r).asInstanceOf[BoxIRef].objRef
} }
...@@ -343,7 +343,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner { ...@@ -343,7 +343,7 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
continueNormally() continueNormally()
} }
case "@uvm.meta.load_hail" => { case "@uvm.meta.load_hail" => {
val Seq(hailScript) = argList val Seq(hailScript) = argList
val hailStr = MemoryOperations.bytesToStr(boxOf(hailScript).asInstanceOf[BoxRef].objRef) val hailStr = MemoryOperations.bytesToStr(boxOf(hailScript).asInstanceOf[BoxRef].objRef)
...@@ -353,6 +353,23 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner { ...@@ -353,6 +353,23 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner {
continueNormally() continueNormally()
} }
case "@uvm.meta.cur_func" => {
val Seq(stack) = argList
???
}
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.enable_watchpoint" => ???
case "@uvm.meta.disable_watchpoint" => ???
case "@uvm.meta.set_trap_handler" => ???
// Insert more CommInsts here. // Insert more CommInsts here.
case ciName => { case ciName => {
......
...@@ -40,7 +40,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator ...@@ -40,7 +40,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator
htr match { htr match {
case HowToResume.PassValues(values) => rebindPassValues(initialStack, values) 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 { ...@@ -87,7 +87,7 @@ trait InterpreterThreadState {
protected def ctx = stack match { protected def ctx = stack match {
case None => "(Thred not bound to stack): " case None => "(Thred not bound to stack): "
case Some(s) => s.top match { 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: UndefinedMuFrame => "TID %d, Function %s (not defined): ".format(id, f.func.repr)
case f: DefinedMuFrame => { case f: DefinedMuFrame => {
val ix = f.curInstIndex val ix = f.curInstIndex
...@@ -96,7 +96,7 @@ trait InterpreterThreadState { ...@@ -96,7 +96,7 @@ trait InterpreterThreadState {
} else { } else {
"TID %d, FuncVer %s, BB %s, Inst(%d): %s (%s): ".format(id, f.funcVer.repr, curBB.repr, ix, curInst.repr, curInst match { "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 ci: InstCommInst => ci.inst.name.get
case _ => curInst.getClass.getSimpleName() case _ => curInst.getClass.getSimpleName()
}) })
} }
} }
...@@ -106,7 +106,7 @@ trait InterpreterThreadState { ...@@ -106,7 +106,7 @@ trait InterpreterThreadState {
/** Get the value box of an SSA variable in the current stack. */ /** Get the value box of an SSA variable in the current stack. */
protected def boxOf(v: SSAVariable): ValueBox = v match { protected def boxOf(v: SSAVariable): ValueBox = v match {
case g: GlobalVariable => microVM.constantPool.getGlobalVarBox(g) 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. */ /** Get the edge-assigned value box of an edge-assigned instruction in the current stack. */
...@@ -165,7 +165,7 @@ trait InterpreterActions extends InterpreterThreadState { ...@@ -165,7 +165,7 @@ trait InterpreterActions extends InterpreterThreadState {
topMu.justCreated = false topMu.justCreated = false
topMu match { topMu match {
case f: DefinedMuFrame => interpretCurrentInstruction() case f: DefinedMuFrame => interpretCurrentInstruction()
case f: UndefinedMuFrame => executeUndefinedMuFrame() case f: UndefinedMuFrame => executeUndefinedMuFrame()
} }
} }
...@@ -176,11 +176,11 @@ trait InterpreterActions extends InterpreterThreadState { ...@@ -176,11 +176,11 @@ trait InterpreterActions extends InterpreterThreadState {
assert(f.virtInst != UndefinedMuFrame.VIRT_INST_NOT_STARTED) assert(f.virtInst != UndefinedMuFrame.VIRT_INST_NOT_STARTED)
f.virtInst match { f.virtInst match {
case UndefinedMuFrame.VIRT_INST_TRAP => { case UndefinedMuFrame.VIRT_INST_TRAP => {
logger.debug(ctx+"Executing virtual trap") logger.debug(ctx + "Executing virtual trap")
doTrap(Seq(), 0) doTrap(Seq(), 0)
} }
case UndefinedMuFrame.VIRT_INST_TAILCALL => { case UndefinedMuFrame.VIRT_INST_TAILCALL => {
logger.debug(ctx+"Executing virtual tail-call") logger.debug(ctx + "Executing virtual tail-call")
val calleeFunc = f.func val calleeFunc = f.func
val argBoxes = f.boxes val argBoxes = f.boxes
...@@ -281,7 +281,7 @@ trait InterpreterActions extends InterpreterThreadState { ...@@ -281,7 +281,7 @@ trait InterpreterActions extends InterpreterThreadState {
maybeDestClause match { maybeDestClause match {
case Some(dc) => (f, dc) case Some(dc) => (f, dc)
case None => f.prev match { 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) case Some(prev) => unwindUntilCatchable(prev)
} }
...@@ -312,10 +312,10 @@ trait InterpreterActions extends InterpreterThreadState { ...@@ -312,10 +312,10 @@ trait InterpreterActions extends InterpreterThreadState {
*/ */
protected def maybeFindExceptionHandler(inst: Instruction): Option[DestClause] = { protected def maybeFindExceptionHandler(inst: Instruction): Option[DestClause] = {
inst match { inst match {
case i: InstCall => i.excClause.map(_.exc) case i: InstCall => i.excClause.map(_.exc)
case i: InstTrap => i.excClause.map(_.exc) case i: InstTrap => i.excClause.map(_.exc)
case i: InstWatchPoint => i.exc case i: InstWatchPoint => i.exc
case i: InstSwapStack => i.excClause.map(_.exc) case i: InstSwapStack => i.excClause.map(_.exc)
case _ => { 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)) 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))
} }
...@@ -447,7 +447,7 @@ trait InterpreterActions extends InterpreterThreadState { ...@@ -447,7 +447,7 @@ trait InterpreterActions extends InterpreterThreadState {
*/ */
protected def branchToExcDestOr(excClause: Option[ExcClause])(f: => Unit): Unit = { protected def branchToExcDestOr(excClause: Option[ExcClause])(f: => Unit): Unit = {
excClause match { excClause match {
case None => f case None => f
case Some(ExcClause(_, excBB)) => branchTo(excBB) case Some(ExcClause(_, excBB)) => branchTo(excBB)
} }
} }
...@@ -486,5 +486,20 @@ trait InterpreterActions extends InterpreterThreadState { ...@@ -486,5 +486,20 @@ trait InterpreterActions extends InterpreterThreadState {
throw new UvmRuntimeException(ctx + "Accessing null reference.") throw new UvmRuntimeException(ctx + "Accessing null reference.")
} }
} }
import MagicalBox.MagicalBox
implicit protected def ssaVariableToMagicalBox(v: SSAVariable) = new MagicalBox(boxOf(v))
implicit protected def boxToMagicalBox(b: ValueBox) = 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