put scope in process dictionary => simplify procs

This commit is contained in:
Helmut Merz 2026-04-27 15:14:24 +02:00
parent 2a64fcb1cf
commit 7a52e75868
2 changed files with 19 additions and 11 deletions

View file

@ -19,7 +19,8 @@ defmodule Scopes.CSys do
# helper functions # helper functions
defp process(msg, scope) do defp process(msg, scope) do
proc(scope).(msg, scope) Process.put(:scope, scope)
proc(scope).(msg)
end end
def state(scope), do: elem(scope, 0) def state(scope), do: elem(scope, 0)

View file

@ -9,28 +9,34 @@ defmodule Scopes.CSys.Program do
# programs # programs
def basic_prog() do def basic_prog() do
%{initial: &std_proc/2, %{initial: &std_proc/1,
active: &std_proc/2, active: &std_proc/1,
retired: &std_proc/2 retired: &std_proc/1
} }
end end
# processors # processors
def std_proc({:parent}, scope) do #def std_proc({:parent}, scope) do
new = create_parent(env(scope)) def std_proc(msg) do
scope = Process.get(:scope)
case msg do
{:parent} ->
new = create_parent(scope)
notify({:created, new}, scope) notify({:created, new}, scope)
_ -> forward(msg, scope) || notify(msg, scope)
end
end end
#def std_proc({:activate}, {state, _proc, syns, env) do #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_next_stage(env, :basic, :initial)
#proc = Environ.get_stage_for(env, :basic, :activate) #proc = Environ.get_stage_for(env, :basic, :activate)
proc = Environ.get_stage(env, :basic, :active) proc = Environ.get_stage(env, :basic, :active)
update_neuron({state, proc, syns, env}) update_neuron({state, proc, syns, env})
end end
def std_proc(msg, scope) do def xx_std_proc(msg, scope) do
forward(msg, scope) || notify(msg, scope) forward(msg, scope) || notify(msg, scope)
end end
@ -46,8 +52,9 @@ defmodule Scopes.CSys.Program do
# step functions # step functions
def create_parent(env) do def create_parent({_state, procs, _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})
neuron({[], procs, [syn], env})
end end
end end