mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-28 22:10:29 +02:00
compiler macros
(Best-ability ChangeLog annotation added by Christine Lemmer-Webber.) * module/language/elisp/boot.el (%define-compiler-macro): New macro. * module/language/elisp/compile-tree-il.scm: New function. (compile-pair): Update to handle %compiler-macro condition.
This commit is contained in:
parent
c8f94d3917
commit
8dcb633909
2 changed files with 24 additions and 0 deletions
|
@ -41,6 +41,18 @@
|
|||
(eval-when-compile ,@body)
|
||||
(progn ,@body)))
|
||||
|
||||
(defmacro %define-compiler-macro (name args &rest body)
|
||||
`(eval-and-compile
|
||||
(%funcall
|
||||
(@ (language elisp runtime) set-symbol-plist!)
|
||||
',name
|
||||
(%funcall
|
||||
(@ (guile) cons*)
|
||||
'%compiler-macro
|
||||
#'(lambda ,args ,@body)
|
||||
(%funcall (@ (language elisp runtime) symbol-plist) ',name)))
|
||||
',name))
|
||||
|
||||
(eval-and-compile
|
||||
(defun eval (form)
|
||||
(%funcall (@ (language elisp runtime) eval-elisp) form)))
|
||||
|
|
|
@ -788,6 +788,11 @@
|
|||
(make-void loc))
|
||||
(else (report-error loc "bad %set-lexical-binding-mode" args))))
|
||||
|
||||
(define (eget s p)
|
||||
(if (symbol-fbound? 'get)
|
||||
((symbol-function 'get) s p)
|
||||
#nil))
|
||||
|
||||
;;; Compile a compound expression to Tree-IL.
|
||||
|
||||
(define (compile-pair loc expr)
|
||||
|
@ -800,6 +805,13 @@
|
|||
((find-operator operator 'macro)
|
||||
=> (lambda (macro-function)
|
||||
(compile-expr (apply macro-function arguments))))
|
||||
((and (symbol? operator)
|
||||
(eget operator '%compiler-macro))
|
||||
=> (lambda (compiler-macro-function)
|
||||
(let ((new (compiler-macro-function expr)))
|
||||
(if (eq? new expr)
|
||||
(compile-expr `(%funcall (%function ,operator) ,@arguments))
|
||||
(compile-expr new)))))
|
||||
(else
|
||||
(compile-expr `(%funcall (%function ,operator) ,@arguments))))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue