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