summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-03-22 18:18:43 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-03-22 18:18:43 -0700
commit28d34640e615912960aea678af060f3e444c2cc8 (patch)
tree26340c33aa437ff88084f38ccfa3bca706b084db /stdlib
parent5ee2cd3b2304287c010237e03be4d181412e066f (diff)
downloadtxr-28d34640e615912960aea678af060f3e444c2cc8.tar.gz
txr-28d34640e615912960aea678af060f3e444c2cc8.tar.bz2
txr-28d34640e615912960aea678af060f3e444c2cc8.zip
compiler: forward source location for defun and defmacro
* stdlib/compiler.tl (expand-defun): Sprinkling of rlcp to pass source location info to the generated lambda, and to the sys:define-method call. (expand-defmacro): bugfix here: in with-gensyms we shadowed the form parameter, and then passed that as both form arguments to expand-bind-mac-params. We rename the gensym to mform, and then for the error-form, we pass the original form, quoted as necessary and with source location info. Thus, now source location info flows from the original defmacro form to the generated let* which binds the destructured parameters.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/compiler.tl26
1 files changed, 15 insertions, 11 deletions
diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl
index b0f2d0f4..3b0e34e1 100644
--- a/stdlib/compiler.tl
+++ b/stdlib/compiler.tl
@@ -2067,7 +2067,7 @@
(defun expand-defun (form)
(mac-param-bind form (t name args . body) form
(flet ((mklambda (block-name block-sym)
- ^(lambda ,args (,block-sym ,block-name ,*body))))
+ (rlcp ^(lambda ,args (,block-sym ,block-name ,*body)) form)))
(cond
((bindable name)
^(sys:rt-defun ',name ,(mklambda name 'sys:blk)))
@@ -2075,7 +2075,8 @@
(caseq (car name)
(meth
(mac-param-bind form (t type slot) name
- ^(sys:define-method ',type ',slot ,(mklambda slot 'block))))
+ (rlcp ^(sys:define-method ',type ',slot ,(mklambda slot 'block))
+ form)))
(macro
(mac-param-bind form (t sym) name
^(sys:rt-defmacro ',sym ',name ,(mklambda sym 'sys:blk))))
@@ -2085,15 +2086,18 @@
(defun expand-defmacro (form)
(mac-param-bind form (t name mac-args . body) form
- (with-gensyms (form menv spine-iter)
- (let ((exp-lam ^(lambda (,form ,menv)
- (let ((,spine-iter (cdr ,form)))
- ,(expand (expand-bind-mac-params form form mac-args
- menv spine-iter
- t nil
- ^((sys:set-macro-ancestor
- (block ,name ,*body)
- ,form))))))))
+ (with-gensyms (mform menv spine-iter)
+ (let ((exp-lam (rlcp ^(lambda (,mform ,menv)
+ (let ((,spine-iter (cdr ,mform)))
+ ,(expand (expand-bind-mac-params mform
+ (rlcp ^',form form)
+ mac-args
+ menv spine-iter
+ t nil
+ ^((sys:set-macro-ancestor
+ (block ,name ,*body)
+ ,mform))))))
+ form)))
^(progn
(sys:rt-defmacro ',name '(macro ,name) ,exp-lam)
',name)))))