From 80de7a55930bb213b7901148e1e3f9624d1adef5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 9 Apr 2023 13:42:22 -0700 Subject: build: rearrange code to fix circular dependency. * stdlib/build.tl (sys:list-builder-flets, sys:build-expander, build, buildn): Move to top of file. This resolves a circular dependency triggered by the defstruct macro: it autoloads struct.tl which autoloads other things, some of which depend on the build macro. If we provide the build macro at the top, everything is cool. The compiled version of build.tl doesn't have this problem, because macro-time dependencies don't affect compiled code. With this change, it's possible to run the tests/012/compile.tl test case without stdlib being compiled. --- stdlib/build.tl | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'stdlib') diff --git a/stdlib/build.tl b/stdlib/build.tl index f29b5bec..708939c1 100644 --- a/stdlib/build.tl +++ b/stdlib/build.tl @@ -25,6 +25,34 @@ ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ;; POSSIBILITY OF SUCH DAMAGE. +(defun sys:list-builder-flets (lb-form) + (nconc + (collect-each ((op '(add add* pend pend* ncon ncon* oust))) + ^(,op (. args) + (qref ,lb-form (,op . args)) + nil)) + ^((get () + (qref ,lb-form (get))) + (del* () + (qref ,lb-form (del*))) + (do-del () + (qref ,lb-form (del)))))) + +(defun sys:build-expander (forms return-get) + (with-gensyms (name) + ^(let ((,name (new list-builder))) + (flet ,(sys:list-builder-flets name) + (macrolet ((del (:form f : (expr nil expr-p)) + (if expr-p f '(do-del)))) + ,*forms + ,*(if return-get ^((qref ,name (get))))))))) + +(defmacro build (. forms) + (sys:build-expander forms t)) + +(defmacro buildn (. forms) + (sys:build-expander forms nil)) + (defstruct list-builder () head tail @@ -117,33 +145,5 @@ (usr:rplacd hd nil) (set self.tail hd)))))) -(defun sys:list-builder-flets (lb-form) - (nconc - (collect-each ((op '(add add* pend pend* ncon ncon* oust))) - ^(,op (. args) - (qref ,lb-form (,op . args)) - nil)) - ^((get () - (qref ,lb-form (get))) - (del* () - (qref ,lb-form (del*))) - (do-del () - (qref ,lb-form (del)))))) - (defun build-list (: init) (new list-builder head init)) - -(defun sys:build-expander (forms return-get) - (with-gensyms (name) - ^(let ((,name (new list-builder))) - (flet ,(sys:list-builder-flets name) - (macrolet ((del (:form f : (expr nil expr-p)) - (if expr-p f '(do-del)))) - ,*forms - ,*(if return-get ^((qref ,name (get))))))))) - -(defmacro build (. forms) - (sys:build-expander forms t)) - -(defmacro buildn (. forms) - (sys:build-expander forms nil)) -- cgit v1.2.3