mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-04-08 01:37:08 +00:00
implicit to given 🍌
This commit is contained in:
parent
495e3ec014
commit
730c4f390d
@ -3,5 +3,5 @@ package com.htmlism.nescant
|
||||
trait ByteSource[A]
|
||||
|
||||
object ByteSource:
|
||||
implicit val sourceForInt: ByteSource[Int] =
|
||||
given sourceForInt: ByteSource[Int] =
|
||||
new ByteSource[Int] {}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.htmlism.nescant
|
||||
|
||||
object GlobalAddress:
|
||||
implicit val sourceForGlobalAddress: ByteSource[GlobalAddress] =
|
||||
given sourceForGlobalAddress: ByteSource[GlobalAddress] =
|
||||
new ByteSource[GlobalAddress] {}
|
||||
|
||||
implicit val sinkForGlobalAddress: ByteSink[GlobalAddress] =
|
||||
given sinkForGlobalAddress: ByteSink[GlobalAddress] =
|
||||
new ByteSink[GlobalAddress] {}
|
||||
|
||||
case class GlobalAddress(n: Int)
|
||||
|
@ -4,5 +4,5 @@ trait Operand[A]:
|
||||
def encode(x: A): String
|
||||
|
||||
object Operand:
|
||||
implicit val operandForInt: Operand[Int] =
|
||||
given operandForInt: Operand[Int] =
|
||||
_.toString
|
||||
|
@ -10,12 +10,12 @@ package com.htmlism.nescant
|
||||
case class ReadWriteLocation[A](name: String, address: ZeroPageAddress)
|
||||
|
||||
object ReadWriteLocation:
|
||||
implicit def sourceForReadWriteLocation[A]: ByteSource[ReadWriteLocation[A]] =
|
||||
given sourceForReadWriteLocation[A]: ByteSource[ReadWriteLocation[A]] =
|
||||
new ByteSource[ReadWriteLocation[A]] {}
|
||||
|
||||
implicit def sinkForReadWriteLocation[A]: ByteSink[ReadWriteLocation[A]] =
|
||||
given sinkForReadWriteLocation[A]: ByteSink[ReadWriteLocation[A]] =
|
||||
new ByteSink[ReadWriteLocation[A]] {}
|
||||
|
||||
implicit def operandForReadWriteLocation[A]: Operand[ReadWriteLocation[A]] =
|
||||
given operandForReadWriteLocation[A]: Operand[ReadWriteLocation[A]] =
|
||||
new Operand[ReadWriteLocation[A]]:
|
||||
def encode(x: ReadWriteLocation[A]): String = ""
|
||||
|
@ -14,9 +14,9 @@ package com.htmlism.nescant
|
||||
case class VolatileDevice[A](name: String, address: ZeroPageAddress)
|
||||
|
||||
object VolatileDevice:
|
||||
implicit def sourceForVolatileDevice[A]: ByteSource[VolatileDevice[A]] =
|
||||
given sourceForVolatileDevice[A]: ByteSource[VolatileDevice[A]] =
|
||||
new ByteSource[VolatileDevice[A]] {}
|
||||
|
||||
implicit def operandForVolatileDevice[A]: Operand[VolatileDevice[A]] =
|
||||
given operandForVolatileDevice[A]: Operand[VolatileDevice[A]] =
|
||||
new Operand[VolatileDevice[A]]:
|
||||
def encode(x: VolatileDevice[A]): String = ""
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.htmlism.nescant
|
||||
|
||||
object ZeroPageAddress:
|
||||
implicit val sourceForZeroPageAddress: ByteSource[ZeroPageAddress] =
|
||||
given sourceForZeroPageAddress: ByteSource[ZeroPageAddress] =
|
||||
new ByteSource[ZeroPageAddress] {}
|
||||
|
||||
implicit val sinkForZeroPageAddress: ByteSink[ZeroPageAddress] =
|
||||
given sinkForZeroPageAddress: ByteSink[ZeroPageAddress] =
|
||||
new ByteSink[ZeroPageAddress] {}
|
||||
|
||||
case class ZeroPageAddress(n: Int)
|
||||
|
@ -4,7 +4,7 @@ sealed trait Address:
|
||||
def n: Int
|
||||
|
||||
object ZeroAddress:
|
||||
implicit val operandZero: Operand[ZeroAddress] =
|
||||
given operandZero: Operand[ZeroAddress] =
|
||||
new Operand[ZeroAddress]:
|
||||
val operandType: OperandType =
|
||||
MemoryLocation
|
||||
@ -15,13 +15,13 @@ object ZeroAddress:
|
||||
def toAddressLiteral(x: ZeroAddress): String =
|
||||
String.format("$%02x", x.n)
|
||||
|
||||
implicit val definitionValueForZero: DefinitionValue[ZeroAddress] =
|
||||
given definitionValueForZero: DefinitionValue[ZeroAddress] =
|
||||
operandZero.toAddressLiteral(_)
|
||||
|
||||
case class ZeroAddress(n: Int) extends Address
|
||||
|
||||
object GlobalAddress:
|
||||
implicit val operandGlobal: Operand[GlobalAddress] =
|
||||
given operandGlobal: Operand[GlobalAddress] =
|
||||
new Operand[GlobalAddress]:
|
||||
val operandType: OperandType =
|
||||
MemoryLocation
|
||||
@ -32,7 +32,7 @@ object GlobalAddress:
|
||||
def toAddressLiteral(x: GlobalAddress): String =
|
||||
String.format("$%04x", x.n)
|
||||
|
||||
implicit val definitionValueForGlobal: DefinitionValue[GlobalAddress] =
|
||||
given definitionValueForGlobal: DefinitionValue[GlobalAddress] =
|
||||
operandGlobal.toAddressLiteral(_)
|
||||
|
||||
case class GlobalAddress(n: Int) extends Address
|
||||
|
@ -83,7 +83,7 @@ case class Definition[A](name: String, x: A, comment: Option[String])(using ev:
|
||||
.value(x)
|
||||
|
||||
object Definition:
|
||||
implicit def namedResourceForDefinition[A]: NamedResource[Definition[A]] =
|
||||
given namedResourceForDefinition[A]: NamedResource[Definition[A]] =
|
||||
new NamedResource[Definition[A]]:
|
||||
def toDefinitions(x: Definition[A]): List[Definition[_]] =
|
||||
List(x)
|
||||
|
@ -5,7 +5,7 @@ import cats.data.NonEmptyList
|
||||
sealed trait Color
|
||||
|
||||
object Color:
|
||||
implicit val colorOperand: Operand[Color] =
|
||||
given colorOperand: Operand[Color] =
|
||||
new Operand[Color]:
|
||||
def toAddressLiteral(x: Color): String =
|
||||
"#" + x.toString.toLowerCase()
|
||||
@ -16,7 +16,7 @@ object Color:
|
||||
def operandType: OperandType =
|
||||
ValueLiteral
|
||||
|
||||
implicit val colorEnum: EnumAsm[Color] =
|
||||
given colorEnum: EnumAsm[Color] =
|
||||
new EnumAsm[Color]:
|
||||
def comment: String =
|
||||
"Colors"
|
||||
|
@ -8,5 +8,5 @@ trait DefinitionValue[A]:
|
||||
def value(x: A): String
|
||||
|
||||
object DefinitionValue:
|
||||
implicit val definitionValueForInt: DefinitionValue[Int] =
|
||||
given definitionValueForInt: DefinitionValue[Int] =
|
||||
(x: Int) => String.format("$%02x", x)
|
||||
|
@ -26,7 +26,7 @@ trait Mapping[A]:
|
||||
def comment(x: A): String
|
||||
|
||||
object Mapping:
|
||||
implicit def mappingForBitField[A](using ev: BitField[A]): Mapping[A] =
|
||||
given mappingForBitField[A](using ev: BitField[A]): Mapping[A] =
|
||||
new Mapping[A]:
|
||||
private lazy val valueMap =
|
||||
ev.all
|
||||
@ -49,7 +49,7 @@ object Mapping:
|
||||
def comment(x: A): String =
|
||||
"" // TODO
|
||||
|
||||
implicit def mappingForEnumAsm[A](using ev: EnumAsm[A]): Mapping[A] =
|
||||
given mappingForEnumAsm[A](using ev: EnumAsm[A]): Mapping[A] =
|
||||
new Mapping[A]:
|
||||
private lazy val valueMap =
|
||||
ev.all
|
||||
|
@ -13,7 +13,7 @@ trait Operand[A]:
|
||||
def operandType: OperandType
|
||||
|
||||
object Operand:
|
||||
implicit val operandInt: Operand[Int] =
|
||||
given operandInt: Operand[Int] =
|
||||
new Operand[Int]:
|
||||
val operandType: OperandType =
|
||||
ValueLiteral
|
||||
@ -24,7 +24,7 @@ object Operand:
|
||||
def toAddressLiteral(x: Int): String =
|
||||
String.format("#$%02x", x)
|
||||
|
||||
implicit def operandForMapping[A](using ev: Mapping[A]): Operand[A] =
|
||||
given operandForMapping[A](using ev: Mapping[A]): Operand[A] =
|
||||
new Operand[A]:
|
||||
def toAddressLiteral(x: A): String =
|
||||
"#" + ev.label(x)
|
||||
|
@ -19,7 +19,7 @@ case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress):
|
||||
ctx.push(STA, this)
|
||||
|
||||
object ReadWriteLocation:
|
||||
implicit def operandForReadWriteLocation[A]: Operand[ReadWriteLocation[A]] =
|
||||
given operandForReadWriteLocation[A]: Operand[ReadWriteLocation[A]] =
|
||||
new Operand[ReadWriteLocation[A]]:
|
||||
def toAddressLiteral(x: ReadWriteLocation[A]): String =
|
||||
x.name
|
||||
@ -30,7 +30,7 @@ object ReadWriteLocation:
|
||||
def operandType: OperandType =
|
||||
MemoryLocation
|
||||
|
||||
implicit def namedResourceForReadWriteLocation[A]: NamedResource[ReadWriteLocation[A]] =
|
||||
given namedResourceForReadWriteLocation[A]: NamedResource[ReadWriteLocation[A]] =
|
||||
new NamedResource[ReadWriteLocation[A]]:
|
||||
def toDefinitions(x: ReadWriteLocation[A]): List[Definition[ZeroAddress]] =
|
||||
List:
|
||||
|
@ -17,7 +17,7 @@ case class VolatileDevice[A](name: String, address: ZeroAddress):
|
||||
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
|
||||
|
||||
object VolatileDevice:
|
||||
implicit def namedResourceForVolatileDevice[A]: NamedResource[VolatileDevice[A]] =
|
||||
given namedResourceForVolatileDevice[A]: NamedResource[VolatileDevice[A]] =
|
||||
new NamedResource[VolatileDevice[A]]:
|
||||
def toDefinitions(x: VolatileDevice[A]): List[Definition[ZeroAddress]] =
|
||||
List:
|
||||
|
@ -90,7 +90,7 @@ case object Wisdom extends Triforce
|
||||
case object Power extends Triforce
|
||||
|
||||
object Triforce:
|
||||
implicit val enumTriforce: EnumAsm[Triforce] =
|
||||
given enumTriforce: EnumAsm[Triforce] =
|
||||
new EnumAsm[Triforce]:
|
||||
def comment: String =
|
||||
"foo as enum"
|
||||
@ -112,7 +112,7 @@ case object Left extends TestDirection
|
||||
case object Right extends TestDirection
|
||||
|
||||
object TestDirection:
|
||||
implicit val bitFieldDirection: BitField[TestDirection] =
|
||||
given bitFieldDirection: BitField[TestDirection] =
|
||||
new BitField[TestDirection]:
|
||||
def definitionGroupComment: String =
|
||||
"foo as bit field"
|
||||
|
@ -4,7 +4,7 @@ package snake
|
||||
import cats.data.NonEmptyList
|
||||
|
||||
object AsciiValue:
|
||||
implicit val asciiValueMapping: Mapping[AsciiValue] =
|
||||
given asciiValueMapping: Mapping[AsciiValue] =
|
||||
new Mapping[AsciiValue]:
|
||||
def definitionGroupComment: String =
|
||||
"ASCII values of keys controlling the snake"
|
||||
|
@ -4,7 +4,7 @@ package snake
|
||||
import cats.data.NonEmptyList
|
||||
|
||||
object Direction:
|
||||
implicit val directionBitField: BitField[Direction] =
|
||||
given directionBitField: BitField[Direction] =
|
||||
new BitField[Direction]:
|
||||
def definitionGroupComment: String =
|
||||
"Directions"
|
||||
|
Loading…
x
Reference in New Issue
Block a user