assembler skeleton

This commit is contained in:
Mark Canlas 2022-12-05 17:19:50 -05:00
parent 0cdc2fc7af
commit 3932c5d856
6 changed files with 46 additions and 13 deletions

View File

@ -15,7 +15,7 @@ lazy val core =
lazy val demo =
module("demo")
.withCats
.dependsOn(core)
.withEfectMonad
.settings(libraryDependencies += "com.htmlism" %% "rufio-zio" % "74-5cd25e9b")

View File

@ -1,14 +1,18 @@
package com.htmlism.firepower.demo.asm
package com.htmlism.firepower.core
sealed trait AsmBlock
case class CommentBlock(xs: List[String]) extends AsmBlock
case class NamedCodeBlock(name: String, comment: Option[String], intents: List[AsmBlock.Intent]) extends AsmBlock
case class AnonymousCodeBlock(intents: List[AsmBlock.Intent]) extends AsmBlock
object AsmBlock:
case class CommentBlock(xs: List[String]) extends AsmBlock
object CommentBlock:
def fromMultiline(s: String): CommentBlock =
CommentBlock(s.split("\\n").toList)
case class NamedCodeBlock(name: String, comment: Option[String], intents: List[AsmBlock.Intent]) extends AsmBlock
case class AnonymousCodeBlock(intents: List[AsmBlock.Intent]) extends AsmBlock
def interFlatMap[A, B](xs: List[A])(x: List[B], f: A => List[B]): List[B] =
xs match
case head :: tail =>
@ -50,7 +54,3 @@ object AsmBlock:
.instructions
.map(i => i.code + i.comment.map(toComment).map(" " + _).getOrElse(" "))
.map(withIndent)
object CommentBlock:
def fromMultiline(s: String): CommentBlock =
CommentBlock(s.split("\\n").toList)

View File

@ -0,0 +1,7 @@
package com.htmlism.firepower.core
case class AssemblerOptions()
object AssemblerOptions:
enum Definitions:
case InlineDefinitions, UseDefinitions, UseDefinitionsWithMath

View File

@ -0,0 +1,11 @@
package com.htmlism.firepower.core
object MacroAssembler:
def assemble(program: List[String], options: AssemblerOptions): List[AsmBlock] =
Nil
def defineGraph(program: List[String]): List[AsmBlock.CommentBlock] =
Nil
def callGraph(program: List[String]): List[String] =
Nil

View File

@ -0,0 +1,14 @@
package com.htmlism.firepower.core
import cats.syntax.all.*
import com.htmlism.firepower.core.AsmBlock._
case class Subroutine(name: String, intents: List[Intent]):
def call: Intent.Instruction =
Intent.Instruction(s"jsr $name", None)
def attach: NamedCodeBlock =
NamedCodeBlock(name, "this is a named block".some, intents)
object Subroutine

View File

@ -7,7 +7,8 @@ import scala.util.chaining._
import cats.syntax.all._
import zio.*
import com.htmlism.firepower.demo.asm._
import com.htmlism.firepower.core.AsmBlock._
import com.htmlism.firepower.core._
import com.htmlism.firepower.demo.str._
import com.htmlism.rufio.withzio.*