From c738a39f7ecd713f47a605ad31851e3fd44cf422 Mon Sep 17 00:00:00 2001 From: Dov Murik Date: Thu, 21 Feb 2019 11:06:20 +0000 Subject: [PATCH] awk: Support catchless try* --- awk/step9_try.awk | 12 +++++++++--- awk/stepA_mal.awk | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/awk/step9_try.awk b/awk/step9_try.awk index 23fee522..79e9ed1a 100644 --- a/awk/step9_try.awk +++ b/awk/step9_try.awk @@ -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 !~ /^\(/) { diff --git a/awk/stepA_mal.awk b/awk/stepA_mal.awk index 06cebcef..5661c53f 100644 --- a/awk/stepA_mal.awk +++ b/awk/stepA_mal.awk @@ -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 !~ /^\(/) {