[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 21/36: compiler macros
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 21/36: compiler macros |
Date: |
Fri, 25 Mar 2016 20:03:47 +0000 |
cwebber pushed a commit to branch wip-elisp
in repository guile.
commit bf142ba6afbec5b724392108a7cf6122bd794ff4
Author: Robin Templeton <address@hidden>
Date: Mon Aug 4 23:11:29 2014 -0400
compiler macros
(Best-ability ChangeLog annotation added by Christopher Allan 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.
---
module/language/elisp/boot.el | 12 ++++++++++++
module/language/elisp/compile-tree-il.scm | 12 ++++++++++++
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/module/language/elisp/boot.el b/module/language/elisp/boot.el
index bef4c1d..fe9af29 100644
--- a/module/language/elisp/boot.el
+++ b/module/language/elisp/boot.el
@@ -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)))
diff --git a/module/language/elisp/compile-tree-il.scm
b/module/language/elisp/compile-tree-il.scm
index b23d939..87ee486 100644
--- a/module/language/elisp/compile-tree-il.scm
+++ b/module/language/elisp/compile-tree-il.scm
@@ -782,6 +782,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)
@@ -794,6 +799,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))))))
- [Guile-commits] 12/36: defvar affects default value, (continued)
- [Guile-commits] 12/36: defvar affects default value, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 11/36: symbol default value procedures, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 14/36: define-module for elisp special modules, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 16/36: fix symbol-function, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 13/36: constant-interning fix, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 15/36: restore special operator handling, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 17/36: fix `nil?' type inference, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 18/36: compile-elisp fn, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 19/36: elisp @@ macro, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 20/36: defconst, defvar: proclaim special at compile-time, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 21/36: compiler macros,
Christopher Allan Webber <=
- [Guile-commits] 22/36: defsubst, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 23/36: use defsubst, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 24/36: fset macro, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 25/36: eval-when, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 26/36: degenerate let forms, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 27/36: only evaluate top-level macro definitions, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 28/36: top level fixes, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 29/36: execute top level require forms, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 31/36: use guile eval for elisp tree-il, Christopher Allan Webber, 2016/03/25
- [Guile-commits] 30/36: deprecated eval-when situations, Christopher Allan Webber, 2016/03/25