as instruction

This commit is contained in:
Mark Canlas 2022-10-03 01:28:18 -04:00
parent d1b07a1fbd
commit 08bc50f137
3 changed files with 29 additions and 15 deletions

View File

@ -3,11 +3,34 @@ package com.htmlism.scratchpad
trait Load[A]:
// TODO genericize to take in encoder
// from constant
def loadInt: String
def instruction: String
def const: Asm1[A] =
Asm1(List(instruction))
// from register
def from: String
def from[B <: Address: ReadAddress]: Asm2[A, B] =
Asm2(List(instruction))
object Load:
def apply[A: Load]: Load[A] =
summon[Load[A]]
case class Asm1[A](xs: List[String]):
def and[B]: Asm2[A, B] =
Asm2(xs)
case class Asm2[A, B](xs: List[String]):
def andThen(that: Asm2[A, B]): Asm2[2, B] =
Asm2(xs ++ that.xs)
// TODO not tested
// B type needs to be a class type, with evidence, not a case class
def swap[AA, BB](f: (R[A], R[B]) => (R[AA], R[BB])): Asm2[AA, BB] =
Asm2.from(f(R[A](), R[B]()), xs)
object Asm2:
def from[A, B](t2: (R[A], R[B]), xs: List[String]) =
Asm2[A, B](xs)
case class R[A]()

View File

@ -15,10 +15,7 @@ object Register:
object A:
given loadA: Load[A] with
def loadInt: String =
"LDA"
def from: String =
def instruction: String =
"LDA"
given storeA: Store[A] with
@ -29,10 +26,7 @@ object Register:
object X:
given loadX: Load[X] with
def loadInt: String =
"LDX"
def from: String =
def instruction: String =
"LDX"
given storeX: Store[X] with
@ -43,10 +37,7 @@ object Register:
object Y:
given loadY: Load[Y] with
def loadInt: String =
"LDY"
def from: String =
def instruction: String =
"LDY"
given storeY: Store[Y] with

View File

@ -14,7 +14,7 @@ package object syntax:
summon[Register[C]].self
val loadInstruction =
Load[C].loadInt // TODO load action needs to interact with encoder
Load[C].instruction // TODO load action needs to interact with encoder
val storeInstruction =
Store[C].to // TODO store action needs to interact with encoder