From 07c6d46b1cc8300042832c9a01fe57cdfb130db3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 14 May 2021 06:11:59 -0700 Subject: compiler: better code for global var definitions. * eval.c (rt_defvarl): More accurate self string. (rt_defv): New static function: like rt_defvarl but ensures that the new variable has a binding cell, and returns that cell instead of the hash cell. (op_defvarl): Take advantage of rt_defv to not have to cons up the binding cell. (eval_init): Register sys:rt-defv intrinsic. * parser.c (read_file_common): Compiled files are now version 7, so we must recognize them. We still load version 6 files because rt:defvarl still exists for them. * share/txr/stdlib/compiler.tl (expand-defvarl): Improve the generated code in two ways. Firstly, use the new sys:rt-defv, which returns the binding cell, so that the value can be stored into it with rplacd without having to cons up anything. Secondly, if there is no value expression, don't emit the code to do the assignment. (%tlo-ver%): Bump compiled file version to (7 0). * txr.1: Add note about TXR 260 loading version 7 and 6. --- share/txr/stdlib/compiler.tl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'share') diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 2dba0bbe..0e0f3f4f 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -1982,10 +1982,12 @@ (defun expand-defvarl (form) (mac-param-bind form (op sym : value) form (with-gensyms (cell) - ^(let ((,cell (sys:rt-defvarl ',sym))) - (if ,cell - (usr:rplacd ,cell (cons ',sym ,value))) - ',sym)))) + (if value + ^(let ((,cell (sys:rt-defv ',sym))) + (if ,cell + (usr:rplacd ,cell ,value)) + ',sym) + ^(progn (sys:rt-defv ',sym) ',sym))))) (defun expand-defun (form) (mac-param-bind form (op name args . body) form @@ -2164,7 +2166,7 @@ (defvarl %big-endian% (equal (ffi-put 1 (ffi uint32)) #b'00000001')) -(defvarl %tlo-ver% ^(6 0 ,%big-endian%)) +(defvarl %tlo-ver% ^(7 0 ,%big-endian%)) (defvarl %package-manip% '(make-package delete-package use-package unuse-package -- cgit v1.2.3