unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: syntax-local-value patch for discussion
Date: Sat, 14 Jan 2012 17:42:58 +0100	[thread overview]
Message-ID: <CAGua6m1EaQWF1_EJe6JJzwsj7k_28wvViXh3foBGZLeL_RyxUQ@mail.gmail.com> (raw)
In-Reply-To: <87fwfq6m5x.fsf@netris.org>

[-- Attachment #1: Type: text/plain, Size: 4328 bytes --]

Ok, I have tried follow your suggestion,
here is what I could make,

        (with-fluids ((*macro-lookup*
                       (lambda (e)
                         (cond
                          ((number? e)
                           (pk w))

                          ((symbol? e)
                           (lookup (id-var-name e w)
                                   r mod))

                          ((syntax-object? e)
                           (lookup (id-var-name
                                    (syntax-object-expression e)
                                    (syntax-object-wrap e))
                                   r
                                   (or
                                    (syntax-object-module e)
                                    mod)))
                          (else #f)))))

just look at the syntax-object? part for now. You will see that I only use
syntax-object-wrap and not the joining with w which fails when I try to do
that using e.g.
 ((syntax-object? e)
          (syntax-type (syntax-object-expression e)
                       r
                       (join-wraps w (syntax-object-wrap e))
                       (or (source-annotation e) s) rib
                       (or (syntax-object-module e) mod) for-car?))

which is the syntax? part of the syntax-type function. Hence I tried
(join-wraps w (syntax-object-wrap e))

but that does not work.

comments?

/Stefan

On Sun, Jan 8, 2012 at 8:15 PM, Mark H Weaver <mhw@netris.org> wrote:

> Hi Stefan,
>
> Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:
> > diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm
> > index e522f54..70463a5 100644
> > --- a/module/ice-9/psyntax.scm
> > +++ b/module/ice-9/psyntax.scm
> > @@ -155,6 +155,10 @@
> >  (eval-when (compile)
> >    (set-current-module (resolve-module '(guile))))
> >
> > +(define *macro-lookup* (make-fluid))
> > +(fluid-set! *macro-lookup*
> > +            (lambda x (error "not in a macro evaluation context")))
> > +
> >  (let ()
> >    (define-syntax define-expansion-constructors
> >      (lambda (x)
> > @@ -1304,8 +1308,12 @@
> >                     (syntax-violation #f "encountered raw symbol in
> macro output"
> >                                       (source-wrap e w (wrap-subst w)
> mod) x))
> >                    (else (decorate-source x s)))))
> > -        (rebuild-macro-output (p (source-wrap e (anti-mark w) s mod))
> > -                              (new-mark))))
> > +        (with-fluids ((*macro-lookup*
> > +                       (lambda (e) (lookup (id-var-name e w)
> > +                                           r mod))))
> > +
> > +          (rebuild-macro-output (p (source-wrap e (anti-mark w) s mod))
> > +                                (new-mark)))))
> >
> >      (define expand-body
> >        ;; In processing the forms of the body, we create a new, empty
> wrap.
>
> This doesn't look quite right to me.
>
> At this one point only, where a macro is expanded, you capture the
> lexical environment (r w mod) in your fluid.  This is the lexical
> environment that you use to lookup plain symbols later passed to
> `syntax-binding-info'.
>
> Will this approach will be robust in the general case?  For example,
> what happens if you use a macro in one module to generate a macro in
> another module that uses syntax-binding-info on a syntax object that
> came from yet another module?
>
> A few suggestions:
>
> First, as others have pointed out, you should be passing syntax-objects
> to `syntax-binding-info' instead of plain symbols.  This one change
> alone will make this code far robust, because syntax-objects include
> their own wrap and module.
>
> Second, in your call to `lookup', you should pass the module that came
> from the syntax-object, instead of the module captured from the most
> recent macro expansion.  Please take a look at how psyntax's internal
> procedure `syntax-type' looks up syntax-objects (compared with how it
> looks up plain symbols).  I think you should emulate that logic.
>
> Third, are you sure that the `r' captured from the most recent macro
> expansion will be recent enough in all cases to include the binding
> that's being queried?  `r' is extended in quite a few places in psyntax,
> for various different binding constructs.
>
>      Best,
>       Mark
>

[-- Attachment #2: Type: text/html, Size: 5144 bytes --]

  parent reply	other threads:[~2012-01-14 16:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-05 18:12 syntax-local-value patch for discussion Stefan Israelsson Tampe
2011-12-08 21:58 ` Ian Price
2011-12-09 11:49   ` Stefan Israelsson Tampe
2012-01-07  0:05 ` Andy Wingo
2012-01-08 17:47   ` Stefan Israelsson Tampe
2012-01-08 19:15 ` Mark H Weaver
2012-01-08 21:28   ` Stefan Israelsson Tampe
2012-01-14 16:42   ` Stefan Israelsson Tampe [this message]
2012-01-19  9:50     ` Stefan Israelsson Tampe
2012-01-23 10:53       ` Andy Wingo
2012-01-23 16:06         ` Stefan Israelsson Tampe
2012-01-26 11:31           ` Andy Wingo
2012-01-26 15:49             ` Stefan Israelsson Tampe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGua6m1EaQWF1_EJe6JJzwsj7k_28wvViXh3foBGZLeL_RyxUQ@mail.gmail.com \
    --to=stefan.itampe@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).