Skip to content

Commit

Permalink
A few presentation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucassifoni committed Apr 14, 2024
1 parent 814487c commit 624d541
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
5 changes: 4 additions & 1 deletion ovo/lib/ovo/builtins.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ defmodule Ovo.Builtins do
[%{kind: :string, value: v}, %{kind: :string, value: v2}] ->
Ovo.Ast.string("#{v}#{v2}")

[%{kind: :list, nodes: n1}, %{kind: :list, nodes: n2}] ->
Ovo.Ast.list(n1 ++ n2)

_ ->
:error
end
Expand All @@ -155,7 +158,7 @@ defmodule Ovo.Builtins do
end
end

defp get_host do
def get_host do
case "#{Node.self()}" |> String.split("@") do
[_, b] -> b
_ -> "nohost"
Expand Down
15 changes: 12 additions & 3 deletions ovo/lib/ovo/interpreter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ defmodule Ovo.Interpreter do
{env, v} = evaluate(rewritten, env)

user_env = Env.get_user_env(env)

stop_env(evaluator_pid)

{v, user_env}
Expand All @@ -73,7 +74,7 @@ defmodule Ovo.Interpreter do
def evaluate(nodes, env) when is_list(nodes), do: reduce_nodes(nodes, env)

def evaluate(%Ovo.Ast{} = ast, env) do
case ast.kind do
res = case ast.kind do
:root ->
evaluate(ast.nodes, env)

Expand Down Expand Up @@ -108,7 +109,8 @@ defmodule Ovo.Interpreter do

Agent.update(env, fn state ->
shake_stack = Map.get(state.shakes, key, [])
put_in(state, [:shakes, key], [res | shake_stack])
out = put_in(state, [:shakes, key], [res | shake_stack])
out
end)

res
Expand All @@ -118,7 +120,7 @@ defmodule Ovo.Interpreter do

:lambda ->
arity = length(ast.value)
program = ast.nodes
program = Ovo.Rewrites.rw(ast.nodes)
user_bindings = Env.user_bindings(env)

{env,
Expand Down Expand Up @@ -197,5 +199,12 @@ defmodule Ovo.Interpreter do
_ ->
{env, ast}
end

case res do
{_, :error} ->
throw [ast, env]
_ ->
res
end
end
end
28 changes: 8 additions & 20 deletions ovo/lib/ovo/rewrites.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ defmodule Ovo.Rewrites do
nodes: %Ovo.Ast{
kind: :call,
nodes: [
maparg0,
%Ovo.Ast{
kind: :lambda,
nodes: %Ovo.Ast{
Expand Down Expand Up @@ -76,7 +75,11 @@ defmodule Ovo.Rewrites do
%Ovo.Ast{
kind: :condition,
nodes: [
%Ovo.Ast{kind: :symbol, nodes: [], value: "mapped"},
%Ovo.Ast{
kind: :call,
nodes: [%Ovo.Ast{kind: :symbol, nodes: [], value: "mapped"}],
value: %Ovo.Ast{kind: :symbol, nodes: [], value: "filter_fn"}
},
%Ovo.Ast{
kind: :block,
nodes: [
Expand Down Expand Up @@ -120,7 +123,9 @@ defmodule Ovo.Rewrites do
%Ovo.Ast{kind: :symbol, nodes: [], value: "acc"},
%Ovo.Ast{kind: :symbol, nodes: [], value: "i"}
]
}
},
maparg0,
%Ovo.Ast{kind: :list, nodes: [], value: nil}
],
value: %Ovo.Ast{kind: :symbol, nodes: [], value: "reduce"}
}
Expand All @@ -138,21 +143,4 @@ defmodule Ovo.Rewrites do
def rewrite(%Ast{kind: k, value: v, nodes: nodes}) do
%Ast{kind: k, value: rw(v), nodes: rw(nodes)}
end

def sample() do
"""
foo = reduce(list, \\acc, i ->
map_fn = \\a -> 5 end
filter_fn = \\b -> T end
mapped = map_fn(i)
if mapped then
concat(acc, [mapped])
else
acc
end
end)
"""
|> Ovo.Tokenizer.tokenize()
|> Ovo.Parser.parse()
end
end
2 changes: 1 addition & 1 deletion ovo/test/ovo_shake_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule OvoTestRecursiveShakenSpecialCase do
test "fishakenacci" do
code = """
fibs = !\\a ->
if greater_or_equals(a, 2) then
if a >= 2 then
add(fibs(subtract(a, 1)), fibs(subtract(a, 2)))
else
1
Expand Down
2 changes: 1 addition & 1 deletion ovo_playground/lib/ovo_playground.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ defmodule OvoPlayground do
"""

for {code, name, args} <- [
{legitimate_hash, "hash function", [{:secret, "the quick brown fox"}]}
{legitimate_hash, "hash function", [{:text, "\"the quick brown fox\""}]}
] do
Ovo.Runner.register(code, name, args)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/>
<% {:secret, a} -> %>
<input
type="text"
type="password"
id={"runner-#{runner.hash}-arg-#{index}"}
phx-hook="change_runner_arg"
data-hash={runner.hash}
Expand Down

0 comments on commit 624d541

Please sign in to comment.