compiler macros
authorRobin Templeton <robin@terpri.org>
Tue, 5 Aug 2014 03:11:29 +0000 (23:11 -0400)
committerRobin Templeton <robin@terpri.org>
Fri, 13 Feb 2015 00:18:54 +0000 (19:18 -0500)
module/language/elisp/boot.el
module/language/elisp/compile-tree-il.scm

index bef4c1d..fe9af29 100644 (file)
      (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)))
index b23d939..87ee486 100644 (file)
      (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)
      ((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))))))