diff --git a/lib/language/ic/checker.effekt b/lib/language/ic/checker.effekt index eb12d8f..59da999 100644 --- a/lib/language/ic/checker.effekt +++ b/lib/language/ic/checker.effekt @@ -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() \ No newline at end of file diff --git a/lib/language/ic/compiler.effekt b/lib/language/ic/compiler.effekt index 2c5de4e..82c90cb 100644 --- a/lib/language/ic/compiler.effekt +++ b/lib/language/ic/compiler.effekt @@ -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!() \ No newline at end of file diff --git a/lib/language/ic/parser.effekt b/lib/language/ic/parser.effekt index a3e9568..30889a9 100644 --- a/lib/language/ic/parser.effekt +++ b/lib/language/ic/parser.effekt @@ -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 } \ No newline at end of file diff --git a/lib/language/ic/ruler.effekt b/lib/language/ic/ruler.effekt index 09efe6a..0542cd5 100644 --- a/lib/language/ic/ruler.effekt +++ b/lib/language/ic/ruler.effekt @@ -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 }})) ] @@ -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()) @@ -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()) }})) ] diff --git a/lib/language/ic/uniquifier.effekt b/lib/language/ic/uniquifier.effekt index 2a6b9fd..4e455ed 100644 --- a/lib/language/ic/uniquifier.effekt +++ b/lib/language/ic/uniquifier.effekt @@ -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()) } } \ No newline at end of file diff --git a/lib/language/lc/compiler.effekt b/lib/language/lc/compiler.effekt index 2db4506..a99bbd7 100644 --- a/lib/language/lc/compiler.effekt +++ b/lib/language/lc/compiler.effekt @@ -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!() \ No newline at end of file diff --git a/lib/language/lc/netter.effekt b/lib/language/lc/netter.effekt index 4e4b41c..2c30916 100644 --- a/lib/language/lc/netter.effekt +++ b/lib/language/lc/netter.effekt @@ -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 = { @@ -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 diff --git a/lib/language/lc/parser.effekt b/lib/language/lc/parser.effekt index 49a1dc2..dcdbd40 100644 --- a/lib/language/lc/parser.effekt +++ b/lib/language/lc/parser.effekt @@ -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 \ No newline at end of file +def parse!(): Unit / { Exception[WrongFormat], next[Char], emit[Term] } = + parseS(collect { loop { do emit(do next[Char]()) } }).each \ No newline at end of file diff --git a/lib/language/parser.effekt b/lib/language/parser.effekt index 2d363ac..44dbd34 100644 --- a/lib/language/parser.effekt +++ b/lib/language/parser.effekt @@ -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 } diff --git a/lib/net/layout.effekt b/lib/net/layout.effekt index f1f2a5c..75741e1 100644 --- a/lib/net/layout.effekt +++ b/lib/net/layout.effekt @@ -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} diff --git a/lib/net/netter.effekt b/lib/net/netter.effekt index bd2c92e..4fdfb30 100644 --- a/lib/net/netter.effekt +++ b/lib/net/netter.effekt @@ -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() @@ -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))) diff --git a/lib/ui/vector.effekt b/lib/ui/vector.effekt index 7738786..e2f2447 100644 --- a/lib/ui/vector.effekt +++ b/lib/ui/vector.effekt @@ -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)) diff --git a/lib/ui/view.effekt b/lib/ui/view.effekt index 2364f47..688fc11 100644 --- a/lib/ui/view.effekt +++ b/lib/ui/view.effekt @@ -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 ) } } diff --git a/lib/utils.effekt b/lib/utils.effekt index 65c2179..57231b7 100644 --- a/lib/utils.effekt +++ b/lib/utils.effekt @@ -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() @@ -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 { @@ -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")