mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-06-26 01:29:31 +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.*
|
import weaver.*
|
||||||
|
|
||||||
object RegisterSuite extends FunSuite:
|
object RegisterSuite extends FunSuite:
|
||||||
private def reg[A](implicit ev: Register[A]) =
|
private def reg[A](using ev: Register[A]) =
|
||||||
ev
|
ev
|
||||||
|
|
||||||
test("the accumulator is a register"):
|
test("the accumulator is a register"):
|
||||||
|
|
|
@ -65,7 +65,7 @@ class DefinitionGroupContext:
|
||||||
private val xs: ListBuffer[Definition[_]] =
|
private val xs: ListBuffer[Definition[_]] =
|
||||||
ListBuffer()
|
ListBuffer()
|
||||||
|
|
||||||
def push[A](x: A)(implicit ev: NamedResource[A]): Unit =
|
def push[A](x: A)(using ev: NamedResource[A]): Unit =
|
||||||
ev
|
ev
|
||||||
.toDefinitions(x)
|
.toDefinitions(x)
|
||||||
.foreach(xs.append)
|
.foreach(xs.append)
|
||||||
|
@ -77,7 +77,7 @@ class DefinitionGroupContext:
|
||||||
* @param comment
|
* @param comment
|
||||||
* Typically used by resources to describe their type safety
|
* 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 =
|
lazy val value: String =
|
||||||
ev
|
ev
|
||||||
.value(x)
|
.value(x)
|
||||||
|
|
|
@ -58,7 +58,7 @@ object registers:
|
||||||
sealed trait IndexRegister
|
sealed trait IndexRegister
|
||||||
|
|
||||||
case object A extends Register:
|
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
|
ev.operandType match
|
||||||
case ValueLiteral =>
|
case ValueLiteral =>
|
||||||
ctx.push(ADC, x, s"add LITERAL to a")
|
ctx.push(ADC, x, s"add LITERAL to a")
|
||||||
|
@ -67,10 +67,10 @@ object registers:
|
||||||
ctx.push(ADC, x, s"add ADDR to a")
|
ctx.push(ADC, x, s"add ADDR to a")
|
||||||
|
|
||||||
case object X extends Register with DestinationA with IndexRegister:
|
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")
|
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) =
|
val (start, stop, instruction) =
|
||||||
spec match
|
spec match
|
||||||
case Incrementing(from, to) =>
|
case Incrementing(from, to) =>
|
||||||
|
@ -95,10 +95,10 @@ class CPU:
|
||||||
def A: registers.A.type =
|
def A: registers.A.type =
|
||||||
registers.A
|
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))
|
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
|
reg match
|
||||||
case registers.X =>
|
case registers.X =>
|
||||||
ctx.push(TXA)
|
ctx.push(TXA)
|
||||||
|
@ -108,13 +108,13 @@ class CPU:
|
||||||
def X: registers.X.type =
|
def X: registers.X.type =
|
||||||
registers.X
|
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")
|
ctx.push(TAX, s"set x to register $reg")
|
||||||
|
|
||||||
def Y: registers.Y.type =
|
def Y: registers.Y.type =
|
||||||
registers.Y
|
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")
|
ctx.push(TAY, s"set x to register $reg")
|
||||||
|
|
||||||
class AssemblyContext:
|
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.
|
* 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 =
|
def apply(n: Int): GlobalAddress =
|
||||||
GlobalAddress(baseAddress + n)
|
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(LDA, x, s"write ${ev.toShow(x)} to $name ($n)")
|
||||||
ctx.push(STA, GlobalAddress(baseAddress + n), "")
|
ctx.push(STA, GlobalAddress(baseAddress + n), "")
|
||||||
|
|
|
@ -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](implicit ev: BitField[A]): Mapping[A] =
|
implicit def 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](implicit ev: EnumAsm[A]): Mapping[A] =
|
implicit def 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
|
||||||
|
|
|
@ -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](implicit ev: Mapping[A]): Operand[A] =
|
implicit def 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)
|
||||||
|
|
|
@ -10,11 +10,11 @@ import com.htmlism.mos6502.model._
|
||||||
* The input type of the write and the output type of the read
|
* The input type of the write and the output type of the read
|
||||||
*/
|
*/
|
||||||
case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress):
|
case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress):
|
||||||
def read(implicit ctx: AssemblyContext): Unit =
|
def read(using ctx: AssemblyContext): Unit =
|
||||||
val _ = ctx
|
val _ = ctx
|
||||||
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
|
// 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(LDA, x)
|
||||||
ctx.push(STA, this)
|
ctx.push(STA, this)
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ case class UnaryInstruction(instruction: Instruction, comment: Option[String]) e
|
||||||
def toTriplet: (String, Option[String], Option[String]) =
|
def toTriplet: (String, Option[String], Option[String]) =
|
||||||
(instruction.toString, None, comment)
|
(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]
|
ev: Operand[A]
|
||||||
) extends Statement:
|
) extends Statement:
|
||||||
def toAsm: String =
|
def toAsm: String =
|
||||||
|
|
|
@ -12,7 +12,7 @@ package com.htmlism.mos6502.dsl
|
||||||
* The return type of the read
|
* The return type of the read
|
||||||
*/
|
*/
|
||||||
case class VolatileDevice[A](name: String, address: ZeroAddress):
|
case class VolatileDevice[A](name: String, address: ZeroAddress):
|
||||||
def read(implicit ctx: AssemblyContext): Unit =
|
def read(using ctx: AssemblyContext): Unit =
|
||||||
val _ = ctx
|
val _ = ctx
|
||||||
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
|
// ctx.push(LDA, ev, s"write ${ev.toShow(x)} to $name ($n)")
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.htmlism.mos6502.dsl
|
||||||
package syntax
|
package syntax
|
||||||
|
|
||||||
trait AsmDocSyntax:
|
trait AsmDocSyntax:
|
||||||
def asm(f: AssemblyContext => Unit)(implicit ctx: AsmDocumentContext): Unit =
|
def asm(f: AssemblyContext => Unit)(using ctx: AsmDocumentContext): Unit =
|
||||||
val asmCtx: AssemblyContext =
|
val asmCtx: AssemblyContext =
|
||||||
new AssemblyContext
|
new AssemblyContext
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ trait AsmDocSyntax:
|
||||||
ctx
|
ctx
|
||||||
.push(asmCtx.toFragment)
|
.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 =
|
val g: DefinitionGroupContext =
|
||||||
new DefinitionGroupContext
|
new DefinitionGroupContext
|
||||||
|
|
||||||
|
@ -23,17 +23,17 @@ trait AsmDocSyntax:
|
||||||
ctx
|
ctx
|
||||||
.push(g.toGroup(s))
|
.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
|
val _ = implicitly[EnumAsm[A]] // TODO unused
|
||||||
|
|
||||||
mapping
|
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
|
val _ = implicitly[BitField[A]] // TODO unused
|
||||||
|
|
||||||
mapping
|
mapping
|
||||||
|
|
||||||
def mapping[A](implicit ctx: AsmDocumentContext, ev: Mapping[A]): Unit =
|
def mapping[A](using ctx: AsmDocumentContext, ev: Mapping[A]): Unit =
|
||||||
val xs =
|
val xs =
|
||||||
ev.all
|
ev.all
|
||||||
.map(x => ev.label(x) -> ev.value(x))
|
.map(x => ev.label(x) -> ev.value(x))
|
||||||
|
|
|
@ -4,7 +4,7 @@ package syntax
|
||||||
import com.htmlism.mos6502.model._
|
import com.htmlism.mos6502.model._
|
||||||
|
|
||||||
trait AsmSyntax:
|
trait AsmSyntax:
|
||||||
def label(s: String)(implicit ctx: AssemblyContext): Unit =
|
def label(s: String)(using ctx: AssemblyContext): Unit =
|
||||||
ctx
|
ctx
|
||||||
.label(s)
|
.label(s)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ trait AsmSyntax:
|
||||||
|
|
||||||
Subroutine(s, ctx.toFragment, ctx.getJumps)
|
Subroutine(s, ctx.toFragment, ctx.getJumps)
|
||||||
|
|
||||||
def jump(s: Subroutine)(implicit ctx: AssemblyContext): Unit =
|
def jump(s: Subroutine)(using ctx: AssemblyContext): Unit =
|
||||||
ctx
|
ctx
|
||||||
.addJump(s)
|
.addJump(s)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.htmlism.mos6502.dsl
|
||||||
package syntax
|
package syntax
|
||||||
|
|
||||||
trait DefinitionGroupSyntax:
|
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 =
|
val definition =
|
||||||
Definition(name, x)
|
Definition(name, x)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ trait DefinitionGroupSyntax:
|
||||||
|
|
||||||
definition
|
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 =
|
val definition =
|
||||||
Definition(name, x)
|
Definition(name, x)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user