add definition literal support

This commit is contained in:
Mark Canlas 2020-08-16 01:51:05 -04:00
parent 9b60d46e03
commit 45af484839
3 changed files with 15 additions and 1 deletions

View File

@ -11,6 +11,9 @@ object ZeroAddress {
def toShow(x: ZeroAddress): String =
String.format("global address 0x%02x", x.n)
def toDefinitionLiteral(x: ZeroAddress): String =
toAddressLiteral(x)
def toAddressLiteral(x: ZeroAddress): String =
String.format("$%02x", x.n)
}
@ -27,6 +30,9 @@ object GlobalAddress {
def toShow(x: GlobalAddress): String =
String.format("global address 0x%04x", x.n)
def toDefinitionLiteral(x: GlobalAddress): String =
toAddressLiteral(x)
def toAddressLiteral(x: GlobalAddress): String =
String.format("$%04x", x.n)
}

View File

@ -57,7 +57,7 @@ class DefinitionGroupContext {
case class Definition[A: Operand](name: String, x: A) {
lazy val value: String =
implicitly[Operand[A]]
.toAddressLiteral(x)
.toDefinitionLiteral(x)
}
class AsmBlockContext {

View File

@ -9,6 +9,8 @@ trait Operand[A] {
def operandType: OperandType
def toDefinitionLiteral(x: A): String
def contra[B](f: B => A, show: B => String): Operand[B] =
new Operand[B] {
val operandType: OperandType =
@ -17,6 +19,9 @@ trait Operand[A] {
def toShow(x: B): String =
show(x)
def toDefinitionLiteral(x: B): String =
toAddressLiteral(x)
def toAddressLiteral(x: B): String =
self.toAddressLiteral(f(x))
}
@ -31,6 +36,9 @@ object Operand {
def toShow(x: Int): String =
x.toString
def toDefinitionLiteral(x: Int): String =
x.toString
def toAddressLiteral(x: Int): String =
String.format("#$%02x", x)
}