From f9e6d664d5483b258564250ce3b4d69694c0d594 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Thu, 7 May 2026 18:51:03 +0200 Subject: [PATCH] shape: initial set-up; csys: standardized message format with head and info parts --- lib/csys/csys.ex | 1 - lib/csys/program.ex | 14 ++++++++------ lib/shape/shape.ex | 5 +++++ test/csys_test.exs | 6 ++++-- test/shape_test.exs | 13 +++++++++++++ 5 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 lib/shape/shape.ex create mode 100644 test/shape_test.exs diff --git a/lib/csys/csys.ex b/lib/csys/csys.ex index 4ecbcce..d6ed946 100644 --- a/lib/csys/csys.ex +++ b/lib/csys/csys.ex @@ -19,7 +19,6 @@ defmodule Scopes.CSys do # helper functions defp process(msg, scope) do - #Process.put(:scope, scope) proc(scope).(msg, scope) end diff --git a/lib/csys/program.ex b/lib/csys/program.ex index f016dae..04ceab6 100644 --- a/lib/csys/program.ex +++ b/lib/csys/program.ex @@ -18,15 +18,17 @@ defmodule Scopes.CSys.Program do # processors - def basic_active(msg, scope) do - #scope = Process.get(:scope) - case msg do + def basic_active({head, _info}, scope) do + case head do [:csys, :create, :parent | _rest] -> create_parent(scope) [:csys, :create, :child | _rest] -> create_child(scope) - _ -> forward(msg, scope) || notify(msg, scope) end end + def basic_active(msg, scope) do + forward(msg, scope) || notify(msg, scope) + end + # processor steps def notify(msg, scope) do @@ -43,14 +45,14 @@ defmodule Scopes.CSys.Program do # 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 + 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}) new = neuron({[], proc, [syn], env}) notify({:created, new}, scope) end - def create_child (scope={state, proc, syns, env}) do + 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}) diff --git a/lib/shape/shape.ex b/lib/shape/shape.ex new file mode 100644 index 0000000..d9150f9 --- /dev/null +++ b/lib/shape/shape.ex @@ -0,0 +1,5 @@ +defmodule Scopes.Shape do + def create(head, info \\ []) do + {head, info} + end +end diff --git a/test/csys_test.exs b/test/csys_test.exs index e4ad866..58d4f7a 100644 --- a/test/csys_test.exs +++ b/test/csys_test.exs @@ -14,10 +14,12 @@ defmodule Scopes.CSysTest do proc = Environ.get_stage(env, :basic, :initial) zero = CSys.neuron({[], proc, [], env}) Actor.send(zero, "Hello Zero!") + # msg = Message.create([:csys, :data], data: %{value: "Hello Zero!"}) + # Actor.send(zero, msg) assert_receive "Hello Zero!" - Actor.send(zero, [:csys, :create, :parent]) + Actor.send(zero, {[:csys, :create, :parent], nil}) assert_receive {:created, new1} - Actor.send(new1, [:csys, :create, :child]) + Actor.send(new1, {[:csys, :create, :child], nil}) assert_receive {:created, _new2} Actor.send(new1, "Hello New1!") assert_receive "Hello New1!" diff --git a/test/shape_test.exs b/test/shape_test.exs new file mode 100644 index 0000000..8a977d2 --- /dev/null +++ b/test/shape_test.exs @@ -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