mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-12-31 20:32:21 +00:00
implement jump registry
This commit is contained in:
parent
3c618410bb
commit
2db25f5982
@ -16,7 +16,6 @@
|
||||
## TODO
|
||||
|
||||
- postfix operations to accumulator values
|
||||
- implement jump registry
|
||||
- maybe implement define registry
|
||||
- register locking (i.e. disallow X writes during indexed traversal that uses X)
|
||||
- compiler optimization
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.htmlism.mos6502.dsl
|
||||
|
||||
import scala.collection.immutable.ListSet
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
case class AsmDocument(xs: List[TopLevelAsmDocumentFragment]) {
|
||||
@ -13,14 +14,21 @@ class AsmDocumentContext {
|
||||
private val xs: ListBuffer[TopLevelAsmDocumentFragment] =
|
||||
ListBuffer()
|
||||
|
||||
private var jumps: ListSet[Subroutine] =
|
||||
ListSet()
|
||||
|
||||
def push(x: TopLevelAsmDocumentFragment): Unit =
|
||||
xs.append(x)
|
||||
|
||||
def attach(sub: Subroutine): Unit =
|
||||
xs.append(sub)
|
||||
def addJumpRegistry(ys: ListSet[Subroutine]): Unit =
|
||||
jumps = jumps ++ ys
|
||||
|
||||
def toDoc: AsmDocument =
|
||||
AsmDocument(xs.toList)
|
||||
def toDoc: AsmDocument = {
|
||||
val asmFragmentsAndSubroutines =
|
||||
xs.toList ::: jumps.toList
|
||||
|
||||
AsmDocument(asmFragmentsAndSubroutines)
|
||||
}
|
||||
}
|
||||
|
||||
sealed trait TopLevelAsmDocumentFragment {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.htmlism.mos6502.dsl
|
||||
|
||||
import scala.collection.immutable.ListSet
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
import cats.implicits._
|
||||
@ -133,6 +134,9 @@ class AssemblyContext {
|
||||
private val xs: ListBuffer[Statement] =
|
||||
ListBuffer()
|
||||
|
||||
private var jumps: ListSet[Subroutine] =
|
||||
ListSet()
|
||||
|
||||
def push(instruction: Instruction): Unit =
|
||||
xs.append(UnaryInstruction(instruction, None))
|
||||
|
||||
@ -151,6 +155,9 @@ class AssemblyContext {
|
||||
def branch(instruction: Instruction, label: String): Unit =
|
||||
xs.append(BranchingInstruction(instruction, label))
|
||||
|
||||
def addJump(subroutine: Subroutine): Unit =
|
||||
jumps = jumps + subroutine
|
||||
|
||||
def printOut(): Unit = {
|
||||
xs.map(_.toAsm)
|
||||
.foreach(println)
|
||||
@ -161,4 +168,7 @@ class AssemblyContext {
|
||||
|
||||
def toFragment: AsmFragment =
|
||||
AsmFragment(xs.toList)
|
||||
|
||||
def getJumps: ListSet[Subroutine] =
|
||||
jumps
|
||||
}
|
||||
|
@ -68,4 +68,4 @@ case class BranchingInstruction(instruction: Instruction, label: String) extends
|
||||
|
||||
def toTriplet: (String, Option[String], Option[String]) =
|
||||
(instruction.toString, label.some, None)
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ trait AsmDocSyntax {
|
||||
|
||||
f(asmCtx)
|
||||
|
||||
ctx
|
||||
.addJumpRegistry(asmCtx.getJumps)
|
||||
|
||||
ctx
|
||||
.push(asmCtx.toFragment)
|
||||
}
|
||||
|
@ -17,7 +17,11 @@ trait AsmSyntax {
|
||||
Subroutine(s, ctx.toFragment)
|
||||
}
|
||||
|
||||
def jump(s: Subroutine)(implicit ctx: AssemblyContext): Unit =
|
||||
def jump(s: Subroutine)(implicit ctx: AssemblyContext): Unit = {
|
||||
ctx
|
||||
.addJump(s)
|
||||
|
||||
ctx
|
||||
.branch(JSR, s.name)
|
||||
}
|
||||
}
|
||||
|
@ -77,8 +77,6 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers {
|
||||
asm { implicit a =>
|
||||
jump(init)
|
||||
}
|
||||
|
||||
ctx.attach(init)
|
||||
}
|
||||
|
||||
println(
|
||||
|
Loading…
Reference in New Issue
Block a user