kawa-commonlisp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Kawa-commonlisp-dev] tagbodies


From: Helmut Eller
Subject: Re: [Kawa-commonlisp-dev] tagbodies
Date: Thu, 26 Jul 2012 21:13:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

On Thu, Jul 26 2012, Charles Turner wrote:

> Most other Lisps use tag bodies quite heavily in some of the system
> functions, SBCL has this in its parse-body routine:
>
> (tagbody
>        :again
>        (if forms
>            (let ((form1 (first forms)))
>              ;; Note: The (IF (IF ..) ..) stuff is because we don't
>              ;; have the macro AND yet.:-|
>              (if (doc-string-p form1 (rest forms))
>                  (setq doc form1)
>                (if (declaration-p form1)
>                    (setq reversed-decls
>                          (cons form1 reversed-decls))
>                  (go :done)))
>              (setq forms (rest forms))
>              (go :again)))
>        :done)
>       (values forms
>               (nreverse reversed-decls)
>               doc))))
>
> I'm sure there's a way to reformulate this without the goto's, maybe
> something like

State machines can be written with LABELS and (local) tail-calls.  Kawa
should recognize those and implement them with gotos.  E.g.

(labels ((again () 
          ...
          (if (declaration-p form1)
              (done)
              (again)))
         (done ()
           (values ...)))
     (again))

>
>       (let ((end-test nil))
>       (do ((form-iter forms (cdr form-iter)))
>           (end-test (values forms (reverse reversed-decls) doc))
>         (if form-iter
>             (let ((form1 (car form-iter)))
>               (if (doc-string-p form1 (cdr form-iter))
>                   (setq doc form1)
>                   (if (declaration-p form1)
>                       (setq reversed-decls
>                             (cons form1 reversed-decls))
>                       (setq end-test t)))))))
>
> (haven't tested that)
>
> but I'm wondering if these sorts of kludges are worth it? 

I think implementing TAGBODY now is a bit of a distraction and messaging
the source into LABELS isn't that hard.

> How hard would it be to implement TAGBODY?  Seems like I could just
> use BlockExp to do it.

In general you need to do a modicum of escape analysis before you can
turn it into BlockExp.  E.g.

(tagbody :foo (bar (lambda () (go :foo))))

needs something like block/return or similar.  There's a paper by Henry
Baker that shows some ideas how tagbody can be emulated in terms of
other special forms: http://home.pipeline.com/~hbaker1/MetaCircular.html

I'm not sure how good Kawa is at analyzing escaping continuations so a
naive translation might allocate continuations even in the simple cases.

One day we will clearly need tagbody and block/return but let's do that
later.

> Implementations also use MACROLET quite a bit
> too, but I'm not sure how to approach that. There's also docstrings..!

Let's not get ahead of ourselves.

> Frankly, I'm loosing my way a bit here in terms of what my goals
> should be, I'm spending a lot of time on just trying to port code from
> SBCL, and I don't feel like I'm making good progress.

Porting DESTRUCTURING-BIND from SBCL seems like the right thing to me.
But you don't need to fix Kawa so that the code runs unmodified.  If the
code uses some exotic features, like that &key ((foo bar)) bit, I would
rewrite that before fixing the compiler.

> DESTRUCTURING-BIND was the goal, but I've pushed several things on my
> todo stack before that can be implemented. Apologies for
> disorientation! I'm still struggling with the whole "what should I
> implement to the spec, what should I skim over to fix later".

So what still on the TODO stack?

You've already done a lot to make &optional/&key work for normal lambdas.
Do you have some test cases for that?  Should it be reviewed?

Helmut



reply via email to

[Prev in Thread] Current Thread [Next in Thread]