[gnu.emacs] Bug fix for byte-compile

worley@EDDIE.MIT.EDU (Dale Worley) (07/13/89)

The following code seems to fix the bug in byte-compiling forms whose
function is a lambda expression.  It does so by rewriting the form
into one that uses funcall (not apply!) as the function:

	((lambda (...) body) a b c ...) => 
		(funcall '(lambda (...) byte-compiled-body) a b c ...)

It seems to work in simple cases.  There is probably a better way.

Don't forget to byte-compile the fix -- it's the inner loop of the
byte-compile functions, which are none too fast!

Dale
--
Dale Worley, Compass, Inc.                      worley@compass.com
The War on Drugs -- Prohibition for the '80s.

(defun byte-compile-form (form)
  (setq form (macroexpand form byte-compile-macro-environment))
  (cond ((eq form 'nil)
	 (byte-compile-constant form))
	((eq form 't)
	 (byte-compile-constant form))
	((symbolp form)
	 (byte-compile-variable-ref 'byte-varref form))
	((not (consp form))
	 (byte-compile-constant form))
	((eq (car-safe (car form)) 'lambda)
	 (byte-compile-form (cons
			     'funcall
			     (cons
			      (list 'quote (byte-compile-lambda (car form)))
			      (cdr form)))))
	((not (symbolp (car form)))
	 (signal 'invalid-function (list (car form))))
	(t
	 (let ((handler (get (car form) 'byte-compile)))
	   (if handler
	       (funcall handler form)
	     (byte-compile-normal-call form)))))
  (setq byte-compile-maxdepth
	(max byte-compile-maxdepth
	     (setq byte-compile-depth (1+ byte-compile-depth)))))