define load and store

This commit is contained in:
Mark Canlas 2022-09-07 11:21:22 -04:00
parent 0a199d6f53
commit 28d945c8f1
16 changed files with 69 additions and 38 deletions

View File

@ -17,6 +17,5 @@ object ReadWriteLocation:
new ByteSink[ReadWriteLocation[A]] {}
implicit def operandForReadWriteLocation[A]: Operand[ReadWriteLocation[A]] =
new Operand[ReadWriteLocation[A]] {
new Operand[ReadWriteLocation[A]]:
def encode(x: ReadWriteLocation[A]): String = ""
}

View File

@ -18,6 +18,5 @@ object VolatileDevice:
new ByteSource[VolatileDevice[A]] {}
implicit def operandForVolatileDevice[A]: Operand[VolatileDevice[A]] =
new Operand[VolatileDevice[A]] {
new Operand[VolatileDevice[A]]:
def encode(x: VolatileDevice[A]): String = ""
}

View File

@ -0,0 +1,8 @@
package com.htmlism.scratchpad
trait Load[A]:
// from constant
def init: String
// from register
def from: String

View File

@ -13,6 +13,44 @@ object Register:
given registerY: Register[Y] with
def self: String = "Y"
object A:
given loadA: Load[A] with
def init: String =
"LDA"
def from: String =
"LDA"
given storeA: Store[A] with
def to: String =
"STA"
class A
object X:
given loadX: Load[X] with
def init: String =
"LDX"
def from: String =
"LDX"
given storeX: Store[X] with
def to: String =
"STX"
class X
object Y:
given loadY: Load[Y] with
def init: String =
"LDY"
def from: String =
"LDY"
given storeY: Store[Y] with
def to: String =
"STY"
class Y

View File

@ -0,0 +1,4 @@
package com.htmlism.scratchpad
trait Store[A]:
def to: String

View File

@ -16,7 +16,7 @@ trait BitExtractor[A]:
* A combinator for appending one extractor to another
*/
def >>[B](that: BitExtractor[B]): BitExtractor[(A, B)] =
new BitExtractor[(A, B)] {
new BitExtractor[(A, B)]:
def length: Int = self.length + that.length
def unapply(n: Int): Option[(A, B)] =
@ -25,7 +25,6 @@ trait BitExtractor[A]:
shifted = n >> that.length
a <- self.unapply(shifted)
} yield (a, b)
}
object AtomExtractor:
@tailrec

View File

@ -5,7 +5,7 @@ sealed trait Address:
object ZeroAddress:
implicit val operandZero: Operand[ZeroAddress] =
new Operand[ZeroAddress] {
new Operand[ZeroAddress]:
val operandType: OperandType =
MemoryLocation
@ -14,7 +14,6 @@ object ZeroAddress:
def toAddressLiteral(x: ZeroAddress): String =
String.format("$%02x", x.n)
}
implicit val definitionValueForZero: DefinitionValue[ZeroAddress] =
operandZero.toAddressLiteral(_)
@ -23,7 +22,7 @@ case class ZeroAddress(n: Int) extends Address
object GlobalAddress:
implicit val operandGlobal: Operand[GlobalAddress] =
new Operand[GlobalAddress] {
new Operand[GlobalAddress]:
val operandType: OperandType =
MemoryLocation
@ -32,7 +31,6 @@ object GlobalAddress:
def toAddressLiteral(x: GlobalAddress): String =
String.format("$%04x", x.n)
}
implicit val definitionValueForGlobal: DefinitionValue[GlobalAddress] =
operandGlobal.toAddressLiteral(_)

View File

