diff --git a/lib/csys/program.ex b/lib/csys/program.ex index 0f1d75c..9b3d6d2 100644 --- a/lib/csys/program.ex +++ b/lib/csys/program.ex @@ -21,9 +21,8 @@ defmodule Scopes.CSys.Program do def std_proc(msg, scope) do #scope = Process.get(:scope) case msg do - {:parent} -> - new = create_parent(scope) - notify({:created, new}, scope) + {:create, :parent} -> create_parent(scope) + {:create, :child} -> create_child(scope) _ -> forward(msg, scope) || notify(msg, scope) end end @@ -48,9 +47,21 @@ defmodule Scopes.CSys.Program do # step functions - def create_parent({_state, proc, _syns, env}) do +# create_... steps +# todo: provide parameters for initial state, proc / stage, op, +# depending on state and stage (proc) of self, as well as message, env, ... + + def create_parent(scope={_state, proc, _syns, env}) do syn = synapse(self(), &Function.identity/1, 0) #neuron({[], Environ.get_stage(env, :basic, :initial), [syn], env}) - neuron({[], proc, [syn], env}) + new = neuron({[], proc, [syn], env}) + notify({:created, new}, scope) + end + + def create_child (scope={state, proc, syns, env}) do + new = neuron({[], proc, [], env}) + syn = synapse(new, &Function.identity/1, 0) + update_neuron({state, proc, [syn | syns], env}) + notify({:created, new}, scope) end end diff --git a/test/csys_test.exs b/test/csys_test.exs index bb67d35..3f69575 100644 --- a/test/csys_test.exs +++ b/test/csys_test.exs @@ -15,11 +15,13 @@ defmodule Scopes.CSysTest do zero = CSys.neuron({[], proc, [], env}) Actor.send(zero, "Hello Zero!") assert_receive "Hello Zero!" - Actor.send(zero, {:parent}) - assert_receive {:created, new} - Actor.send(new, "Hello New!") - assert_receive "Hello New!" - # assert_receive "Hello New!" + Actor.send(zero, {:create, :parent}) + assert_receive {:created, new1} + Actor.send(new1, {:create, :child}) + assert_receive {:created, _new2} + Actor.send(new1, "Hello New1!") + assert_receive "Hello New1!" + assert_receive "Hello New1!" Process.sleep(50) # Actor.stop(zero) refute_received msg, "unhandled message(s): #{inspect(msg)}"