summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-04-09 13:42:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-04-09 13:42:22 -0700
commitf5d6762fca0a1336079de616fd4122912303e800 (patch)
tree154660855fdb8cdaf4446f6d2f9372740df1cf6c
parent1c5e9c9cc734eb69f9129d74f2250032dd1a1749 (diff)
downloadtxr-f5d6762fca0a1336079de616fd4122912303e800.tar.gz
txr-f5d6762fca0a1336079de616fd4122912303e800.tar.bz2
txr-f5d6762fca0a1336079de616fd4122912303e800.zip
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.
-rw-r--r--stdlib/build.tl56
1 files changed, 28 insertions, 28 deletions
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))