summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-06 00:39:17 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-06 00:39:17 -0800
commit6a63a6b32065f6a5839571b378605f875f9c5240 (patch)
tree3ffb3de049fdcefeed5f7a11cab48602729f95c5
parent87ef0e20b4e9d8f82d061ddc6993d04a2f6eda9d (diff)
downloadtxr-6a63a6b32065f6a5839571b378605f875f9c5240.tar.gz
txr-6a63a6b32065f6a5839571b378605f875f9c5240.tar.bz2
txr-6a63a6b32065f6a5839571b378605f875f9c5240.zip
* eval.c (op_dwim): Gutted down to just a few lines.
Basically the dwim operator is just a Lisp-1 version of the call operator now. It doesn't have to do anything funny with non-function objects, since they are callable. * lib.c (chr_str, chr_str_set, vecref, vecref_l): Replace inappropriate internal assertions with error exceptions. * unwind.h (numeric_assert, range_bug_unless): Unused macros removed.
-rw-r--r--ChangeLog13
-rw-r--r--eval.c76
-rw-r--r--lib.c17
-rw-r--r--unwind.h13
4 files changed, 27 insertions, 92 deletions
diff --git a/ChangeLog b/ChangeLog
index 1dd09d96..859da73e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2014-02-06 Kaz Kylheku <kaz@kylheku.com>
+
+ * eval.c (op_dwim): Gutted down to just a few lines.
+ Basically the dwim operator is just a Lisp-1 version of the call
+ operator now. It doesn't have to do anything funny with non-function
+ objects, since they are callable.
+
+ * lib.c (chr_str, chr_str_set, vecref, vecref_l): Replace
+ inappropriate internal assertions with error exceptions.
+
+ * unwind.h (numeric_assert, range_bug_unless): Unused macros
+ removed.
+
2014-02-05 Kaz Kylheku <kaz@kylheku.com>
* lib.c (generic_funcall): If a cons cell is passed as
diff --git a/eval.c b/eval.c
index a70d8474..c469adf4 100644
--- a/eval.c
+++ b/eval.c
@@ -1224,81 +1224,7 @@ static val op_dwim(val form, val env)
{
val obj = eval_lisp1(second(form), env, form);
val args = eval_args_lisp1(rest(rest(form)), env, form);
-
- switch (type(obj)) {
- case NIL:
- return nil;
- case LIT:
- case STR:
- case LSTR:
- if (rest(args))
- eval_error(form, lit("[~s ...]: string indexing needs one arg"),
- obj, nao);
- {
- val index = first(args);
- if (consp(index)) {
- return sub_str(obj, car(index), cdr(index));
- } else {
- return chr_str(obj, first(args));
- }
- }
- case SYM:
- {
- val fbinding = lookup_fun(env, obj);
-
- if (!fbinding)
- eval_error(form, lit("[~s ...]: no function exists named ~s"),
- obj, obj, nao);
-
- return apply(cdr(fbinding), args, form);
- }
- case FUN:
- return apply(obj, args, form);
- case VEC:
- if (rest(args))
- eval_error(form, lit("[~s ...]: vector indexing needs one arg"),
- obj, nao);
- {
- val index = first(args);
-
- if (consp(index)) {
- return sub_vec(obj, car(index), cdr(index));
- } else {
- return vecref(obj, first(args));
- }
- }
- case CONS:
- case LCONS:
- if (rest(args))
- eval_error(form, lit("[~s ...]: list indexing needs one arg"),
- obj, nao);
- {
- val index = first(args);
- if (!bignump(index) && !fixnump(index) && !consp(index))
- eval_error(form, lit("[~s ~s]: index must be integer or pair"),
- obj, index, nao);
-
- if (consp(index)) {
- return sub_list(obj, car(index), cdr(index));
- } else {
- return listref(obj, first(args));
- }
- }
- case COBJ:
- {
- if (hashp(obj)) {
- if (lt(length(args), one))
- eval_error(form, lit("[~s ...]: hash indexing needs at least one arg"),
- obj, nao);
- return gethash_n(obj, first(args), second(args));
- }
- }
- /* fallthrough */
- default:
- eval_error(form, lit("object ~s not supported by [] notation"), obj, nao);
- }
-
- return nil;
+ return apply(obj, args, form);
}
static val op_catch(val form, val env)
diff --git a/lib.c b/lib.c
index 03961597..6798cb4f 100644
--- a/lib.c
+++ b/lib.c
@@ -2610,7 +2610,9 @@ val chr_str(val str, val ind)
index = c_num(ind);
}
- bug_unless (index >= 0 && length_str_gt(str, ind));
+ if (index < 0 || !length_str_gt(str, ind))
+ uw_throwf(error_s, lit("chr-str: ~s is out of range for string ~s"),
+ ind, str, nao);
if (lazy_stringp(str)) {
lazy_str_force_upto(str, ind);
@@ -2629,7 +2631,10 @@ val chr_str_set(val str, val ind, val chr)
index = c_num(ind);
}
- bug_unless (index >= 0 && length_str_gt(str, ind));
+ if (index < 0 || !length_str_gt(str, ind))
+ uw_throwf(error_s, lit("chr-str-set: ~s is out of range for string ~s"),
+ ind, str, nao);
+
if (lazy_stringp(str)) {
lazy_str_force_upto(str, ind);
@@ -3894,7 +3899,9 @@ val vecref(val vec, val ind)
cnum len = c_num(length_vec(vec));
if (index < 0)
index = len + index;
- range_bug_unless (index >= 0 && index < len);
+ if (index < 0 || index >= len)
+ uw_throwf(error_s, lit("vecref: ~s is out of range for vector ~s"),
+ ind, vec, nao);
return vec->v.vec[index];
}
@@ -3902,7 +3909,9 @@ val *vecref_l(val vec, val ind)
{
cnum index = c_num(ind);
cnum len = c_num(length_vec(vec));
- range_bug_unless (index >= 0 && index < len);
+ if (index < 0 || index >= len)
+ uw_throwf(error_s, lit("vecref: ~s is out of range for vector ~s"),
+ ind, vec, nao);
return vec->v.vec + index;
}
diff --git a/unwind.h b/unwind.h
index 884f0451..ea92e9b1 100644
--- a/unwind.h
+++ b/unwind.h
@@ -213,16 +213,3 @@ noreturn val type_mismatch(val, ...);
internal_error("assertion " \
#EXPR \
" failed")
-
-#define numeric_assert(EXPR) \
- if (!(EXPR)) \
- uw_throwf(numeric_error_s, \
- lit("assertion " #EXPR \
- " failed"), nao)
-
-#define range_bug_unless(EXPR) \
- if (!(EXPR)) \
- uw_throwf(range_error_s, \
- lit("assertion " #EXPR \
- " failed"), nao)
-