From ae49cf61d21270bca77b803125e47f84ebe081fe Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Mon, 2 Jan 2023 13:02:03 -0500 Subject: [PATCH] fmt --- .scalafmt.conf | 33 +++++++-- .../com/htmlism/firepower/core/asm.scala | 2 +- .../firepower/demo/PrintPrograms.scala | 14 ++-- src/main/scala/com/htmlism/MatchOpcodes.scala | 2 +- .../com/htmlism/mos6502/dsl/Statement.scala | 4 +- .../htmlism/mos6502/model/Instruction.scala | 68 +++++++++---------- 6 files changed, 74 insertions(+), 49 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index a9cbf03..81243f0 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -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 diff --git a/firepower-core/src/main/scala/com/htmlism/firepower/core/asm.scala b/firepower-core/src/main/scala/com/htmlism/firepower/core/asm.scala index 4946465..f269a3a 100644 --- a/firepower-core/src/main/scala/com/htmlism/firepower/core/asm.scala +++ b/firepower-core/src/main/scala/com/htmlism/firepower/core/asm.scala @@ -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 diff --git a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintPrograms.scala b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintPrograms.scala index a6a57e5..8a94aac 100644 --- a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintPrograms.scala +++ b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/PrintPrograms.scala @@ -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 () diff --git a/src/main/scala/com/htmlism/MatchOpcodes.scala b/src/main/scala/com/htmlism/MatchOpcodes.scala index 55b5f9b..08df56f 100644 --- a/src/main/scala/com/htmlism/MatchOpcodes.scala +++ b/src/main/scala/com/htmlism/MatchOpcodes.scala @@ -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 = diff --git a/src/main/scala/com/htmlism/mos6502/dsl/Statement.scala b/src/main/scala/com/htmlism/mos6502/dsl/Statement.scala index 3171509..c37235a 100644 --- a/src/main/scala/com/htmlism/mos6502/dsl/Statement.scala +++ b/src/main/scala/com/htmlism/mos6502/dsl/Statement.scala @@ -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]) = diff --git a/src/main/scala/com/htmlism/mos6502/model/Instruction.scala b/src/main/scala/com/htmlism/mos6502/model/Instruction.scala index bb3e4d3..361e136 100644 --- a/src/main/scala/com/htmlism/mos6502/model/Instruction.scala +++ b/src/main/scala/com/htmlism/mos6502/model/Instruction.scala @@ -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