Hi<div><br></div><div>I had a bug in my compiler generator and found it difficult to trace the root of the error</div><div>I could not find something like macroexpand-1 but expands all macros</div><div><br></div><div>I wrote the following macro to do that and would like to share it (any comments are welcome)</div>
<div><br></div><div><div>? (defun expand-macros (code macros)</div><div> (labels ((%expand-macros (code)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (cond</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> ((null code) nil)</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> ((atom code) code)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> ((member (car code) macros)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (%expand-macros (macroexpand-1 code)))</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> (t</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (loop for c in code</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> collect (%expand-macros c))))))</div>
<div> (pprint (%expand-macros (macroexpand-1 code)))))</div><div>EXPAND-MACROS</div><div>? (expand-macros '(gen-guido-compiler) '(destructuring-match-specials cond-match-specials))</div><div><br></div><div>(DEFUN COMPILE/0 (EXPR &OPTIONAL (GENV (MAKE-HASH-TABLE)))</div>
<div> (DELCARE (SPECIAL X) (SPECIAL L))</div><div> (LET ((#:G28589</div><div> (BLOCK NIL</div><div> (LET* ((#:G28590 EXPR)</div><div> (N</div><div> (IF (AND (ATOM #:G28590)</div>
<div> (TYPEP #:G28590 '(UNSIGNED-BYTE 32)))</div><div> #:G28590</div><div> (RETURN-FROM NIL NIL))))</div><div> (DECLARE (SPECIAL N))</div>
<div> (PROGN (EMIT 17 *OPCODE-SIZE*) (EMIT N *WORD-SIZE*))))))</div><div> (IF (NOT (NULL #:G28589))</div><div> (PROGN (FORMAT T</div><div><div> "expression ~A matched ~A~%"</div>
<div> EXPR</div><div> '(:TYPE N '(UNSIGNED-BYTE 32)))</div><div> #:G28589)</div><div> (LET ((#:G28589</div><div> (LET ((#:G28591</div>
<div> (BLOCK NIL</div><div> (LET* ((#:G28592 EXPR)</div><div> (X</div><div> (IF (AND (ATOM #:G28592)</div><div> (TYPEP #:G28592 'SYMBOL))</div>
<div> #:G28592</div><div> (RETURN-FROM NIL NIL))))</div><div> (DECLARE (SPECIAL X))</div><div> (PROGN (EMIT 8 *OPCODE-SIZE*)</div>
<div> (EMIT (IFNULL. (CAR (GETHASH X GENV)) 0)</div><div> *WORD-SIZE*)</div><div> (EMIT 0 *WORD-SIZE*)</div><div> (EMIT 19 *OPCODE-SIZE*))))))</div>
<div> ........</div><div><br></div></div><div>Kind regatds</div><div>Taoufik</div><div><br></div></div>