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

Re: problem in initialize-instance

Here's a patch we did for HP Common Lisp which also has a non-reentrant
compiler.  It has the nasty feature of redefining the function COMPILE, but
what it does is returns a closure that will compile the function later
(when the function is invoked at runtime and the compiler is not running)
if the compiler is currently active.  You'll need to find a way in KCL to
figure out if the compiler is running.  The flag COMPILER::*COMP-RUNNING*
does this in HP-CL.


(in-package :lisp)

(unless (fboundp 'basic-compile)
  (setf (symbol-function 'basic-compile)
	(symbol-function 'compile)))

(defun deferred-compile (name &optional definition)
  (if compiler::*comp-running*		; is the compiler running?

    ;; then return a function which not only executes the definitions, but
    ;; also compiles itself at runtime (later when the compiler is not running)
    (let* ((original-definition (or definition
                                    (symbol-function name)))
           (deferred-function #'(lambda (&rest args)
                                  (if compiler::*comp-running*
                                    (apply original-definition args)
                                    (apply (if (null definition)
					     (basic-compile name)
					     (basic-compile name definition))
      (if name
          (setf (symbol-function name) deferred-function)
    ;; else, the compiler is not running, so call the old compile function
    (if (null definition)
      (basic-compile name)
      (basic-compile name definition))))

(eval-when (eval load)
  (setf (symbol-function 'compile)
	(symbol-function 'deferred-compile)))