scala3 fmt

This commit is contained in:
Mark Canlas 2023-10-03 16:15:10 -04:00
parent 4d47714e77
commit 2ac62b5af7
29 changed files with 72 additions and 80 deletions

View File

@ -48,3 +48,5 @@ docstrings.blankFirstLine = yes
includeNoParensInSelectChains = true includeNoParensInSelectChains = true
optIn.breakChainOnFirstMethodDot = true optIn.breakChainOnFirstMethodDot = true
rewrite.scala3.convertToNewSyntax = true

View File

@ -1,6 +1,6 @@
package com.htmlism.firepower.core package com.htmlism.firepower.core
import cats.syntax.all._ import cats.syntax.all.*
sealed trait AsmBlock sealed trait AsmBlock
@ -55,12 +55,9 @@ object AsmBlock:
def toHex(n: Int): String = def toHex(n: Int): String =
val hex = val hex =
if (n < 16 * 16) if n < 16 * 16 then String.format("%1$02x", n)
String.format("%1$02x", n) else if n < 16 * 16 * 16 then String.format("%1$03x", n)
else if (n < 16 * 16 * 16) else String.format("%1$04x", n)
String.format("%1$03x", n)
else
String.format("%1$04x", n)
"$" + hex.toUpperCase "$" + hex.toUpperCase

View File

@ -5,7 +5,7 @@ object CodeGenerator extends App:
('A' to 'Z') ('A' to 'Z')
.map(_.toString) .map(_.toString)
for (n <- 1 to 3) for n <- 1 to 3 do
val letters = val letters =
allLetters.take(n) allLetters.take(n)
@ -44,7 +44,7 @@ object CodeGenerator extends App:
println(" copy(oComment = Some(s))") println(" copy(oComment = Some(s))")
println println
for (n <- 1 to 3) for n <- 1 to 3 do
val classNum = val classNum =
n n

View File

@ -1,6 +1,6 @@
package com.htmlism.firepower.core package com.htmlism.firepower.core
import com.htmlism.firepower.core.AsmBlock._ import com.htmlism.firepower.core.AsmBlock.*
case class Subroutine(name: String, description: String, intents: () => List[MetaIntent]): case class Subroutine(name: String, description: String, intents: () => List[MetaIntent]):
def call: MetaIntent = def call: MetaIntent =

View File

@ -1,9 +1,9 @@
package com.htmlism.firepower.core package com.htmlism.firepower.core
import org.scalatest.funsuite.AnyFunSuite import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should._ import org.scalatest.matchers.should.*
import com.htmlism.firepower.core.syntax._ import com.htmlism.firepower.core.syntax.*
object ExampleRegister extends ZeroPageAddress(0x01, "example") with WriteOnlyByteAddress[ExampleRegister] object ExampleRegister extends ZeroPageAddress(0x01, "example") with WriteOnlyByteAddress[ExampleRegister]

View File

@ -1,6 +1,6 @@
package com.htmlism.firepower.core package com.htmlism.firepower.core
import weaver._ import weaver.*
object MoveSuite extends FunSuite: object MoveSuite extends FunSuite:
test("TODO move constant"): test("TODO move constant"):

View File

@ -60,10 +60,8 @@ object Easy6502:
extension (x: Pixel) extension (x: Pixel)
def toDefine: String = def toDefine: String =
if (x.offset == 0) if x.offset == 0 then "SCREEN"
"SCREEN" else "TODO"
else
"TODO"
extension (x: Pixel) extension (x: Pixel)
def toDefineWithMath: String = def toDefineWithMath: String =

View File

@ -1,11 +1,11 @@
package com.htmlism.firepower.demo package com.htmlism.firepower.demo
import scala.util.chaining._ import scala.util.chaining.*
import cats.syntax.all._ import cats.syntax.all.*
import com.htmlism.firepower.core.AsmBlock._ import com.htmlism.firepower.core.AsmBlock.*
import com.htmlism.firepower.core._ import com.htmlism.firepower.core.*
object FeatureDemo: object FeatureDemo:
val program: List[String] = val program: List[String] =

View File

@ -1,12 +1,12 @@
package com.htmlism.firepower.demo package com.htmlism.firepower.demo
import scala.util.chaining._ import scala.util.chaining.*
import zio.* import zio.*
import com.htmlism.firepower.core.AsmBlock._ import com.htmlism.firepower.core.AsmBlock.*
import com.htmlism.firepower.core.AssemblerOptions._ import com.htmlism.firepower.core.AssemblerOptions.*
import com.htmlism.firepower.core._ import com.htmlism.firepower.core.*
import com.htmlism.rufio.withzio.* import com.htmlism.rufio.withzio.*
object PrintPrograms extends ZIOAppDefault: object PrintPrograms extends ZIOAppDefault:

View File

@ -1,11 +1,11 @@
package com.htmlism.firepower.demo package com.htmlism.firepower.demo
import scala.util.chaining._ import scala.util.chaining.*
import cats.syntax.all._ import cats.syntax.all.*
import com.htmlism.firepower.core.AsmBlock._ import com.htmlism.firepower.core.AsmBlock.*
import com.htmlism.firepower.core._ import com.htmlism.firepower.core.*
object PrintThree: object PrintThree:
def build(screen: Easy6502.Screen): List[MetaIntent.Move[Easy6502.Color, Easy6502.Screen.Pixel]] = def build(screen: Easy6502.Screen): List[MetaIntent.Move[Easy6502.Color, Easy6502.Screen.Pixel]] =

View File

@ -4,7 +4,7 @@ import scala.annotation.tailrec
import scala.collection.immutable.ListMap import scala.collection.immutable.ListMap
import scala.util.chaining.* import scala.util.chaining.*
import cats.syntax.all._ import cats.syntax.all.*
import com.htmlism.firepower.core.AsmBlock.Intent import com.htmlism.firepower.core.AsmBlock.Intent
import com.htmlism.firepower.core.* import com.htmlism.firepower.core.*
@ -51,7 +51,7 @@ object SnakeEasy6502:
): ListMap[String, AsmBlock.NamedCodeBlock] = ): ListMap[String, AsmBlock.NamedCodeBlock] =
todo.collect { case x: MetaIntent.Jump => x } match todo.collect { case x: MetaIntent.Jump => x } match
case head :: tail => case head :: tail =>
if (callGraph.contains(head.target)) callGraphRecur(callGraph, tail) if callGraph.contains(head.target) then callGraphRecur(callGraph, tail)
else else
val rts = val rts =
AsmBlock.Intent( AsmBlock.Intent(

View File

@ -1,8 +1,8 @@
package com.htmlism.nescant package com.htmlism.nescant
package dsl package dsl
import org.scalatest.flatspec._ import org.scalatest.flatspec.*
import org.scalatest.matchers._ import org.scalatest.matchers.*
class ByteSinkSpec extends AnyFlatSpec with should.Matchers: class ByteSinkSpec extends AnyFlatSpec with should.Matchers:
"A zero page address" should "be a byte-wide sync" in: "A zero page address" should "be a byte-wide sync" in:

View File

@ -1,8 +1,8 @@
package com.htmlism.nescant package com.htmlism.nescant
package dsl package dsl
import org.scalatest.flatspec._ import org.scalatest.flatspec.*
import org.scalatest.matchers._ import org.scalatest.matchers.*
class ByteSourceSpec extends AnyFlatSpec with should.Matchers: class ByteSourceSpec extends AnyFlatSpec with should.Matchers:
private val sink = private val sink =

View File

@ -1,8 +1,8 @@
package com.htmlism.nescant package com.htmlism.nescant
package dsl package dsl
import org.scalatest.flatspec._ import org.scalatest.flatspec.*
import org.scalatest.matchers._ import org.scalatest.matchers.*
class PostFixOpsSpec extends AnyFlatSpec with should.Matchers: class PostFixOpsSpec extends AnyFlatSpec with should.Matchers:
"Numbers" should "support zero page ops" in: "Numbers" should "support zero page ops" in:

View File

@ -14,7 +14,7 @@ object CatsEffectForkPlugin extends AutoPlugin {
// cats-effect prefers to run in its own main thread // cats-effect prefers to run in its own main thread
// https://github.com/typelevel/cats-effect/pull/3774 // https://github.com/typelevel/cats-effect/pull/3774
override val buildSettings: Seq[Setting[_]] = Seq( override val buildSettings: Seq[Setting[?]] = Seq(
fork := true fork := true
) )
} }

View File

@ -1,5 +1,5 @@
import sbt._ import sbt.*
import sbt.Keys._ import sbt.Keys.*
/** /**
* Automatically enriches projects with the following settings (despite the word "override"). * Automatically enriches projects with the following settings (despite the word "override").

View File

@ -1,6 +1,6 @@
import sbt.Keys._ import sbt.Keys.*
import sbt._ import sbt.*
import scalafix.sbt.ScalafixPlugin.autoImport._ import scalafix.sbt.ScalafixPlugin.autoImport.*
object LintingPlugin extends AutoPlugin { object LintingPlugin extends AutoPlugin {
override def trigger = override def trigger =

View File

@ -1,5 +1,5 @@
import sbt.Keys._ import sbt.Keys.*
import sbt._ import sbt.*
object ProjectPlugin extends AutoPlugin { object ProjectPlugin extends AutoPlugin {
override def trigger = allRequirements override def trigger = allRequirements

View File

@ -1,5 +1,5 @@
import sbt.Keys._ import sbt.Keys.*
import sbt._ import sbt.*
/** /**
* Automatically enriches projects with the following settings (despite the word "override"). * Automatically enriches projects with the following settings (despite the word "override").
@ -11,11 +11,11 @@ object Scala3Plugin extends AutoPlugin {
*/ */
override def trigger: PluginTrigger = AllRequirements override def trigger: PluginTrigger = AllRequirements
override val buildSettings: Seq[Setting[_]] = Seq( override val buildSettings: Seq[Setting[?]] = Seq(
scalaVersion := "3.3.1" scalaVersion := "3.3.1"
) )
override val projectSettings: Seq[Setting[_]] = Seq( override val projectSettings: Seq[Setting[?]] = Seq(
scalacOptions ++= Seq("-indent", "-rewrite") scalacOptions ++= Seq("-indent", "-rewrite")
) )
} }

