-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lukasrieger/develop
Develop
- Loading branch information
Showing
9 changed files
with
212 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
package alpha: | ||
|
||
trait Term[E, V <: E]: | ||
this: E => | ||
|
||
def free: Set[V] | ||
def rename(re: Map[V, V]): E | ||
def subst(su: Map[V, E]): E | ||
|
||
def subst(v: V, e: E): E = subst(Map(v -> e)) | ||
|
||
|
||
trait X[E, V <: E] extends Term[E, V]: | ||
this: V => | ||
|
||
def fresh(index: Int): V | ||
def free: Set[V] = Set(this) | ||
def rename(re: Map[V, V]): V = re.getOrElse(this, this) | ||
def subst(su: Map[V, E]): E = su.getOrElse(this, this) | ||
|
||
|
||
|
||
trait Alpha[E <: alpha.Term[E, V], V <: E with alpha.X[E, V]]: | ||
context => | ||
|
||
type Term = alpha.Term[E, V] | ||
type X = alpha.X[E, V] | ||
|
||
trait Bind[A]: | ||
def bound: Set[V] | ||
def rename(a: Map[V, V], re: Map[V, V]): A | ||
def subst(a: Map[V, V], su: Map[V, E]): A | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Expr.Var | ||
|
||
enum Expr: | ||
case Var(name: String, index: Option[Int] = None) | ||
|
||
|
||
|
||
given exprShow: Show[Expr] with | ||
override def show(value: Expr): String = value match | ||
case Var(name, index) => s"$name$$$index" | ||
|
||
given [Sub <: Expr] (using s: Show[Expr]) : Show[Sub] with | ||
override def show(value: Sub): String = s.show(value) | ||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import Expression.Var | ||
import Expr.Var | ||
|
||
enum Program: | ||
case Assign(x: Var, expr: Expression) | ||
case Load(x: Expression, pointer: Expression) | ||
case Store(pointer: Expression, arg: Expression) | ||
case Alloc(pointer: Expression) | ||
case Free(pointer: Expression) | ||
case Assign(x: Var, expr: Expr) | ||
case Load(x: Expr, pointer: Expr) | ||
case Store(pointer: Expr, arg: Expr) | ||
case Alloc(pointer: Expr) | ||
case Free(pointer: Expr) | ||
case Block(programs: List[Program]) | ||
case If(test: Expression, left: Program, right: Program) | ||
case While(test: Expression, inv: Assert, body: Program) | ||
case If(test: Expr, left: Program, right: Program) | ||
case While(test: Expr, inv: Assert, body: Program) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
trait Show[A]: | ||
def show(value: A): String | ||
|
||
|
||
extension [A: Show] (value: A) | ||
def show: String = summon[Show[A]].show(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import Expression.Var | ||
import Expr.Var | ||
import Program.Free | ||
|
||
@main | ||
def main(): Unit = { | ||
val test = dsl { | ||
Var("a") |-> Var("b") | ||
(Var("a") |-> Var("b")) ~~> (Var("c") |-> Var("d")) | ||
|
||
Free(Var("a")) `;` Free(Var("a")) | ||
|
||
(Var("a") |-> Var("b")) ~~> (Var("c") |-> Var("d")) ** (Var("e") |-> Var("f")) | ||
} | ||
|
||
println(Var("test").show) | ||
println(test) | ||
} |