shape: initial set-up; csys: standardized message format with head and info parts
This commit is contained in:
parent
2fa57ee8fb
commit
f9e6d664d5
5 changed files with 30 additions and 9 deletions
|
|
@ -19,7 +19,6 @@ defmodule Scopes.CSys do
|
||||||
# helper functions
|
# helper functions
|
||||||
|
|
||||||
defp process(msg, scope) do
|
defp process(msg, scope) do
|
||||||
#Process.put(:scope, scope)
|
|
||||||
proc(scope).(msg, scope)
|
proc(scope).(msg, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,17 @@ defmodule Scopes.CSys.Program do
|
||||||
|
|
||||||
# processors
|
# processors
|
||||||
|
|
||||||
def basic_active(msg, scope) do
|
def basic_active({head, _info}, scope) do
|
||||||
#scope = Process.get(:scope)
|
case head do
|
||||||
case msg do
|
|
||||||
[:csys, :create, :parent | _rest] -> create_parent(scope)
|
[:csys, :create, :parent | _rest] -> create_parent(scope)
|
||||||
[:csys, :create, :child | _rest] -> create_child(scope)
|
[:csys, :create, :child | _rest] -> create_child(scope)
|
||||||
_ -> forward(msg, scope) || notify(msg, scope)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def basic_active(msg, scope) do
|
||||||
|
forward(msg, scope) || notify(msg, scope)
|
||||||
|
end
|
||||||
|
|
||||||
# processor steps
|
# processor steps
|
||||||
|
|
||||||
def notify(msg, scope) do
|
def notify(msg, scope) do
|
||||||
|
|
@ -43,14 +45,14 @@ defmodule Scopes.CSys.Program do
|
||||||
# todo: provide parameters for initial state, proc / stage, op,
|
# todo: provide parameters for initial state, proc / stage, op,
|
||||||
# depending on state and stage (proc) of self, as well as message, env, ...
|
# depending on state and stage (proc) of self, as well as message, env, ...
|
||||||
|
|
||||||
def create_parent(scope={_state, proc, _syns, env}) do
|
def create_parent(scope = {_state, proc, _syns, env}) do
|
||||||
syn = synapse(self(), &Function.identity/1, 0)
|
syn = synapse(self(), &Function.identity/1, 0)
|
||||||
#neuron({[], Environ.get_stage(env, :basic, :initial), [syn], env})
|
#neuron({[], Environ.get_stage(env, :basic, :initial), [syn], env})
|
||||||
new = neuron({[], proc, [syn], env})
|
new = neuron({[], proc, [syn], env})
|
||||||
notify({:created, new}, scope)
|
notify({:created, new}, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_child (scope={state, proc, syns, env}) do
|
def create_child (scope = {state, proc, syns, env}) do
|
||||||
new = neuron({[], proc, [], env})
|
new = neuron({[], proc, [], env})
|
||||||
syn = synapse(new, &Function.identity/1, 0)
|
syn = synapse(new, &Function.identity/1, 0)
|
||||||
update_neuron({state, proc, [syn | syns], env})
|
update_neuron({state, proc, [syn | syns], env})
|
||||||
|
|
|
||||||
5
lib/shape/shape.ex
Normal file
5
lib/shape/shape.ex
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
defmodule Scopes.Shape do
|
||||||
|
def create(head, info \\ []) do
|
||||||
|
{head, info}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -14,10 +14,12 @@ defmodule Scopes.CSysTest do
|
||||||
proc = Environ.get_stage(env, :basic, :initial)
|
proc = Environ.get_stage(env, :basic, :initial)
|
||||||
zero = CSys.neuron({[], proc, [], env})
|
zero = CSys.neuron({[], proc, [], env})
|
||||||
Actor.send(zero, "Hello Zero!")
|
Actor.send(zero, "Hello Zero!")
|
||||||
|
# msg = Message.create([:csys, :data], data: %{value: "Hello Zero!"})
|
||||||
|
# Actor.send(zero, msg)
|
||||||
assert_receive "Hello Zero!"
|
assert_receive "Hello Zero!"
|
||||||
Actor.send(zero, [:csys, :create, :parent])
|
Actor.send(zero, {[:csys, :create, :parent], nil})
|
||||||
assert_receive {:created, new1}
|
assert_receive {:created, new1}
|
||||||
Actor.send(new1, [:csys, :create, :child])
|
Actor.send(new1, {[:csys, :create, :child], nil})
|
||||||
assert_receive {:created, _new2}
|
assert_receive {:created, _new2}
|
||||||
Actor.send(new1, "Hello New1!")
|
Actor.send(new1, "Hello New1!")
|
||||||
assert_receive "Hello New1!"
|
assert_receive "Hello New1!"
|
||||||
|
|
|
||||||
13
test/shape_test.exs
Normal file
13
test/shape_test.exs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
defmodule Scopes.ShapeTest do
|
||||||
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
|
alias Scopes.Shape
|
||||||
|
|
||||||
|
describe "shape:" do
|
||||||
|
test "basic" do
|
||||||
|
obj = Shape.create([:dom, :data], data: %{value: 42})
|
||||||
|
{_head, info} = obj
|
||||||
|
assert 42 = info[:data].value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Reference in a new issue