;;; -*- Mode:LISP; Package:LISP-INTERNALS; Base:10; Readtable:CL -*-
;;;
;;; HOT-BOOT.LISP
;;;
;;; (li::hot-boot) is called after the evaluator is loaded.  It does the 
;;; following:
;;;    [1] Installs the definitions of DEFVAR, DEFUN, etc., the hard way.
;;;    [2] Evaluates the forms on k2::*cold-eval-list* and k2::*warm-eval-list*
;;;    [3] Informs the fasloader that the evaluator is available.

;;+++ It should also call new-math:init-float.   --wkf

(defun hot-boot ()
  (install-top-level-macros)
  (eval '(DEFVAR SETF::*GRODY-SETF-MACRO-TABLE* NIL))
  (map-eval-onto-list (censor-and-reverse-list k2::*warm-eval-list*))
  (eval '(DEFVAR *EVALUATOR-AVAILABLE?* T))
  )

(defun install-top-level-macros ()
  (setf (symbol-function 'DEFUN)
	(symbol-function 'DEFUN-K))
  (setf (symbol-function 'DEFVAR)
	(symbol-function 'DEFVAR-K))
  (setf (symbol-function 'DEFPARAMETER)
	(symbol-function 'DEFPARAMETER-K))
  (setf (symbol-function 'DEFCONSTANT)
	(symbol-function 'DEFCONSTANT-K)))
				      
(defun map-eval-onto-list (list)
  (dolist (form list)
    (eval-special-ok form)))

(defun censor-and-reverse-list (list)
  "Remove anything from LIST that the evaluator will barf on, and 
also reverse it."
  (let ((censored-list nil))
    (dolist (form list)
      (unless (or (bogus-compiler-form? form)
		  (export-form? form)
		  (defmacro-form? form)
		  (contains-big-number? form))
	(push form censored-list)))
    censored-list))

;;; These predicates detect forms which can cause evaluator barfage.
;;;
(defun bogus-compiler-form? (form)
  (and (consp form)
       (symbolp (car form))
       (string= (package-name (symbol-package (car form)))
		"NC")))

(defun export-form? (form)
  (and (consp form)
       (eq (car form) 'EXPORT)))

(defun defmacro-form? (form)
  (and (consp form)
       (eq (car form) 'DEFMACRO)))

(defun contains-big-number? (form)
  (and (consp form)
       (eq (car form) 'DEFCONSTANT)
       (eq (cadr form) 'MOST-NEGATIVE-FIXNUM)))

