source: trunk/j/src/org/armedbear/lisp/typep.lisp @ 3751

Last change on this file since 3751 was 3751, checked in by piso, 20 years ago

Work in progress.

File size: 3.1 KB
Line 
1;;; typep.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: typep.lisp,v 1.3 2003-09-14 12:25:27 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20;;; Adapted from GCL.
21
22(in-package "SYSTEM")
23
24(resolve 'subtypep)
25
26(defun simple-array-p (object)
27  (and (arrayp object)
28       (not (array-has-fill-pointer-p object))
29       (multiple-value-bind (displaced-to offset) (array-displacement object)
30         (and (null displaced-to) (zerop offset)))))
31
32(defun match-dimensions (dim pat)
33  (if (null dim)
34      (null pat)
35      (and (or (eq (car pat) '*)
36         (eql (car dim) (car pat)))
37     (match-dimensions (cdr dim) (cdr pat)))))
38
39(defun typep (object type)
40  (when (atom type)
41    (return-from typep (simple-typep object type)))
42  (let ((tp (car type))
43        (i (cdr type)))
44    (case tp
45      (SIMPLE-BIT-VECTOR
46       (and (simple-bit-vector-p object)
47            (or (endp i) (match-dimensions (array-dimensions object) i))))
48      (BIT-VECTOR
49       (and (bit-vector-p object)
50            (or (endp i) (match-dimensions (array-dimensions object) i))))
51      (SIMPLE-VECTOR
52       (and (simple-vector-p object)
53            (or (endp i) (eq (car i) '*)
54                (= (length object) (car i)))))
55      (VECTOR
56       (and (vectorp object)
57            (or (endp i)
58                (eq (car i) '*)
59                (and (eq (car i) t) (not (stringp object)) (not (bit-vector-p object)))
60                (and (stringp object) (subtypep (car i) 'character))
61                (equal (array-element-type object) (car i)))
62            (or (endp (cdr i)) (match-dimensions (array-dimensions object) (cdr i)))))
63      (SIMPLE-ARRAY
64       (and (simple-array-p object)
65            (or (endp i) (eq (car i) '*)
66                (equal (array-element-type object) (upgraded-array-element-type (car i))))
67            (or (endp (cdr i)) (eq (cadr i) '*)
68                (if (listp (cadr i))
69                    (match-dimensions (array-dimensions object) (cadr i))
70                    (eql (array-rank object) (cadr i))))))
71      (ARRAY
72       (and (arrayp object)
73            (or (null i) (eq (car i) '*)
74                (equal (array-element-type object) (upgraded-array-element-type (car i))))
75            (or (null (cdr i)) (eq (cadr i) '*)
76                (if (listp (cadr i))
77                    (match-dimensions (array-dimensions object) (cadr i))
78                    (eql (array-rank object) (cadr i))))))
79      (t
80       nil))))
Note: See TracBrowser for help on using the repository browser.