mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-06-01 15:41:35 +00:00
use meta intent dsl now
This commit is contained in:
parent
4adb4ab4cd
commit
9d038a0160
|
@ -7,14 +7,13 @@ import com.htmlism.firepower.core.*
|
||||||
/**
|
/**
|
||||||
* Anything that can be compiled into an `Intent`
|
* Anything that can be compiled into an `Intent`
|
||||||
*/
|
*/
|
||||||
sealed trait MetaIntent
|
sealed trait MetaIntent:
|
||||||
|
def toIntent: AsmBlock.Intent
|
||||||
|
|
||||||
object MetaIntent:
|
object MetaIntent:
|
||||||
case class Jump(target: String, description: String, xs: List[MetaIntent.Jump]) extends MetaIntent
|
case class Jump(target: String, description: String, xs: List[MetaIntent]) extends MetaIntent:
|
||||||
|
def toIntent: AsmBlock.Intent =
|
||||||
object Jump:
|
AsmBlock.Intent(None, List(AsmBlock.Intent.Instruction.one("jsr", target)))
|
||||||
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):
|
case class Move[A: Definable, B: Definable](src: A, dest: B):
|
||||||
def defines: List[Definable.Table] =
|
def defines: List[Definable.Table] =
|
||||||
|
|
|
@ -4,8 +4,8 @@ import cats.syntax.all.*
|
||||||
|
|
||||||
import com.htmlism.firepower.core.AsmBlock._
|
import com.htmlism.firepower.core.AsmBlock._
|
||||||
|
|
||||||
case class Subroutine(name: String, description: String, intents: () => List[MetaIntent.Jump]):
|
case class Subroutine(name: String, description: String, intents: () => List[MetaIntent]):
|
||||||
def call: MetaIntent.Jump =
|
def call: MetaIntent =
|
||||||
MetaIntent.Jump(name, description, intents())
|
MetaIntent.Jump(name, description, intents())
|
||||||
|
|
||||||
object Subroutine:
|
object Subroutine:
|
||||||
|
|
|
@ -10,7 +10,7 @@ import com.htmlism.firepower.core.AsmBlock.Intent
|
||||||
import com.htmlism.firepower.core.*
|
import com.htmlism.firepower.core.*
|
||||||
|
|
||||||
object SnakeEasy6502:
|
object SnakeEasy6502:
|
||||||
val program: List[MetaIntent.Jump] =
|
val program: List[MetaIntent] =
|
||||||
List(
|
List(
|
||||||
init.call,
|
init.call,
|
||||||
loop.call
|
loop.call
|
||||||
|
@ -31,11 +31,11 @@ object SnakeEasy6502:
|
||||||
lazy val initSnake =
|
lazy val initSnake =
|
||||||
Subroutine("initSnake", "initializes the snake")
|
Subroutine("initSnake", "initializes the snake")
|
||||||
|
|
||||||
def firstCodeBlock(xs: List[MetaIntent.Jump]): AsmBlock.AnonymousCodeBlock =
|
def firstCodeBlock(xs: List[MetaIntent]): AsmBlock.AnonymousCodeBlock =
|
||||||
AsmBlock
|
AsmBlock
|
||||||
.AnonymousCodeBlock(xs.map(MetaIntent.Jump.toIntent))
|
.AnonymousCodeBlock(xs.map(_.toIntent))
|
||||||
|
|
||||||
def callGraph(xs: List[MetaIntent.Jump]): List[AsmBlock.NamedCodeBlock] =
|
def callGraph(xs: List[MetaIntent]): List[AsmBlock.NamedCodeBlock] =
|
||||||
callGraphRecur(ListMap.empty, xs)
|
callGraphRecur(ListMap.empty, xs)
|
||||||
.values
|
.values
|
||||||
.toList
|
.toList
|
||||||
|
@ -43,9 +43,9 @@ object SnakeEasy6502:
|
||||||
@tailrec
|
@tailrec
|
||||||
private def callGraphRecur(
|
private def callGraphRecur(
|
||||||
callGraph: ListMap[String, AsmBlock.NamedCodeBlock],
|
callGraph: ListMap[String, AsmBlock.NamedCodeBlock],
|
||||||
todo: List[MetaIntent.Jump]
|
todo: List[MetaIntent]
|
||||||
): ListMap[String, AsmBlock.NamedCodeBlock] =
|
): ListMap[String, AsmBlock.NamedCodeBlock] =
|
||||||
todo match
|
todo.collect { case x: MetaIntent.Jump => x } match
|
||||||
case head :: tail =>
|
case head :: tail =>
|
||||||
if (callGraph.contains(head.target)) callGraphRecur(callGraph, tail)
|
if (callGraph.contains(head.target)) callGraphRecur(callGraph, tail)
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user