diff src/eval.c @ 5615:5f4f92a31875

Move the functionality of #'cl-macroexpand into Fmacroexpand, eval.c src/ChangeLog addition: 2011-12-22 Aidan Kehoe <kehoea@parhasard.net> * eval.c (Fmacroexpand): Rename Fmacroexpand_internal, add the functionality that used to be in #'cl-macroexpand--it makes no sense for us, and needlessly slows things down, to have two separate functions. * eval.c: * eval.c (syms_of_eval): Move byte-compile-macro-environment here, now it's used by #'macroexpand. lisp/ChangeLog addition: 2011-12-22 Aidan Kehoe <kehoea@parhasard.net> * bytecomp-runtime.el: * bytecomp-runtime.el (byte-compile-macro-environment): Moved to eval.c. * cl.el: * cl.el ('cl-macroexpand): New alias. * cl.el ('macroexpand-internal): New alias. * cl.el (cl-macroexpand): Move the functionality of this to #'macroexpand (formerly #'macroexpand-internal) in eval.c; since CL is always loaded in XEmacs, it brings nothing and slows things down to have the two functions separate.
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 22 Dec 2011 12:51:03 +0000
parents 56144c8593a8
children f5315ccbf005
line wrap: on
line diff
--- a/src/eval.c	Wed Dec 21 16:54:30 2011 +0000
+++ b/src/eval.c	Thu Dec 22 12:51:03 2011 +0000
@@ -230,7 +230,7 @@
 Lisp_Object Qand_rest, Qand_optional;
 Lisp_Object Qdebug_on_error, Qstack_trace_on_error;
 Lisp_Object Qdebug_on_signal, Qstack_trace_on_signal;
-Lisp_Object Qdebugger;
+Lisp_Object Qdebugger, Qbyte_compile_macro_environment;
 Lisp_Object Qinhibit_quit;
 Lisp_Object Qfinalize_list;
 Lisp_Object Qrun_hooks;
@@ -273,7 +273,7 @@
    (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide.  */
 Lisp_Object Vautoload_queue;
 
-Lisp_Object Vmacro_declaration_function;
+Lisp_Object Vmacro_declaration_function, Vbyte_compile_macro_environment;
 
 /* Current number of specbindings allocated in specpdl.  */
 int specpdl_size;
@@ -1549,7 +1549,7 @@
 /* XEmacs: user-variable-p is in symbols.c, since it needs to mess around
    with the symbol variable aliases. */
 
-DEFUN ("macroexpand-internal", Fmacroexpand_internal, 1, 2, 0, /*
+DEFUN ("macroexpand", Fmacroexpand, 1, 2, 0, /*
 Return result of expanding macros at top level of FORM.
 If FORM is not a macro call, it is returned unchanged.
 Otherwise, the macro is expanded and the expansion is considered
@@ -1563,11 +1563,51 @@
   /* This function can GC */
   /* With cleanups from Hallvard Furuseth.  */
   REGISTER Lisp_Object expander, sym, def, tem;
+  int speccount = specpdl_depth ();
+
+  if (!NILP (environment))
+    {
+      if (NILP (Vbyte_compile_macro_environment))
+        {
+          specbind (Qbyte_compile_macro_environment, environment);
+        }
+      else
+        {
+          specbind (Qbyte_compile_macro_environment,
+                    nconc2 (Fcopy_list (environment),
+                            Vbyte_compile_macro_environment));
+          environment = Vbyte_compile_macro_environment;
+        }
+    }
 
   while (1)
     {
       /* Come back here each time we expand a macro call,
 	 in case it expands into another macro call.  */
+      if (SYMBOLP (form))
+        {
+          Lisp_Object hashed = make_integer ((EMACS_INT) (LISP_HASH (form)));
+          Lisp_Object assocked;
+
+          if (BIGNUMP (hashed))
+            {
+              struct gcpro gcpro1;
+              GCPRO1 (hashed);
+              assocked = Fassoc (hashed, environment);
+              UNGCPRO;
+            }
+          else
+            {
+              assocked = Fassq (hashed, environment);
+            }
+
+          if (CONSP (assocked) && !NILP (XCDR (assocked)))
+            {
+              form = Fcar (XCDR (assocked));
+              continue;
+            }
+        }
+
       if (!CONSP (form))
 	break;
       /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
@@ -1624,6 +1664,9 @@
 	}
       form = apply1 (expander, XCDR (form));
     }
+
+  unbind_to (speccount);
+
   return form;
 }
 
@@ -7334,6 +7377,7 @@
 
   DEFSYMBOL (Qinhibit_quit);
   DEFSYMBOL (Qautoload);
+  DEFSYMBOL (Qbyte_compile_macro_environment);
   DEFSYMBOL (Qdebug_on_error);
   DEFSYMBOL (Qstack_trace_on_error);
   DEFSYMBOL (Qdebug_on_signal);
@@ -7379,7 +7423,7 @@
   DEFSUBR (Flet);
   DEFSUBR (FletX);
   DEFSUBR (Fwhile);
-  DEFSUBR (Fmacroexpand_internal);
+  DEFSUBR (Fmacroexpand);
   DEFSUBR (Fcatch);
   DEFSUBR (Fthrow);
   DEFSUBR (Funwind_protect);
@@ -7611,6 +7655,13 @@
 */);
   Vmacro_declaration_function = Qnil;
 
+  DEFVAR_LISP ("byte-compile-macro-environment", &Vbyte_compile_macro_environment /*
+Alist of macros defined in the file being compiled.
+Each element looks like (MACRONAME . DEFINITION).  It is
+\(MACRONAME . nil) when a macro is redefined as a function.
+*/);
+  Vbyte_compile_macro_environment = Qnil;
+
   staticpro (&Vcatch_everything_tag);
   Vcatch_everything_tag = make_opaque (OPAQUE_CLEAR, 0);