specify that resources are byte length

This commit is contained in:
Mark Canlas 2022-10-20 14:08:11 -07:00
parent 3a7f7b99a1
commit 7ac6d8f831
4 changed files with 18 additions and 9 deletions

View File

@ -9,7 +9,7 @@ trait Load[A]:
Asm1Instructions(List(instruction))
// from register
def from[B <: Address: ReadAddress]: Asm2Instructions[A, B] =
def from[B <: Address: ReadByteAddress]: Asm2Instructions[A, B] =
Asm2Instructions(List(instruction))
object Load:

View File

@ -9,12 +9,21 @@ class ZeroPageAddress(val n: Int, val alias: String) extends Address
class AbsoluteAddress(val n: Int, val alias: String) extends Address
sealed trait ReadAddress[A] extends Address
sealed trait ReadByteAddress[A] extends Address
sealed trait WriteAddress[A] extends Address
sealed trait WriteByteAddress[A] extends Address
trait Volatile[A] extends ReadAddress[A]
/**
* To be extended by the address companion object, to signify that this is a volatile resource of length byte
*/
trait VolatileByte[A] extends ReadByteAddress[A]
trait ReadWriteAddress[A] extends ReadAddress[A] with WriteAddress[A]
/**
* To be extended by the address companion object, to signify that this is a read/write resource of length byte
*/
trait ReadWriteByteAddress[A] extends ReadByteAddress[A] with WriteByteAddress[A]
trait WriteOnlyAddress[A] extends WriteAddress[A]
/**
* To be extended by the address companion object, to signify that this is a write-only resource of length byte
*/
trait WriteOnlyByteAddress[A] extends WriteByteAddress[A]

View File

@ -1,14 +1,14 @@
package com.htmlism.scratchpad
package object syntax:
implicit class WriteRegisterOps[Addr](reg: WriteAddress[Addr]):
implicit class WriteRegisterOps[Addr](reg: WriteByteAddress[Addr]):
def writeConst[A: Loadable](x: A): syntax.PartiallyAppliedWrite[A, Addr] =
new syntax.PartiallyAppliedWrite(reg, x)
def writeFrom[R: Store]: Asm2[R, Addr] =
StoreTo[R, Addr]()
class PartiallyAppliedWrite[Addr: Loadable, A](reg: WriteAddress[A], x: Addr):
class PartiallyAppliedWrite[Addr: Loadable, A](reg: WriteByteAddress[A], x: Addr):
def apply[R: Load: Store: Register]: String =
val literal =
summon[Loadable[Addr]].show(x)

View File

@ -5,7 +5,7 @@ import org.scalatest.matchers.should._
import com.htmlism.scratchpad.syntax._
object ExampleRegister extends ZeroPageAddress(0x01, "example") with WriteOnlyAddress[ExampleRegister]
object ExampleRegister extends ZeroPageAddress(0x01, "example") with WriteOnlyByteAddress[ExampleRegister]
class ExampleRegister