mirror of
https://github.com/kanaka/mal.git
synced 2024-11-14 00:09:01 +03:00
prepare for later
This commit is contained in:
parent
9088c0fa75
commit
b27d81d826
28
jq/interp.jq
28
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)");
|
||||
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)")
|
@ -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"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user