use lines writer from rufio

This commit is contained in:
Mark Canlas 2022-12-07 13:36:57 -05:00
parent 248cafbdae
commit ae319b35b2
7 changed files with 9 additions and 29 deletions

View File

@ -17,7 +17,7 @@ lazy val demo =
module("demo") module("demo")
.dependsOn(core) .dependsOn(core)
.withEfectMonad .withEfectMonad
.settings(libraryDependencies += "com.htmlism" %% "rufio-zio" % "74-5cd25e9b") .settings(libraryDependencies += "com.htmlism" %% "rufio-zio" % "76-c565ab28")
ThisBuild / resolvers += "mcanlas/rufio" at "https://maven.pkg.github.com/mcanlas/rufio/" ThisBuild / resolvers += "mcanlas/rufio" at "https://maven.pkg.github.com/mcanlas/rufio/"

View File

@ -1 +0,0 @@
one line

View File

@ -8,7 +8,7 @@ import com.htmlism.firepower.core.AsmBlock._
import com.htmlism.firepower.core._ import com.htmlism.firepower.core._
object FeatureDemo: object FeatureDemo:
val program: String = val program: List[String] =
List( List(
CommentBlock.fromMultiline(asciiArt), CommentBlock.fromMultiline(asciiArt),
CommentBlock(List("Change direction: W A S D")), CommentBlock(List("Change direction: W A S D")),
@ -53,7 +53,6 @@ object FeatureDemo:
) )
.map(AsmBlock.toLines(AssemblerOptions.InstructionCase.Lowercase)) .map(AsmBlock.toLines(AssemblerOptions.InstructionCase.Lowercase))
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity)) .pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
.pipe(str.Line.mkString)
private lazy val asciiArt = private lazy val asciiArt =
""" ___ _ __ ___ __ ___ """ ___ _ __ ___ __ ___

View File

@ -10,30 +10,20 @@ 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.firepower.demo.str._
import com.htmlism.rufio.withzio.* import com.htmlism.rufio.withzio.*
object PrintPrograms extends ZIOAppDefault: object PrintPrograms extends ZIOAppDefault:
private def writeLine(file: String)(s: String) =
File(s"data/$file.txt")
.writeLine(s)
private val programs = private val programs =
List[(String, String)]( List[(String, List[String])](
// FEATURE: writing a string to a file is easy (thanks, rufio) // FEATURE: writing lines to a file is easy (thanks, rufio)
"one-line.txt" -> "one line", "two-lines.txt" -> List("foo", "bar"),
// FEATURE: writing lines to a file is easy
"two-lines.txt" -> List("foo", "bar")
.pipe(Line.mkString),
// FEATURE: writing paragraphs separated by newlines is easy // FEATURE: writing paragraphs separated by newlines is easy
"two-paragraphs.txt" -> List( "two-paragraphs.txt" -> List(
List("foo", "bar"), List("foo", "bar"),
List("alpha", "bravo") List("alpha", "bravo")
) )
.pipe(xxs => AsmBlock.interFlatMap(xxs)(List("", ""), identity)) .pipe(xxs => AsmBlock.interFlatMap(xxs)(List("", ""), identity)),
.pipe(Line.mkString),
"feature-demo.asm" -> FeatureDemo.program, "feature-demo.asm" -> FeatureDemo.program,
"print-three-upper-math.asm" -> PrintThree.assemble( "print-three-upper-math.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitionsWithMath) AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitionsWithMath)
@ -53,6 +43,6 @@ object PrintPrograms extends ZIOAppDefault:
for { for {
// just a traverse in slow motion... // just a traverse in slow motion...
_ <- programs _ <- programs
.map { case (f, s) => File(s"data/$f").writeLine(s) } .map { case (f, xs) => File(s"data/$f").writeLines(xs) }
.foldLeft[Task[Unit]](ZIO.unit)((acc, z) => acc *> z) .foldLeft[Task[Unit]](ZIO.unit)((acc, z) => acc *> z)
} yield () } yield ()

View File

@ -28,11 +28,10 @@ object PrintThree:
val program: List[Move[Easy6502.Color, Easy6502.Screen.Pixel]] = val program: List[Move[Easy6502.Color, Easy6502.Screen.Pixel]] =
build(Easy6502.Screen(0x200)) build(Easy6502.Screen(0x200))
def assemble(opts: AssemblerOptions): String = def assemble(opts: AssemblerOptions): List[String] =
(defines(opts.definitionsMode) ++ codes(opts.definitionsMode)) (defines(opts.definitionsMode) ++ codes(opts.definitionsMode))
.map(AsmBlock.toLines(opts.instructionCase)) .map(AsmBlock.toLines(opts.instructionCase))
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity)) .pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
.pipe(str.Line.mkString)
private def defines(opts: AssemblerOptions.DefinitionsMode) = private def defines(opts: AssemblerOptions.DefinitionsMode) =
opts match opts match

View File

@ -5,8 +5,7 @@ import scala.util.chaining._
import com.htmlism.firepower.core._ import com.htmlism.firepower.core._
object SnakeEasy6502: object SnakeEasy6502:
def assemble(opts: AssemblerOptions): String = def assemble(opts: AssemblerOptions): List[String] =
(Nil) (Nil)
.map(AsmBlock.toLines(opts.instructionCase)) .map(AsmBlock.toLines(opts.instructionCase))
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity)) .pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
.pipe(str.Line.mkString)

View File

@ -1,6 +0,0 @@
package com.htmlism.firepower.demo.str
object Line:
def mkString(xs: List[String]): String =
xs
.mkString("\n")