summaryrefslogtreecommitdiffstats
path: root/stdlib
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
commit80de7a55930bb213b7901148e1e3f9624d1adef5 (patch)
tree154660855fdb8cdaf4446f6d2f9372740df1cf6c /stdlib
parent310b3d130c19ae862da352e4e2f29ecb21235846 (diff)
downloadtxr-80de7a55930bb213b7901148e1e3f9624d1adef5.tar.gz
txr-80de7a55930bb213b7901148e1e3f9624d1adef5.tar.bz2
txr-80de7a55930bb213b7901148e1e3f9624d1adef5.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.
Diffstat (limited to 'stdlib')
-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))