collapse store/load hierarchy

This commit is contained in:
Mark Canlas 2022-11-19 22:43:10 -05:00
parent f2fba577b6
commit b91df3e1b8
4 changed files with 14 additions and 60 deletions

View File

@ -1,47 +1,25 @@
package com.htmlism.scratchpad
// on the 6502, every register of this kind can store and load; so that capability was not parceled out into traits
// (unlike read/write leases)
sealed trait Register[A]:
def name: String
object Register:
given registerA: Register[A] with
def name: String = "A"
given registerX: Register[X] with
def name: String = "X"
given registerY: Register[Y] with
def name: String = "Y"
object A:
given loadA: Load[A] with
def instruction: String =
"LDA"
given storeA: Store[A] with
def instruction: String =
"STA"
given registerA: Register[A] with
def name: String = "A"
class A
object X:
given loadX: Load[X] with
def instruction: String =
"LDX"
given storeX: Store[X] with
def instruction: String =
"STX"
given registerX: Register[X] with
def name: String = "X"
class X
object Y:
given loadY: Load[Y] with
def instruction: String =
"LDY"
given storeY: Store[Y] with
def instruction: String =
"STY"
given registerY: Register[Y] with
def name: String = "Y"
class Y

View File

@ -1,8 +0,0 @@
package com.htmlism.scratchpad
trait Store[A]:
def instruction: String
object Store:
def apply[A: Store]: Store[A] =
summon[Store[A]]

View File

@ -1,21 +1,5 @@
package com.htmlism.scratchpad
trait Load[A]:
// TODO genericize to take in encoder
// from constant
def instruction: String
def const: Asm1Instructions[A] =
Asm1Instructions(List(instruction))
// from register
def from[B <: Address: ReadByteAddress]: Asm2Instructions[A, B] =
Asm2Instructions(List(instruction))
object Load:
def apply[A: Load]: Load[A] =
summon[Load[A]]
trait Asm1[A]:
def xs: List[String]
@ -51,12 +35,12 @@ case class Asm3Instructions[A, B, C](xs: List[String]) extends Asm3[A, B, C]
case class R[A]()
// TODO needs evidence that it is a storable target of one thing
case class StoreTo[A: Store, B]() extends Asm2[A, B]:
case class StoreTo[A: Register, B]() extends Asm2[A, B]:
// TODO
def xs: List[String] =
Nil
case class LoadImmediate[R: Load, A: ImmediateValue]() extends Asm1[R]:
case class LoadImmediate[R: Register, A: ImmediateValue]() extends Asm1[R]:
// TODO
def xs: List[String] =
Nil

View File

@ -5,11 +5,11 @@ package object syntax:
def writeConst[A: Loadable](x: A): syntax.PartiallyAppliedWrite[A, Addr] =
new syntax.PartiallyAppliedWrite(reg, x)
def writeFrom[R: Store]: Asm2[R, Addr] =
def writeFrom[R: Register]: Asm2[R, Addr] =
StoreTo[R, Addr]()
class PartiallyAppliedWrite[Addr: Loadable, A](reg: WriteByteAddress[A], x: Addr):
def apply[R: Load: Store: Register]: String =
def apply[R: Register]: String =
val literal =
summon[Loadable[Addr]].show(x)
@ -17,10 +17,10 @@ package object syntax:
summon[Register[R]].name
val loadInstruction =
Load[R].instruction // TODO load action needs to interact with encoder
"LD" + register // TODO load action needs to interact with encoder
val storeInstruction =
Store[R].instruction // TODO store action needs to interact with encoder
"ST" + register // TODO store action needs to interact with encoder
val first =
s"$loadInstruction $literal"