View File

@ -2,9 +2,9 @@ package com.htmlism
import java.io.PrintWriter import java.io.PrintWriter
import cats.syntax.all._ import cats.syntax.all.*
import com.htmlism.mos6502.model._ import com.htmlism.mos6502.model.*
object MatchOpcodes: object MatchOpcodes:
def paddedBinary(n: Int, width: Int) = def paddedBinary(n: Int, width: Int) =
@ -95,18 +95,17 @@ object MatchOpcodes:
b <- 0 to 7 b <- 0 to 7
} yield b * 4 + c } yield b * 4 + c
for (f <- fancyColumns) for f <- fancyColumns do out.print(s"<th>${paddedBinary(f, 8)}</th>")
out.print(s"<th>${paddedBinary(f, 8)}</th>")
out.print("</tr>") out.print("</tr>")
for (r <- Seq(0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0)) for r <- Seq(0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0) do
out.print("<tr>") out.print("<tr>")
// left header // left header
out.print(s"<th>${paddedBinary(r, 3)}</th>") out.print(s"<th>${paddedBinary(r, 3)}</th>")
for (f <- fancyColumns) for f <- fancyColumns do
val fullInt = r + f val fullInt = r + f
lookup.get(fullInt) match lookup.get(fullInt) match
@ -129,18 +128,17 @@ object MatchOpcodes:
out.print("<tr>") out.print("<tr>")
out.print("<th/>") out.print("<th/>")
for (c <- wideColumns) for c <- wideColumns do out.print(s"<th>${paddedBinary(c, 5)}</th>")
out.print(s"<th>${paddedBinary(c, 5)}</th>")
out.print("</tr>") out.print("</tr>")
for (r <- wideRows) for r <- wideRows do
out.print("<tr>") out.print("<tr>")
// left header // left header
out.print(s"<th>${paddedBinary(r, 3)}</th>") out.print(s"<th>${paddedBinary(r, 3)}</th>")
for (c <- wideColumns) for c <- wideColumns do
val fullInt = (r << 5) + c val fullInt = (r << 5) + c
lookup.get(fullInt) match lookup.get(fullInt) match
@ -181,18 +179,17 @@ object MatchOpcodes:
val rows = val rows =
0 to 7 0 to 7
for (c <- columns) for c <- columns do out.print(s"<th>${paddedBinary(c, 3)}</th>")
out.print(s"<th>${paddedBinary(c, 3)}</th>")
out.print("</tr>") out.print("</tr>")
for (r <- rows) for r <- rows do
out.print("<tr>") out.print("<tr>")
// left header // left header
out.print(s"<th>${paddedBinary(r, 3)}</th>") out.print(s"<th>${paddedBinary(r, 3)}</th>")
for (c <- columns) for c <- columns do
val fullInt = (r << (3 + 2)) + (c << 2) + n val fullInt = (r << (3 + 2)) + (c << 2) + n
lookup.get(fullInt) match lookup.get(fullInt) match

