defintion groups

This commit is contained in:
Mark Canlas 2020-08-15 14:45:08 -04:00
parent e5d7f30bbc
commit 35d5523647
3 changed files with 11 additions and 11 deletions

View File

@ -19,17 +19,17 @@ sealed trait TopLevelAsmDocumentFragment
sealed trait AsmBlockFragment extends TopLevelAsmDocumentFragment
case class DefineGroup(comment: String, xs: List[Definition[_]]) extends TopLevelAsmDocumentFragment
case class DefinitionGroup(comment: String, xs: List[Definition[_]]) extends TopLevelAsmDocumentFragment
class DefineGroupContext {
class DefinitionGroupContext {
private val xs: ListBuffer[Definition[_]] =
ListBuffer()
def push(x: Definition[_]): Unit =
xs.append(x)
def toGroup(s: String): DefineGroup =
DefineGroup(s, xs.toList)
def toGroup(s: String): DefinitionGroup =
DefinitionGroup(s, xs.toList)
}
case class Definition[A : Operand](name: String, x: A)

View File

@ -11,9 +11,9 @@ package object dsl {
.toDoc
}
def group(s: String)(f: DefineGroupContext => Unit)(implicit ctx: AsmDocumentContext): Unit = {
val g: DefineGroupContext =
new DefineGroupContext
def group(s: String)(f: DefinitionGroupContext => Unit)(implicit ctx: AsmDocumentContext): Unit = {
val g: DefinitionGroupContext =
new DefinitionGroupContext
f(g)
@ -21,7 +21,7 @@ package object dsl {
.push(g.toGroup(s))
}
def define[A : Operand](name: String, x: A)(implicit ctx: DefineGroupContext): Unit =
def define[A : Operand](name: String, x: A)(implicit ctx: DefinitionGroupContext): Unit =
ctx
.push(Definition(name, x))

View File

@ -28,18 +28,18 @@ class DslSpec extends AnyFlatSpec with should.Matchers {
}
doc shouldEqual AsmDocument(List(
DefineGroup("snake things", List(
DefinitionGroup("snake things", List(
Definition("snakeBodyStart", 0x12.z),
Definition("snakeDirection", 0x02.z),
Definition("snakeLength", 0x03.z)
)),
DefineGroup("ASCII values of keys controlling the snake", List(
DefinitionGroup("ASCII values of keys controlling the snake", List(
Definition("ASCII_w", 0x77),
Definition("ASCII_a", 0x61),
Definition("ASCII_s", 0x73),
Definition("ASCII_d", 0x64)
)),
DefineGroup("System variables", List(
DefinitionGroup("System variables", List(
Definition("sysRandom", 0xfe),
Definition("sysLastKey", 0xff)
))