package scala.tools.nsc
package backend
package icode
trait TypeStacks {
self: ICodes =>
import opcodes._
type Rep = List[TypeKind]
class TypeStack(var types: Rep) {
if (types.nonEmpty)
checkerDebug("Created " + this)
def this() = this(Nil)
def this(that: TypeStack) = this(that.types)
def length: Int = types.length
def isEmpty = length == 0
def nonEmpty = length != 0
def push(t: TypeKind) = {
if (t != UNIT)
types = t :: types
}
def head: TypeKind = types.head
def pop: TypeKind = {
val t = types.head
types = types.tail
t
}
def pop2: (TypeKind, TypeKind) = (pop, pop)
def pop3: (TypeKind, TypeKind, TypeKind) = (pop, pop, pop)
def pop(n: Int): List[TypeKind] = {
val prefix = types.take(n)
types = types.drop(n)
prefix
}
def apply(n: Int): TypeKind = types(n)
def agreesWith(other: TypeStack): Boolean =
(types corresponds other.types)((t1, t2) => t1 <:< t2 || t2 <:< t1)
override def toString() =
if (types.isEmpty) "[]"
else types.mkString("[", " ", "]")
override def hashCode() = types.hashCode()
override def equals(other: Any): Boolean = other match {
case x: TypeStack => x.types == types
case _ => false
}
}
}
<iframe src="https://xuwei-k.github.io/scala-compiler-sxr/scala-compiler-2.9.1/scala/tools/nsc/backend/icode/TypeStacks.scala.html" width="1280" height="720" frameborder="0"> </iframe>