Compare commits
2 commits
ea03dccf53
...
22bf6fdf2c
| Author | SHA1 | Date | |
|---|---|---|---|
| 22bf6fdf2c | |||
| 3aafb36bd3 |
6 changed files with 41 additions and 35 deletions
|
|
@ -11,11 +11,9 @@ defmodule Scopes.CSys.Application do
|
||||||
def start(type, args) do
|
def start(type, args) do
|
||||||
IO.puts("Hello CSys")
|
IO.puts("Hello CSys")
|
||||||
Logger.info(Util.show [type, args])
|
Logger.info(Util.show [type, args])
|
||||||
# input_neurons = Environ.create_input
|
|
||||||
IO.inspect Scopes.CSys.Server.Endpoint.child_spec(input: %{[:csys, :s01] => "dummy"})
|
|
||||||
children = [
|
children = [
|
||||||
#Scopes.CSys.Server.Endpoint
|
Scopes.Core.Environ,
|
||||||
{Scopes.CSys.Server.Endpoint, input: %{[:csys, :s01] => "dummy"}}
|
Scopes.CSys.Server.Endpoint
|
||||||
]
|
]
|
||||||
opts = [strategy: :one_for_one, name: Scopes.CSys.Supervisor]
|
opts = [strategy: :one_for_one, name: Scopes.CSys.Supervisor]
|
||||||
Supervisor.start_link(children, opts)
|
Supervisor.start_link(children, opts)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
defmodule Scopes.CSys.Server.Endpoint do
|
defmodule Scopes.CSys.Server.Endpoint do
|
||||||
use Phoenix.Endpoint, otp_app: :scopes_csys
|
use Phoenix.Endpoint, otp_app: :scopes_csys
|
||||||
|
|
||||||
def init(arg) do
|
|
||||||
IO.inspect(arg)
|
|
||||||
IO.inspect(Process.get())
|
|
||||||
:ignore
|
|
||||||
end
|
|
||||||
|
|
||||||
plug Plug.Static,
|
plug Plug.Static,
|
||||||
at: "/",
|
at: "/",
|
||||||
from: :scopes_csys,
|
from: :scopes_csys,
|
||||||
|
|
@ -22,5 +16,4 @@ defmodule Scopes.CSys.Server.Endpoint do
|
||||||
json_decoder: Phoenix.json_library()
|
json_decoder: Phoenix.json_library()
|
||||||
|
|
||||||
plug Scopes.CSys.Server.Router
|
plug Scopes.CSys.Server.Router
|
||||||
#input_neurons: @input
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ defmodule Scopes.Application do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def start(type, args) do
|
def start(type, args) do
|
||||||
IO.puts("Hello World")
|
IO.puts("Hello Scopes!")
|
||||||
Logger.info(Util.show [type, args])
|
Logger.info(Util.show [type, args])
|
||||||
children = [
|
children = [
|
||||||
#Scopes.Web.Server.Telemetry,
|
#Scopes.Web.Server.Telemetry,
|
||||||
|
|
@ -28,7 +28,7 @@ defmodule Scopes.Application do
|
||||||
|
|
||||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||||
# for other strategies and supported options
|
# for other strategies and supported options
|
||||||
opts = [strategy: :one_for_one, name: ScopesApi.Supervisor]
|
opts = [strategy: :one_for_one, name: Scopes.Supervisor]
|
||||||
Supervisor.start_link(children, opts)
|
Supervisor.start_link(children, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
defmodule Scopes.Core.Environ do
|
defmodule Scopes.Core.Environ do
|
||||||
|
@cell_registry __MODULE__.Cells
|
||||||
|
|
||||||
alias Scopes.Core
|
alias Scopes.Core
|
||||||
alias Scopes.Core.Shape
|
alias Scopes.Core.Shape
|
||||||
|
|
@ -7,6 +8,17 @@ defmodule Scopes.Core.Environ do
|
||||||
defstruct [cells: %{}, init_seq: []]
|
defstruct [cells: %{}, init_seq: []]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def child_spec(opts) do
|
||||||
|
%{id: __MODULE__,
|
||||||
|
start: {__MODULE__, :start_link, opts}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_link() do
|
||||||
|
Registry.start_link(keys: :unique, name: @cell_registry)
|
||||||
|
end
|
||||||
|
|
||||||
|
def cells(), do: @cell_registry
|
||||||
|
|
||||||
def setup({state, proc}, init_seq, proc_env \\ &proc_env/2) do
|
def setup({state, proc}, init_seq, proc_env \\ &proc_env/2) do
|
||||||
env_scope = {%State{init_seq: init_seq}, proc_env, [], self()}
|
env_scope = {%State{init_seq: init_seq}, proc_env, [], self()}
|
||||||
env = Core.neuron(env_scope)
|
env = Core.neuron(env_scope)
|
||||||
|
|
@ -30,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
|
||||||
|
|
@ -129,33 +140,22 @@ defmodule Scopes.Core.Program do
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ defmodule Scopes.CoreTest do
|
||||||
|
|
||||||
describe "core-basic:" do
|
describe "core-basic:" do
|
||||||
test "minimal-b1" do
|
test "minimal-b1" do
|
||||||
|
Environ.start_link()
|
||||||
env = Environ.setup(Program.prepare_basic(), Program.init_seq_b1())
|
env = Environ.setup(Program.prepare_basic(), Program.init_seq_b1())
|
||||||
Process.sleep(50)
|
Process.sleep(50)
|
||||||
Environ.forward_value(env, [:csys, :c00, "0-0"], 0)
|
Environ.forward_value(env, [:csys, :c00, "0-0"], 0)
|
||||||
|
|
@ -31,6 +32,7 @@ defmodule Scopes.CoreTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "recursive-1" do
|
test "recursive-1" do
|
||||||
|
Environ.start_link()
|
||||||
env = Environ.setup(Program.prepare_basic(), Program.init_recursive_1())
|
env = Environ.setup(Program.prepare_basic(), Program.init_recursive_1())
|
||||||
Process.sleep(50)
|
Process.sleep(50)
|
||||||
Environ.forward_value(env, [:csys, :s01, "1-1"], 42)
|
Environ.forward_value(env, [:csys, :s01, "1-1"], 42)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue