;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:8; Patch-File:T -*-
;;; Patch file for System version 126.109
;;; Reason:
;;;  EXPAND-MACRO-CALL changed so that cross compilation will not use local
;;;  SUBSTs on the compiling machine.  MACROs from the compiling machine
;;;  are still used with a warning, if there is no macro for the target.
;;; Written 14-Oct-88 18:50:09 by smh at site Gigamos Cambridge
;;; while running on Alex from band 4
;;; with Experimental System 126.105, Experimental ZWEI 126.19, Experimental ZMail 74.9, Experimental Local-File 76.0, Experimental File-Server 25.0, Experimental Unix-Interface 15.0, Experimental Tape 26.4, Experimental Lambda-Diag 18.0, microcode 1762, SDU Boot Tape 3.14, SDU ROM 102, 10/4.



; From modified file DJ: L.SYS; QFCTNS.LISP#857 at 14-Oct-88 18:50:10
#8R SYSTEM-INTERNALS#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "SYSTEM-INTERNALS")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: SYS; QFCTNS  "

(defun expand-macro-call (macro-call environment expand-substs &key inhibitor macro-function-finder)
  (declare (values expansion expanded-flag))
  (if (atom macro-call) macro-call
    (let ((name (car macro-call))
	  (out-of-this-world nil))
      (cond ((not (atom name))
	     (cond ((eq (caar macro-call) 'curry-after)
		    (values `(,(cadar macro-call) ,@(cdr macro-call) . ,(cddar macro-call))
			    t))
		   ((eq (caar macro-call) 'curry-before)
		    (values `(,(cadar macro-call) ,@(cddar macro-call) . ,(cdr macro-call))
			    t))
		   ;; Have to ignore EXPAND-SUBSTS here since compiler can't deal with ((SUBST ...) ...)
		   ((memq (caar macro-call) '(subst cli:subst named-subst))
		    (values (funcall *macroexpand-hook* 'subst-expand-1 macro-call environment)
			    t))
		   (t macro-call)))
	    ((not (symbolp name)) macro-call)
	    (t
	     (let ((tm (fsymeval-in-environment name environment nil)))
	       (cond (tm ; local definition
		      (if (eq (car-safe tm) 'macro)
			  (call-macro-expander (cdr tm) macro-call environment)
			macro-call))
		     ;; Possibly inhibit macro expansion.
		     ((and inhibitor (funcall inhibitor name)) macro-call)
		     ((and macro-function-finder (setq tm (funcall macro-function-finder name)))
		      (record-macro-expanded name)
		      (values (call-macro-expander tm macro-call environment)
			      t))
		     (t
		      (multiple-value-setq (tm out-of-this-world) (declared-definition name))
		      (cond ((typep tm 'compiled-function)	; Possible compiler-defined subst
			     (if expand-substs
				 (if out-of-this-world		;||| Cross compiler ignores native SUBSTs - 14oct smh
				     (progn
				       (compiler:warn 'cross-compilation :NOT-PORTABLE
					 "Cross compilation for ~s ignoring ~s subst definition from ~s host."
					 compiler:*target-computer* name compiler:*host-computer*)
				       macro-call)
				   (progn
				     ;; If function is compiled, see if its interpreted defn is recorded.
				     (setq tm (assq 'interpreted-definition (debugging-info tm)))
				     (if (and tm (memq (caadr tm) '(subst cli:subst named-subst)))
					 (progn
					   (record-macro-expanded name)
					   (values (funcall *macroexpand-hook* 'subst-expand-1 macro-call environment)
						   t))
				       macro-call)))			       
			       macro-call))
			    ((atom tm) macro-call) ; ordinary function
			    ((eq (car tm) 'macro)
			     (when out-of-this-world
			       (compiler:warn 'cross-compilation :NOT-PORTABLE
				 "Cross compilation for ~s taking ~s macro definition from ~s host."
				 compiler:*target-computer* name compiler:*host-computer*))
			     (record-macro-expanded name)
			     (values (call-macro-expander (cdr tm) macro-call environment) t))
			    ((memq (car tm) '(subst cli:subst named-subst)) ; interpreter-defined SUBST
			     (if expand-substs
				 (if out-of-this-world		;||| Cross compiler ignores native SUBSTs - 14oct smh
				     (progn
				       (compiler:warn 'cross-compilation :NOT-PORTABLE
					 "Cross compilation for ~s ignoring ~s subst definition from ~s host."
					 compiler:*target-computer* name compiler:*host-computer*)
				       macro-call)
				   (progn
				     (record-macro-expanded name)
				     (values (funcall *macroexpand-hook* 'subst-expand-1 macro-call environment)
					     t)))
			       macro-call))
			    (t macro-call)))
		     (t macro-call))))))))

))
