From 539f19c3603bba7b150097e0b03243b3e3aeb6ed Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 30 Apr 2020 14:07:21 -0500 Subject: [PATCH] Add `reource_type` and `resource_id` to point lookup (required for variable MARK AS) --- .../lib/farmbot_celery_script/compiler.ex | 5 +++-- .../lib/farmbot_os/sys_calls/point_lookup.ex | 14 ++++++++++++-- .../test/farmbot_os/syscalls/point_lookup_test.exs | 6 ++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/farmbot_celery_script/lib/farmbot_celery_script/compiler.ex b/farmbot_celery_script/lib/farmbot_celery_script/compiler.ex index 08d1714f..c72576d1 100644 --- a/farmbot_celery_script/lib/farmbot_celery_script/compiler.ex +++ b/farmbot_celery_script/lib/farmbot_celery_script/compiler.ex @@ -65,7 +65,6 @@ defmodule FarmbotCeleryScript.Compiler do end def compile(%AST{kind: kind} = ast, env) when kind in @valid_entry_points do - raise "This is the entrypoint to everything... Figure out where :name, :x, :y, :z come from..." compile_entry_point(compile_ast(ast, env), env, []) end @@ -78,7 +77,9 @@ defmodule FarmbotCeleryScript.Compiler do # TODO: investigate why i have to turn this to a string # before eval ing it? # case Code.eval_quoted(compiled, [], __ENV__) do - case Macro.to_string(compiled) |> Code.eval_string(new_env, __ENV__) do + result = Macro.to_string(compiled) |> Code.eval_string(new_env, __ENV__) + + case result do {fun, new_env} when is_function(fun, 1) -> env = Keyword.merge(env, new_env) compile_entry_point(rest, env, acc ++ apply(fun, [env])) diff --git a/farmbot_os/lib/farmbot_os/sys_calls/point_lookup.ex b/farmbot_os/lib/farmbot_os/sys_calls/point_lookup.ex index 0cad972e..a60fdcac 100644 --- a/farmbot_os/lib/farmbot_os/sys_calls/point_lookup.ex +++ b/farmbot_os/lib/farmbot_os/sys_calls/point_lookup.ex @@ -8,8 +8,18 @@ defmodule FarmbotOS.SysCalls.PointLookup do def point(kind, id) do case Asset.get_point(id: id) do - nil -> {:error, "#{kind || "point?"} #{id} not found"} - %{name: name, x: x, y: y, z: z} -> %{name: name, x: x, y: y, z: z} + nil -> + {:error, "#{kind || "point?"} #{id} not found"} + + %{name: name, x: x, y: y, z: z} -> + %{ + name: name, + resource_type: "Point", + resource_id: id, + x: x, + y: y, + z: z + } end end diff --git a/farmbot_os/test/farmbot_os/syscalls/point_lookup_test.exs b/farmbot_os/test/farmbot_os/syscalls/point_lookup_test.exs index 45459818..99313189 100644 --- a/farmbot_os/test/farmbot_os/syscalls/point_lookup_test.exs +++ b/farmbot_os/test/farmbot_os/syscalls/point_lookup_test.exs @@ -17,7 +17,7 @@ defmodule FarmbotOS.SysCalls.PointLookupTest do test "failure cases" do err1 = PointLookup.point("GenericPointer", 24) - assert {:error, "GenericPointer not found"} == err1 + assert {:error, "GenericPointer 24 not found"} == err1 err2 = PointLookup.get_toolslot_for_tool(24) assert {:error, "Could not find point for tool by id: 24"} == err2 @@ -33,7 +33,9 @@ defmodule FarmbotOS.SysCalls.PointLookupTest do name: "test suite III", x: 1.2, y: 3.4, - z: 5.6 + z: 5.6, + resource_id: 555, + resource_type: "Point" } p = point(expected)