with instructions

This commit is contained in:
Mark Canlas 2022-12-04 17:30:36 -05:00
parent 54ffb91104
commit 7bae8fef9a
3 changed files with 36 additions and 12 deletions

View File

@ -5,5 +5,19 @@
; Change direction: W A S D
lda $00
lda $01 ; instruction comment
; this block has some preamble
lda $00
lda $01 ; instruction comment
labeled:
; This is a subroutine description
lda $00
lda $01 ; instruction comment
; this block has some preamble
lda $00
lda $01 ; instruction comment

View File

@ -39,15 +39,15 @@ object PrintPrograms extends ZIOAppDefault:
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction("hello", None),
AsmBlock.Intent.Instruction("world", "instruction comment".some)
AsmBlock.Intent.Instruction("lda $00", None),
AsmBlock.Intent.Instruction("lda $01", "instruction comment".some)
)
),
AsmBlock.Intent(
"this block has some preamble".some,
List(
AsmBlock.Intent.Instruction("hello", None),
AsmBlock.Intent.Instruction("world", "instruction comment".some)
AsmBlock.Intent.Instruction("lda $00", None),
AsmBlock.Intent.Instruction("lda $01", "instruction comment".some)
)
)
)
@ -59,15 +59,15 @@ object PrintPrograms extends ZIOAppDefault:
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction("hello", None),
AsmBlock.Intent.Instruction("world", "instruction comment".some)
AsmBlock.Intent.Instruction("lda $00", None),
AsmBlock.Intent.Instruction("lda $01", "instruction comment".some)
)
),
AsmBlock.Intent(
"this block has some preamble".some,
List(
AsmBlock.Intent.Instruction("hello", None),
AsmBlock.Intent.Instruction("world", "instruction comment".some)
AsmBlock.Intent.Instruction("lda $00", None),
AsmBlock.Intent.Instruction("lda $01", "instruction comment".some)
)
)
)

View File

@ -24,25 +24,35 @@ object AsmBlock:
Paragraph(ys.map(toComment))
)
case NamedCodeBlock(label, oComment, _) =>
case NamedCodeBlock(label, oComment, intents) =>
val headerParagraph =
Paragraph(
List(label + ":") ++ oComment.map(toComment).map(withIndent).toList
)
val intentParagraphs =
Nil
intents
.map(Intent.toParagraph)
headerParagraph :: intentParagraphs
case AnonymousCodeBlock(_) =>
Nil
case AnonymousCodeBlock(intents) =>
intents
.map(Intent.toParagraph)
case class Intent(label: Option[String], instructions: List[Intent.Instruction])
object Intent:
case class Instruction(code: String, comment: Option[String])
def toParagraph(x: Intent): Paragraph =
Paragraph(
x.label.map(toComment).map(withIndent).toList ++ x
.instructions
.map(i => i.code + i.comment.map(toComment).map(" " + _).getOrElse(" "))
.map(withIndent)
)
object CommentBlock:
def fromMultiline(s: String): CommentBlock =
CommentBlock(s.split("\\n").toList)