define table is a function of an instance

This commit is contained in:
Mark Canlas 2022-12-06 16:39:00 -05:00
parent a43d4745b9
commit 501bc4b527
6 changed files with 16 additions and 16 deletions

View File

@ -16,7 +16,7 @@ define COLOR_LightBlue 14
define COLOR_LightGrey 15
define SCREEN TODO
define SCREEN 200
; Screen(0) = White

View File

@ -16,7 +16,7 @@ define COLOR_LightBlue 14
define COLOR_LightGrey 15
define SCREEN TODO
define SCREEN 200
; Screen(0) = White

View File

@ -9,7 +9,7 @@ object AsmBlock:
def fromMultiline(s: String): CommentBlock =
CommentBlock(s.split("\\n").toList)
case class DefinesBlock(xs: List[(String, String)]) extends AsmBlock
case class DefinesBlock(xs: List[(String, Int)]) extends AsmBlock
case class NamedCodeBlock(name: String, comment: Option[String], intents: List[AsmBlock.Intent]) extends AsmBlock

View File

@ -3,7 +3,7 @@ package com.htmlism.firepower.demo
import scala.collection.immutable._
trait Definable[A]:
def table: ListMap[String, String]
def table(x: A): ListMap[String, Int]
extension (x: A) def toComment: String

View File

@ -10,12 +10,12 @@ object Easy6502:
object Color:
given Definable[Color] with
def table: ListMap[String, String] =
def table(x: Color): ListMap[String, Int] =
Color
.values
.iterator
.map { c =>
"COLOR_" + c.toString -> c.ordinal.toString
"COLOR_" + c.toString -> c.ordinal
}
.pipe(ListMap.from)
@ -40,8 +40,8 @@ object Easy6502:
object Pixel:
given Definable[Pixel] with
def table: ListMap[String, String] =
ListMap("SCREEN" -> "TODO") // define table needs to be a function of an instance
def table(x: Pixel): ListMap[String, Int] =
ListMap("SCREEN" -> x.baseAddr) // define table needs to be a function of an instance
extension (x: Pixel)
def toComment: String =

View File

@ -9,14 +9,14 @@ import com.htmlism.firepower.core.AsmBlock._
import com.htmlism.firepower.core._
object PrintThree:
trait DefinesHelper(xs: Definable[_]*):
def defines: Seq[ListMap[String, String]] =
xs
.iterator
.map(_.table)
.toList
case class Move[A: Definable, B: Definable](src: A, dest: B) extends DefinesHelper(Definable[A], Definable[B])
case class Move[A: Definable, B: Definable](src: A, dest: B):
def defines: List[ListMap[String, Int]] =
List(
Definable[A]
.table(src),
Definable[B]
.table(dest)
)
def build(screen: Easy6502.Screen): List[Move[Easy6502.Color, Easy6502.Screen.Pixel]] =
List(