From b27d81d8268d6e7c8743d29687d635d0741e23b7 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sun, 5 Jan 2020 18:38:15 +0330 Subject: [PATCH] prepare for later --- jq/interp.jq | 28 +++++++++++++++------------- jq/step2_eval.jq | 4 ++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/jq/interp.jq b/jq/interp.jq index 51642802..0fa2f3a2 100644 --- a/jq/interp.jq +++ b/jq/interp.jq @@ -9,16 +9,18 @@ def arg_check(args): def interpret(arguments; env): - arg_check(arguments) | ( - select(.function == "number_add") | - arguments | map(.value) | .[0] + .[1] | wrap("number") - ) // ( - select(.function == "number_sub") | - arguments | map(.value) | .[0] - .[1] | wrap("number") - ) // ( - select(.function == "number_mul") | - arguments | map(.value) | .[0] * .[1] | wrap("number") - ) // ( - select(.function == "number_div") | - arguments | map(.value) | .[0] / .[1] | wrap("number") - ) // jqmal_error("Unknown function \(.function)"); \ No newline at end of file + select(.kind == "fn") | ( + arg_check(arguments) | ( + select(.function == "number_add") | + arguments | map(.value) | .[0] + .[1] | wrap("number") + ) // ( + select(.function == "number_sub") | + arguments | map(.value) | .[0] - .[1] | wrap("number") + ) // ( + select(.function == "number_mul") | + arguments | map(.value) | .[0] * .[1] | wrap("number") + ) // ( + select(.function == "number_div") | + arguments | map(.value) | .[0] / .[1] | wrap("number") + ) // jqmal_error("Unknown native function \(.function)"); + ) // jqmal_error("Unsupported function kind \(.kind)") \ No newline at end of file diff --git a/jq/step2_eval.jq b/jq/step2_eval.jq index b54cd6fa..6df358fe 100644 --- a/jq/step2_eval.jq +++ b/jq/step2_eval.jq @@ -73,18 +73,22 @@ def replEnv: parent: null, environment: { "+": { + kind: "fn", # native function inputs: 2, function: "number_add" }, "-": { + kind: "fn", # native function inputs: 2, function: "number_sub" }, "*": { + kind: "fn", # native function inputs: 2, function: "number_mul" }, "/": { + kind: "fn", # native function inputs: 2, function: "number_div" },