From a7ab58f66078621a8a6ddc465369dad61389d46b Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Sun, 4 Dec 2022 17:15:29 -0500 Subject: [PATCH] expand model --- build.sbt | 1 + data/annotated-snake.asm | 1 + .../firepower/demo/PrintPrograms.scala | 41 ++++++++++++++++++- .../htmlism/firepower/demo/asm/AsmBlock.scala | 22 +++++----- 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/build.sbt b/build.sbt index e8c063b..a9f9b45 100644 --- a/build.sbt +++ b/build.sbt @@ -18,6 +18,7 @@ lazy val scratchpad = lazy val demo = module("demo") + .withCats .withEfectMonad .settings(libraryDependencies += "com.htmlism" %% "rufio-zio" % "74-5cd25e9b") diff --git a/data/annotated-snake.asm b/data/annotated-snake.asm index 7af02ae..4c05fae 100644 --- a/data/annotated-snake.asm +++ b/data/annotated-snake.asm @@ -6,4 +6,5 @@ ; Change direction: W A S D + labeled: 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 5d21d89..bed3c4b 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 @@ -1,5 +1,7 @@ package com.htmlism.firepower.demo +import cats.syntax.all._ + import com.htmlism.firepower.demo.asm._ import com.htmlism.firepower.demo.str._ import zio.* @@ -32,8 +34,43 @@ object PrintPrograms extends ZIOAppDefault: List( CommentBlock.fromMultiline(asciiArt), CommentBlock(List("Change direction: W A S D")), - CodeBlock(None, Nil), - CodeBlock(Some("labeled"), Nil) + AnonymousCodeBlock( + List( + AsmBlock.Intent( + None, + List( + AsmBlock.Intent.Instruction("hello", None), + AsmBlock.Intent.Instruction("world", "instruction comment".some) + ) + ), + AsmBlock.Intent( + "this block has some preamble".some, + List( + AsmBlock.Intent.Instruction("hello", None), + AsmBlock.Intent.Instruction("world", "instruction comment".some) + ) + ) + ) + ), + NamedCodeBlock( + "labeled", + List( + AsmBlock.Intent( + None, + List( + AsmBlock.Intent.Instruction("hello", None), + AsmBlock.Intent.Instruction("world", "instruction comment".some) + ) + ), + AsmBlock.Intent( + "this block has some preamble".some, + List( + AsmBlock.Intent.Instruction("hello", None), + AsmBlock.Intent.Instruction("world", "instruction comment".some) + ) + ) + ) + ) ) ) ) diff --git a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala index ffa4252..fa19567 100644 --- a/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala +++ b/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala @@ -6,13 +6,9 @@ sealed trait AsmBlock case class CommentBlock(xs: List[String]) extends AsmBlock -case class CodeBlock(name: Option[String], chunks: List[CodeBlock.Chunk]) extends AsmBlock +case class NamedCodeBlock(name: String, intents: List[AsmBlock.Intent]) extends AsmBlock -object CodeBlock: - case class Chunk(label: Option[String], instructions: List[Chunk.Instruction]) - - object Chunk: - case class Instruction(code: String, comment: Option[String]) +case class AnonymousCodeBlock(intents: List[AsmBlock.Intent]) extends AsmBlock object AsmBlock: def toParagraph(xs: AsmBlock): Paragraph = @@ -20,13 +16,19 @@ object AsmBlock: case CommentBlock(ys) => Paragraph(ys.map("; " + _)) - case CodeBlock(oLabel, _) => + case NamedCodeBlock(label, _) => Paragraph( - oLabel - .map(_ + ":") - .toList + List(label + ":") ) + case AnonymousCodeBlock(_) => + Paragraph("") + + case class Intent(label: Option[String], instructions: List[Intent.Instruction]) + + object Intent: + case class Instruction(code: String, comment: Option[String]) + object CommentBlock: def fromMultiline(s: String): CommentBlock = CommentBlock(s.split("\\n").toList)