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