View File

@ -29,10 +29,8 @@ trait BitExtractor[A]:
object AtomExtractor: object AtomExtractor:
@tailrec @tailrec
def pow(ex: Int, acc: Int = 1): Int = def pow(ex: Int, acc: Int = 1): Int =
if (ex == 0) if ex == 0 then acc
acc else pow(ex - 1, acc * 2)
else
pow(ex - 1, acc * 2)
abstract class PrimitiveBitExtractor(val length: Int) extends BitExtractor[Int]: abstract class PrimitiveBitExtractor(val length: Int) extends BitExtractor[Int]:
private lazy val mask = private lazy val mask =

View File

@ -3,7 +3,7 @@ package com.htmlism.mos6502.dsl
import scala.collection.immutable.ListSet import scala.collection.immutable.ListSet
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer
import cats.syntax.all._ import cats.syntax.all.*
case class AsmDocument(xs: List[TopLevelAsmDocumentFragment]): case class AsmDocument(xs: List[TopLevelAsmDocumentFragment]):
def toAsm: String = def toAsm: String =

View File

@ -3,9 +3,9 @@ package com.htmlism.mos6502.dsl
import scala.collection.immutable.ListSet import scala.collection.immutable.ListSet
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer
import cats.syntax.all._ import cats.syntax.all.*
import com.htmlism.mos6502.model._ import com.htmlism.mos6502.model.*
object DslDemo extends App: object DslDemo extends App:
val cpu = val cpu =

View File

@ -1,6 +1,6 @@
package com.htmlism.mos6502.dsl package com.htmlism.mos6502.dsl
import com.htmlism.mos6502.model._ import com.htmlism.mos6502.model.*
/** /**
* A typed collection, like memory mapped to screen pixels. Access by index instead of by address. * A typed collection, like memory mapped to screen pixels. Access by index instead of by address.

View File

@ -1,6 +1,6 @@
package com.htmlism.mos6502.dsl package com.htmlism.mos6502.dsl
import com.htmlism.mos6502.model._ import com.htmlism.mos6502.model.*
/** /**
* @param name * @param name

View File

@ -1,6 +1,6 @@
package com.htmlism.mos6502.dsl package com.htmlism.mos6502.dsl
import cats.syntax.all._ import cats.syntax.all.*
import com.htmlism.mos6502.model.Instruction import com.htmlism.mos6502.model.Instruction

View File

@ -1,7 +1,7 @@
package com.htmlism.mos6502.dsl package com.htmlism.mos6502.dsl
package syntax package syntax
import com.htmlism.mos6502.model._ import com.htmlism.mos6502.model.*
trait AsmSyntax: trait AsmSyntax:
def label(s: String)(using ctx: AssemblyContext): Unit = def label(s: String)(using ctx: AssemblyContext): Unit =

View File

@ -1,8 +1,8 @@
package com.htmlism.mos6502.dsl package com.htmlism.mos6502.dsl
import cats.data.NonEmptyList import cats.data.NonEmptyList
import org.scalatest.flatspec._ import org.scalatest.flatspec.*
import org.scalatest.matchers._ import org.scalatest.matchers.*
class DslSpec extends AnyFlatSpec with should.Matchers: class DslSpec extends AnyFlatSpec with should.Matchers:

View File

@ -1,11 +1,11 @@
package com.htmlism.mos6502.dsl package com.htmlism.mos6502.dsl
package snake package snake
import cats.syntax.all._ import cats.syntax.all.*
import org.scalatest.flatspec._ import org.scalatest.flatspec.*
import org.scalatest.matchers._ import org.scalatest.matchers.*
import com.htmlism.mos6502.model._ import com.htmlism.mos6502.model.*
class Easy6502Spec extends AnyFlatSpec with should.Matchers: class Easy6502Spec extends AnyFlatSpec with should.Matchers: