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")
.dependsOn(core)
.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/"

View File

@ -1 +0,0 @@
one line

View File

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

View File

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

View File

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

View File

@ -5,8 +5,7 @@ import scala.util.chaining._
import com.htmlism.firepower.core._
object SnakeEasy6502:
def assemble(opts: AssemblerOptions): String =
def assemble(opts: AssemblerOptions): List[String] =
(Nil)
.map(AsmBlock.toLines(opts.instructionCase))
.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")