thread opts more specifically

This commit is contained in:
Mark Canlas 2022-12-06 18:06:09 -05:00
parent def9668d82
commit 1bf474d6bb
3 changed files with 28 additions and 25 deletions

View File

@ -40,7 +40,7 @@ object AsmBlock:
"$" + hex.toUpperCase
def toLines(xs: AsmBlock): List[String] =
def toLines(opts: AssemblerOptions.InstructionCase)(xs: AsmBlock): List[String] =
xs match
case CommentBlock(ys) =>
ys.map(toComment)
@ -61,12 +61,12 @@ object AsmBlock:
List(label + ":") ++ oComment.map(toComment).map(withIndent).toList
val intentParagraphs =
intents.map(Intent.toLines)
intents.map(Intent.toLines(opts))
interFlatMap(headerParagraph :: intentParagraphs)(List(""), identity)
case AnonymousCodeBlock(intents) =>
interFlatMap(intents)(List(""), Intent.toLines)
interFlatMap(intents)(List(""), Intent.toLines(opts))
case class Intent(label: Option[String], instructions: List[Intent.Instruction])
@ -82,7 +82,7 @@ object AsmBlock:
def length: Int =
0
def toLines(x: Intent): List[String] =
def toLines(opts: AssemblerOptions.InstructionCase)(x: Intent): List[String] =
val comment =
x.label.map(toComment).map(withIndent).toList
@ -97,16 +97,19 @@ object AsmBlock:
.instructions
.map {
case Instruction.Zero(code, oComment) =>
val codeUpperLower =
instruction(code, opts)
oComment match
case Some(c) =>
String.format(s"%-${maximumLength}s", code) + " " + toComment(c)
String.format(s"%-${maximumLength}s", codeUpperLower) + " " + toComment(c)
case None =>
code
codeUpperLower
case Instruction.One(code, operand, oComment) =>
val leftSlug =
code + " " + operand
instruction(code, opts) + " " + operand
oComment match
case Some(c) =>
@ -118,3 +121,11 @@ object AsmBlock:
.map(withIndent)
comment ++ instructions
def instruction(s: String, instructionCase: AssemblerOptions.InstructionCase): String =
instructionCase match
case AssemblerOptions.InstructionCase.Uppercase =>
s.toUpperCase
case AssemblerOptions.InstructionCase.Lowercase =>
s.toLowerCase

View File

@ -51,7 +51,7 @@ object AnnotatedSnake:
)
)
)
.map(AsmBlock.toLines)
.map(AsmBlock.toLines(AssemblerOptions.InstructionCase.Lowercase))
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
.pipe(str.Line.mkString)

View File

@ -29,13 +29,13 @@ object PrintThree:
build(Easy6502.Screen(0x200))
def assemble(opts: AssemblerOptions): String =
(defines(opts) ++ codes(opts))
.map(AsmBlock.toLines)
(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) =
opts.definitionsMode match
private def defines(opts: AssemblerOptions.DefinitionsMode) =
opts match
case AssemblerOptions.DefinitionsMode.UseLiterals =>
Nil
@ -49,11 +49,11 @@ object PrintThree:
.pipe(AsmBlock.DefinesBlock(_))
}
private def codes(opts: AssemblerOptions) =
private def codes(opts: AssemblerOptions.DefinitionsMode) =
program
.map { mv =>
val argument =
opts.definitionsMode match
opts match
case AssemblerOptions.DefinitionsMode.UseLiterals =>
f"#$$${mv.src.toValue}%02X"
@ -62,7 +62,7 @@ object PrintThree:
"#" + mv.src.toDefine
val argumentTwo =
opts.definitionsMode match
opts match
case AssemblerOptions.DefinitionsMode.UseLiterals =>
AsmBlock.toHex(mv.dest.toValue)
@ -78,12 +78,12 @@ object PrintThree:
AsmBlock
.Intent
.Instruction
.One(instruction("LDA", opts.instructionCase), argument, s"a = ${mv.src.toComment}".some),
.One("LDA", argument, s"a = ${mv.src.toComment}".some),
AsmBlock
.Intent
.Instruction
.One(
instruction("STA", opts.instructionCase),
"STA",
argumentTwo,
s"${mv.dest.toComment} = a".some
)
@ -92,11 +92,3 @@ object PrintThree:
}
.pipe(AnonymousCodeBlock(_))
.pipe(List(_))
def instruction(s: String, instructionCase: AssemblerOptions.InstructionCase): String =
instructionCase match
case AssemblerOptions.InstructionCase.Uppercase =>
s.toUpperCase
case AssemblerOptions.InstructionCase.Lowercase =>
s.toLowerCase