mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-17 20:12:24 +02:00
store macro definitions in the function slot
Guile Emacs Lisp previously kept macros in a separate macro slot; now macros are stored as macro objects in the function slot for compatibility with other implementations. * module/language/elisp/compile-tree-il.scm (macro-slot): Remove. (is-macro?): Check that the argument is a symbol. Now-unnecessary check removed in `compile-tree-il'. (macro?, define-macro!, get-macro): Store macro definitions in the function slot, not in a separate macro slot. * module/language/elisp/runtime.scm (built-in-macro): Wrap the macro function in a macro object (i.e., cons the symbol `macro' onto it). * module/language/elisp/runtime/function-slot.scm: Move contents to "subrs.scm". Re-export function and macro definitions instead of defining functions directly in this module. * module/language/elisp/runtime/macro-slot.scm: Move contents to "macros.scm" and remove. * module/language/elisp/runtime/macros.scm: New file containing macro definitions from "macro-slot.scm". * module/language/elisp/runtime/subrs.scm: New file containing function definitions from "function-slot.scm".
This commit is contained in:
parent
88698140c0
commit
c55a2ddc1b
5 changed files with 451 additions and 352 deletions
|
@ -69,8 +69,6 @@
|
|||
|
||||
(define runtime '(language elisp runtime))
|
||||
|
||||
(define macro-slot '(language elisp runtime macro-slot))
|
||||
|
||||
(define value-slot (@ (language elisp runtime) value-slot-module))
|
||||
|
||||
(define function-slot (@ (language elisp runtime) function-slot-module))
|
||||
|
@ -543,18 +541,21 @@
|
|||
;;; Handle macro bindings.
|
||||
|
||||
(define (is-macro? sym)
|
||||
(module-defined? (resolve-interface macro-slot) sym))
|
||||
(and
|
||||
(symbol? sym)
|
||||
(module-defined? (resolve-interface function-slot) sym)
|
||||
(let ((macro (module-ref (resolve-module function-slot) sym)))
|
||||
(and (pair? macro) (eq? (car macro) 'macro)))))
|
||||
|
||||
(define (define-macro! loc sym definition)
|
||||
(let ((resolved (resolve-module macro-slot)))
|
||||
(if (is-macro? sym)
|
||||
(report-error loc "macro is already defined" sym)
|
||||
(begin
|
||||
(module-define! resolved sym definition)
|
||||
(module-export! resolved (list sym))))))
|
||||
(let ((resolved (resolve-module function-slot)))
|
||||
(module-define! resolved sym (cons 'macro definition))
|
||||
(module-export! resolved (list sym))))
|
||||
|
||||
(define (get-macro sym)
|
||||
(module-ref (resolve-module macro-slot) sym))
|
||||
(and
|
||||
(is-macro? sym)
|
||||
(cdr (module-ref (resolve-module function-slot) sym))))
|
||||
|
||||
;;; See if a (backquoted) expression contains any unquotes.
|
||||
|
||||
|
@ -876,9 +877,8 @@
|
|||
|
||||
;; Macro calls are simply expanded and recursively compiled.
|
||||
|
||||
((,macro . ,args) (guard (and (symbol? macro) (is-macro? macro)))
|
||||
(let ((expander (get-macro macro)))
|
||||
(compile-expr (apply expander args))))
|
||||
((,macro . ,args) (guard (is-macro? macro))
|
||||
(compile-expr (apply (get-macro macro) args)))
|
||||
|
||||
;; Function calls using (function args) standard notation; here, we
|
||||
;; have to take the function value of a symbol if it is one. It
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue