1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-13 01:43:50 +03:00

awk: Support catchless try*

This commit is contained in:
Dov Murik 2019-02-21 11:06:20 +00:00
parent 4afc9decd5
commit c738a39f7e
2 changed files with 18 additions and 6 deletions

View File

@ -257,11 +257,17 @@ function EVAL_defmacro(ast, env, idx, sym, ret, len)
function EVAL_try(ast, env, catch_body, catch_env, idx, catch, catch_idx, catch_sym, ret, len, str)
{
idx = substr(ast, 2)
if (types_heap[idx]["len"] != 3) {
len = types_heap[idx]["len"]
len = types_heap[idx]["len"]
if (len != 2 && len != 3) {
types_release(ast)
env_release(env)
return "!\"Invalid argument length for 'try*'. Expects exactly 2 arguments, supplied" (len - 1) "."
return "!\"Invalid argument length for 'try*'. Expects 1 or 2 arguments, supplied" (len - 1) "."
}
if (len == 2) {
ret = EVAL(types_addref(types_heap[idx][1]), env)
types_release(ast)
env_release(env)
return ret
}
catch = types_heap[idx][2]
if (catch !~ /^\(/) {

View File

@ -257,11 +257,17 @@ function EVAL_defmacro(ast, env, idx, sym, ret, len)
function EVAL_try(ast, env, catch_body, catch_env, idx, catch, catch_idx, catch_sym, ret, len, str)
{
idx = substr(ast, 2)
if (types_heap[idx]["len"] != 3) {
len = types_heap[idx]["len"]
len = types_heap[idx]["len"]
if (len != 2 && len != 3) {
types_release(ast)
env_release(env)
return "!\"Invalid argument length for 'try*'. Expects exactly 2 arguments, supplied" (len - 1) "."
return "!\"Invalid argument length for 'try*'. Expects 1 or 2 arguments, supplied" (len - 1) "."
}
if (len == 2) {
ret = EVAL(types_addref(types_heap[idx][1]), env)
types_release(ast)
env_release(env)
return ret
}
catch = types_heap[idx][2]
if (catch !~ /^\(/) {