summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-07-16 23:40:26 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-07-16 23:40:26 -0700
commit858aa11f2dbd5db5245bd3a0b1aa5fe9d91c7f65 (patch)
treead88dc5233a908ba64539c1067698f2d01cade57 /stdlib
parent339d41fabd0f41e2c1008d38f215327cc36af783 (diff)
downloadtxr-858aa11f2dbd5db5245bd3a0b1aa5fe9d91c7f65.tar.gz
txr-858aa11f2dbd5db5245bd3a0b1aa5fe9d91c7f65.tar.bz2
txr-858aa11f2dbd5db5245bd3a0b1aa5fe9d91c7f65.zip
Simplify top-level variable and function environments.
Since their inception, the top_fb and top_fb hashes associated symbols with bindings cells, causing an extra cons cell to be allocated for each entry. I don't remember why this is. It might have been that way so that gethash(top_fb, sym) would return a cell when the variable exists, or else nil. This was before we had functions like gethash_e and inhash that return the hash cell itself. A hash cell is also a cons and can serve as a binding just fine by itself.Let's make it so. For now, the macro and symbol macro environments stay the way they are; I will likely convert them also. * eval.c (env_fbind, env_vbind, lookup_global_var, lookup_sym_lisp1, lookup_fun, func_get_name, rt_defv, rt_defun, set_symbol_value, reg_fun, reg_varl): Update all these functions so they treat the hash cell from top_vb or top_fb as the binding cell, rather than putting or expecting the cdr of that cell (i.e the hash value) to be a binding cell. * hash.[ch] (gethash_d): New function. Jus gethash_e without the pesky self argument, that would only be needed for error reporting if we pass an object that isn't a hash. * stdlib/place.tl (sys:get-fun-getter-setter, sys:get-vb): These two functions must be adjusted since they refer to the top-fb and top-vb variables. sys:get-vb isn't used anywhere; it continues to exist in order to provide run-time support to files that were compiled with an buggy version of the symbol-value place.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/place.tl6
1 files changed, 2 insertions, 4 deletions
diff --git a/stdlib/place.tl b/stdlib/place.tl
index fdd4e544..f1bef38a 100644
--- a/stdlib/place.tl
+++ b/stdlib/place.tl
@@ -823,8 +823,7 @@
(compile-error f "cannot assign to lambda")
(compile-error f "invalid function syntax ~s" sym)))
(else
- (let ((cell (or (gethash sys:top-fb sym)
- (sethash sys:top-fb sym (cons else nil)))))
+ (let ((cell (inhash sys:top-fb else nil)))
(cons (op cdr)
(op sys:rplacd cell))))))
@@ -857,8 +856,7 @@
,body)))
(defun sys:get-vb (sym)
- (or (gethash sys:top-vb sym)
- (sethash sys:top-vb sym (cons sym nil))))
+ (inhash sys:top-vb sym nil))
(defplace (symbol-value sym-expr) body
(getter setter