🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #189342

Byte Compiler Hack

#189342
From: Mark Weissman
Date: Thu, 28 Feb 1991 17:29
40 lines
2381 bytes
The following is a useful hack for working around some weak spots
in the byte compiler.  I thought it might be useful to others
so here it is.

For some files on the net it is necessary to load them before 
compiling or other such stuff.  Also, Macros which expand
into top level PROGN's don't compile in byte compiled files.

If you include the following in an emacs lisp file before compiling
it, these problems go away. 

(require;; This stuff is evaluated at load and comile time!!
 (let ((provide (make-symbol "Provide")))
   (provide provide)
   (defvar *read-from-list* nil)
   (defvar *read-recursive* nil)
   (defvar *old-eobp* (symbol-function 'eobp))
   (defvar *old-read* (symbol-function 'read))
   (defun eobp () (or *read-from-list* (funcall *old-eobp*)))
   ;; Redefine read!!
   ;; See definition byte-compile-file in "bytecomp.el" for ramifications
   ;; of this stuff.
   ;; Macroexpands read forms and treats toplevel progn forms as if they
   ;; were read forms.
   ;; When called with an argument other then the compiler input buffer,
   ;; this will revert to the old definition of read!!
   ;; Kludge... Kludge... Kludge...
   (defun read (&optional stream)
     (if (and stream (eq stream (get-buffer " *Compiler Input*")))
	 (let ((r (if *read-from-list* (pop *read-from-list*) (funcall *old-read* stream))))
	   (while (eq 'progn (car (setf r (macroexpand r byte-compile-macro-environment))))
	     (setf *read-from-list* (append (cddr r) *read-from-list*) r (cadr r)))
	   (if (and (consp r) (eq (car r) 'defmacro)) (eval r))
	   r)
       (progn
	 (setq *read-from-list* nil)
	 (fset 'read *old-read*)
	 (fset 'eobp *old-eobp*)
	 (funcall *old-read* stream))))
   provide))
Technical Details
Message-ID: <10678@bunny.GTE.COM>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!spool.mu.edu!sdd.hp.com!uakari.primate.wisc.edu!dali.cs.montana.edu!ogicse!hsdndev!bbn.com!nic!bunny!harvey.gte.com!mw06

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 103b8b,d130ffaa9e344b09,start
X-Google-Attributes: gid103b8b,public
X-Google-ArrivalTime: 1991-02-28 22:23:43 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!spool.mu.edu!sdd.hp.com!uakari.primate.wisc.edu!dali.cs.montana.edu!ogicse!hsdndev!bbn.com!nic!bunny!harvey.gte.com!mw06
From: mw06@harvey.gte.com (Mark Weissman)
Newsgroups: gnu.emacs.help
Subject: Byte Compiler Hack
Message-ID: <10678@bunny.GTE.COM>
Date: 28 Feb 91 17:29:50 GMT
Sender: news@gte.com
Reply-To: mw06@harvey.gte.com (Mark Weissman)
Organization: GTE Laboratories, Inc.
Lines: 40