From 787b60b4ed56e7805fd0bb5c9b3a450cc850ac9c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 19 Apr 2025 10:54:44 -0700 Subject: op: reduce and mitigate multiple expansion. * stdlib/op.tl (sys:op-expand): Bind *expand-hook* to nil in several places so that the unavoidable multiple expansions we perform do not re-invoke hooks. Finally, when we interpolate the calculated lambda-interior into the output templates, we mark it noexpand since the material already underwent several expansions. --- stdlib/op.tl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/op.tl b/stdlib/op.tl index bd5b7a2f..26061a6f 100644 --- a/stdlib/op.tl +++ b/stdlib/op.tl @@ -125,7 +125,8 @@ ;; Try to expand args as-is, catching errors. (let ((syn (op-ignerr (sys:op-alpha-rename e syntax-0 - nil)))) + nil))) + (*expand-hook* nil)) (if syn ;; Args expanded. (if (or (slot ctx 'gens) (slot ctx 'nested)) @@ -156,6 +157,7 @@ ;; There were no metas. Let's return the ;; form augmented with do-gen. syn))))) + (*expand-hook* nil) (syntax-2 (sys:op-alpha-rename e syntax-1 t)) (metas (slot ctx 'gens)) (rec (slot ctx 'rec)) @@ -189,13 +191,13 @@ (cond (recvar ^(sys:lbind ((,rec (lambda (,*(cdr metas) . ,rest-sym) (let ((,rec (fun ,rec))) - ,lambda-interior)))) + ,(noexpand lambda-interior))))) (fun ,rec))) (rec ^(sys:lbind ((,rec (lambda (,*(cdr metas) . ,rest-sym) - ,lambda-interior))) + ,(noexpand lambda-interior)))) (fun ,rec))) (t ^(lambda (,*(cdr metas) . ,rest-sym) - ,lambda-interior)))))) + ,(noexpand lambda-interior))))))) (defmacro op (:form f :env e . args) (sys:op-expand f e args)) -- cgit v1.2.3