comparison lisp/emacs-lisp/bytecomp.el @ 105337:507e3735eed8

(byte-compile-defmacro-declaration): New fun. (byte-compile-file-form-defmumble, byte-compile-defmacro): Use it. (byte-compile-defmacro): Use backquotes.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 01 Oct 2009 04:38:52 +0000
parents 12bb7892ba1d
children a3acd4b1e5cc
comparison
equal deleted inserted replaced
105336:bd4a08d4865a 105337:507e3735eed8
2427 2427
2428 (put 'defmacro 'byte-hunk-handler 'byte-compile-file-form-defmacro) 2428 (put 'defmacro 'byte-hunk-handler 'byte-compile-file-form-defmacro)
2429 (defun byte-compile-file-form-defmacro (form) 2429 (defun byte-compile-file-form-defmacro (form)
2430 (byte-compile-file-form-defmumble form t)) 2430 (byte-compile-file-form-defmumble form t))
2431 2431
2432 (defun byte-compile-defmacro-declaration (form)
2433 "Generate code for declarations in macro definitions.
2434 Remove declarations from the body of the macro definition
2435 by side-effects."
2436 (let ((tail (nthcdr 2 form))
2437 (res '()))
2438 (when (stringp (car (cdr tail)))
2439 (setq tail (cdr tail)))
2440 (while (and (consp (car (cdr tail)))
2441 (eq (car (car (cdr tail))) 'declare))
2442 (let ((declaration (car (cdr tail))))
2443 (setcdr tail (cdr (cdr tail)))
2444 (push `(if macro-declaration-function
2445 (funcall macro-declaration-function
2446 ',(car (cdr form)) ',declaration))
2447 res)))
2448 res))
2449
2432 (defun byte-compile-file-form-defmumble (form macrop) 2450 (defun byte-compile-file-form-defmumble (form macrop)
2433 (let* ((bytecomp-name (car (cdr form))) 2451 (let* ((bytecomp-name (car (cdr form)))
2434 (bytecomp-this-kind (if macrop 'byte-compile-macro-environment 2452 (bytecomp-this-kind (if macrop 'byte-compile-macro-environment
2435 'byte-compile-function-environment)) 2453 'byte-compile-function-environment))
2436 (bytecomp-that-kind (if macrop 'byte-compile-function-environment 2454 (bytecomp-that-kind (if macrop 'byte-compile-function-environment
2496 (nth 1 form)))) 2514 (nth 1 form))))
2497 2515
2498 ;; Generate code for declarations in macro definitions. 2516 ;; Generate code for declarations in macro definitions.
2499 ;; Remove declarations from the body of the macro definition. 2517 ;; Remove declarations from the body of the macro definition.
2500 (when macrop 2518 (when macrop
2501 (let ((tail (nthcdr 2 form))) 2519 (dolist (decl (byte-compile-defmacro-declaration form))
2502 (when (stringp (car (cdr tail))) 2520 (prin1 decl bytecomp-outbuffer)))
2503 (setq tail (cdr tail)))
2504 (while (and (consp (car (cdr tail)))
2505 (eq (car (car (cdr tail))) 'declare))
2506 (let ((declaration (car (cdr tail))))
2507 (setcdr tail (cdr (cdr tail)))
2508 (prin1 `(if macro-declaration-function
2509 (funcall macro-declaration-function
2510 ',bytecomp-name ',declaration))
2511 bytecomp-outbuffer)))))
2512 2521
2513 (let* ((new-one (byte-compile-lambda (nthcdr 2 form) t)) 2522 (let* ((new-one (byte-compile-lambda (nthcdr 2 form) t))
2514 (code (byte-compile-byte-code-maker new-one))) 2523 (code (byte-compile-byte-code-maker new-one)))
2515 (if bytecomp-this-one 2524 (if bytecomp-this-one
2516 (setcdr bytecomp-this-one new-one) 2525 (setcdr bytecomp-this-one new-one)
4001 (byte-compile-constant (nth 1 form))) 4010 (byte-compile-constant (nth 1 form)))
4002 4011
4003 (defun byte-compile-defmacro (form) 4012 (defun byte-compile-defmacro (form)
4004 ;; This is not used for file-level defmacros with doc strings. 4013 ;; This is not used for file-level defmacros with doc strings.
4005 (byte-compile-body-do-effect 4014 (byte-compile-body-do-effect
4006 (list (list 'fset (list 'quote (nth 1 form)) 4015 (let ((decls (byte-compile-defmacro-declaration form))
4007 (let ((code (byte-compile-byte-code-maker 4016 (code (byte-compile-byte-code-maker
4008 (byte-compile-lambda (cdr (cdr form)) t)))) 4017 (byte-compile-lambda (cdr (cdr form)) t))))
4009 (if (eq (car-safe code) 'make-byte-code) 4018 `((defalias ',(nth 1 form)
4010 (list 'cons ''macro code) 4019 ,(if (eq (car-safe code) 'make-byte-code)
4011 (list 'quote (cons 'macro (eval code)))))) 4020 `(cons 'macro ,code)
4012 (list 'quote (nth 1 form))))) 4021 `'(macro . ,(eval code))))
4022 ,@decls
4023 ',(nth 1 form)))))
4013 4024
4014 (defun byte-compile-defvar (form) 4025 (defun byte-compile-defvar (form)
4015 ;; This is not used for file-level defvar/consts with doc strings. 4026 ;; This is not used for file-level defvar/consts with doc strings.
4016 (let ((fun (nth 0 form)) 4027 (let ((fun (nth 0 form))
4017 (var (nth 1 form)) 4028 (var (nth 1 form))