@ -84,10 +84,9 @@ case class Definition[A](name: String, x: A, comment: Option[String])(implicit e
object Definition:
implicit def namedResourceForDefinition[A]: NamedResource[Definition[A]] =
new NamedResource[Definition[A]] {
new NamedResource[Definition[A]]:
def toDefinitions(x: Definition[A]): List[Definition[_]] =
List(x)
}
def apply[A: DefinitionValue](name: String, x: A): Definition[A] =
Definition(name, x, None)

View File

@ -6,7 +6,7 @@ sealed trait Color
object Color:
implicit val colorOperand: Operand[Color] =
new Operand[Color] {
new Operand[Color]:
def toAddressLiteral(x: Color): String =
"#" + x.toString.toLowerCase()
@ -15,10 +15,9 @@ object Color:
def operandType: OperandType =
ValueLiteral
}
implicit val colorEnum: EnumAsm[Color] =
new EnumAsm[Color] {
new EnumAsm[Color]:
def comment: String =
"Colors"
@ -47,7 +46,6 @@ object Color:
def comment(x: Color): String =
x.toString
}
case object Black extends Color
case object White extends Color

View File

@ -27,7 +27,7 @@ trait Mapping[A]:
object Mapping:
implicit def mappingForBitField[A](implicit ev: BitField[A]): Mapping[A] =
new Mapping[A] {
new Mapping[A]:
private lazy val valueMap =
ev.all
.toList
@ -48,10 +48,9 @@ object Mapping:
def comment(x: A): String =
"" // TODO
}
implicit def mappingForEnumAsm[A](implicit ev: EnumAsm[A]): Mapping[A] =
new Mapping[A] {
new Mapping[A]:
private lazy val valueMap =
ev.all
.toList
@ -72,4 +71,3 @@ object Mapping:
def comment(x: A): String =
ev.comment(x)
}

View File

@ -14,7 +14,7 @@ trait Operand[A]:
object Operand:
implicit val operandInt: Operand[Int] =
new Operand[Int] {
new Operand[Int]:
val operandType: OperandType =
ValueLiteral
@ -23,10 +23,9 @@ object Operand:
def toAddressLiteral(x: Int): String =
String.format("#$%02x", x)
}
implicit def operandForMapping[A](implicit ev: Mapping[A]): Operand[A] =
new Operand[A] {
new Operand[A]:
def toAddressLiteral(x: A): String =
"#" + ev.label(x)
@ -35,4 +34,3 @@ object Operand:
def operandType: OperandType =
ValueLiteral
}

View File

@ -20,7 +20,7 @@ case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress):
object ReadWriteLocation:
implicit def operandForReadWriteLocation[A]: Operand[ReadWriteLocation[A]] =
new Operand[ReadWriteLocation[A]] {
new Operand[ReadWriteLocation[A]]:
def toAddressLiteral(x: ReadWriteLocation[A]): String =
x.name
@ -29,12 +29,10 @@ object ReadWriteLocation:
def operandType: OperandType =
MemoryLocation
}
implicit def namedResourceForReadWriteLocation[A]: NamedResource[ReadWriteLocation[A]] =
new NamedResource[ReadWriteLocation[A]] {
new NamedResource[ReadWriteLocation[A]]:
def toDefinitions(x: ReadWriteLocation[A]): List[Definition[ZeroAddress]] =
List {
Definition(x.name, x.address, "Read/write location for A values")
}
}

View File

@ -18,9 +18,8 @@ case class VolatileDevice[A](name: String, address: ZeroAddress):
object VolatileDevice:
implicit def namedResourceForVolatileDevice[A]: NamedResource[VolatileDevice[A]] =
new NamedResource[VolatileDevice[A]] {
new NamedResource[VolatileDevice[A]]:
def toDefinitions(x: VolatileDevice[A]): List[Definition[ZeroAddress]] =
List {
Definition(x.name, x.address, "Volatile generator for A values")
}
}

View File

@ -95,7 +95,7 @@ case object Power extends Triforce
object Triforce:
implicit val enumTriforce: EnumAsm[Triforce] =
new EnumAsm[Triforce] {
new EnumAsm[Triforce]:
def comment: String =
"foo as enum"
@ -107,7 +107,6 @@ object Triforce:
def comment(x: Triforce): String =
x.toString
}
sealed trait TestDirection
@ -118,7 +117,7 @@ case object Right extends TestDirection
object TestDirection:
implicit val bitFieldDirection: BitField[TestDirection] =
new BitField[TestDirection] {
new BitField[TestDirection]:
def definitionGroupComment: String =
"foo as bit field"
@ -127,4 +126,3 @@ object TestDirection:
def label(x: TestDirection): String =
x.toString.toLowerCase
}

View File

@ -5,7 +5,7 @@ import cats.data.NonEmptyList
object AsciiValue:
implicit val asciiValueMapping: Mapping[AsciiValue] =
new Mapping[AsciiValue] {
new Mapping[AsciiValue]:
def definitionGroupComment: String =
"ASCII values of keys controlling the snake"
@ -24,7 +24,6 @@ object AsciiValue:
def comment(x: AsciiValue): String =
x.toString
}
sealed trait AsciiValue

View File

@ -5,7 +5,7 @@ import cats.data.NonEmptyList
object Direction:
implicit val directionBitField: BitField[Direction] =
new BitField[Direction] {
new BitField[Direction]:
def definitionGroupComment: String =
"Directions"
@ -14,7 +14,6 @@ object Direction:
def label(x: Direction): String =
"moving" + x.toString
}
sealed trait Direction