package scala.tools.nsc
package backend
package icode;
import java.io.PrintWriter;
trait Primitives { self: ICodes =>
class Primitive {
}
case class Negation(kind: TypeKind) extends Primitive
case class Test(op: TestOp, kind: TypeKind, zero: Boolean) extends Primitive
case class Comparison(op: ComparisonOp, kind: TypeKind) extends Primitive
case class Arithmetic(op: ArithmeticOp, kind: TypeKind) extends Primitive
case class Logical(op: LogicalOp, kind: TypeKind) extends Primitive
case class Shift(op: ShiftOp, kind: TypeKind) extends Primitive
case class Conversion(src: TypeKind, dst: TypeKind) extends Primitive;
case class ArrayLength(kind: TypeKind) extends Primitive;
case class StringConcat(el: TypeKind) extends Primitive
case object StartConcat extends Primitive
case object EndConcat extends Primitive
class PrimitivePrinter(out: PrintWriter) {
def print(s: String): PrimitivePrinter = {
out.print(s)
this
}
def print(o: AnyRef): PrimitivePrinter = print(o.toString())
def printPrimitive(prim: Primitive) = prim match {
case Negation(kind) =>
print("!")
case Test(op, kind, zero) =>
print(op).print(kind)
case Comparison(op, kind) =>
print(op).print("(").print(kind)
}
}
class ComparisonOp {
override def toString(): String = this match {
case CMPL => "CMPL"
case CMP => "CMP"
case CMPG => "CMPG"
case _ => throw new RuntimeException("ComparisonOp unknown case")
}
}
case object CMPL extends ComparisonOp
case object CMP extends ComparisonOp
case object CMPG extends ComparisonOp
class TestOp {
def negate(): TestOp = this match {
case EQ => NE
case NE => EQ
case LT => GE
case GE => LT
case LE => GT
case GT => LE
case _ => throw new RuntimeException("TestOp unknown case")
}
override def toString(): String = this match {
case EQ => "EQ"
case NE => "NE"
case LT => "LT"
case GE => "GE"
case LE => "LE"
case GT => "GT"
case _ => throw new RuntimeException("TestOp unknown case")
}
}
case object EQ extends TestOp
case object NE extends TestOp
case object LT extends TestOp
case object GE extends TestOp
case object LE extends TestOp
case object GT extends TestOp
class ArithmeticOp {
override def toString(): String = this match {
case ADD => "ADD"
case SUB => "SUB"
case MUL => "MUL"
case DIV => "DIV"
case REM => "REM"
case NOT => "NOT"
case _ => throw new RuntimeException("ArithmeticOp unknown case")
}
}
case object ADD extends ArithmeticOp
case object SUB extends ArithmeticOp
case object MUL extends ArithmeticOp
case object DIV extends ArithmeticOp
case object REM extends ArithmeticOp
case object NOT extends ArithmeticOp
class ShiftOp {
override def toString(): String = this match {
case LSL => "LSL"
case ASR => "ASR"
case LSR => "LSR"
case _ => throw new RuntimeException("ShitOp unknown case")
}
}
case object LSL extends ShiftOp
case object ASR extends ShiftOp
case object LSR extends ShiftOp
class LogicalOp {
override def toString(): String = this match {
case AND => return "AND"
case OR => return "OR"
case XOR => return "XOR"
case _ => throw new RuntimeException("LogicalOp unknown case")
}
}
case object AND extends LogicalOp
case object OR extends LogicalOp
case object XOR extends LogicalOp
}