Skip to content

Commit ba71877

Browse files
committed
Store compiled IC in sources
1 parent 50e7369 commit ba71877

4 files changed

Lines changed: 29 additions & 19 deletions

File tree

app/model.effekt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import lib/net/net
66
import lib/ui/model
77
import lib/ui/dirty
88
import lib/ui/vector
9+
import lib/language/ic/term
910
import lib/language/ic/parser
1011
import lib/language/ic/compiler
1112
import lib/language/lc/compiler
1213

13-
import lib/language/ic/term
14-
15-
type Mode { SourceLanguage(); LambdaCalculus(); InteractionCalculus() }
14+
// TODO: add SourceLanguage
15+
type Mode { LambdaCalculus(); InteractionCalculus() }
1616

1717
type TextStream = => Unit / emit[Char] at {global}
1818
record EvaluatorState[N](mode: Mode, sources: Map[Mode, TextStream], net: N, errors: String)
@@ -41,18 +41,15 @@ interface Model[C, O] {
4141
}
4242

4343
def show(m: Mode) = m match {
44-
case SourceLanguage() => "Source Language"
4544
case LambdaCalculus() => "Lambda Calculus"
4645
case InteractionCalculus() => "Interaction Calculus"
4746
}
4847

4948
def empty[N, C, O](): EvaluatorState[N] / NetModel[N, C, O] = {
5049
var map = map::emptyGeneric[Mode, TextStream]()
5150
val emptyStream: => Unit / emit[Char] at {global} = box{}
52-
map = map.put(SourceLanguage(), emptyStream)
5351
map = map.put(LambdaCalculus(), emptyStream)
5452
map = map.put(InteractionCalculus(), emptyStream)
55-
// EvaluatorState(InteractionCalculus(), map, do empty(), "")
5653
EvaluatorState(LambdaCalculus(), map, do empty(), "")
5754
}
5855

@@ -67,9 +64,8 @@ def report[E, N](proxy: on[E], rollback: EvaluatorState[N]) { prog: => Evaluator
6764
def nextMode[N](state: EvaluatorState[N]): EvaluatorState[N] / Redraw = {
6865
do redrawFull()
6966
state match {
70-
case EvaluatorState(SourceLanguage(), sources, net, errors) => EvaluatorState(LambdaCalculus(), sources, net, errors)
7167
case EvaluatorState(LambdaCalculus(), sources, net, errors) => EvaluatorState(InteractionCalculus(), sources, net, errors)
72-
case EvaluatorState(InteractionCalculus(), sources, net, errors) => EvaluatorState(SourceLanguage(), sources, net, errors)
68+
case EvaluatorState(InteractionCalculus(), sources, net, errors) => EvaluatorState(LambdaCalculus(), sources, net, errors)
7369
}
7470
}
7571

@@ -99,10 +95,11 @@ def render[N, C, O](state: EvaluatorState[N]): EvaluatorState[N] / { NetModel[N,
9995
EvaluatorState(InteractionCalculus(), sources, net_, "")
10096
}
10197
case EvaluatorState(LambdaCalculus(), sources, net, errors) => {
102-
val net_ = do render(do load(net) { lc::compile!() })
103-
EvaluatorState(LambdaCalculus(), sources, net_, "")
98+
val prog: Program = collect { lc::compile!() } // reify for storing in IC source
99+
val sources_ = sources.put(InteractionCalculus(), box { prog.show.each })
100+
val net_ = do render(do load(net) { prog() })
101+
EvaluatorState(LambdaCalculus(), sources_, net_, "")
104102
}
105-
case _ => <>
106103
}
107104
}
108105

@@ -111,12 +108,12 @@ def model[C, O, R, N] { prog: => R / Model[C, O] }: R / { State[EvaluatorState[N
111108

112109
try { prog() }
113110
with Model[C, O] {
114-
def render() = resume { modifyState { st => st.render } }
111+
def render() = resume { modifyState { st => st.render } }
115112
def stepReduction() = resume { modifyState { net => do step(net) } }
116113
def stepAnimation() = resume { modifyState { net => do render(net) } }
117-
def nextMode() = resume { modifyState { st => st.nextMode } }
118-
def setSource(c) = resume { modifyState { st => st.setSource(c) } }
119-
def onContext(op) = resume { modifyState { net => do operation(net, op) } }
114+
def nextMode() = resume { modifyState { st => st.nextMode } }
115+
def setSource(c) = resume { modifyState { st => st.setSource(c) } }
116+
def onContext(op) = resume { modifyState { net => do operation(net, op) } }
120117

121118
def getMode() = resume((do getState()).mode)
122119
def getSource(mode) = {

lib/language/ic/term.effekt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ def show(port: Port) = port.name ++ port.pol.show()
2727
def show(ctor: Constructor) = {
2828
val pp = ctor.pp.show()
2929
val aux = ctor.aux.map { p => p.show() }.join(", ")
30-
"${pp}(${aux})"
30+
ctor.kind match {
31+
case LightTriangle() => "${pp}(${aux})"
32+
case DarkTriangle() => "${pp}[${aux}]"
33+
}
34+
}
35+
36+
def show(prog: Program) = {
37+
var res = ""
38+
try prog()
39+
with emit[Constructor] { ctor =>
40+
res = "${res}${ctor.show}\n"
41+
resume(())
42+
}
43+
res
3144
}
3245

3346
def arity(ctor: Constructor) = ctor.aux.size

lib/net/layout.effekt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def geometry(wire: Wire) { agents: => Unit / AgentStream }: (Vector, Vector) = {
1919
(from, from.direction(to))
2020
}
2121

22-
def springTargets(wire: Wire, agent: Agent, length: Double) { agents: => Unit / AgentStream }: Unit / emit[Vector] = {
22+
def springTarget(wire: Wire, agent: Agent, length: Double) { agents: => Unit / AgentStream }: Unit / emit[Vector] = {
2323
val (pos, direction) = wire.geometry {agents}
2424
do emit((pos + direction.normalize) * length)
2525
}
@@ -29,9 +29,9 @@ def wireForce(agent: Agent, length: Double) { agents: => Unit / AgentStream } {
2929
do emit(forceSum {
3030
for {
3131
for { agent.adverseAgents(wire) {agents} } { a =>
32-
wire.flip.springTargets(a, length) {agents} }
32+
wire.flip.springTarget(a, length) {agents} }
3333
} { adverseTarget =>
34-
for { wire.springTargets(agent, length) {agents} } { agentTarget =>
34+
for { wire.springTarget(agent, length) {agents} } { agentTarget =>
3535
do emit(agentTarget.attraction(adverseTarget))
3636
}
3737
}

lib/net/reducer.effekt

Whitespace-only changes.

0 commit comments

Comments
 (0)