unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* unwind-protect for lexical binding
@ 2014-03-11  3:42 Sergey Mozgovoy
  2014-03-11 17:21 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Sergey Mozgovoy @ 2014-03-11  3:42 UTC (permalink / raw)
  To: Emacs-devel

I propose a patch for Emacs 24.3 that implements a new byte code for
unwind-protect which is more friendly for lexical scope.

100  lex-unwind-protect <address>   ------o
103  {protection body}                            |
...    .................                                   |
176  byte-return                                    |
177  {protected-form}        <------------------o
...    ..................
217  byte-unbind 1
...    ..................


This works as shown above: execution of `unwind-protect' starts with
retaining where the protection body is and jumping to the protected
form.  When unwinding, the remembered element is popped off the
specpdl stack, and a call into the necessary spot inside the bytecode
string is made.

I'll be very thankful to see any comments and thoughts on this idea.

Unfortunately, for this aproach to work I had to disable some
byte-level optimizations in `byte-opt.el' -- namely, the
`byte-after-unbind-ops' variable and the corresponding trick which
moves some bytecodes past an `unbind'.

Here's a list of patched files:

alloc.c.diff <http://emacs.1067599.n5.nabble.com/file/n316523/alloc.c.diff>  
bytecode.c.diff
<http://emacs.1067599.n5.nabble.com/file/n316523/bytecode.c.diff>  
lisp.h.diff <http://emacs.1067599.n5.nabble.com/file/n316523/lisp.h.diff>  
bytecomp.el.diff
<http://emacs.1067599.n5.nabble.com/file/n316523/bytecomp.el.diff>  
byte-opt.el.diff
<http://emacs.1067599.n5.nabble.com/file/n316523/byte-opt.el.diff>  
cconv.el.diff
<http://emacs.1067599.n5.nabble.com/file/n316523/cconv.el.diff>  

---
Best regards,
Sergey Mozgovoy.



--
View this message in context: http://emacs.1067599.n5.nabble.com/unwind-protect-for-lexical-binding-tp316523.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: unwind-protect for lexical binding
  2014-03-11  3:42 unwind-protect for lexical binding Sergey Mozgovoy
@ 2014-03-11 17:21 ` Stefan Monnier
  2014-03-11 20:09   ` Sergey Mozgovoy
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2014-03-11 17:21 UTC (permalink / raw)
  To: Sergey Mozgovoy; +Cc: Emacs-devel

> I propose a patch for Emacs 24.3 that implements a new byte code for
> unwind-protect which is more friendly for lexical scope.

> 100  lex-unwind-protect <address>   ------o
> 103  {protection body}                            |
> ...    .................                                   |
> 176  byte-return                                    |
> 177  {protected-form}        <------------------o
> ...    ..................
> 217  byte-unbind 1
> ...    ..................

Have you looked at the trunk version of bytecode.c ?
I added some byte-codes for the same problem a few months ago (to make
the byte-compiler use them, set byte-compile--use-old-handlers to nil).


        Stefan



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: unwind-protect for lexical binding
  2014-03-11 17:21 ` Stefan Monnier
@ 2014-03-11 20:09   ` Sergey Mozgovoy
  2014-03-12 13:20     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Sergey Mozgovoy @ 2014-03-11 20:09 UTC (permalink / raw)
  To: Emacs-devel

Stefan Monnier wrote
> Have you looked at the trunk version of bytecode.c ?

No, I haven't. I implemented this thing about a half a year ago,
and this is the first time I tried to make it public. Seems to
be too late :)




--
View this message in context: http://emacs.1067599.n5.nabble.com/unwind-protect-for-lexical-binding-tp316523p316572.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: unwind-protect for lexical binding
  2014-03-11 20:09   ` Sergey Mozgovoy
@ 2014-03-12 13:20     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2014-03-12 13:20 UTC (permalink / raw)
  To: Sergey Mozgovoy; +Cc: Emacs-devel

>> Have you looked at the trunk version of bytecode.c ?
> No, I haven't. I implemented this thing about a half a year ago,
> and this is the first time I tried to make it public.  Seems to
> be too late :)

Well, the new opcodes are pretty much unused so far (since the default
for byte-compile--use-old-handlers is t) and 24.4 is not yet released,
so if you find some problem with the new opcodes, it's not too late.


        Stefan



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-12 13:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-11  3:42 unwind-protect for lexical binding Sergey Mozgovoy
2014-03-11 17:21 ` Stefan Monnier
2014-03-11 20:09   ` Sergey Mozgovoy
2014-03-12 13:20     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).