Compare commits
2 commits
7dd2b1e137
...
8b590695bb
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b590695bb | |||
| cdff646437 |
3 changed files with 28 additions and 12 deletions
|
|
@ -20,7 +20,7 @@ defmodule Scopes.CSys.Program do
|
|||
end
|
||||
|
||||
def get_proc(state) do
|
||||
get_proc(elem(state.prog, 0), state.stage)
|
||||
get_proc(state.prog, state.stage)
|
||||
end
|
||||
|
||||
defp get_proc(stages, stage) do
|
||||
|
|
@ -31,18 +31,11 @@ defmodule Scopes.CSys.Program do
|
|||
|
||||
def basic_prog(args) do
|
||||
default = basic_active(args)
|
||||
stages = %{
|
||||
default: default,
|
||||
%{default: default,
|
||||
initial: basic_initial(args),
|
||||
active: default,
|
||||
retired: default
|
||||
}
|
||||
transitions = %{
|
||||
restart: :initial,
|
||||
retire: :retired,
|
||||
next: [initial: :active, active: :retired]
|
||||
}
|
||||
{stages, transitions}
|
||||
end
|
||||
|
||||
def prepare_basic(args \\ []) do
|
||||
|
|
@ -67,8 +60,7 @@ defmodule Scopes.CSys.Program do
|
|||
[:csys, :connect | _rest] -> CSys.connect(msg, scope)
|
||||
[:csys, :create, :succ | _rest] -> create_succ(msg, scope)
|
||||
[:csys, :create, :pred | _rest] -> create_pred(msg, scope)
|
||||
#[:csys, :next | _rest] -> next(scope, meta)
|
||||
#[:csys, action | rest] -> transition(action, scope)
|
||||
#[:csys, :next | _rest] -> next(msg, scope)
|
||||
_ -> CSys.forward(msg, scope) || CSys.notify(msg, scope)
|
||||
end
|
||||
end
|
||||
|
|
@ -82,7 +74,7 @@ defmodule Scopes.CSys.Program do
|
|||
limit = args[:limit]
|
||||
data = Shape.data(msg)
|
||||
state = CSys.state(scope)
|
||||
Logger.info data: data, state_value: state.value, threshold: threshold
|
||||
Logger.info data: data, state_value: state.value, threshold: threshold, self: self()
|
||||
value_n = state.value + data.value
|
||||
if value_n >= threshold do
|
||||
value_out = limit && rem(value_n - 1, limit) + limit || value_n
|
||||
|
|
|
|||
9
lib/util.ex
Normal file
9
lib/util.ex
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
defmodule Scopes.Util do
|
||||
|
||||
defmacro fields_info(fields) do
|
||||
names = for {f, _, _} <- fields do f end
|
||||
quote do
|
||||
Enum.zip(unquote(names), unquote(fields))
|
||||
end
|
||||
end
|
||||
end
|
||||
15
test/util_test.exs
Normal file
15
test/util_test.exs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
defmodule Scopes.UtilTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Scopes.Util
|
||||
require Scopes.Util
|
||||
|
||||
describe "info:" do
|
||||
test "fields" do
|
||||
a = 17
|
||||
b = 22
|
||||
c = 42
|
||||
assert [a: 17, b: 22, c: 42] = Util.fields_info([a, b, c])
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue