From 844d34dd5de029eedb9cfdd972eadac7d0cabc75 Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Sun, 4 Dec 2022 16:56:03 -0500 Subject: [PATCH] demonstrate code block --- data/annotated-snake.asm | 3 +++ .../htmlism/firepower/demo/PrintPrograms.scala | 6 ++++-- .../htmlism/firepower/demo/asm/AsmBlock.scala | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/data/annotated-snake.asm b/data/annotated-snake.asm index 6547cf4..7af02ae 100644 --- a/data/annotated-snake.asm +++ b/data/annotated-snake.asm @@ -4,3 +4,6 @@ ; |___/_||_\__,_|_\_\___\___/___/\__/___| ; 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 cf169af..5d21d89 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 @@ -27,11 +27,13 @@ object PrintPrograms extends ZIOAppDefault: ), "annotated-snake.asm" -> (Line.mkString _) .compose(Paragraph.mkLines) - .compose((xs: List[CommentBlock]) => xs.map(CommentBlock.toParagraph)) + .compose((xs: List[AsmBlock]) => xs.map(AsmBlock.toParagraph)) .apply( List( CommentBlock.fromMultiline(asciiArt), - CommentBlock(List("Change direction: W A S D")) + CommentBlock(List("Change direction: W A S D")), + CodeBlock(None, Nil), + CodeBlock(Some("labeled"), Nil) ) ) ) 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 7b2df77..ffa4252 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,11 +6,27 @@ sealed trait AsmBlock case class CommentBlock(xs: List[String]) extends AsmBlock -object CommentBlock: +case class CodeBlock(name: Option[String], chunks: List[CodeBlock.Chunk]) extends AsmBlock + +object CodeBlock: + case class Chunk(label: Option[String], instructions: List[Chunk.Instruction]) + + object Chunk: + case class Instruction(code: String, comment: Option[String]) + +object AsmBlock: def toParagraph(xs: AsmBlock): Paragraph = xs match case CommentBlock(ys) => Paragraph(ys.map("; " + _)) + case CodeBlock(oLabel, _) => + Paragraph( + oLabel + .map(_ + ":") + .toList + ) + +object CommentBlock: def fromMultiline(s: String): CommentBlock = CommentBlock(s.split("\\n").toList)