Iterate over groups with the new MARK AS step
parent
229aa645c9
commit
786fd450be
|
@ -30,8 +30,7 @@ defmodule FarmbotCeleryScript.Compiler.Sequence do
|
||||||
def compile_sequence_iterable(
|
def compile_sequence_iterable(
|
||||||
iterable_ast,
|
iterable_ast,
|
||||||
%{
|
%{
|
||||||
args:
|
args: %{locals: %{body: _} = locals} = sequence_args,
|
||||||
%{ locals: %{ body: _ } = locals } = sequence_args,
|
|
||||||
meta: sequence_meta
|
meta: sequence_meta
|
||||||
} = sequence_ast,
|
} = sequence_ast,
|
||||||
env
|
env
|
||||||
|
@ -114,9 +113,11 @@ defmodule FarmbotCeleryScript.Compiler.Sequence do
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_better_params(body, env) do
|
def create_better_params(body, env) do
|
||||||
parameter_declarations = Enum.reduce(env, %{}, fn
|
parameter_declarations =
|
||||||
|
Enum.reduce(env, %{}, fn
|
||||||
{key, value}, map ->
|
{key, value}, map ->
|
||||||
encoded_label = "#{key}"
|
encoded_label = "#{key}"
|
||||||
|
|
||||||
if String.starts_with?(encoded_label, "unsafe_") do
|
if String.starts_with?(encoded_label, "unsafe_") do
|
||||||
Map.put(map, IdentifierSanitizer.to_string(encoded_label), value)
|
Map.put(map, IdentifierSanitizer.to_string(encoded_label), value)
|
||||||
else
|
else
|
||||||
|
@ -126,13 +127,18 @@ defmodule FarmbotCeleryScript.Compiler.Sequence do
|
||||||
|
|
||||||
Enum.reduce(body, parameter_declarations, fn ast, map ->
|
Enum.reduce(body, parameter_declarations, fn ast, map ->
|
||||||
case ast do
|
case ast do
|
||||||
|
%{kind: :parameter_application} ->
|
||||||
|
args = Map.fetch!(ast, :args)
|
||||||
|
label = Map.fetch!(args, :label)
|
||||||
|
Map.put(map, label, Map.fetch!(args, :data_value))
|
||||||
|
|
||||||
%{kind: :variable_declaration} ->
|
%{kind: :variable_declaration} ->
|
||||||
args = Map.fetch!(ast, :args)
|
args = Map.fetch!(ast, :args)
|
||||||
label = Map.fetch!(args, :label)
|
label = Map.fetch!(args, :label)
|
||||||
Map.put(map, label, Map.fetch!(args, :data_value))
|
Map.put(map, label, Map.fetch!(args, :data_value))
|
||||||
|
|
||||||
%{kind: :parameter_declaration} -> map
|
%{kind: :parameter_declaration} ->
|
||||||
_ -> raise "How do I compile this? #{inspect(ast)}"
|
map
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule FarmbotCeleryScript.Compiler.UpdateResource do
|
defmodule FarmbotCeleryScript.Compiler.UpdateResource do
|
||||||
alias FarmbotCeleryScript.{ AST, DotProps}
|
alias FarmbotCeleryScript.{AST, DotProps}
|
||||||
|
|
||||||
def update_resource(%AST{args: args, body: body}, _env) do
|
def update_resource(%AST{args: args, body: body}, _env) do
|
||||||
quote location: :keep do
|
quote location: :keep do
|
||||||
|
@ -13,11 +13,15 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
|
||||||
label = Map.fetch!(args, :label)
|
label = Map.fetch!(args, :label)
|
||||||
resource = Map.fetch!(better_params, label)
|
resource = Map.fetch!(better_params, label)
|
||||||
me.do_update(resource, update)
|
me.do_update(resource, update)
|
||||||
|
|
||||||
%AST{kind: :point} ->
|
%AST{kind: :point} ->
|
||||||
me.do_update(variable.args, update)
|
me.do_update(variable.args, update)
|
||||||
|
|
||||||
%AST{kind: :resource} ->
|
%AST{kind: :resource} ->
|
||||||
me.do_update(variable.args, update)
|
me.do_update(variable.args, update)
|
||||||
res -> raise "Resource error. Please notfiy support: #{inspect(res)}"
|
|
||||||
|
res ->
|
||||||
|
raise "Resource error. Please notfiy support: #{inspect(res)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,9 +35,10 @@ defmodule FarmbotOS.SysCalls.ResourceUpdate do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def point_update_resource(type, id, params) do
|
def point_update_resource(type, id, params) do
|
||||||
with %{} = point <- Asset.get_point(pointer_type: type, id: id),
|
with %{} = point <- Asset.get_point(id: id),
|
||||||
{:ok, point} <- Asset.update_point(point, params) do
|
{:ok, point} <- Asset.update_point(point, params) do
|
||||||
_ = Private.mark_dirty!(point)
|
_ = Private.mark_dirty!(point)
|
||||||
|
IO.puts("Updated point #{id}: #{inspect(params)}")
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
nil ->
|
nil ->
|
||||||
|
|
Loading…
Reference in New Issue