add defines

This commit is contained in:
Mark Canlas 2020-08-21 16:43:23 -04:00
parent 6c97461275
commit 92af2e7d8a
4 changed files with 27 additions and 22 deletions

View File

@ -25,7 +25,7 @@ class AsmDocumentContext {
def toDoc: AsmDocument = {
val asmFragmentsAndSubroutines =
xs.toList ::: jumps.toList ++ jumps.flatMap(_.jumpRegistry).toList
xs.toList ::: jumps.toList ++ jumps.flatMap(_.jumpRegistry).toList
AsmDocument(asmFragmentsAndSubroutines)
}
@ -40,7 +40,8 @@ case class AsmFragment(xs: List[Statement]) extends TopLevelAsmDocumentFragment
xs.map(_.toAsm).mkString("\n")
}
case class Subroutine(name: String, fragment: AsmFragment, jumpRegistry: ListSet[Subroutine]) extends TopLevelAsmDocumentFragment {
case class Subroutine(name: String, fragment: AsmFragment, jumpRegistry: ListSet[Subroutine])
extends TopLevelAsmDocumentFragment {
def toAsm: String =
name + ":" + "\n" + fragment.toAsm
}

View File

@ -8,4 +8,4 @@ sealed trait RangeSpec {
case class Incrementing(from: Int, to: Int) extends RangeSpec
case class Decrementing(from: Int, to: Int) extends RangeSpec
case class Decrementing(from: Int, to: Int) extends RangeSpec

View File

@ -88,7 +88,7 @@ class DslSpec extends AnyFlatSpec with should.Matchers {
"bit field" should "compile" in {
val doc =
asmDoc { implicit ctx =>
bitField[Direction]
bitField[TestDirection]
}
doc shouldEqual AsmDocument(
@ -109,7 +109,7 @@ class DslSpec extends AnyFlatSpec with should.Matchers {
"mapping" should "compile" in {
val doc =
asmDoc { implicit ctx =>
mapping[Direction]
mapping[TestDirection]
}
doc shouldEqual AsmDocument(
@ -170,38 +170,38 @@ object Triforce {
}
}
sealed trait Direction
sealed trait TestDirection
case object Up extends Direction
case object Down extends Direction
case object Left extends Direction
case object Right extends Direction
case object Up extends TestDirection
case object Down extends TestDirection
case object Left extends TestDirection
case object Right extends TestDirection
object Direction {
implicit val bitFieldDirection: BitField[Direction] =
new BitField[Direction] {
object TestDirection {
implicit val bitFieldDirection: BitField[TestDirection] =
new BitField[TestDirection] {
def comment: String =
"foo as bit field"
def all: NonEmptyList[Direction] =
def all: NonEmptyList[TestDirection] =
NonEmptyList.of(Up, Down, Left, Right)
def label(x: Direction): String =
def label(x: TestDirection): String =
x.toString.toLowerCase
def comment(x: Direction): String =
def comment(x: TestDirection): String =
x.toString
}
implicit val mappingDirection: Mapping[Direction] =
new Mapping[Direction] {
implicit val mappingDirection: Mapping[TestDirection] =
new Mapping[TestDirection] {
def comment: String =
"foo as a mapping"
def all: NonEmptyList[Direction] =
def all: NonEmptyList[TestDirection] =
NonEmptyList.of(Up, Down, Left, Right)
def value(x: Direction): Int =
def value(x: TestDirection): Int =
x match {
case Up => 0x77
case Down => 0x61
@ -209,10 +209,10 @@ object Direction {
case Right => 0x64
}
def label(x: Direction): String =
def label(x: TestDirection): String =
x.toString.toLowerCase
def comment(x: Direction): String =
def comment(x: TestDirection): String =
x.toString
}
}

View File

@ -1,4 +1,5 @@
package com.htmlism.mos6502.dsl
package snake
import cats.implicits._
import org.scalatest.flatspec._
@ -125,6 +126,9 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers {
val doc =
asmDoc { implicit ctx =>
bitField[Direction]
mapping[AsciiValue]
asm { implicit a =>
jump(init)
jump(loop)