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`
|
||||
*/
|
||||
sealed trait MetaIntent
|
||||
sealed trait MetaIntent:
|
||||
def toIntent: AsmBlock.Intent
|
||||
|
||||
object MetaIntent:
|
||||
case class Jump(target: String, description: String, xs: List[MetaIntent.Jump]) extends MetaIntent
|
||||
|
||||
object Jump:
|
||||
def toIntent(j: Jump): AsmBlock.Intent =
|
||||
AsmBlock.Intent(None, List(AsmBlock.Intent.Instruction.one("jsr", j.target)))
|
||||
case class Jump(target: String, description: String, xs: List[MetaIntent]) extends MetaIntent:
|
||||
def toIntent: AsmBlock.Intent =
|
||||
AsmBlock.Intent(None, List(AsmBlock.Intent.Instruction.one("jsr", target)))
|
||||
|
||||
case class Move[A: Definable, B: Definable](src: A, dest: B):
|
||||
def defines: List[Definable.Table] =
|
||||
|
|
|
@ -4,8 +4,8 @@ import cats.syntax.all.*
|
|||
|
||||
import com.htmlism.firepower.core.AsmBlock._
|
||||
|
||||
case class Subroutine(name: String, description: String, intents: () => List[MetaIntent.Jump]):
|
||||
def call: MetaIntent.Jump =
|
||||
case class Subroutine(name: String, description: String, intents: () => List[MetaIntent]):
|
||||
def call: MetaIntent =
|
||||
MetaIntent.Jump(name, description, intents())
|
||||
|
||||
object Subroutine:
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.htmlism.firepower.core.AsmBlock.Intent
|
|||
import com.htmlism.firepower.core.*
|
||||
|
||||
object SnakeEasy6502:
|
||||
val program: List[MetaIntent.Jump] =
|
||||
val program: List[MetaIntent] =
|
||||
List(
|
||||
init.call,
|
||||
loop.call
|
||||
|
@ -31,11 +31,11 @@ object SnakeEasy6502:
|
|||
lazy val initSnake =
|
||||
Subroutine("initSnake", "initializes the snake")
|
||||
|
||||
def firstCodeBlock(xs: List[MetaIntent.Jump]): AsmBlock.AnonymousCodeBlock =
|
||||
def firstCodeBlock(xs: List[MetaIntent]): AsmBlock.AnonymousCodeBlock =
|
||||
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)
|
||||
.values
|
||||
.toList
|
||||
|
@ -43,9 +43,9 @@ object SnakeEasy6502:
|
|||
@tailrec
|
||||
private def callGraphRecur(
|
||||
callGraph: ListMap[String, AsmBlock.NamedCodeBlock],
|
||||
todo: List[MetaIntent.Jump]
|
||||
todo: List[MetaIntent]
|
||||
): ListMap[String, AsmBlock.NamedCodeBlock] =
|
||||
todo match
|
||||
todo.collect { case x: MetaIntent.Jump => x } match
|
||||
case head :: tail =>
|
||||
if (callGraph.contains(head.target)) callGraphRecur(callGraph, tail)
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue