Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/language/ic/checker.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ import map

import lib/language/ic/term

def checkPolarities(): Unit / { Exception[WrongFormat], read[Constructor], emit[Constructor] } = {
def checkPolarities(): Unit / { Exception[WrongFormat], next[Constructor], emit[Constructor] } = {
var map: Map[String, Polarity] = emptyGeneric()

def check(port: Port) = {
map.get(port.name) match {
case Some(Pos()) and port.pol is Neg() => map = map.delete(port.name)
case Some(Neg()) and port.pol is Pos() => map = map.delete(port.name)
case Some(_) => wrongFormat("invalid '${port.pol.show}'-polarity of ${port.name}")
case Some(_) => wrongFormat(s"invalid '${port.pol.show}'-polarity of ${port.name}")
case None() => map = map.put(port.name, port.pol)
}
}

loop {
val ctor = do read()
val ctor = do next()
println(ctor.show)
ctor.pp.check()
ctor.aux.foreach { p => p.check() }
do emit(ctor)
}

if (map.size > 1) wrongFormat("only 1 wire is allowed to be free, but ${map.size.show} are")
if (map.size > 1) wrongFormat(s"only 1 wire is allowed to be free, but ${map.size.show} are")
}

def check!(): Unit / { Exception[WrongFormat], read[Constructor], emit[Constructor] } =
def check!(): Unit / { Exception[WrongFormat], next[Constructor], emit[Constructor] } =
checkPolarities()
2 changes: 1 addition & 1 deletion lib/language/ic/compiler.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import lib/language/ic/parser
import lib/language/ic/checker
import lib/language/ic/uniquifier

def compile!(): Unit / { Exception[WrongFormat], read[Char], emit[Constructor] } =
def compile!(): Unit / { Exception[WrongFormat], next[Char], emit[Constructor] } =
with source[Constructor] { parse!() }
with source[Constructor] { check!() }
uniquify!()
6 changes: 3 additions & 3 deletions lib/language/ic/parser.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def parseS(input: String): List[Constructor] / Exception[WrongFormat] =
}
def fail(msg) = Error(WrongFormat(), msg)
}
with LexerError { (msg, pos) => Error(WrongFormat(), "${pos.show}: ${msg}") }
with LexerError { (msg, pos) => Error(WrongFormat(), s"${pos.show}: ${msg}") }
.value

// TODO: also support parsing rules (emit[Rule])
// "! f-(a-, k+) <> f+(x+, b-) ~> [a-/x-][k-/b-]"
// TODO: we sometimes swallow parsing errors because everything is streamed, is there an easy fix?
def parse!(): Unit / { Exception[WrongFormat], read[Char], emit[Constructor] } = {
parseS(collect { loop { do emit(do read[Char]()) } }).each
def parse!(): Unit / { Exception[WrongFormat], next[Char], emit[Constructor] } = {
parseS(collect { loop { do emit(do next[Char]()) } }).each
}
18 changes: 9 additions & 9 deletions lib/language/ic/ruler.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ val icRules = [
})),
] else [
ManyFinally(LeftBiased(box { (i, ai) =>
val ais = m.list::build { i => Port("${ai.name}_${i.show}", Pos()) }.reverse
val ais = m.list::build { i => Port(s"${ai.name}_${i.show}", Pos()) }.reverse
do constructor(ai, ais, DarkTriangle()) // DUP
}), Symmetric(box { (i, k, f) =>
val ks = m.list::build { i => Port("${k.name}_${i.show}", Neg()) }.reverse
val ks = m.list::build { i => Port(s"${k.name}_${i.show}", Neg()) }.reverse
do constructor(k, ks, DarkTriangle()) // SUP
})),
Many(RightBiased(box { (i, fj) => if (i <= m) {
val k = do left(n - 1)
val ki = Port("${k.name}_${i.show}", Pos())
val ais = (n - 1).list::build { j => Port("${do left(j).name}_${i.show}", Neg()) }
val ki = Port(s"${k.name}_${i.show}", Pos())
val ais = (n - 1).list::build { j => Port(s"${do left(j).name}_${i.show}", Neg()) }
do constructor(fj, ais.append(singleton(ki)), LightTriangle()) // APP
}}))
]
Expand All @@ -107,7 +107,7 @@ val icRules = [
// k-(k1+, ..., km+) <> k+(x1+, ..., xn+, b-) ~> b-(b1+, ..., bm+), x1+(x11-, ..., x1m-), ..., xn+(xn1-, ..., xnm-), // DUP, SUPs
// k1+(x11+, ..., xn1+, b1-), ..., km+(x1m+, ..., xnm+, bm-) // LAMs
// lambda commutation duplicator in LC: DUP-LAM
Rule(DarkTriangle(), LightTriangle(), box { (m, n) =>
Rule(DarkTriangle(), LightTriangle(), box { (m, n) =>
if (m == 0) [
Many(RightBiased(box { (i, xbi) =>
do constructor(xbi, [], DarkTriangle())
Expand All @@ -119,16 +119,16 @@ val icRules = [
})),
] else [
ManyFinally(RightBiased(box { (i, xi) =>
val xis = m.list::build { i => Port("${xi.name}_${i.show}", Neg()) }.reverse
val xis = m.list::build { i => Port(s"${xi.name}_${i.show}", Neg()) }.reverse
do constructor(xi, xis, DarkTriangle()) // DUP
}), Symmetric(box { (i, k, b) =>
val bs = m.list::build { i => Port("${b.name}_${i.show}", Pos()) }.reverse
val bs = m.list::build { i => Port(s"${b.name}_${i.show}", Pos()) }.reverse
do constructor(b, bs, DarkTriangle()) // SUP
})),
Many(LeftBiased(box { (i, ki) => if (i <= m) {
val b = do right(n - 1)
val bi = Port("${b.name}_${i.show}", Neg())
val xis = (n - 1).list::build { j => Port("${do right(j).name}_${i.show}", Pos()) }
val bi = Port(s"${b.name}_${i.show}", Neg())
val xis = (n - 1).list::build { j => Port(s"${do right(j).name}_${i.show}", Pos()) }
do constructor(ki, xis.append(singleton(bi)), LightTriangle())
}}))
]
Expand Down
4 changes: 2 additions & 2 deletions lib/language/ic/uniquifier.effekt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import lib/language/ic/term

// TODO: actually uniquify (not really required though if the user is nice)
def uniquify!(): Unit / { read[Constructor], emit[Constructor] } = {
def uniquify!(): Unit / { next[Constructor], emit[Constructor] } = {
loop {
do emit(do read())
do emit(do next())
}
}
2 changes: 1 addition & 1 deletion lib/language/lc/compiler.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import lib/language/lc/parser
import lib/language/lc/netter
import lib/language/ic/term

def compile!(): Unit / { Exception[WrongFormat], read[Char], emit[Constructor] } =
def compile!(): Unit / { Exception[WrongFormat], next[Char], emit[Constructor] } =
with source[Term] { parse!() }
net!()
6 changes: 3 additions & 3 deletions lib/language/lc/netter.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def plumbing { prog: => Unit / port } = {
}
}

def net!(): Unit / { Exception[WrongFormat], read[Term], emit[Constructor] } = {
def net!(): Unit / { Exception[WrongFormat], next[Term], emit[Constructor] } = {
with plumbing
with loop

val term = do read[Term]()
val term = do next[Term]()
// println("term: '${term.show}'")

def bind(bindings: Map[String, List[Port]], x: String): Label = {
Expand All @@ -33,7 +33,7 @@ def net!(): Unit / { Exception[WrongFormat], read[Term], emit[Constructor] } = {

val duplicity = bound.size
duplicity match {
case 0 =>
case 0 =>
val pk = do port(x ++ "Era")
do emit(Constructor(Port(pk, Neg()), [], DarkTriangle()))
pk
Expand Down
6 changes: 3 additions & 3 deletions lib/language/lc/parser.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def parseS(input: String): List[Term] / Exception[WrongFormat] =
}
def fail(msg) = Error(WrongFormat(), msg)
}
with LexerError { (msg, pos) => Error(WrongFormat(), "${pos.show}: ${msg}") }
with LexerError { (msg, pos) => Error(WrongFormat(), s"${pos.show}: ${msg}") }
.value

def parse!(): Unit / { Exception[WrongFormat], read[Char], emit[Term] } =
parseS(collect { loop { do emit(do read[Char]()) } }).each
def parse!(): Unit / { Exception[WrongFormat], next[Char], emit[Term] } =
parseS(collect { loop { do emit(do next[Char]()) } }).each
2 changes: 1 addition & 1 deletion lib/language/parser.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ effect Parser = { Nondet, Lexer }
def accept { p: Token => Bool } : Token / Parser = {
val got = do next();
if (p(got)) got
else do fail("Unexpected ${got.show} token")
else do fail(s"Unexpected ${got.show} token")
}

def any() = accept { t => true }
Expand Down
2 changes: 1 addition & 1 deletion lib/net/layout.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def coulombForce(agent: Agent) { agents: => Unit / AgentStream }: Vector / Force
with forceSum
with source[Vector] { agentPositions {agents} }
with loop
do emit(repulsion(do read[Vector], agent.pos))
do emit(repulsion(do next[Vector], agent.pos))

def geometry(wire: Wire) { agents: => Unit / AgentStream }: (Vector, Vector) = {
val (from, to) = wire.fromTo {agents}
Expand Down
4 changes: 2 additions & 2 deletions lib/net/netter.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def circularLayout(k: Int): Vector = {
Vector((k.mod(3) + 1).toDouble * scale, (k.mod(3) + 1).toDouble * scale).rotate(k.toDouble)
}

def net!(): Unit / { read[Constructor], NetStream } = {
def net!(): Unit / { next[Constructor], NetStream } = {
var ids: Label = 0
var map: Map[String, Label] = emptyGeneric()

Expand All @@ -31,7 +31,7 @@ def net!(): Unit / { read[Constructor], NetStream } = {
var k = 0

with loop
val ctor = do read()
val ctor = do next()
val pp_ = ctor.pp.uniqueMatch()
val aux_ = ctor.aux.map { p => p.uniqueMatch() }
do emit(Agent(ctor.pp.name, pp_, aux_, ctor.kind, circularLayout(k)))
Expand Down
10 changes: 5 additions & 5 deletions lib/ui/vector.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

record Vector(x: Double, y: Double)

def infixAdd(v1: Vector, v2: Vector) = Vector(v1.x + v2.x, v1.y + v2.y)
def infixSub(v1: Vector, v2: Vector) = Vector(v1.x - v2.x, v1.y - v2.y)
def infixAdd(v: Vector, s: Double) = Vector(v.x + s, v.y + s)
def infixMul(v: Vector, s: Double) = Vector(v.x * s, v.y * s)
def infixDiv(v: Vector, s: Double) = Vector(v.x / s, v.y / s)
def infixPlus(v1: Vector, v2: Vector) = Vector(v1.x + v2.x, v1.y + v2.y)
def infixMinus(v1: Vector, v2: Vector) = Vector(v1.x - v2.x, v1.y - v2.y)
def infixPlus(v: Vector, s: Double) = Vector(v.x + s, v.y + s)
def infixStar(v: Vector, s: Double) = Vector(v.x * s, v.y * s)
def infixSlash(v: Vector, s: Double) = Vector(v.x / s, v.y / s)

def dot(v1: Vector, v2: Vector) = (v1.x * v2.x) + (v1.y * v2.y)
def magnitude(v: Vector) = sqrt(v.dot(v))
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/view.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def run[St, Ev](root: Node, init: St, app: View[St, Ev]) = {
def merge(current: Node, fresh: Node) = {
with on[MissingValue].ignore // can happen on race conditions
dirtyTags.get.toList.sort.reverse.foreach { tag =>
current.querySelector("[data-tag='${tag.show}']").value.replaceWith(
fresh.querySelector("[data-tag='${tag.show}']").value
current.querySelector(s"[data-tag='${tag.show}']").value.replaceWith(
fresh.querySelector(s"[data-tag='${tag.show}']").value
)
}
}
Expand Down
24 changes: 0 additions & 24 deletions lib/utils.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

import test

// println without the ln: only for jsNode, of course
extern def print(s: String) at io: Unit =
jsNode "process.stdout.write(${s})"
jsWeb "console.log(${s})"
default { println(s) }

def size[A] { s: => Unit / emit[A] }: Int = {
var size = 0
try s()
Expand All @@ -25,12 +19,6 @@ def choose[A] { stream: () => Unit / emit[A] }: A / fail =
else resume(())
}

def init[A](l: List[A]): List[A] / Exception[MissingValue] = l match {
case Nil() => do raise(MissingValue(), "Trying to get the beginning of an empty list")
case Cons(a, Nil()) => Nil()
case Cons(a, as) => Cons(a, as.init)
}

def exhaustively[R](init: R) { program: () => R / fail }: R =
var res: R = init
try {
Expand All @@ -42,15 +30,3 @@ def exhaustively[R](init: R) { program: () => R / fail }: R =
} with fail {
res
}

def assertNotThrown[E](ex: on[E]) { body: => Unit / Exception[E] }: Unit / Assertion =
ex.default { do assert(false, "Unexpected Exception") } {body}

def assertNoThrow[E] { body: => Unit / Exception[E] }: Unit / Assertion =
on[E].default{ do assert(false, "Unexpected Exception") } {body}

def assertThrown[E](ex: on[E]) { body: => Unit / Exception[E] }: Unit / Assertion =
do assert(ex.default { true } { body(); false }, "Expected Exception, but exited normally")

def assertThrows[E] { body: => Unit / Exception[E] }: Unit / Assertion =
do assert(on[E].default { true } { body(); false }, "Expected Exception, but exited normally")
Loading