1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-16 00:30:21 +02:00

a different tack for syncase macro representation

* libguile/macros.c (macro_print): Show syntax-case bindings, if present.
  (macro_mark): Mark the extra two words if they're there.
  (scm_make_syncase_macro, scm_make_extended_syncase_macro): OK! A new
  take at the "how do we represent syncase macros in Guile" problem.
  Whereas we need a disjoint type, but would like it to be compatible
  with old predicates (e.g. `macro?'), and need to be able to extend
  existing syntax definitions (e.g. `cond'), let's add a bit to macros to
  indicate whether they have syncase macro bindings or not, and a fourth
  macro type for native syncase macros.
  (scm_macro_type): Return 'syntax-case for native syntax-case macros.
  Note that other macro types may have syntax-case bindings.
  (scm_macro_name): Return #f if the transformer is not a procedure.
  (scm_syncase_macro_type, scm_syncase_macro_binding): New accessors for
  the syncase macro bindings.

* libguile/macros.h: Add API for syncase macros.

* module/ice-9/boot-9.scm (module-define-keyword!): Adapt to use syncase
  macros, though they are not yet used. Reorder other syncase API.

* module/ice-9/psyntax.scm (chi-expr): Fix syntax-violation invocation.
This commit is contained in:
Andy Wingo 2009-04-29 00:38:12 +02:00
parent 5f1a2fb10f
commit 5a0132b337
5 changed files with 132 additions and 31 deletions

View file

@ -161,12 +161,13 @@
;;; Keywords are syntactic bindings; variables are value bindings.
(define (module-define-keyword! mod sym type val)
(let ((v (or (module-local-variable mod sym)
(let ((v (make-variable val)))
(let ((v (make-undefined-variable)))
(module-add! mod sym v)
v))))
(if (or (not (variable-bound? v))
(not (macro? (variable-ref v))))
(variable-set! v val))
(variable-set! v
(if (and (variable-bound? v) (macro? (variable-ref v)))
(make-extended-syncase-macro (variable-ref v) type val)
(make-syncase-macro type val)))
(set-object-property! v '*sc-expander* (cons type val))))
(define (module-lookup-keyword mod sym)
@ -180,20 +181,25 @@
;; probably should unbind the variable too
(set-object-properties! v (delq p (object-properties v)))))))
(define sc-expand #f)
(define sc-expand3 #f)
(define install-global-transformer #f)
(define $sc-dispatch #f)
;;; API provided by psyntax
(define syntax-violation #f)
(define (annotation? x) #f)
(define datum->syntax #f)
(define syntax->datum #f)
(define identifier? #f)
(define generate-temporaries #f)
(define bound-identifier=? #f)
(define free-identifier=? #f)
(define sc-expand #f)
(define sc-expand3 #f)
;;; Implementation detail of psyntax -- the thing that does expand-time
;;; dispatch for syntax-case macros
(define $sc-dispatch #f)
;;; Useless crap I'd like to get rid of
(define install-global-transformer #f)
(define (annotation? x) #f)
(define andmap
(lambda (f first . rest)
@ -213,14 +219,9 @@
(apply f (cons x xr))
(and (apply f (cons x xr)) (andmap first rest)))))))))
(define (syncase-error who format-string why what)
(%start-stack 'syncase-stack
(lambda ()
(scm-error 'misc-error who "~A ~S" (list why what) '()))))
;; Until the module system is booted, this will be the current expander.
(primitive-load-path "ice-9/psyntax-pp")
;; Until the module system is booted, this will be the current expander.
(define %pre-modules-transformer sc-expand)

File diff suppressed because one or more lines are too long

View file

@ -1167,8 +1167,8 @@
(syntax-violation #f "reference to pattern variable outside syntax form"
(source-wrap e w s mod)))
((displaced-lexical)
(syntax-violation #f (source-wrap e w s mod)
"reference to identifier outside its scope"))
(syntax-violation #f "reference to identifier outside its scope"
(source-wrap e w s mod)))
(else (syntax-violation #f "unexpected syntax"
(source-wrap e w s mod))))))