10dfebe0d7e601760802114abb274a3dc889305a — Rob Browning 2 months ago 886bead main
ns: fix syntax expansion scoping issues

Previously ns was picking up refer (at least) indirectly (and
incorrectly), but recent guile changes fixed that, which caused builds
fail like this:

  ERROR: In procedure %resolve-variable:
  In procedure module-lookup: Unbound variable: refer

Rework the expansion to refer to the correct refer, and adjust other
ns directives to produce syntaxes rather than datums.

cf. 9e0f03c5fd36764827c8bb03887f14640c883b70

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
1 files changed, 22 insertions(+), 10 deletions(-)

M mod/lokke/ns.scm
M mod/lokke/ns.scm => mod/lokke/ns.scm +22 -10
@@ 464,23 464,36 @@ not bound."
(define (refer-clojure . filters)
  (apply refer 'clojure.core filters))

(define (incorporate-refs-syntax refs core?)
(define (quote-spec-args ctx args)
  (if (null? args)
      (map (lambda (arg)
             #`(quote #,(let recur ((x arg))
                           ((list? x) (map (lambda (item) (recur item)) x))
                           ((vector? x) (list->vector (recur (vector->list x))))
                           ((symbol? x) (datum->syntax ctx x))
                           ((keyword? x) x)
                           (else (error "foo"))))))

(define (expand-specs ctx specs core?)
  ;; Can currently expect scheme vectors for say (:require [foo ...])
  (let* ((quotify (lambda (lst) (map (lambda (x) (list 'quote x)) lst)))
  (let* ((refs (clj-syntax->scm specs))
         (cmds (map (lambda (ref)
                      (case (car ref)
                        ((#:require) `(require ,@(quotify (cdr ref))))
                        ((#:use) `(use ,@(quotify (cdr ref))))
                        ((#:refer-clojure) `(refer-clojure ,@(quotify (cdr ref))))
                        ;;((#:load) `(load ,@(quotify (cdr ref))))
                        ((#:require) #`(require #,@(quote-spec-args ctx (cdr ref))))
                        ((#:use) #`(use #,@(quote-spec-args ctx (cdr ref))))
                        ((#:refer-clojure) #`(refer-clojure #,@(quote-spec-args ctx (cdr ref))))
                        ;;((#:load) `(load ,@(quote-spec-args ctx (cdr ref))))
                        ((#:import) (error ":import is not supported yet"))
                        ((#:gen-class) '(do))
                        ((#:gen-class) #'(begin))
                        (else (error "Unrecognized ns directive" ref))))
         (cmds (if (or core?
                       (find (lambda (x) (eq? #:refer-clojure (car x))) refs))
                   (cons '(refer 'clojure.core) cmds))))
                   (cons #'(refer 'clojure.core) cmds))))

(define (clj-syntax->scm syn)

@@ 533,8 546,7 @@ not bound."
(define (expand-ns ctx name specs)
  (let* ((mod (ns-sym->mod-name (require-ns-sym (syntax->datum name))))
         (core? (core-module? mod))
         (specs (clj-syntax->scm specs))
         (ref-cmds (datum->syntax ctx (incorporate-refs-syntax specs core?))))
         (ref-cmds (expand-specs ctx specs core?)))
    #`(eval-when (expand load eval)
        ;; Only define the module here -- needs to be top level,
        ;; and language will be lokke, so we don't want to let it