diff --git a/ovo/lib/ovo/registry.ex b/ovo/lib/ovo/registry.ex
index 50e1ee3..693613a 100644
--- a/ovo/lib/ovo/registry.ex
+++ b/ovo/lib/ovo/registry.ex
@@ -21,6 +21,10 @@ defmodule Ovo.Registry do
)
end
+ def stop do
+ Agent.stop(__MODULE__)
+ end
+
defp view_runner(hash, %{metadata: metadata, stack: stack}) do
%{
stack: stack,
@@ -56,9 +60,10 @@ defmodule Ovo.Registry do
end)
end
- def register_runner(pid, hash, metadata \\ %{}) do
+ def wrap_registration(ast, code, name, hash, args) do
Agent.update(__MODULE__, fn state ->
- state |> Map.put(hash, %{runner: pid, stack: [], last_env: %{}, metadata: metadata})
+ {:ok, pid} = Ovo.Runner.start_link(%Ovo.Runner{ast: ast, code: code, name: name, hash: hash})
+ state |> Map.put(hash, %{runner: pid, stack: [], last_env: %{}, metadata: %{code: code, name: name, args: args}})
end)
end
diff --git a/ovo/lib/ovo/runner.ex b/ovo/lib/ovo/runner.ex
index 653099a..77ab02d 100644
--- a/ovo/lib/ovo/runner.ex
+++ b/ovo/lib/ovo/runner.ex
@@ -23,15 +23,9 @@ defmodule Ovo.Runner do
hash = :crypto.hash(:md5, normalized_form) |> Base.encode64() |> String.slice(0..4)
Logger.info("Registered program with code #{code} at hash #{hash}")
- case Ovo.Registry.find_runner(hash) do
- {:ok, _pid} ->
- {:ok, hash}
-
- {:error, _} ->
- case Ovo.Runner.instantiate(ast, code, name, hash, args) do
- {:error, _reason} = e -> e
- {:ok, _pid} -> {:ok, hash}
- end
+ case Ovo.Runner.instantiate(ast, code, name, hash, args) do
+ {:error, _reason} = e -> e
+ :ok -> {:ok, hash}
end
end
@@ -63,8 +57,7 @@ defmodule Ovo.Runner do
@spec instantiate(Ovo.Ast.t(), binary(), binary(), binary(), integer()) :: {:ok, pid()}
def instantiate(ast, code, name, hash, args) do
- {:ok, pid} = start_link(%__MODULE__{ast: ast, code: code, name: name, hash: hash})
- Ovo.Registry.register_runner(pid, hash, %{code: code, name: name, args: args})
- {:ok, pid}
+ Ovo.Registry.wrap_registration(ast, code, name, hash, args)
+ :ok
end
end
diff --git a/ovo/test/ovo_shake_test.exs b/ovo/test/ovo_shake_test.exs
index 8af9531..30e9ae2 100644
--- a/ovo/test/ovo_shake_test.exs
+++ b/ovo/test/ovo_shake_test.exs
@@ -12,11 +12,9 @@ defmodule OvoTestRecursiveShakenSpecialCase do
end
fibs(5)
-
- add(shake(fibs), shake(fibs))
"""
- assert {%Ovo.Ast{kind: :integer, nodes: [], value: 11}, _} = Ovo.run(code)
+ assert {%Ovo.Ast{kind: :integer, nodes: [], value: 8}, _} = Ovo.run(code)
end
test "another shake test" do
diff --git a/ovo_playground/lib/ovo_playground.ex b/ovo_playground/lib/ovo_playground.ex
index 347612f..ee6625a 100644
--- a/ovo_playground/lib/ovo_playground.ex
+++ b/ovo_playground/lib/ovo_playground.ex
@@ -22,10 +22,7 @@ defmodule OvoPlayground do
end
def setup_bottles do
- register_bottles_example
- end
-
- def register_bob_examples do
+ register_bottles_example()
end
@doc """
@@ -145,15 +142,25 @@ defmodule OvoPlayground do
end
end
- def register_alice_tricks do
- Ovo.Registry.remove_runner("Sj2py")
+ def register_bob_examples do
+ hash_with_alice = """
+ invoke(`Sj2py@alice`, [arg(0)])
+ """
+ for {code, name, args} <- [
+ {hash_with_alice, "hash by Alice", [{:secret, "\"the quick brown fox\""}]}
+ ] do
+ Ovo.Runner.register(code, name, args)
+ end
+ end
+
+ def register_alice_tricks do
# hashes to yfHDp
logger = """
arg(0)
"""
- totally_legitimate_hash_function_nothing_to_see_here = """
+ hash_function = """
len = length(arg(0))
~~ = \\a ->
overflow(a)
@@ -182,8 +189,7 @@ defmodule OvoPlayground do
for {code, name, args} <- [
{logger, "logger", [{:text, "100"}]},
- {totally_legitimate_hash_function_nothing_to_see_here, "hash",
- [{:secret, "\"the quick brown fox\""}]}
+ {hash_function, "hash", [{:secret, "\"the quick brown fox\""}]}
] do
Ovo.Runner.register(code, name, args)
end
diff --git a/ovo_playground/lib/ovo_playground/transforms.ex b/ovo_playground/lib/ovo_playground/transforms.ex
index 6fcad3c..7b47e4c 100644
--- a/ovo_playground/lib/ovo_playground/transforms.ex
+++ b/ovo_playground/lib/ovo_playground/transforms.ex
@@ -19,11 +19,6 @@ defmodule OvoPlayground.Transforms do
end
end
- defp list([a]), do: [a]
- defp list(a), do: [a]
- defp nodes(%Ovo.Ast{nodes: nodes}), do: nodes
- defp concat(a, b), do: list(a) ++ list(b)
-
def maybe_rewrap({:ok, %Ovo.Ast{} = ast, []}, fun) do
{:ok, fun.(ast), []}
end
@@ -36,17 +31,17 @@ defmodule OvoPlayground.Transforms do
Ast.root(nodes)
end
- def default() do
+ def default do
Ovo.tokenize(@default_code) |> Ovo.parse()
end
- def default_assignment() do
+ def default_assignment do
produce("foo = 5")
end
def push_node(arg, node) do
maybe_rewrap(arg, fn a ->
- %Ovo.Ast{a | nodes: concat(nodes(a), node)}
+ %Ovo.Ast{a | nodes: (a.nodes ++ node)}
end)
end
end
diff --git a/ovo_playground/lib/ovo_playground_web/components/layouts/app.html.heex b/ovo_playground/lib/ovo_playground_web/components/layouts/app.html.heex
index f5b4665..90789bb 100644
--- a/ovo_playground/lib/ovo_playground_web/components/layouts/app.html.heex
+++ b/ovo_playground/lib/ovo_playground_web/components/layouts/app.html.heex
@@ -4,8 +4,8 @@
- <.live_title suffix=" · Phoenix Framework">
- <%= assigns[:page_title] || "OvoPlayground" %>
+ <.live_title suffix="">
+ <%= System.get_env("NAME", "foo") %> - OvoPlayground