Commit ceb1729b authored by Kunshan Wang's avatar Kunshan Wang

Removed Function.versions

parent 5a4ee17f
......@@ -63,6 +63,8 @@ class TrantientBundle extends Bundle {
* This kind of bundle holds the global state. Functions and versions are fully merged.
*/
class GlobalBundle extends Bundle {
val funcToVers = new HashMap[Function, List[FuncVer]]()
private def simpleMerge[T <: Identified](oldNs: Namespace[T], newNs: Namespace[T], newSourceInfoRepo: SourceInfoRepo) {
for (cand <- newNs.all) {
try {
......@@ -87,7 +89,10 @@ class GlobalBundle extends Bundle {
private def redefineFunctions(newNs: Namespace[FuncVer]) {
for (fv <- newNs.all) {
fv.func.versions = fv :: fv.func.versions
val func = fv.func
val oldVers = funcToVers.getOrElse(func, Nil)
val newVers = fv :: oldVers
funcToVers(func) = newVers
}
}
......
......@@ -16,7 +16,6 @@ object FuncSig {
class Function extends GlobalVariable {
var sig: FuncSig = null
var versions: List[FuncVer] = Nil
}
/**
......
......@@ -318,7 +318,6 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
addFuncVer(ver, toSourceInfo(fDefCtx.ver))
ver.func = func
//func.versions = ver :: func.versions // Don't override here. Let the MicroVM redefine functions.
ver.bbNs = bundle.allNs.makeSubSpace[BasicBlock]("basic block")
......
......@@ -98,6 +98,7 @@ object ValueBox {
case TypeStruct(fieldTys) => BoxSeq(fieldTys.map(makeBoxForType))
case TypeArray(elemTy, len) => BoxSeq(Seq.fill(len.toInt)(makeBoxForType(elemTy)))
case _: TypeHybrid => throw new UvmRefImplException("hybrid cannot be an SSA variable type")
case _: TypeVoid => throw new UvmRefImplException("void cannot be an SSA variable type")
case _: TypeFuncRef => BoxFunc(None)
case _: TypeStackRef => BoxStack(None)
case _: TypeThreadRef => BoxThread(None)
......
......@@ -31,7 +31,7 @@ object FrameState {
* Implements a Mu Stack. Contains both Mu frames and native frames.
*/
class InterpreterStack(val id: Int, val stackMemory: StackMemory, stackBottomFunc: Function)(
implicit nativeCallHelper: NativeCallHelper) extends HasID {
implicit nativeCallHelper: NativeCallHelper, microVM: MicroVM) extends HasID {
var gcMark: Boolean = false // Mark for GC.
private var _top: InterpreterFrame = InterpreterFrame.forMuFunc(stackMemory.top, stackBottomFunc, 0L, None)
......@@ -344,8 +344,8 @@ abstract class InterpreterFrame(val prev: Option[InterpreterFrame]) {
}
object InterpreterFrame {
def forMuFunc(savedStackPointer: Word, func: Function, cookie: Long, prev: Option[InterpreterFrame]): MuFrame = {
val frm = func.versions.headOption match {
def forMuFunc(savedStackPointer: Word, func: Function, cookie: Long, prev: Option[InterpreterFrame])(implicit microVM: MicroVM): MuFrame = {
val frm = microVM.globalBundle.funcToVers.getOrElse(func, Nil).headOption match {
case None => new UndefinedMuFrame(func, prev)
case Some(funcVer) => new DefinedMuFrame(savedStackPointer, funcVer, cookie, prev)
}
......@@ -469,7 +469,11 @@ object DefinedMuFrame {
* of the stack when the current frame is pushed.
* @param cookie: The cookie in the native interface. When called by another Mu function, cookie can be any value.
*/
class DefinedMuFrame(val savedStackPointer: Word, val funcVer: FuncVer, val cookie: Long, prev: Option[InterpreterFrame])
class DefinedMuFrame(
val savedStackPointer: Word,
val funcVer: FuncVer,
val cookie: Long,
prev: Option[InterpreterFrame])
extends MuFrame(funcVer.func, prev) {
import DefinedMuFrame._
......
......@@ -297,7 +297,6 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our func "@signal" shouldBeA[Function] { its =>
its.sig shouldBe (our sig "@signal_sig")
its.versions shouldBe Nil
}
our const "@zero" shouldBeA[ConstInt] { its =>
......@@ -307,7 +306,6 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our func "@main" shouldBeA[Function] { its =>
its.sig shouldBe (our sig "@baz")
its.versions.head shouldBe (our funcVer "@main.v1")
}
our funcVer "@main.v1" shouldBeA[FuncVer] { its =>
......@@ -353,8 +351,8 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our anything mainNativeGN shouldBe mainNative
}
def in(func: Function)(f: (Function, FuncVer) => Unit) {
val ver = func.versions.head
def in(func: Function)(f: (Function, FuncVer) => Unit)(implicit bundle: GlobalBundle) {
val ver = bundle.funcToVers(func).head
f(func, ver)
}
......@@ -367,6 +365,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
}
def validateInstructions(bundle: GlobalBundle) {
implicit val _bundle = bundle
val our = bundle
in (our func "@intBinOpTest") { (func, the) =>
......@@ -1295,11 +1294,14 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
}
}
}
}
def versionsOf(func: Function)(implicit bundle: GlobalBundle): List[FuncVer] = {
bundle.funcToVers.getOrElse(func, Nil)
}
def validateRedef(globalBundle: GlobalBundle, b1: TrantientBundle, b2: TrantientBundle) {
val ourGlobal = globalBundle
implicit val ourGlobal = globalBundle
val ourOld = b1
val ourNew = b2
......@@ -1312,8 +1314,8 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
}
}
(ourGlobal func "@foxsay").versions shouldBe Nil
(ourGlobal func "@meaning_of_life").versions shouldBe Seq(ourGlobal funcVer "@meaning_of_life.v1")
versionsOf(ourGlobal func "@foxsay") shouldBe empty
versionsOf(ourGlobal func "@meaning_of_life") shouldBe Seq(ourGlobal funcVer "@meaning_of_life.v1")
ourNew.funcNs.get("@foxsay") shouldBe None
ourNew.funcNs.get("@meaning_of_life") shouldBe None
......@@ -1340,13 +1342,13 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
}
}
def validateRedefAfterMerge(globalBundle: Bundle, bundle: Bundle) {
val ourGlobal = globalBundle
def validateRedefAfterMerge(globalBundle: GlobalBundle, bundle: TrantientBundle) {
implicit val ourGlobal = globalBundle
val ourNew = bundle
(ourGlobal func "@foxsay").versions.head shouldBe (ourNew funcVer "@foxsay.v1")
(ourGlobal func "@meaning_of_life").versions.head shouldBe (ourNew funcVer "@meaning_of_life.v2")
(ourGlobal func "@meaning_of_life").versions.tail.head shouldBe (ourGlobal funcVer "@meaning_of_life.v1")
versionsOf(ourGlobal func "@foxsay").head shouldBe (ourNew funcVer "@foxsay.v1")
versionsOf(ourGlobal func "@meaning_of_life").head shouldBe (ourNew funcVer "@meaning_of_life.v2")
versionsOf(ourGlobal func "@meaning_of_life").tail.head shouldBe (ourGlobal funcVer "@meaning_of_life.v1")
(ourGlobal funcVer "@meaning_of_life.v1").func shouldBe (ourGlobal func "@meaning_of_life")
(ourGlobal funcVer "@meaning_of_life.v2").func shouldBe (ourGlobal func "@meaning_of_life")
......
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