cmp: Ignore compiler macros in (eval-when (:compile-toplevel))

Some of the compiler macros expand into FFI:C-INLINE forms, precluding
the compilation of statements like
  (eval-when (:compile-toplevel :load-toplevel :execute)
    (print "test")).

Commit b00e62f9d3 (now reverted)
attempted to fix this previously, but introduced other bugs (see #553).
Instead of the naive solution of evaluating everything
in (eval-when (:compile-toplevel)) directly with the bytecodes
compiler, the approach used in this commit is to be more specific and
ignore compiler macros during compile time evaluation (i.e. the output
of the compiler macro is used only in the emitted C code, but not as
input for CMP-EVAL).

Fixes #553.
This commit is contained in:
Marius Gerbershagen 2020-02-02 16:33:41 +01:00
parent 41fef66e1e
commit f1a92c422a

View file

@ -52,8 +52,14 @@
(multiple-value-setq (fd success)
(cmp-expand-macro fd form))
success))
(push 'macroexpand *current-toplevel-form*)
(t1expr* fd))
(when *compile-time-too*
;; Ignore compiler macros during compile time evaluation
;; (they may expand in ffi:c-inline which the bytecodes
;; compiler can't execute).
(cmp-eval form))
(let ((*compile-time-too* nil))
(push 'macroexpand *current-toplevel-form*)
(t1expr* fd)))
((setq fd (cmp-macro-function fun))
(push 'macroexpand *current-toplevel-form*)
(t1expr* (cmp-expand-macro fd form)))