specify byte width

This commit is contained in:
Mark Canlas 2020-08-28 12:31:13 -04:00
parent 3c1d811aef
commit 65065e074e
12 changed files with 81 additions and 78 deletions

View File

@ -1,7 +1,7 @@
package com.htmlism.nescant
trait Sink[A]
trait ByteSink[A]
object Sink {
object ByteSink {
// TODO int cannot be a source
}

View File

@ -0,0 +1,8 @@
package com.htmlism.nescant
trait ByteSource[A]
object ByteSource {
implicit val sourceForInt: ByteSource[Int] =
new ByteSource[Int] {}
}

View File

@ -1,11 +1,11 @@
package com.htmlism.nescant
object GlobalAddress {
implicit val sourceForGlobalAddress: Source[GlobalAddress] =
new Source[GlobalAddress] {}
implicit val sourceForGlobalAddress: ByteSource[GlobalAddress] =
new ByteSource[GlobalAddress] {}
implicit val sinkForGlobalAddress: Sink[GlobalAddress] =
new Sink[GlobalAddress] {}
implicit val sinkForGlobalAddress: ByteSink[GlobalAddress] =
new ByteSink[GlobalAddress] {}
}
case class GlobalAddress(n: Int)

View File

@ -8,11 +8,11 @@ package com.htmlism.nescant
case class ReadWriteLocation[A](name: String, address: ZeroPageAddress)
object ReadWriteLocation {
implicit def sourceForReadWriteLocation[A: Operand]: Source[ReadWriteLocation[A]] =
new Source[ReadWriteLocation[A]] {}
implicit def sourceForReadWriteLocation[A: Operand]: ByteSource[ReadWriteLocation[A]] =
new ByteSource[ReadWriteLocation[A]] {}
implicit def sinkForReadWriteLocation[A: Operand]: Sink[ReadWriteLocation[A]] =
new Sink[ReadWriteLocation[A]] {}
implicit def sinkForReadWriteLocation[A: Operand]: ByteSink[ReadWriteLocation[A]] =
new ByteSink[ReadWriteLocation[A]] {}
implicit def operandForReadWriteLocation[A: Operand]: Operand[ReadWriteLocation[A]] =
new Operand[ReadWriteLocation[A]] {

View File

@ -1,8 +0,0 @@
package com.htmlism.nescant
trait Source[A]
object Source {
implicit val sourceForInt: Source[Int] =
new Source[Int] {}
}

View File

@ -12,8 +12,8 @@ package com.htmlism.nescant
case class VolatileDevice[A](name: String, address: ZeroPageAddress)
object VolatileDevice {
implicit def sourceForVolatileDevice[A: Operand]: Source[VolatileDevice[A]] =
new Source[VolatileDevice[A]] {}
implicit def sourceForVolatileDevice[A: Operand]: ByteSource[VolatileDevice[A]] =
new ByteSource[VolatileDevice[A]] {}
implicit def operandForVolatileDevice[A: Operand]: Operand[VolatileDevice[A]] =
new Operand[VolatileDevice[A]] {

View File

@ -1,11 +1,11 @@
package com.htmlism.nescant
object ZeroPageAddress {
implicit val sourceForZeroPageAddress: Source[ZeroPageAddress] =
new Source[ZeroPageAddress] {}
implicit val sourceForZeroPageAddress: ByteSource[ZeroPageAddress] =
new ByteSource[ZeroPageAddress] {}
implicit val sinkForZeroPageAddress: Sink[ZeroPageAddress] =
new Sink[ZeroPageAddress] {}
implicit val sinkForZeroPageAddress: ByteSink[ZeroPageAddress] =
new ByteSink[ZeroPageAddress] {}
}
case class ZeroPageAddress(n: Int)

View File

@ -9,8 +9,8 @@ package object dsl {
GlobalAddress(n)
}
implicit class SinkOps[A: Sink](x: A) {
def write[B: Source](src: B): Unit = {
implicit class SinkOps[A: ByteSink](x: A) {
def write[B: ByteSource](src: B): Unit = {
val _ = src
}
}

View File

@ -0,0 +1,21 @@
package com.htmlism.nescant
package dsl
import org.scalatest.flatspec._
import org.scalatest.matchers._
class ByteSinkSpec extends AnyFlatSpec with should.Matchers {
"A zero page address" should "be a byte-wide sync" in {
123.z.write(456)
}
"A global address" should "be a byte-wide sync" in {
123.g.write(456)
}
"A read write location" should "be a byte-wide sync" in {
val sink = ReadWriteLocation[Int]("", 0.z)
sink.write(456)
}
}

View File

@ -0,0 +1,34 @@
package com.htmlism.nescant
package dsl
import org.scalatest.flatspec._
import org.scalatest.matchers._
class ByteSourceSpec extends AnyFlatSpec with should.Matchers {
private val sink =
123.z
"A number" should "be a byte-wide source" in {
sink.write(456)
}
"A zero page address" should "be a byte-wide source" in {
sink.write(456.z)
}
"A global address" should "be a byte-wide source" in {
sink.write(456.g)
}
"A volatile device" should "be a byte-wide source" in {
val src = VolatileDevice[Int]("", 0.z)
sink.write(src)
}
"A read write location" should "be a byte-wide source" in {
val src = ReadWriteLocation[Int]("", 0.z)
sink.write(src)
}
}

View File

@ -1,21 +0,0 @@
package com.htmlism.nescant
package dsl
import org.scalatest.flatspec._
import org.scalatest.matchers._
class SinkSpec extends AnyFlatSpec with should.Matchers {
"A zero page address" should "be a sink" in {
123.z.write(456)
}
"A global address" should "be a sink" in {
123.g.write(456)
}
"A read write location" should "be a sink" in {
val sink = ReadWriteLocation[Int]("", 0.z)
sink.write(456)
}
}

View File

@ -1,31 +0,0 @@
package com.htmlism.nescant
package dsl
import org.scalatest.flatspec._
import org.scalatest.matchers._
class SourceSpec extends AnyFlatSpec with should.Matchers {
"A number" should "be a source" in {
123.z.write(456)
}
"A zero page address" should "be a source" in {
123.z.write(456.z)
}
"A global address" should "be a source" in {
123.z.write(456.g)
}
"A volatile device" should "be a source" in {
val src = VolatileDevice[Int]("", 0.z)
123.z.write(src)
}
"A read write location" should "be a source" in {
val src = ReadWriteLocation[Int]("", 0.z)
123.z.write(src)
}
}