mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 22:50:18 +00:00
feat!: add name scopes to if/else/try blocks (#715)
This commit is contained in:
parent
94503218cf
commit
e4205dfbbf
@ -2,6 +2,7 @@ package aqua.semantics
|
||||
|
||||
import aqua.parser.lexer.Token
|
||||
import aqua.semantics.rules.abilities.AbilitiesAlgebra
|
||||
import aqua.semantics.rules.locations.LocationsAlgebra
|
||||
import aqua.semantics.rules.names.NamesAlgebra
|
||||
import cats.Monad
|
||||
import cats.syntax.flatMap.*
|
||||
@ -37,6 +38,14 @@ sealed abstract class Prog[Alg[_]: Monad, A] extends (Alg[A] => Alg[A]) {
|
||||
(_: Unit, m: A) => N.endScope() as m
|
||||
)
|
||||
)
|
||||
|
||||
def locationsScope[S[_]]()(implicit L: LocationsAlgebra[S, Alg]): Prog[Alg, A] =
|
||||
wrap(
|
||||
RunAround(
|
||||
L.beginScope(),
|
||||
(_: Unit, m: A) => L.endScope() as m
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
case class RunAfter[Alg[_]: Monad, A](prog: Alg[A]) extends Prog[Alg, A] {
|
||||
|
@ -5,16 +5,24 @@ import aqua.parser.expr.func.ElseOtherwiseExpr
|
||||
import aqua.raw.Raw
|
||||
import aqua.semantics.Prog
|
||||
import aqua.semantics.rules.abilities.AbilitiesAlgebra
|
||||
import aqua.semantics.rules.locations.LocationsAlgebra
|
||||
import aqua.semantics.rules.names.NamesAlgebra
|
||||
import cats.syntax.applicative.*
|
||||
import cats.Monad
|
||||
|
||||
class ElseOtherwiseSem[S[_]](val expr: ElseOtherwiseExpr[S]) extends AnyVal {
|
||||
|
||||
def program[Alg[_]: Monad](implicit A: AbilitiesAlgebra[S, Alg]): Prog[Alg, Raw] =
|
||||
def program[Alg[_]: Monad](implicit
|
||||
A: AbilitiesAlgebra[S, Alg],
|
||||
N: NamesAlgebra[S, Alg],
|
||||
L: LocationsAlgebra[S, Alg]
|
||||
): Prog[Alg, Raw] =
|
||||
Prog
|
||||
.after[Alg, Raw] {
|
||||
case FuncOp(g) => XorTag.wrap(g).toFuncOp.pure[Alg]
|
||||
case g => g.pure[Alg]
|
||||
}
|
||||
.abilitiesScope(expr.token)
|
||||
.namesScope(expr.token)
|
||||
.locationsScope()
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import aqua.raw.Raw
|
||||
import aqua.semantics.Prog
|
||||
import aqua.semantics.rules.ValuesAlgebra
|
||||
import aqua.semantics.rules.abilities.AbilitiesAlgebra
|
||||
import aqua.semantics.rules.locations.LocationsAlgebra
|
||||
import aqua.semantics.rules.names.NamesAlgebra
|
||||
import aqua.semantics.rules.types.TypesAlgebra
|
||||
import aqua.types.Type
|
||||
import cats.Monad
|
||||
@ -19,7 +21,9 @@ class IfSem[S[_]](val expr: IfExpr[S]) extends AnyVal {
|
||||
def program[Alg[_]: Monad](implicit
|
||||
V: ValuesAlgebra[S, Alg],
|
||||
T: TypesAlgebra[S, Alg],
|
||||
A: AbilitiesAlgebra[S, Alg]
|
||||
A: AbilitiesAlgebra[S, Alg],
|
||||
N: NamesAlgebra[S, Alg],
|
||||
L: LocationsAlgebra[S, Alg]
|
||||
): Prog[Alg, Raw] =
|
||||
Prog
|
||||
.around(
|
||||
@ -55,4 +59,6 @@ class IfSem[S[_]](val expr: IfExpr[S]) extends AnyVal {
|
||||
}
|
||||
)
|
||||
.abilitiesScope[S](expr.token)
|
||||
.namesScope[S](expr.token)
|
||||
.locationsScope()
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import aqua.raw.Raw
|
||||
import aqua.semantics.Prog
|
||||
import aqua.semantics.rules.ValuesAlgebra
|
||||
import aqua.semantics.rules.abilities.AbilitiesAlgebra
|
||||
import aqua.semantics.rules.locations.LocationsAlgebra
|
||||
import aqua.semantics.rules.names.NamesAlgebra
|
||||
import aqua.semantics.rules.types.TypesAlgebra
|
||||
import cats.syntax.applicative.*
|
||||
import cats.Monad
|
||||
@ -13,9 +15,9 @@ import cats.Monad
|
||||
class TrySem[S[_]](val expr: TryExpr[S]) extends AnyVal {
|
||||
|
||||
def program[Alg[_]: Monad](implicit
|
||||
V: ValuesAlgebra[S, Alg],
|
||||
T: TypesAlgebra[S, Alg],
|
||||
A: AbilitiesAlgebra[S, Alg]
|
||||
A: AbilitiesAlgebra[S, Alg],
|
||||
N: NamesAlgebra[S, Alg],
|
||||
L: LocationsAlgebra[S, Alg]
|
||||
): Prog[Alg, Raw] =
|
||||
Prog
|
||||
.after[Alg, Raw] {
|
||||
@ -25,4 +27,6 @@ class TrySem[S[_]](val expr: TryExpr[S]) extends AnyVal {
|
||||
Raw.error("Wrong body of the try expression").pure[Alg]
|
||||
}
|
||||
.abilitiesScope(expr.token)
|
||||
.namesScope(expr.token)
|
||||
.locationsScope()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user