mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-03-13 13:30:43 +00:00
implicit to using 🤖
This commit is contained in:
parent
23380e3e7c
commit
495e3ec014
@ -3,7 +3,7 @@ package com.htmlism.firepower.core
|
||||
import weaver.*
|
||||
|
||||
object RegisterSuite extends FunSuite:
|
||||
private def reg[A](implicit ev: Register[A]) =
|
||||
private def reg[A](using ev: Register[A]) =
|
||||
ev
|
||||
|
||||
test("the accumulator is a register"):
|
||||
|
@ -65,7 +65,7 @@ class DefinitionGroupContext:
|
||||
private val xs: ListBuffer[Definition[_]] =
|
||||
ListBuffer()
|
||||
|
||||
def push[A](x: A)(implicit ev: NamedResource[A]): Unit =
|
||||
def push[A](x: A)(using ev: NamedResource[A]): Unit =
|
||||
ev
|
||||
.toDefinitions(x)
|
||||
.foreach(xs.append)
|
||||
@ -77,7 +77,7 @@ class DefinitionGroupContext:
|
||||
* @param comment
|
||||
* Typically used by resources to describe their type safety
|
||||
*/
|
||||
case class Definition[A](name: String, x: A, comment: Option[String])(implicit ev: DefinitionValue[A]):
|
||||
case class Definition[A](name: String, x: A, comment: Option[String])(using ev: DefinitionValue[A]):
|
||||
lazy val value: String =
|
||||
ev
|
||||
.value(x)
|
||||
|
@ -58,7 +58,7 @@ object registers:
|
||||
sealed trait IndexRegister
|
||||
|
||||
case object A extends Register:
|
||||
def add[A](x: A)(implicit ctx: AssemblyContext, ev: Operand[A]): Unit =
|
||||
def add[A](x: A)(using ctx: AssemblyContext, ev: Operand[A]): Unit =
|
||||
ev.operandType match
|
||||
case ValueLiteral =>
|
||||
ctx.push(ADC, x, s"add LITERAL to a")
|
||||
@ -67,10 +67,10 @@ object registers:
|
||||
ctx.push(ADC, x, s"add ADDR to a")
|
||||
|
||||
case object X extends Register with DestinationA with IndexRegister:
|
||||
def incr(implicit ctx: AssemblyContext): Unit =
|
||||
def incr(using ctx: AssemblyContext): Unit =
|
||||
ctx.push(INX, "incr x")
|
||||
|
||||
def loop(s: String, spec: RangeSpec)(f: AssemblyContext => Unit)(implicit ctx: AssemblyContext): Unit =
|
||||
def loop(s: String, spec: RangeSpec)(f: AssemblyContext => Unit)(using ctx: AssemblyContext): Unit =
|
||||
val (start, stop, instruction) =
|
||||
spec match
|
||||
case Incrementing(from, to) =>
|
||||
@ -95,10 +95,10 @@ class CPU:
|
||||
def A: registers.A.type =
|
||||
registers.A
|
||||
|
||||
def A_=[A](x: A)(implicit ctx: AssemblyContext, ev: Operand[A]): Unit =
|
||||
def A_=[A](x: A)(using ctx: AssemblyContext, ev: Operand[A]): Unit =
|
||||
ctx.push(LDA, x, "set A to " + ev.toShow(x))
|
||||
|
||||
def A_=(reg: registers.DestinationA)(implicit ctx: AssemblyContext): Unit =
|
||||
def A_=(reg: registers.DestinationA)(using ctx: AssemblyContext): Unit =
|
||||
reg match
|
||||
case registers.X =>
|
||||
ctx.push(TXA)
|
||||
@ -108,13 +108,13 @@ class CPU:
|
||||
def X: registers.X.type =
|
||||
registers.X
|
||||
|
||||
def X_=(reg: registers.A.type)(implicit ctx: AssemblyContext): Unit =
|
||||
def X_=(reg: registers.A.type)(using ctx: AssemblyContext): Unit =
|
||||
ctx.push(TAX, s"set x to register $reg")
|
||||
|
||||
def Y: registers.Y.type =
|
||||
registers.Y
|
||||
|
||||
def Y_=(reg: registers.A.type)(implicit ctx: AssemblyContext): Unit =
|
||||
def Y_=(reg: registers.A.type)(using ctx: AssemblyContext): Unit =
|
||||
ctx.push(TAY, s"set x to register $reg")
|
||||
|
||||
class AssemblyContext:
|
||||
|
@ -5,10 +5,10 @@ import com.htmlism.mos6502.model._
|
||||
/**
|
||||
* A typed collection, like memory mapped to screen pixels. Access by index instead of by address.
|
||||
*/
|
||||
case class IndexedAddressCollection[A](baseAddress: Int, name: String)(implicit ev: Operand[A]):
|
||||
case class IndexedAddressCollection[A](baseAddress: Int, name: String)(using ev: Operand[A]):
|
||||
def apply(n: Int): GlobalAddress =
|
||||
GlobalAddress(baseAddress + n)
|
||||
|
||||
def write(n: Int, x: A)(implicit ctx: AssemblyContext): Unit =
|
||||
def write(n: Int, x: A)(using ctx: AssemblyContext): Unit =
|
||||
ctx.push(LDA, x, s"write ${ev.toShow(x)} to $name ($n)")
|
||||
ctx.push(STA, GlobalAddress(baseAddress + n), "")
|
||||
|
@ -26,7 +26,7 @@ trait Mapping[A]:
|
||||
def comment(x: A): String
|
||||
|
||||
object Mapping:
|
||||
implicit def mappingForBitField[A](implicit ev: BitField[A]): Mapping[A] =
|
||||
implicit def 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](implicit ev: EnumAsm[A]): Mapping[A] =
|
||||
implicit def mappingForEnumAsm[A](using ev: EnumAsm[A]): Mapping[A] =
|
||||
new Mapping[A]:
|
||||
private lazy val valueMap =
|
||||
ev.all
|
||||
|
@ -24,7 +24,7 @@ object Operand:
|
||||
def toAddressLiteral(x: Int): String =
|
||||
String.format("#$%02x", x)
|
||||
|
||||
implicit def operandForMapping[A](implicit ev: Mapping[A]): Operand[A] =
|
||||
implicit def operandForMapping[A](using ev: Mapping[A]): Operand[A] =
|
||||
new Operand[A]:
|
||||
def toAddressLiteral(x: A): String =
|
||||
"#" + ev.label(x)
|
||||
|
@ -10,11 +10,11 @@ import com.htmlism.mos6502.model._
|
||||
* The input type of the write and the output type of the read
|
||||
*/
|
||||
case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress):
|
||||
def read(implicit ctx: AssemblyContext): Unit =
|
||||
def read(using ctx: AssemblyContext): Unit =
|
||||
val _ = ctx
|
||||
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
|
||||
|
||||
def write(x: A)(implicit ctx: AssemblyContext): Unit =
|
||||
def write(x: A)(using ctx: AssemblyContext): Unit =
|
||||
ctx.push(LDA, x)
|
||||
ctx.push(STA, this)
|
||||
|
||||
|
@ -27,7 +27,7 @@ case class UnaryInstruction(instruction: Instruction, comment: Option[String]) e
|
||||
def toTriplet: (String, Option[String], Option[String]) =
|
||||
(instruction.toString, None, comment)
|
||||
|
||||
case class InstructionWithOperand[A](instruction: Instruction, operand: A, comment: Option[String])(implicit
|
||||
case class InstructionWithOperand[A](instruction: Instruction, operand: A, comment: Option[String])(using
|
||||
ev: Operand[A]
|
||||
) extends Statement:
|
||||
def toAsm: String =
|
||||
|
@ -12,7 +12,7 @@ package com.htmlism.mos6502.dsl
|
||||
* The return type of the read
|
||||
*/
|
||||
case class VolatileDevice[A](name: String, address: ZeroAddress):
|
||||
def read(implicit ctx: AssemblyContext): Unit =
|
||||
def read(using ctx: AssemblyContext): Unit =
|
||||
val _ = ctx
|
||||
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
|
||||
|
||||
|
@ -2,7 +2,7 @@ package com.htmlism.mos6502.dsl
|
||||
package syntax
|
||||
|
||||
trait AsmDocSyntax:
|
||||
def asm(f: AssemblyContext => Unit)(implicit ctx: AsmDocumentContext): Unit =
|
||||
def asm(f: AssemblyContext => Unit)(using ctx: AsmDocumentContext): Unit =
|
||||
val asmCtx: AssemblyContext =
|
||||
new AssemblyContext
|
||||
|
||||
@ -14,7 +14,7 @@ trait AsmDocSyntax:
|
||||
ctx
|
||||
.push(asmCtx.toFragment)
|
||||
|
||||
def group[A](s: String)(f: DefinitionGroupContext => A)(implicit ctx: AsmDocumentContext): Unit =
|
||||
def group[A](s: String)(f: DefinitionGroupContext => A)(using ctx: AsmDocumentContext): Unit =
|
||||
val g: DefinitionGroupContext =
|
||||
new DefinitionGroupContext
|
||||
|
||||
@ -23,17 +23,17 @@ trait AsmDocSyntax:
|
||||
ctx
|
||||
.push(g.toGroup(s))
|
||||
|
||||
def enumAsm[A: EnumAsm: Mapping](implicit ctx: AsmDocumentContext): Unit =
|
||||
def enumAsm[A: EnumAsm: Mapping](using ctx: AsmDocumentContext): Unit =
|
||||
val _ = implicitly[EnumAsm[A]] // TODO unused
|
||||
|
||||
mapping
|
||||
|
||||
def bitField[A: BitField: Mapping](implicit ctx: AsmDocumentContext): Unit =
|
||||
def bitField[A: BitField: Mapping](using ctx: AsmDocumentContext): Unit =
|
||||
val _ = implicitly[BitField[A]] // TODO unused
|
||||
|
||||
mapping
|
||||
|
||||
def mapping[A](implicit ctx: AsmDocumentContext, ev: Mapping[A]): Unit =
|
||||
def mapping[A](using ctx: AsmDocumentContext, ev: Mapping[A]): Unit =
|
||||
val xs =
|
||||
ev.all
|
||||
.map(x => ev.label(x) -> ev.value(x))
|
||||
|
@ -4,7 +4,7 @@ package syntax
|
||||
import com.htmlism.mos6502.model._
|
||||
|
||||
trait AsmSyntax:
|
||||
def label(s: String)(implicit ctx: AssemblyContext): Unit =
|
||||
def label(s: String)(using ctx: AssemblyContext): Unit =
|
||||
ctx
|
||||
.label(s)
|
||||
|
||||
@ -18,7 +18,7 @@ trait AsmSyntax:
|
||||
|
||||
Subroutine(s, ctx.toFragment, ctx.getJumps)
|
||||
|
||||
def jump(s: Subroutine)(implicit ctx: AssemblyContext): Unit =
|
||||
def jump(s: Subroutine)(using ctx: AssemblyContext): Unit =
|
||||
ctx
|
||||
.addJump(s)
|
||||
|
||||
|
@ -2,7 +2,7 @@ package com.htmlism.mos6502.dsl
|
||||
package syntax
|
||||
|
||||
trait DefinitionGroupSyntax:
|
||||
def define[A <: Address: DefinitionValue](name: String, x: A)(implicit ctx: DefinitionGroupContext): Definition[A] =
|
||||
def define[A <: Address: DefinitionValue](name: String, x: A)(using ctx: DefinitionGroupContext): Definition[A] =
|
||||
val definition =
|
||||
Definition(name, x)
|
||||
|
||||
@ -11,7 +11,7 @@ trait DefinitionGroupSyntax:
|
||||
|
||||
definition
|
||||
|
||||
def constant(name: String, x: Int)(implicit ctx: DefinitionGroupContext): Definition[Int] =
|
||||
def constant(name: String, x: Int)(using ctx: DefinitionGroupContext): Definition[Int] =
|
||||
val definition =
|
||||
Definition(name, x)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user