This commit is contained in:
Mark Canlas 2023-01-02 13:02:03 -05:00
parent 17f6b1fe20
commit ae49cf61d2
6 changed files with 74 additions and 49 deletions

View File

@ -2,12 +2,37 @@ version = "3.6.1"
runner.dialect = "scala3"
align.preset = more
align.tokens = [
{ code = "=" },
{ code = "extends" },
{ code = "//" },
{ code = "<-", owners = ["Enumerator.Generator"] },
{ code = "=", owners = ["(Enumerator.Val|Defn.(Va(l|r)|GivenAlias|Def|Type))"] },
{ code = "=>", owners = ["Case"] },
{ code = "->", owners = ["Term.ApplyInfix"] },
{ code = ":=", owners = ["Term.ApplyInfix"] },
{ code = "%", owners = ["Term.ApplyInfix"] },
{ code = "%%", owners = ["Term.ApplyInfix"] }
]
align.allowOverflow = true,
align.tokenCategory = {
Equals = Assign,
LeftArrow = Assign
}
maxColumn = 120
align.openParenCallSite = false
align.preset = most
docstrings = ScalaDoc
docstrings.blankFirstLine = yes

View File

@ -42,7 +42,7 @@ case class AndThen2[A, B](left: Asm2[A, B], right: Asm2[A, B], oComment: Option[
copy(oComment = Some(s))
case class Asm2Instructions[A, B](xs: List[String], oComment: Option[String] = None) extends Asm2[A, B]:
def comment(s: String): Asm2[A, B] =
def comment(s: String): Asm2[A, B] =
copy(oComment = Some(s))
// TODO not tested
// B type needs to be a class type, with evidence, not a case class

View File

@ -19,22 +19,22 @@ object PrintPrograms extends ZIOAppDefault:
"two-lines.txt" -> List("foo", "bar"),
// FEATURE: writing paragraphs separated by newlines is easy
"two-paragraphs.txt" -> List(
"two-paragraphs.txt" -> List(
List("foo", "bar"),
List("alpha", "bravo")
)
.pipe(xxs => AsmBlock.interFlatMap(xxs)(List("", ""), identity)),
"feature-demo.asm" -> FeatureDemo.program,
"feature-demo.asm" -> FeatureDemo.program,
"print-three-upper-math.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitionsWithMath)
),
"print-three-upper.asm" -> PrintThree.assemble(
"print-three-upper.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitions)
),
"print-three-lower.asm" -> PrintThree.assemble(
"print-three-lower.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Lowercase, DefinitionsMode.UseLiterals)
),
"snake-easy-6502.asm" -> SnakeEasy6502.assemble(
"snake-easy-6502.asm" -> SnakeEasy6502.assemble(
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitions)
)
)
@ -43,6 +43,6 @@ object PrintPrograms extends ZIOAppDefault:
for {
// just a traverse in slow motion...
_ <- programs
.map { case (f, xs) => File(s"data/$f").writeLines(xs) }
.foldLeft[Task[Unit]](ZIO.unit)((acc, z) => acc *> z)
.map { case (f, xs) => File(s"data/$f").writeLines(xs) }
.foldLeft[Task[Unit]](ZIO.unit)((acc, z) => acc *> z)
} yield ()

View File

@ -234,7 +234,7 @@ object MatchOpcodes:
case 1 => c01(aaa, bbb)
case 2 => c10(aaa, bbb)
case 3 => None
case _ => throw new IllegalStateException("an int should always have bits to find")
case _ => throw new IllegalStateException("an int should always have bits to find")
def c01(aaa: Int, bbb: Int): Option[(Instruction, AddressingMode)] =
val instruction =

View File

@ -21,7 +21,7 @@ case class UnaryInstruction(instruction: Instruction, comment: Option[String]) e
comment match
case Some(c) =>
Statement.indent + f"$left%-16s ; " + c
case None =>
case None =>
Statement.indent + left
def toTriplet: (String, Option[String], Option[String]) =
@ -40,7 +40,7 @@ case class InstructionWithOperand[A](instruction: Instruction, operand: A, comme
comment match
case Some(c) =>
Statement.indent + f"$left%-5s $operandStr%-11s; " + c
case None =>
case None =>
Statement.indent + f"$left%-5s $operandStr"
def toTriplet: (String, Option[String], Option[String]) =

View File

@ -24,9 +24,9 @@ case object CPY extends Arithmetic
sealed trait Load extends Instruction:
def theme: String = "load"; def color: String = "BurlyWood"
case object LDA extends Load
case object LDX extends Load
case object LDY extends Load
case object LDA extends Load
case object LDX extends Load
case object LDY extends Load
sealed trait Store extends Instruction:
def theme: String = "store"; def color: String = "Bisque"
@ -59,52 +59,52 @@ case object DEY extends Decrement
sealed trait Jump extends Instruction:
def theme: String = "jump"; def color: String = "Salmon"
case object JMP extends Jump
case object JSR extends Jump
case object RTS extends Jump
case object JMP extends Jump
case object JSR extends Jump
case object RTS extends Jump
sealed trait Branch extends Instruction:
def theme: String = "branch"; def color: String = "DodgerBlue"
case object BCC extends Branch
case object BCS extends Branch
case object BEQ extends Branch
case object BMI extends Branch
case object BNE extends Branch
case object BPL extends Branch
case object BVC extends Branch
case object BVS extends Branch
case object BCC extends Branch
case object BCS extends Branch
case object BEQ extends Branch
case object BMI extends Branch
case object BNE extends Branch
case object BPL extends Branch
case object BVC extends Branch
case object BVS extends Branch
sealed trait System extends Instruction:
def theme: String = "system"; def color: String = "Peru"
case object BRK extends System
case object NOP extends System
case object RTI extends System
case object BRK extends System
case object NOP extends System
case object RTI extends System
sealed trait Stack extends Instruction:
def theme: String = "stack"; def color: String = "Wheat"
case object TSX extends Stack
case object TXS extends Stack
case object PHA extends Stack
case object PHP extends Stack
case object PLA extends Stack
case object PLP extends Stack
case object TSX extends Stack
case object TXS extends Stack
case object PHA extends Stack
case object PHP extends Stack
case object PLA extends Stack
case object PLP extends Stack
sealed trait Transfer extends Instruction:
def theme: String = "transfer"; def color: String = "Teal"
case object TAX extends Transfer
case object TAY extends Transfer
case object TXA extends Transfer
case object TYA extends Transfer
case object TAX extends Transfer
case object TAY extends Transfer
case object TXA extends Transfer
case object TYA extends Transfer
sealed trait Clear extends Instruction:
def theme: String = "clear"; def color: String = "LightSteelBlue"
case object CLC extends Clear
case object CLD extends Clear
case object CLI extends Clear
case object CLV extends Clear
case object CLC extends Clear
case object CLD extends Clear
case object CLI extends Clear
case object CLV extends Clear
sealed trait SetFlag extends Instruction:
def theme: String = "set"; def color: String = "Thistle"
case object SEC extends SetFlag
case object SED extends SetFlag
case object SEI extends SetFlag
case object SEC extends SetFlag
case object SED extends SetFlag
case object SEI extends SetFlag