put scope in process dictionary => simplify procs
This commit is contained in:
parent
2a64fcb1cf
commit
7a52e75868
2 changed files with 19 additions and 11 deletions
|
|
@ -19,7 +19,8 @@ defmodule Scopes.CSys do
|
|||
# helper functions
|
||||
|
||||
defp process(msg, scope) do
|
||||
proc(scope).(msg, scope)
|
||||
Process.put(:scope, scope)
|
||||
proc(scope).(msg)
|
||||
end
|
||||
|
||||
def state(scope), do: elem(scope, 0)
|
||||
|
|
|
|||
|
|
@ -9,28 +9,34 @@ defmodule Scopes.CSys.Program do
|
|||
# programs
|
||||
|
||||
def basic_prog() do
|
||||
%{initial: &std_proc/2,
|
||||
active: &std_proc/2,
|
||||
retired: &std_proc/2
|
||||
%{initial: &std_proc/1,
|
||||
active: &std_proc/1,
|
||||
retired: &std_proc/1
|
||||
}
|
||||
end
|
||||
|
||||
# processors
|
||||
|
||||
def std_proc({:parent}, scope) do
|
||||
new = create_parent(env(scope))
|
||||
notify({:created, new}, scope)
|
||||
#def std_proc({:parent}, scope) do
|
||||
def std_proc(msg) do
|
||||
scope = Process.get(:scope)
|
||||
case msg do
|
||||
{:parent} ->
|
||||
new = create_parent(scope)
|
||||
notify({:created, new}, scope)
|
||||
_ -> forward(msg, scope) || notify(msg, scope)
|
||||
end
|
||||
end
|
||||
|
||||
#def std_proc({:activate}, {state, _proc, syns, env) do
|
||||
def std_proc({:next}, {state, _proc, syns, env}) do
|
||||
def xx_std_proc({:next}, {state, _proc, syns, env}) do
|
||||
#proc = Environ.get_next_stage(env, :basic, :initial)
|
||||
#proc = Environ.get_stage_for(env, :basic, :activate)
|
||||
proc = Environ.get_stage(env, :basic, :active)
|
||||
update_neuron({state, proc, syns, env})
|
||||
end
|
||||
|
||||
def std_proc(msg, scope) do
|
||||
def xx_std_proc(msg, scope) do
|
||||
forward(msg, scope) || notify(msg, scope)
|
||||
end
|
||||
|
||||
|
|
@ -46,8 +52,9 @@ defmodule Scopes.CSys.Program do
|
|||
|
||||
# step functions
|
||||
|
||||
def create_parent(env) do
|
||||
def create_parent({_state, procs, _syns, env}) do
|
||||
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})
|
||||
neuron({[], procs, [syn], env})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue