mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 20:30:28 +02:00
refactor chi-top-sequence
* module/ice-9/psyntax.scm (chi-top-sequence): Refactor slightly. * module/ice-9/psyntax-pp.scm: Regenerate.
This commit is contained in:
parent
dd64fe65fd
commit
148dfc2409
2 changed files with 8926 additions and 8951 deletions
File diff suppressed because it is too large
Load diff
|
@ -916,137 +916,129 @@
|
||||||
;; in reversed order
|
;; in reversed order
|
||||||
exps)
|
exps)
|
||||||
(else
|
(else
|
||||||
(call-with-values
|
(scan
|
||||||
(lambda ()
|
(cdr body) r w s m esew mod
|
||||||
(call-with-values
|
(call-with-values
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let ((e (car body)))
|
(let ((e (car body)))
|
||||||
(syntax-type e r w (or (source-annotation e) s) #f mod #f)))
|
(syntax-type e r w (or (source-annotation e) s) #f mod #f)))
|
||||||
(lambda (type value e w s mod)
|
(lambda (type value e w s mod)
|
||||||
(case type
|
(case type
|
||||||
((begin-form)
|
((begin-form)
|
||||||
(syntax-case e ()
|
(syntax-case e ()
|
||||||
((_) exps)
|
((_) exps)
|
||||||
((_ e1 e2 ...)
|
((_ e1 e2 ...)
|
||||||
(scan #'(e1 e2 ...) r w s m esew mod exps))))
|
(scan #'(e1 e2 ...) r w s m esew mod exps))))
|
||||||
((local-syntax-form)
|
((local-syntax-form)
|
||||||
(chi-local-syntax value e r w s mod
|
(chi-local-syntax value e r w s mod
|
||||||
(lambda (body r w s mod)
|
(lambda (body r w s mod)
|
||||||
(scan body r w s m esew mod exps))))
|
(scan body r w s m esew mod exps))))
|
||||||
((eval-when-form)
|
((eval-when-form)
|
||||||
(syntax-case e ()
|
(syntax-case e ()
|
||||||
((_ (x ...) e1 e2 ...)
|
((_ (x ...) e1 e2 ...)
|
||||||
(let ((when-list (chi-when-list e #'(x ...) w))
|
(let ((when-list (chi-when-list e #'(x ...) w))
|
||||||
(body #'(e1 e2 ...)))
|
(body #'(e1 e2 ...)))
|
||||||
(cond
|
(cond
|
||||||
((eq? m 'e)
|
((eq? m 'e)
|
||||||
(if (memq 'eval when-list)
|
(if (memq 'eval when-list)
|
||||||
(scan body r w s
|
(scan body r w s
|
||||||
(if (memq 'expand when-list) 'c&e 'e)
|
(if (memq 'expand when-list) 'c&e 'e)
|
||||||
'(eval)
|
'(eval)
|
||||||
mod exps)
|
mod exps)
|
||||||
(begin
|
(begin
|
||||||
(if (memq 'expand when-list)
|
(if (memq 'expand when-list)
|
||||||
(top-level-eval-hook
|
(top-level-eval-hook
|
||||||
(chi-top-sequence body r w s 'e '(eval) mod)
|
(chi-top-sequence body r w s 'e '(eval) mod)
|
||||||
mod))
|
mod))
|
||||||
(values exps))))
|
exps)))
|
||||||
((memq 'load when-list)
|
((memq 'load when-list)
|
||||||
(if (or (memq 'compile when-list)
|
(if (or (memq 'compile when-list)
|
||||||
(memq 'expand when-list)
|
(memq 'expand when-list)
|
||||||
(and (eq? m 'c&e) (memq 'eval when-list)))
|
(and (eq? m 'c&e) (memq 'eval when-list)))
|
||||||
(scan body r w s 'c&e '(compile load) mod exps)
|
(scan body r w s 'c&e '(compile load) mod exps)
|
||||||
(if (memq m '(c c&e))
|
(if (memq m '(c c&e))
|
||||||
(scan body r w s 'c '(load) mod exps)
|
(scan body r w s 'c '(load) mod exps)
|
||||||
(values exps))))
|
exps)))
|
||||||
((or (memq 'compile when-list)
|
((or (memq 'compile when-list)
|
||||||
(memq 'expand when-list)
|
(memq 'expand when-list)
|
||||||
(and (eq? m 'c&e) (memq 'eval when-list)))
|
(and (eq? m 'c&e) (memq 'eval when-list)))
|
||||||
(top-level-eval-hook
|
(top-level-eval-hook
|
||||||
(chi-top-sequence body r w s 'e '(eval) mod)
|
(chi-top-sequence body r w s 'e '(eval) mod)
|
||||||
mod)
|
mod)
|
||||||
(values exps))
|
exps)
|
||||||
(else
|
(else
|
||||||
(values exps)))))))
|
exps))))))
|
||||||
((define-syntax-form)
|
((define-syntax-form)
|
||||||
(let ((n (id-var-name value w)) (r (macros-only-env r)))
|
(let ((n (id-var-name value w)) (r (macros-only-env r)))
|
||||||
(case m
|
(case m
|
||||||
((c)
|
((c)
|
||||||
(if (memq 'compile esew)
|
(if (memq 'compile esew)
|
||||||
(let ((e (chi-install-global n (chi e r w mod))))
|
(let ((e (chi-install-global n (chi e r w mod))))
|
||||||
(top-level-eval-hook e mod)
|
(top-level-eval-hook e mod)
|
||||||
(if (memq 'load esew)
|
(if (memq 'load esew)
|
||||||
(values (cons e exps))
|
(cons e exps)
|
||||||
(values exps)))
|
exps))
|
||||||
(if (memq 'load esew)
|
(if (memq 'load esew)
|
||||||
(values (cons (chi-install-global n (chi e r w mod))
|
(cons (chi-install-global n (chi e r w mod))
|
||||||
exps))
|
exps)
|
||||||
(values exps))))
|
exps)))
|
||||||
((c&e)
|
((c&e)
|
||||||
(let ((e (chi-install-global n (chi e r w mod))))
|
(let ((e (chi-install-global n (chi e r w mod))))
|
||||||
(top-level-eval-hook e mod)
|
(top-level-eval-hook e mod)
|
||||||
(values (cons e exps))))
|
(cons e exps)))
|
||||||
(else
|
|
||||||
(if (memq 'eval esew)
|
|
||||||
(top-level-eval-hook
|
|
||||||
(chi-install-global n (chi e r w mod))
|
|
||||||
mod))
|
|
||||||
(values exps)))))
|
|
||||||
((define-form)
|
|
||||||
(let* ((n (id-var-name value w))
|
|
||||||
;; Lookup the name in the module of the define form.
|
|
||||||
(type (binding-type (lookup n r mod))))
|
|
||||||
(case type
|
|
||||||
((global core macro module-ref)
|
|
||||||
;; affect compile-time environment (once we have booted)
|
|
||||||
(if (and (memq m '(c c&e))
|
|
||||||
(not (module-local-variable (current-module) n))
|
|
||||||
(current-module))
|
|
||||||
(let ((old (module-variable (current-module) n)))
|
|
||||||
;; use value of the same-named imported variable, if
|
|
||||||
;; any
|
|
||||||
(if (and (variable? old) (variable-bound? old))
|
|
||||||
(module-define! (current-module) n (variable-ref old))
|
|
||||||
(module-add! (current-module) n (make-undefined-variable)))))
|
|
||||||
(values
|
|
||||||
(cons
|
|
||||||
(if (eq? m 'c&e)
|
|
||||||
(let ((x (build-global-definition s n (chi e r w mod))))
|
|
||||||
(top-level-eval-hook x mod)
|
|
||||||
x)
|
|
||||||
(lambda ()
|
|
||||||
(build-global-definition s n (chi e r w mod))))
|
|
||||||
exps)))
|
|
||||||
((displaced-lexical)
|
|
||||||
(syntax-violation #f "identifier out of context"
|
|
||||||
e (wrap value w mod)))
|
|
||||||
(else
|
|
||||||
(syntax-violation #f "cannot define keyword at top level"
|
|
||||||
e (wrap value w mod))))))
|
|
||||||
(else
|
(else
|
||||||
(values (cons
|
(if (memq 'eval esew)
|
||||||
(if (eq? m 'c&e)
|
(top-level-eval-hook
|
||||||
(let ((x (chi-expr type value e r w s mod)))
|
(chi-install-global n (chi e r w mod))
|
||||||
(top-level-eval-hook x mod)
|
mod))
|
||||||
x)
|
exps))))
|
||||||
(lambda ()
|
((define-form)
|
||||||
(chi-expr type value e r w s mod)))
|
(let* ((n (id-var-name value w))
|
||||||
exps)))))))
|
;; Lookup the name in the module of the define form.
|
||||||
(lambda (exps)
|
(type (binding-type (lookup n r mod))))
|
||||||
(scan (cdr body) r w s m esew mod exps))))))
|
(case type
|
||||||
|
((global core macro module-ref)
|
||||||
(call-with-values (lambda ()
|
;; affect compile-time environment (once we have booted)
|
||||||
(scan body r w s m esew mod '()))
|
(if (and (memq m '(c c&e))
|
||||||
(lambda (exps)
|
(not (module-local-variable (current-module) n))
|
||||||
(if (null? exps)
|
(current-module))
|
||||||
(build-void s)
|
(let ((old (module-variable (current-module) n)))
|
||||||
(build-sequence
|
;; use value of the same-named imported variable, if
|
||||||
s
|
;; any
|
||||||
(let lp ((in exps) (out '()))
|
(if (and (variable? old) (variable-bound? old))
|
||||||
(if (null? in) out
|
(module-define! (current-module) n (variable-ref old))
|
||||||
(let ((e (car in)))
|
(module-add! (current-module) n (make-undefined-variable)))))
|
||||||
(lp (cdr in)
|
(cons (if (eq? m 'c&e)
|
||||||
(cons (if (procedure? e) (e) e) out)))))))))))
|
(let ((x (build-global-definition s n (chi e r w mod))))
|
||||||
|
(top-level-eval-hook x mod)
|
||||||
|
x)
|
||||||
|
(lambda ()
|
||||||
|
(build-global-definition s n (chi e r w mod))))
|
||||||
|
exps))
|
||||||
|
((displaced-lexical)
|
||||||
|
(syntax-violation #f "identifier out of context"
|
||||||
|
e (wrap value w mod)))
|
||||||
|
(else
|
||||||
|
(syntax-violation #f "cannot define keyword at top level"
|
||||||
|
e (wrap value w mod))))))
|
||||||
|
(else
|
||||||
|
(cons (if (eq? m 'c&e)
|
||||||
|
(let ((x (chi-expr type value e r w s mod)))
|
||||||
|
(top-level-eval-hook x mod)
|
||||||
|
x)
|
||||||
|
(lambda ()
|
||||||
|
(chi-expr type value e r w s mod)))
|
||||||
|
exps)))))))))
|
||||||
|
(let ((exps (scan body r w s m esew mod '())))
|
||||||
|
(if (null? exps)
|
||||||
|
(build-void s)
|
||||||
|
(build-sequence
|
||||||
|
s
|
||||||
|
(let lp ((in exps) (out '()))
|
||||||
|
(if (null? in) out
|
||||||
|
(let ((e (car in)))
|
||||||
|
(lp (cdr in)
|
||||||
|
(cons (if (procedure? e) (e) e) out))))))))))
|
||||||
|
|
||||||
(define chi-install-global
|
(define chi-install-global
|
||||||
(lambda (name e)
|
(lambda (name e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue