diff --git a/lib/core/core.ex b/lib/core/core.ex index b8fdf66..60a13da 100644 --- a/lib/core/core.ex +++ b/lib/core/core.ex @@ -1,10 +1,10 @@ -defmodule Scopes.CSys do +defmodule Scopes.Core do require Logger - require Scopes.Util + require Scopes.Core.Util alias Scopes.Core.Actor - alias Scopes.Shape - alias Scopes.Util + alias Scopes.Core.Shape + alias Scopes.Core.Util def neuron(scope) do #Logger.info(Util.show [scope]) diff --git a/lib/core/environ.ex b/lib/core/environ.ex index bf51dbb..ad8696c 100644 --- a/lib/core/environ.ex +++ b/lib/core/environ.ex @@ -1,7 +1,7 @@ -defmodule Scopes.CSys.Environ do +defmodule Scopes.Core.Environ do - alias Scopes.CSys - alias Scopes.Shape + alias Scopes.Core + alias Scopes.Core.Shape defmodule State do 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 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}]}) proc = {state, proc, [], env} - CSys.create(msg, proc) + Core.create(msg, proc) env end @@ -37,7 +37,7 @@ defmodule Scopes.CSys.Environ do end {step, seq} = List.pop_at(state.init_seq, 0) state1 = %State{cells: cells, init_seq: seq} - CSys.update({state1, proc, syns, env}) + Core.update({state1, proc, syns, env}) if step do step.(state1) end @@ -51,7 +51,7 @@ defmodule Scopes.CSys.Environ do def send_message(state, addr, head, data) do cell = get_cell(state, addr) - CSys.send_message(cell, head, data) + Core.send_message(cell, head, data) end def connect(state, addr, target, op \\ []) do @@ -62,7 +62,7 @@ defmodule Scopes.CSys.Environ do # delegating tasks to env def delegate(env, func) do - CSys.send_message(env, {:exec, func}) + Core.send_message(env, {:exec, func}) end def forward_value(env, addr, value) do diff --git a/lib/core/program.ex b/lib/core/program.ex index a144cc7..1fe4014 100644 --- a/lib/core/program.ex +++ b/lib/core/program.ex @@ -1,11 +1,11 @@ -defmodule Scopes.CSys.Program do +defmodule Scopes.Core.Program do require Logger - require Scopes.Util + require Scopes.Core.Util - alias Scopes.CSys - alias Scopes.CSys.Environ - alias Scopes.Shape - alias Scopes.Util + alias Scopes.Core + alias Scopes.Core.Environ + alias Scopes.Core.Shape + alias Scopes.Core.Util defmodule State do defstruct [:value, :count, :stage, :prog] @@ -59,11 +59,11 @@ defmodule Scopes.CSys.Program do case Shape.head(msg) do [:csys, :data | _rest] -> process_basic(msg, scope, args) #[: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, :pred | _rest] -> create_pred(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 @@ -75,32 +75,32 @@ defmodule Scopes.CSys.Program do bias = args[:bias] || 0 limit = args[:limit] data = Shape.data(msg) - state = CSys.state(scope) + state = Core.state(scope) Logger.debug(Util.show [data, state.value, threshold]) value_n = state.value + data.value if value_n >= threshold do value_out = limit && rem(value_n - 1, limit) + limit || value_n value_next = limit && max(value_n - limit, bias) || bias 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} - CSys.update(put_elem(scope, 0, state_n)) + Core.update(put_elem(scope, 0, state_n)) else state_n = %{state | value: value_n} - CSys.update(put_elem(scope, 0, state_n)) + Core.update(put_elem(scope, 0, state_n)) end end def create_succ(msg, scope) do - new = CSys.create(msg, restart(scope)) + new = Core.create(msg, restart(scope)) 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 def create_pred(msg, scope) do - new = CSys.create(msg, restart(scope)) + new = Core.create(msg, restart(scope)) 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 # synapse operations @@ -131,11 +131,11 @@ defmodule Scopes.CSys.Program do [ fn state -> 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, fn state -> Environ.send_message(state, one, ~w(csys create succ)a, - %{op: CSys.data_only(), addr: two}) + %{op: Core.data_only(), addr: two}) end, fn state -> Environ.send_message(state, two, ~w(csys create pred)a, %{addr: three}) diff --git a/lib/core/shape.ex b/lib/core/shape.ex index 8ac8149..2fd8b0f 100644 --- a/lib/core/shape.ex +++ b/lib/core/shape.ex @@ -1,4 +1,4 @@ -defmodule Scopes.Shape do +defmodule Scopes.Core.Shape do def create(head, info \\ []) do {head, info} end diff --git a/lib/core/util.ex b/lib/core/util.ex index a21a1a9..520b631 100644 --- a/lib/core/util.ex +++ b/lib/core/util.ex @@ -1,4 +1,4 @@ -defmodule Scopes.Util do +defmodule Scopes.Core.Util do defmacro show(fields) do names = for f <- fields do Macro.to_string(f) end quote bind_quoted: [names: names, fields: fields] do diff --git a/test/core/core_test.exs b/test/core/core_test.exs index 4508f4e..183882b 100644 --- a/test/core/core_test.exs +++ b/test/core/core_test.exs @@ -2,9 +2,9 @@ defmodule Scopes.CoreTest do use ExUnit.Case, async: false @moduletag timeout: 5000 - alias Scopes.CSys.Environ - alias Scopes.CSys.Program - alias Scopes.Shape + alias Scopes.Core.Environ + alias Scopes.Core.Program + alias Scopes.Core.Shape def receive_select(head) do assert_receive {^head, info}, 100 diff --git a/test/core/shape_test.exs b/test/core/shape_test.exs index acd12f2..584d47d 100644 --- a/test/core/shape_test.exs +++ b/test/core/shape_test.exs @@ -1,7 +1,7 @@ defmodule Scopes.CoreShapeTest do use ExUnit.Case, async: true - alias Scopes.Shape + alias Scopes.Core.Shape describe "shape:" do test "basic" do diff --git a/test/core/util_test.exs b/test/core/util_test.exs index b90d3d5..74a1645 100644 --- a/test/core/util_test.exs +++ b/test/core/util_test.exs @@ -1,8 +1,8 @@ defmodule Scopes.CoreUtilTest do use ExUnit.Case, async: true - alias Scopes.Util - require Scopes.Util + alias Scopes.Core.Util + require Scopes.Core.Util describe "info:" do test "fields" do