summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-11 05:32:33 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-11 05:32:33 -0800
commit7843bdd7550a1cf3213a184c350b3175d8e8e562 (patch)
tree764006074bab0f72f91900685b056826c32cbf11
parent5405583c3e39f0aa1a5f1ea93f106f5dd598b757 (diff)
downloadtxr-7843bdd7550a1cf3213a184c350b3175d8e8e562.tar.gz
txr-7843bdd7550a1cf3213a184c350b3175d8e8e562.tar.bz2
txr-7843bdd7550a1cf3213a184c350b3175d8e8e562.zip
Streamline variable assignment operators slightly.
* eval.c (op_setq, op_lisp1_setq): Take the bindable(var) test out of the frequently executed path. We can safely do the variable lookup with any object. If the lookup fails, then we can complain that the object isn't a bindable symbol, if that is the case.
-rw-r--r--eval.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/eval.c b/eval.c
index a0c610c9..b6503280 100644
--- a/eval.c
+++ b/eval.c
@@ -1905,15 +1905,13 @@ static val op_setq(val form, val env)
val args = rest(form);
val var = pop(&args);
val newval = pop(&args);
-
- if (!bindable(var)) {
- eval_error(form, lit("sys:setq: ~s is not a bindable symbol"), var, nao);
- } else {
- val binding = lookup_var(env, var);
- if (nilp(binding))
- eval_error(form, lit("unbound variable ~s"), var, nao);
- return sys_rplacd(binding, eval(newval, env, form));
+ val binding = lookup_var(env, var);
+ if (nilp(binding)) {
+ if (!bindable(var))
+ eval_error(form, lit("sys:setq: ~s is not a bindable symbol"), var, nao);
+ eval_error(form, lit("unbound variable ~s"), var, nao);
}
+ return sys_rplacd(binding, eval(newval, env, form));
}
static val op_lisp1_setq(val form, val env)
@@ -1922,14 +1920,13 @@ static val op_lisp1_setq(val form, val env)
val var = pop(&args);
val newval = pop(&args);
- if (!bindable(var)) {
- eval_error(form, lit("sys:lisp1-setq: ~s is not a bindable symbol"), var, nao);
- } else {
- val binding = lookup_sym_lisp1(env, var);
- if (nilp(binding))
- eval_error(form, lit("unbound variable ~s"), var, nao);
- return sys_rplacd(binding, eval(newval, env, form));
+ val binding = lookup_sym_lisp1(env, var);
+ if (nilp(binding)) {
+ if (!bindable(var))
+ eval_error(form, lit("sys:lisp1-setq: ~s is not a bindable symbol"), var, nao);
+ eval_error(form, lit("unbound variable ~s"), var, nao);
}
+ return sys_rplacd(binding, eval(newval, env, form));
}
static val expand_lisp1_value(val form, val menv)