consume meta intent jump

This commit is contained in:
Mark Canlas 2022-12-07 14:50:12 -05:00
parent f1beb9a316
commit bf3ad70090
5 changed files with 17 additions and 7 deletions

View File

@ -1,2 +1,3 @@
JSR init
JSR loop

View File

@ -103,9 +103,12 @@ object AsmBlock:
(code + " " + operand.getOrElse("")).length
object Instruction:
def one(code: String, operand: String, comment: Option[String]): Instruction =
def one(code: String, operand: String, comment: Option[String] = None): Instruction =
Instruction(code, operand.some, comment)
def zero(code: String, comment: Option[String] = None): Instruction =
Instruction(code, None, comment)
def toLines(opts: AssemblerOptions.InstructionCase)(x: Intent): List[String] =
val comment =
x.label.map(toComment).map(withIndent).toList

View File

@ -7,6 +7,12 @@ import com.htmlism.firepower.core.*
sealed trait MetaIntent
object MetaIntent:
case class Jump(target: String)
object Jump:
def toIntent(j: Jump): AsmBlock.Intent =
AsmBlock.Intent(None, List(AsmBlock.Intent.Instruction.one("jsr", j.target)))
case class Move[A: Definable, B: Definable](src: A, dest: B):
def defines: List[Definable.Table] =
List(

View File

@ -5,8 +5,8 @@ import cats.syntax.all.*
import com.htmlism.firepower.core.AsmBlock._
case class Subroutine(name: String, intents: List[MetaIntent]):
def call: Intent.Instruction =
Intent.Instruction.one("jsr", name, None)
def call: MetaIntent.Jump =
MetaIntent.Jump(name)
def attach: NamedCodeBlock =
NamedCodeBlock(name, "this is a named block".some, intents.map(_ => Intent("TODO".some, Nil)))

View File

@ -6,7 +6,7 @@ import com.htmlism.firepower.core.AsmBlock.Intent
import com.htmlism.firepower.core.*
object SnakeEasy6502:
val program: List[Intent.Instruction] =
val program: List[MetaIntent.Jump] =
List(
init.call,
loop.call
@ -21,11 +21,11 @@ object SnakeEasy6502:
lazy val initSnake =
Subroutine("initSnake")
def firstCodeBlock(xs: List[Intent.Instruction]): AsmBlock.AnonymousCodeBlock =
def firstCodeBlock(xs: List[MetaIntent.Jump]): AsmBlock.AnonymousCodeBlock =
AsmBlock
.AnonymousCodeBlock(List(Intent(None, xs)))
.AnonymousCodeBlock(xs.map(MetaIntent.Jump.toIntent))
def callGraph(xs: List[Intent.Instruction]): List[AsmBlock.NamedCodeBlock] =
def callGraph(xs: List[MetaIntent.Jump]): List[AsmBlock.NamedCodeBlock] =
Nil
def assemble(opts: AssemblerOptions): List[String] =