1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-19 09:38:28 +03:00

prepare for later

This commit is contained in:
AnotherTest 2020-01-05 18:38:15 +03:30
parent 9088c0fa75
commit b27d81d826
2 changed files with 19 additions and 13 deletions

View File

@ -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)");
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)")

View File

@ -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"
},