Fix compiler-macro interaction with LOAD-TIME-VALUE and CONSTANTP.
When CONSTANTP is supplied an &environment object from the compiler macro it can determine forms involving MACROLET to be constant, but such forms are problematic for LOAD-TIME-VALUE and its null lexical environment execution requirements.
This commit is contained in:
30
api.lisp
30
api.lisp
@ -277,9 +277,11 @@ internal purposes."))
|
||||
(values (car match) (cdr match) reg-starts reg-ends))))))
|
||||
|
||||
#-:cormanlisp
|
||||
(define-compiler-macro scan (&whole form &environment env regex target-string &rest rest)
|
||||
(define-compiler-macro scan (&whole form regex target-string &rest rest)
|
||||
"Make sure that constant forms are compiled into scanners at compile time."
|
||||
(cond ((constantp regex env)
|
||||
;; Don't pass &environment to CONSTANTP, it may not be digestable by
|
||||
;; LOAD-TIME-VALUE, e.g., MACROLETs.
|
||||
(cond ((constantp regex)
|
||||
`(scan (load-time-value (create-scanner ,regex))
|
||||
,target-string ,@rest))
|
||||
(t form)))
|
||||
@ -311,9 +313,9 @@ share structure with TARGET-STRING."
|
||||
|
||||
#-:cormanlisp
|
||||
(define-compiler-macro scan-to-strings
|
||||
(&whole form &environment env regex target-string &rest rest)
|
||||
(&whole form regex target-string &rest rest)
|
||||
"Make sure that constant forms are compiled into scanners at compile time."
|
||||
(cond ((constantp regex env)
|
||||
(cond ((constantp regex)
|
||||
`(scan-to-strings (load-time-value (create-scanner ,regex))
|
||||
,target-string ,@rest))
|
||||
(t form)))
|
||||
@ -524,10 +526,10 @@ the scan is continued one position behind this match."
|
||||
(push match-end result-list))))
|
||||
|
||||
#-:cormanlisp
|
||||
(define-compiler-macro all-matches (&whole form &environment env regex &rest rest)
|
||||
(define-compiler-macro all-matches (&whole form regex &rest rest)
|
||||
"Make sure that constant forms are compiled into scanners at
|
||||
compile time."
|
||||
(cond ((constantp regex env)
|
||||
(cond ((constantp regex)
|
||||
`(all-matches (load-time-value (create-scanner ,regex))
|
||||
,@rest))
|
||||
(t form)))
|
||||
@ -547,10 +549,10 @@ share structure with TARGET-STRING."
|
||||
(push match result-list))))
|
||||
|
||||
#-:cormanlisp
|
||||
(define-compiler-macro all-matches-as-strings (&whole form &environment env regex &rest rest)
|
||||
(define-compiler-macro all-matches-as-strings (&whole form regex &rest rest)
|
||||
"Make sure that constant forms are compiled into scanners at
|
||||
compile time."
|
||||
(cond ((constantp regex env)
|
||||
(cond ((constantp regex)
|
||||
`(all-matches-as-strings
|
||||
(load-time-value (create-scanner ,regex))
|
||||
,@rest))
|
||||
@ -628,9 +630,9 @@ structure with TARGET-STRING."
|
||||
nil)))))
|
||||
|
||||
#-:cormanlisp
|
||||
(define-compiler-macro split (&whole form &environment env regex target-string &rest rest)
|
||||
(define-compiler-macro split (&whole form regex target-string &rest rest)
|
||||
"Make sure that constant forms are compiled into scanners at compile time."
|
||||
(cond ((constantp regex env)
|
||||
(cond ((constantp regex)
|
||||
`(split (load-time-value (create-scanner ,regex))
|
||||
,target-string ,@rest))
|
||||
(t form)))
|
||||
@ -996,9 +998,9 @@ match.
|
||||
|
||||
#-:cormanlisp
|
||||
(define-compiler-macro regex-replace
|
||||
(&whole form &environment env regex target-string replacement &rest rest)
|
||||
(&whole form regex target-string replacement &rest rest)
|
||||
"Make sure that constant forms are compiled into scanners at compile time."
|
||||
(cond ((constantp regex env)
|
||||
(cond ((constantp regex)
|
||||
`(regex-replace (load-time-value (create-scanner ,regex))
|
||||
,target-string ,replacement ,@rest))
|
||||
(t form)))
|
||||
@ -1060,9 +1062,9 @@ match.
|
||||
|
||||
#-:cormanlisp
|
||||
(define-compiler-macro regex-replace-all
|
||||
(&whole form &environment env regex target-string replacement &rest rest)
|
||||
(&whole form regex target-string replacement &rest rest)
|
||||
"Make sure that constant forms are compiled into scanners at compile time."
|
||||
(cond ((constantp regex env)
|
||||
(cond ((constantp regex)
|
||||
`(regex-replace-all (load-time-value (create-scanner ,regex))
|
||||
,target-string ,replacement ,@rest))
|
||||
(t form)))
|
||||
|
||||
@ -364,3 +364,11 @@ characters if there's a match."
|
||||
(regex-replace-all (create-scanner "\\p{even}") "abcd" "+")
|
||||
(regex-replace-all (create-scanner "\\p{true}") "abcd" "+")))
|
||||
'("+b+d" "a+c+" "++++")))
|
||||
|
||||
(macrolet ((z () "(a)*b"))
|
||||
(equalp (multiple-value-list (scan (z) "xaaabd"))
|
||||
(list 1 5 #(3) #(4))))
|
||||
|
||||
(macrolet ((z () "[^b]*b"))
|
||||
(equalp (multiple-value-list (scan-to-strings (z) "aaabd"))
|
||||
(list "aaab" #())))
|
||||
|
||||
Reference in New Issue
Block a user