renames and rearrangements: get rid of CSys, move core stuff to Core
This commit is contained in:
parent
b34fb9cfa8
commit
611b20b3b3
8 changed files with 38 additions and 38 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
defmodule Scopes.CSys do
|
defmodule Scopes.Core do
|
||||||
require Logger
|
require Logger
|
||||||
require Scopes.Util
|
require Scopes.Core.Util
|
||||||
|
|
||||||
alias Scopes.Core.Actor
|
alias Scopes.Core.Actor
|
||||||
alias Scopes.Shape
|
alias Scopes.Core.Shape
|
||||||
alias Scopes.Util
|
alias Scopes.Core.Util
|
||||||
|
|
||||||
def neuron(scope) do
|
def neuron(scope) do
|
||||||
#Logger.info(Util.show [scope])
|
#Logger.info(Util.show [scope])
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule Scopes.CSys.Environ do
|
defmodule Scopes.Core.Environ do
|
||||||
|
|
||||||
alias Scopes.CSys
|
alias Scopes.Core
|
||||||
alias Scopes.Shape
|
alias Scopes.Core.Shape
|
||||||
|
|
||||||
defmodule State do
|
defmodule State do
|
||||||
defstruct [cells: %{}, init_seq: []]
|
defstruct [cells: %{}, init_seq: []]
|
||||||
|
|
@ -9,10 +9,10 @@ defmodule Scopes.CSys.Environ do
|
||||||
|
|
||||||
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 = CSys.neuron(env_scope)
|
env = Core.neuron(env_scope)
|
||||||
msg = Shape.create([:csys, :zero], data: %{addr: [:csys, :c00, {0, 0}]})
|
msg = Shape.create([:csys, :zero], data: %{addr: [:csys, :c00, {0, 0}]})
|
||||||
proc = {state, proc, [], env}
|
proc = {state, proc, [], env}
|
||||||
CSys.create(msg, proc)
|
Core.create(msg, proc)
|
||||||
env
|
env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ defmodule Scopes.CSys.Environ do
|
||||||
end
|
end
|
||||||
{step, seq} = List.pop_at(state.init_seq, 0)
|
{step, seq} = List.pop_at(state.init_seq, 0)
|
||||||
state1 = %State{cells: cells, init_seq: seq}
|
state1 = %State{cells: cells, init_seq: seq}
|
||||||
CSys.update({state1, proc, syns, env})
|
Core.update({state1, proc, syns, env})
|
||||||
if step do
|
if step do
|
||||||
step.(state1)
|
step.(state1)
|
||||||
end
|
end
|
||||||
|
|
@ -51,7 +51,7 @@ defmodule Scopes.CSys.Environ do
|
||||||
|
|
||||||
def send_message(state, addr, head, data) do
|
def send_message(state, addr, head, data) do
|
||||||
cell = get_cell(state, addr)
|
cell = get_cell(state, addr)
|
||||||
CSys.send_message(cell, head, data)
|
Core.send_message(cell, head, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect(state, addr, target, op \\ []) do
|
def connect(state, addr, target, op \\ []) do
|
||||||
|
|
@ -62,7 +62,7 @@ defmodule Scopes.CSys.Environ do
|
||||||
# delegating tasks to env
|
# delegating tasks to env
|
||||||
|
|
||||||
def delegate(env, func) do
|
def delegate(env, func) do
|
||||||
CSys.send_message(env, {:exec, func})
|
Core.send_message(env, {:exec, func})
|
||||||
end
|
end
|
||||||
|
|
||||||
def forward_value(env, addr, value) do
|
def forward_value(env, addr, value) do
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
defmodule Scopes.CSys.Program do
|
defmodule Scopes.Core.Program do
|
||||||
require Logger
|
require Logger
|
||||||
require Scopes.Util
|
require Scopes.Core.Util
|
||||||
|
|
||||||
alias Scopes.CSys
|
alias Scopes.Core
|
||||||
alias Scopes.CSys.Environ
|
alias Scopes.Core.Environ
|
||||||
alias Scopes.Shape
|
alias Scopes.Core.Shape
|
||||||
alias Scopes.Util
|
alias Scopes.Core.Util
|
||||||
|
|
||||||
defmodule State do
|
defmodule State do
|
||||||
defstruct [:value, :count, :stage, :prog]
|
defstruct [:value, :count, :stage, :prog]
|
||||||
|
|
@ -59,11 +59,11 @@ defmodule Scopes.CSys.Program do
|
||||||
case Shape.head(msg) do
|
case Shape.head(msg) do
|
||||||
[:csys, :data | _rest] -> process_basic(msg, scope, args)
|
[:csys, :data | _rest] -> process_basic(msg, scope, args)
|
||||||
#[:csys, :trigger | _rest] -> process_trigger(msg, scope)
|
#[:csys, :trigger | _rest] -> process_trigger(msg, scope)
|
||||||
[:csys, :connect | _rest] -> CSys.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, :next | _rest] -> next(msg, scope)
|
#[:csys, :next | _rest] -> next(msg, scope)
|
||||||
_ -> CSys.forward(msg, scope) || CSys.notify(msg, scope)
|
_ -> Core.forward(msg, scope) || Core.notify(msg, scope)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -75,32 +75,32 @@ defmodule Scopes.CSys.Program do
|
||||||
bias = args[:bias] || 0
|
bias = args[:bias] || 0
|
||||||
limit = args[:limit]
|
limit = args[:limit]
|
||||||
data = Shape.data(msg)
|
data = Shape.data(msg)
|
||||||
state = CSys.state(scope)
|
state = Core.state(scope)
|
||||||
Logger.debug(Util.show [data, state.value, threshold])
|
Logger.debug(Util.show [data, state.value, threshold])
|
||||||
value_n = state.value + data.value
|
value_n = state.value + data.value
|
||||||
if value_n >= threshold do
|
if value_n >= threshold do
|
||||||
value_out = limit && rem(value_n - 1, limit) + limit || value_n
|
value_out = limit && rem(value_n - 1, limit) + limit || value_n
|
||||||
value_next = limit && max(value_n - limit, bias) || bias
|
value_next = limit && max(value_n - limit, bias) || bias
|
||||||
msg = Shape.create(Shape.head(msg), data: %{data | value: value_out})
|
msg = Shape.create(Shape.head(msg), data: %{data | value: value_out})
|
||||||
CSys.forward(msg, scope) || CSys.notify(msg, scope)
|
Core.forward(msg, scope) || Core.notify(msg, scope)
|
||||||
state_n = %{state | value: value_next}
|
state_n = %{state | value: value_next}
|
||||||
CSys.update(put_elem(scope, 0, state_n))
|
Core.update(put_elem(scope, 0, state_n))
|
||||||
else
|
else
|
||||||
state_n = %{state | value: value_n}
|
state_n = %{state | value: value_n}
|
||||||
CSys.update(put_elem(scope, 0, state_n))
|
Core.update(put_elem(scope, 0, state_n))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_succ(msg, scope) do
|
def create_succ(msg, scope) do
|
||||||
new = CSys.create(msg, restart(scope))
|
new = Core.create(msg, restart(scope))
|
||||||
data = Shape.data(msg)
|
data = Shape.data(msg)
|
||||||
CSys.send_message(self(), ~w(csys connect)a, Map.put(data, :target, new))
|
Core.send_message(self(), ~w(csys connect)a, Map.put(data, :target, new))
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_pred(msg, scope) do
|
def create_pred(msg, scope) do
|
||||||
new = CSys.create(msg, restart(scope))
|
new = Core.create(msg, restart(scope))
|
||||||
data = Shape.data(msg)
|
data = Shape.data(msg)
|
||||||
CSys.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
|
||||||
|
|
||||||
# synapse operations
|
# synapse operations
|
||||||
|
|
@ -131,11 +131,11 @@ defmodule Scopes.CSys.Program do
|
||||||
[
|
[
|
||||||
fn state ->
|
fn state ->
|
||||||
Environ.send_message(state, zero, ~w(csys create pred)a,
|
Environ.send_message(state, zero, ~w(csys create pred)a,
|
||||||
%{op: [CSys.data_only(), negate()], addr: one})
|
%{op: [Core.data_only(), negate()], addr: one})
|
||||||
end,
|
end,
|
||||||
fn state ->
|
fn state ->
|
||||||
Environ.send_message(state, one, ~w(csys create succ)a,
|
Environ.send_message(state, one, ~w(csys create succ)a,
|
||||||
%{op: CSys.data_only(), addr: two})
|
%{op: Core.data_only(), addr: two})
|
||||||
end,
|
end,
|
||||||
fn state ->
|
fn state ->
|
||||||
Environ.send_message(state, two, ~w(csys create pred)a, %{addr: three})
|
Environ.send_message(state, two, ~w(csys create pred)a, %{addr: three})
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Scopes.Shape do
|
defmodule Scopes.Core.Shape do
|
||||||
def create(head, info \\ []) do
|
def create(head, info \\ []) do
|
||||||
{head, info}
|
{head, info}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Scopes.Util do
|
defmodule Scopes.Core.Util do
|
||||||
defmacro show(fields) do
|
defmacro show(fields) do
|
||||||
names = for f <- fields do Macro.to_string(f) end
|
names = for f <- fields do Macro.to_string(f) end
|
||||||
quote bind_quoted: [names: names, fields: fields] do
|
quote bind_quoted: [names: names, fields: fields] do
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ defmodule Scopes.CoreTest do
|
||||||
use ExUnit.Case, async: false
|
use ExUnit.Case, async: false
|
||||||
@moduletag timeout: 5000
|
@moduletag timeout: 5000
|
||||||
|
|
||||||
alias Scopes.CSys.Environ
|
alias Scopes.Core.Environ
|
||||||
alias Scopes.CSys.Program
|
alias Scopes.Core.Program
|
||||||
alias Scopes.Shape
|
alias Scopes.Core.Shape
|
||||||
|
|
||||||
def receive_select(head) do
|
def receive_select(head) do
|
||||||
assert_receive {^head, info}, 100
|
assert_receive {^head, info}, 100
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule Scopes.CoreShapeTest do
|
defmodule Scopes.CoreShapeTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
alias Scopes.Shape
|
alias Scopes.Core.Shape
|
||||||
|
|
||||||
describe "shape:" do
|
describe "shape:" do
|
||||||
test "basic" do
|
test "basic" do
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
defmodule Scopes.CoreUtilTest do
|
defmodule Scopes.CoreUtilTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
alias Scopes.Util
|
alias Scopes.Core.Util
|
||||||
require Scopes.Util
|
require Scopes.Core.Util
|
||||||
|
|
||||||
describe "info:" do
|
describe "info:" do
|
||||||
test "fields" do
|
test "fields" do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue