From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sergey Mozgovoy Newsgroups: gmane.emacs.devel Subject: unwind-protect for lexical binding Date: Mon, 10 Mar 2014 20:42:59 -0700 (PDT) Message-ID: <1394509379969-316523.post@n5.nabble.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1394509386 22030 80.91.229.3 (11 Mar 2014 03:43:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 11 Mar 2014 03:43:06 +0000 (UTC) To: Emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 11 04:43:15 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WNDb1-0000Fa-CB for ged-emacs-devel@m.gmane.org; Tue, 11 Mar 2014 04:43:15 +0100 Original-Received: from localhost ([::1]:52183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNDb1-0006OP-1w for ged-emacs-devel@m.gmane.org; Mon, 10 Mar 2014 23:43:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNDat-0006O2-8j for Emacs-devel@gnu.org; Mon, 10 Mar 2014 23:43:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNDam-0000Lf-UG for Emacs-devel@gnu.org; Mon, 10 Mar 2014 23:43:07 -0400 Original-Received: from sam.nabble.com ([216.139.236.26]:35833) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNDam-0000Lb-P6 for Emacs-devel@gnu.org; Mon, 10 Mar 2014 23:43:00 -0400 Original-Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1WNDal-0007aS-Vy for Emacs-devel@gnu.org; Mon, 10 Mar 2014 20:42:59 -0700 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 216.139.236.26 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:170269 Archived-At: 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
------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 bytecode.c.diff lisp.h.diff bytecomp.el.diff byte-opt.el.diff 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.