2022-12-01 12:07:05 +00:00
|
|
|
package com.htmlism.firepower.demo
|
|
|
|
|
2022-12-05 14:14:58 +00:00
|
|
|
import java.io.IOException
|
|
|
|
|
2022-12-04 23:17:31 +00:00
|
|
|
import scala.util.chaining._
|
|
|
|
|
2022-12-04 22:15:29 +00:00
|
|
|
import cats.syntax.all._
|
2022-12-05 14:14:58 +00:00
|
|
|
import zio.*
|
2022-12-04 22:15:29 +00:00
|
|
|
|
2022-12-05 22:19:50 +00:00
|
|
|
import com.htmlism.firepower.core.AsmBlock._
|
2022-12-06 18:43:48 +00:00
|
|
|
import com.htmlism.firepower.core.AssemblerOptions._
|
2022-12-05 22:19:50 +00:00
|
|
|
import com.htmlism.firepower.core._
|
2022-12-04 20:40:37 +00:00
|
|
|
import com.htmlism.firepower.demo.str._
|
|
|
|
import com.htmlism.rufio.withzio.*
|
2022-12-01 13:17:33 +00:00
|
|
|
|
2022-12-01 11:50:22 +00:00
|
|
|
object PrintPrograms extends ZIOAppDefault:
|
2022-12-04 18:26:52 +00:00
|
|
|
private def writeLine(file: String)(s: String) =
|
|
|
|
File(s"data/$file.txt")
|
|
|
|
.writeLine(s)
|
|
|
|
|
|
|
|
private val programs =
|
|
|
|
List[(String, String)](
|
2022-12-07 12:45:10 +00:00
|
|
|
// 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")
|
2022-12-04 23:17:31 +00:00
|
|
|
.pipe(Line.mkString),
|
2022-12-07 12:45:10 +00:00
|
|
|
|
|
|
|
// FEATURE: writing paragraphs separated by newlines is easy
|
2022-12-06 20:22:37 +00:00
|
|
|
"two-paragraphs.txt" -> List(
|
2022-12-04 23:17:31 +00:00
|
|
|
List("foo", "bar"),
|
|
|
|
List("alpha", "bravo")
|
|
|
|
)
|
|
|
|
.pipe(xxs => AsmBlock.interFlatMap(xxs)(List("", ""), identity))
|
|
|
|
.pipe(Line.mkString),
|
2022-12-07 15:22:42 +00:00
|
|
|
"feature-demo.asm" -> FeatureDemo.program,
|
2022-12-06 20:22:37 +00:00
|
|
|
"print-three-upper-math.asm" -> PrintThree.assemble(
|
|
|
|
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitionsWithMath)
|
|
|
|
),
|
|
|
|
"print-three-upper.asm" -> PrintThree.assemble(
|
2022-12-06 19:58:20 +00:00
|
|
|
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitions)
|
2022-12-06 18:43:48 +00:00
|
|
|
),
|
2022-12-06 20:22:37 +00:00
|
|
|
"print-three-lower.asm" -> PrintThree.assemble(
|
2022-12-06 19:30:35 +00:00
|
|
|
AssemblerOptions(InstructionCase.Lowercase, DefinitionsMode.UseLiterals)
|
2022-12-06 18:43:48 +00:00
|
|
|
)
|
2022-12-04 18:26:52 +00:00
|
|
|
)
|
2022-12-04 18:01:22 +00:00
|
|
|
|
2022-12-04 18:26:52 +00:00
|
|
|
def run: Task[Unit] =
|
|
|
|
for {
|
|
|
|
// just a traverse in slow motion...
|
|
|
|
_ <- programs
|
|
|
|
.map { case (f, s) => File(s"data/$f").writeLine(s) }
|
|
|
|
.foldLeft[Task[Unit]](ZIO.unit)((acc, z) => acc *> z)
|
2022-12-04 18:01:22 +00:00
|
|
|
} yield ()
|