core.program: provide new generic :create action; clean up init seq
This commit is contained in:
parent
3aafb36bd3
commit
22bf6fdf2c
2 changed files with 23 additions and 22 deletions
|
|
@ -42,6 +42,7 @@ defmodule Scopes.Core.Environ do
|
||||||
addr = data[:addr]
|
addr = data[:addr]
|
||||||
cells = if addr do
|
cells = if addr do
|
||||||
[dom, cat, item] = addr
|
[dom, cat, item] = addr
|
||||||
|
# update (or create and register) proxy cell
|
||||||
Map.update(state.cells, {dom, cat}, %{item => new},
|
Map.update(state.cells, {dom, cat}, %{item => new},
|
||||||
fn x -> Map.put(x, item, new) end)
|
fn x -> Map.put(x, item, new) end)
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ defmodule Scopes.Core.Program do
|
||||||
[:csys, :connect | _rest] -> Core.connect(msg, scope)
|
[:csys, :connect | _rest] -> Core.connect(msg, scope)
|
||||||
[:csys, :create, :succ | _rest] -> create_succ(msg, scope)
|
[:csys, :create, :succ | _rest] -> create_succ(msg, scope)
|
||||||
[:csys, :create, :pred | _rest] -> create_pred(msg, scope)
|
[:csys, :create, :pred | _rest] -> create_pred(msg, scope)
|
||||||
|
[:csys, :create | _rest] -> create(msg, scope)
|
||||||
#[:csys, :next | _rest] -> next(msg, scope)
|
#[:csys, :next | _rest] -> next(msg, scope)
|
||||||
_ -> Core.forward(msg, scope) || Core.notify(msg, scope)
|
_ -> Core.forward(msg, scope) || Core.notify(msg, scope)
|
||||||
end
|
end
|
||||||
|
|
@ -103,6 +104,16 @@ defmodule Scopes.Core.Program do
|
||||||
Core.send_message(new, ~w(csys connect)a, Map.put(data, :target, self()))
|
Core.send_message(new, ~w(csys connect)a, Map.put(data, :target, self()))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create(msg, scope) do
|
||||||
|
new = Core.create(msg, restart(scope))
|
||||||
|
data = Shape.data(msg)
|
||||||
|
case data[:dir] do
|
||||||
|
:succ -> Core.send_message(self(), ~w(csys connect)a, Map.put(data, :target, new))
|
||||||
|
:pred -> Core.send_message(new, ~w(csys connect)a, Map.put(data, :target, self()))
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# synapse operations
|
# synapse operations
|
||||||
|
|
||||||
def multiply(n) do
|
def multiply(n) do
|
||||||
|
|
@ -128,34 +139,23 @@ defmodule Scopes.Core.Program do
|
||||||
one = [:csys, :s01, "1-0"]
|
one = [:csys, :s01, "1-0"]
|
||||||
two = [:csys, :c00, "1-1"]
|
two = [:csys, :c00, "1-1"]
|
||||||
three = [:csys, :s01, "1-1"]
|
three = [:csys, :s01, "1-1"]
|
||||||
[
|
[
|
||||||
fn state ->
|
&Environ.send_message(&1, zero, ~w(csys create pred)a,
|
||||||
Environ.send_message(state, zero, ~w(csys create pred)a,
|
%{op: [Core.data_only(), negate()], addr: one}),
|
||||||
%{op: [Core.data_only(), negate()], addr: one})
|
&Environ.send_message(&1, one, ~w(csys create succ)a,
|
||||||
end,
|
%{op: Core.data_only(), addr: two}),
|
||||||
fn state ->
|
&Environ.send_message(&1, two, ~w(csys create pred)a, %{addr: three}),
|
||||||
Environ.send_message(state, one, ~w(csys create succ)a,
|
&Environ.connect(&1, three, zero)
|
||||||
%{op: Core.data_only(), addr: two})
|
|
||||||
end,
|
|
||||||
fn state ->
|
|
||||||
Environ.send_message(state, two, ~w(csys create pred)a, %{addr: three})
|
|
||||||
end,
|
|
||||||
fn state -> Environ.connect(state, three, zero) end
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_recursive_1() do
|
def init_recursive_1() do
|
||||||
zero = [:csys, :c00, "0-0"]
|
zero = [:csys, :c00, "0-0"]
|
||||||
[
|
[
|
||||||
fn state ->
|
&Environ.send_message(&1, zero, ~w(csys create succ)a, %{}),
|
||||||
Environ.connect(state, zero, zero, negate())
|
&Environ.send_message(&1, zero, ~w(csys create pred)a,
|
||||||
Environ.send_message(state, zero, ~w(csys create succ)a,
|
%{addr: [:csys, :s01, "1-1"]}),
|
||||||
%{addr: [:csys, :e01, "1-1"]})
|
&Environ.connect(&1, zero, zero, negate())
|
||||||
end,
|
|
||||||
fn state ->
|
|
||||||
Environ.send_message(state, zero, ~w(csys create pred)a,
|
|
||||||
%{addr: [:csys, :s01, "1-1"]})
|
|
||||||
end
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue