[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
compilation: Expanding macros didn't do what I thought...
From: |
Rob Browning |
Subject: |
compilation: Expanding macros didn't do what I thought... |
Date: |
11 May 2001 01:04:57 -0500 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
I'm trying to create a guile function that will take a scheme form and
then expand all macros contained within it - at least all macros that
aren't "normal scheme" -- i.e. aren't stuff that hobbit would already
know about like "quote".
I thought I was making progress, but then hit a snag. The code below
works for many cases, including a syntax-case/rules definitions and
define-macro definitions, but it goes into an infinite loop if it hits
eval-case (i.e. mmacros), which get returned unaffected by
macroexpand. Now of course, I can skip them by just checking if the
output of macroexpand is eq? to the input, but that doesn't really
address the problem. I need *everything* to be expanded before I hand
the code to hobbit.
Further, I'm wondering how acros, mmacros, and macros *should* be
treated compilation-wise -- most particularly mmacros...
To some extent, I'm kind of blundering around in the dark here, which
has been kinda fun for a while, but is there any documentation really
explaining how guile's current read/expansion/evaluation process
works?
(define-module (ice-9 simple-compile)
:use-module (ice-9 syncase)
:export (compile-form))
(define internal-eval (nested-ref the-scm-module '(app modules guile eval)))
(define (expand-all-macros x)
(cond
((null? x) x)
((and (pair? x)
(symbol? (car x))
(defined? (car x))
(macro? (internal-eval (car x) (interaction-environment)))
(not (primitive-macro?
(internal-eval (car x) (interaction-environment)))))
(write (list 'expanding-macro (car x))) (newline)
(expand-all-macros (macroexpand x)))
((pair? x)
(cons (expand-all-macros (car x))
(expand-all-macros (cdr x))))
(else x)))
(export expand-all-macros)
(define (make-compilable-form x)
(let ((sc-expanded-form (if (and (pair? x)
(equal? (car x) "noexpand"))
(cadr x)
(sc-expand x))))
(expand-all-macros sc-expanded-form)))
Thanks
--
Rob Browning <address@hidden> PGP=E80E0D04F521A094 532B97F5D64E3930
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- compilation: Expanding macros didn't do what I thought...,
Rob Browning <=