mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 22:50:18 +00:00
Basic PeerIdInterpreter
This commit is contained in:
parent
b8d72677ee
commit
ab4a26ee96
@ -0,0 +1,25 @@
|
||||
package aqua.ast.algebra.scope
|
||||
|
||||
import aqua.ast.algebra.{ReportError, StackInterpreter}
|
||||
import aqua.parser.lexer.Value
|
||||
import cats.data.State
|
||||
import cats.~>
|
||||
import monocle.Lens
|
||||
import monocle.macros.GenLens
|
||||
|
||||
class PeerIdInterpreter[F[_], X](implicit lens: Lens[X, PeerIdState[F]], error: ReportError[F, X])
|
||||
extends StackInterpreter[F, X, PeerIdState[F], Value[F]](GenLens[PeerIdState[F]](_.stack))
|
||||
with (PeerIdOp[F, *] ~> State[X, *]) {
|
||||
|
||||
override def apply[A](fa: PeerIdOp[F, A]): State[X, A] =
|
||||
(fa match {
|
||||
case CurrentPeerId() =>
|
||||
getState.map(_.stack.headOption)
|
||||
case _: ErasePeerId[F] =>
|
||||
endScope
|
||||
case opi: OnPeerId[F] =>
|
||||
beginScope(opi.id)
|
||||
}).asInstanceOf[State[X, A]]
|
||||
}
|
||||
|
||||
case class PeerIdState[F[_]](stack: List[Value[F]])
|
@ -2,7 +2,7 @@ package aqua.ast.algebra.scope
|
||||
|
||||
import aqua.parser.lexer.Value
|
||||
|
||||
trait PeerIdOp[F[_], T]
|
||||
sealed trait PeerIdOp[F[_], T]
|
||||
|
||||
case class OnPeerId[F[_]](id: Value[F]) extends PeerIdOp[F, Unit]
|
||||
case class ErasePeerId[F[_]]() extends PeerIdOp[F, Unit]
|
||||
|
Loading…
Reference in New Issue
Block a user