mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 22:50:18 +00:00
Precompile WIP
This commit is contained in:
parent
4356620579
commit
fb176ebc15
41
src/main/scala/aqua/context/Precompile.scala
Normal file
41
src/main/scala/aqua/context/Precompile.scala
Normal file
@ -0,0 +1,41 @@
|
||||
package aqua.context
|
||||
|
||||
import aqua.context.walker.Walker
|
||||
import aqua.interim.{Func, Op}
|
||||
import aqua.parser.{Block, DefFunc, FuncExpr}
|
||||
import cats.Comonad
|
||||
import shapeless._
|
||||
|
||||
case class Precompile(funcs: Map[String, Func] = Map.empty, build: Option[Op] = None)
|
||||
|
||||
object Precompile {
|
||||
|
||||
class Pass[F[_]: Comonad, I <: HList, O <: HList](extend: Walker[F, I, O]) extends Walker[F, I, Precompile :: O] {
|
||||
|
||||
override def exitFuncExprGroup(group: FuncExpr[F, I], last: Out): Out =
|
||||
last.head :: extend.exitFuncExprGroup(group, last.tail)
|
||||
|
||||
override def funcOpCtx(op: FuncExpr[F, I], prev: Out): Out = prev.head :: extend.funcOpCtx(op, prev.tail)
|
||||
|
||||
override def blockCtx(block: Block[F, I]): Out =
|
||||
(block match {
|
||||
case DefFunc(head, body, context) =>
|
||||
// get func types from vartypes
|
||||
// (later) get result type
|
||||
//
|
||||
???
|
||||
}) :: extend.blockCtx(block)
|
||||
|
||||
override def emptyCtx: Out = Precompile() :: extend.emptyCtx
|
||||
|
||||
override def combineBlockCtx(prev: Out, block: Out): Out =
|
||||
Precompile(prev.head.funcs ++ block.head.funcs) :: extend.combineBlockCtx(prev.tail, block.tail)
|
||||
|
||||
override def duplicates(prev: Out, next: Out): List[Walker.DupError[F]] = extend.duplicates(prev.tail, next.tail)
|
||||
|
||||
override def unresolved(ctx: Out): (List[Walker.UnresolvedError[F]], Out) = {
|
||||
val (extErr, extOut) = extend.unresolved(ctx.tail)
|
||||
(extErr, ctx.head :: extOut)
|
||||
}
|
||||
}
|
||||
}
|
7
src/main/scala/aqua/interim/Func.scala
Normal file
7
src/main/scala/aqua/interim/Func.scala
Normal file
@ -0,0 +1,7 @@
|
||||
package aqua.interim
|
||||
|
||||
case class Op(label: String, ops: List[Ctx => Op])
|
||||
|
||||
case class Ctx(on: String, prefix: String)
|
||||
|
||||
case class Func(args: List[(String, Type)], body: Ctx => Op)
|
Loading…
Reference in New Issue
Block a user