TR: [cl-ppcre-devel] New release 1.2.4
Gary King
gwking at metabang.com
Wed Mar 9 01:27:55 UTC 2005
I have code that could be adapted for this purpose. It is designed to
add automatic type checking for methods and to allow optimizations to
be turned off. I don't think it would be too hard to adapt it to
changing optimization settings.
Here is the code. I could work on adapting it if no one else is
interested. Let me know.
#| simple-header
$Id: lift.lisp,v 1.28 2005/02/08 01:42:27 gwking Exp $
$Author: gwking $
$Date: 2005/02/08 01:42:27 $
Copyright (c) 2001-2005 Gary Warren King (gwking at cs.umass.edu)
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"),
to deal in the Software without restriction, including without
limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
|#
(in-package user)
(defvar *optimizations-to-ignore*
'()
"Declarations in this list are ignored in defmethod* and defun*
forms.")
;;;
------------------------------------------------------------------------
---
(defvar *add-check-types* t
"If true (the default), type declarations are parsed and check-types
are added for each of them.")
;;;
------------------------------------------------------------------------
---
#+test
(setf *add-check-types* t
*optimizations-to-ignore* '(list type optimize))
;;;
------------------------------------------------------------------------
---
(defmacro defmethod* (name &rest args)
`(defmethod ,name ,@(parse-defun args)))
;;;
------------------------------------------------------------------------
---
(defmacro defun* (name args &body body)
`(defun ,name ,args ,@(parse-defun body)))
;;;
------------------------------------------------------------------------
---
(defun parse-defun (forms)
;; minor optimization
(when (and (not *add-check-types*)
(null *optimizations-to-ignore*))
(return-from parse-defun forms))
(let ((check-types nil))
(labels ((do-it (body)
(cond ((null body) nil)
((atom body) body)
((eq (first body) 'declare)
(multiple-value-bind (parsed-version checks)
(parse-declare body)
(setf check-types (append check-types checks))
parsed-version))
(t
(when (and (consp (car body))
check-types
(not (eq (first (car body)) 'declare)))
(setf body (append check-types body))
(setf check-types nil))
(cons (do-it (car body))
(do-it (cdr body)))))))
(do-it forms))))
;;;
------------------------------------------------------------------------
---
(defun parse-declare (declaration)
"Takes a single declare form and returns 2 values:
(1) the declarations (with declarations of type
*optimizations-to-ignore* removed)
(2) a list of CHECK-TYPE forms that enforce all the type
declarations from the DECLAREs
(if *ADD-CHECK-TYPES* is true)."
(assert (member (first declaration) '(declare declaim proclaim)))
(let ((checks nil)
(final-declares nil))
(dolist (dcl (rest declaration))
;; add the check-types
(when (and *add-check-types*
(type-declaration-p dcl))
(destructuring-bind (type &rest vars)
(if (eq (first dcl) 'type)
(rest dcl)
dcl)
(dolist (var vars)
(push `(check-type ,var ,type) checks))))
;; filter the declarations
(unless (member (first dcl) *optimizations-to-ignore*)
(push dcl final-declares)))
(values
(cons 'declare (nreverse final-declares))
(nreverse checks))))
;;;
------------------------------------------------------------------------
---
(defun type-declaration-p (declaration)
(and (consp declaration)
(not (member (first declaration)
'(dynamic-extent ignore optimize inline
special ignorable notinline)))
(or (eq (first declaration) 'type)
#+MCL
(ccl:type-specifier-p (first declaration))
#-MCL
(find (first declaration)
'(sequence symbol number character hash-table function
readtable
package pathname stream random-state condition
restart
standard-object structure-object)
:test 'subtypep))))
On Mar 8, 2005, at 2:48 PM, Kick Damien-DKICK1 wrote:
> Edi Weitz [edi at agharta.de] wrote:
>>
>> On Tue, 8 Mar 2005 13:17:41 -0600, Kick Damien-DKICK1
>> <DKICK1 at motorola.com> wrote:
>>
>>> New code: (EVAL-WHEN (EVAL COMPILE LOAD)
>>> (DEFVAR *STANDARD-SPEED-AND-SAFETY*
>>> '((SPEED 0) (SAFETY 3))))
>>> (DEFUN FOO ()
>>> (DECLARE (OPTIMIZE #.*STANDARD-SPEED-AND-SAFETY*))
>>> ...)
>>
>> Looks cool to me. How about a patch for CL-PPCRE?
>
> I'd be more than happy to be able to help with something like this.
> Should be able to find spare time to put something together by <pause>
> I dunno, next week.
>
> --
> Damien Kick
> _______________________________________________
> cl-ppcre-devel site list
> cl-ppcre-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/cl-ppcre-devel
>
--
Gary Warren King, Lab Manager
EKSL East, University of Massachusetts * 413 577 0176
Power is actualized only where word and deed have not parted company,
where words are not empty and deeds not brutal, where words are not
used to veil intentions but to disclose realities, and deeds are not
used to violate and destroy but to establish relations and create new
realities.
-- Hannah Arendt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 6849 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cl-ppcre-devel/attachments/20050308/3c2086cc/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2367 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cl-ppcre-devel/attachments/20050308/3c2086cc/attachment-0001.bin>
More information about the Cl-ppcre-devel
mailing list