| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: C -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; Copyright (c) 2010, Juan Jose Garcia Ripoll |
| 5 |
;;;; |
| 6 |
;;;; See the file 'LICENSE' for the copyright details. |
| 7 |
;;;; |
| 8 |
|
| 9 |
;;;; Type propagators for arrays. |
| 10 |
|
| 11 |
(in-package "COMPILER") |
| 12 |
|
| 13 |
(defun type-from-array-elt (array &aux name) |
| 14 |
"Input is a lisp type representing a valid subtype of ARRAY. Output is either |
| 15 |
the array element type or NIL, denoting that we are not able to compute it. This |
| 16 |
version only handles the simplest cases." |
| 17 |
(values (cond ((eq array 'string) |
| 18 |
'character) |
| 19 |
((eq array 'base-string) |
| 20 |
'base-char) |
| 21 |
((member (setf array (si::expand-deftype array *cmp-env*)) |
| 22 |
'(array vector simple-array)) |
| 23 |
t) |
| 24 |
((atom array) |
| 25 |
(setf array 'array) |
| 26 |
t) |
| 27 |
((eq (setf name (first array)) 'OR) |
| 28 |
`(OR ,@(mapcar #'type-from-array-elt (rest array)))) |
| 29 |
((eq (setf name (first array)) 'AND) |
| 30 |
`(AND ,@(mapcar #'type-from-array-elt (rest array)))) |
| 31 |
((not (member (first array) |
| 32 |
'(array vector simple-array))) |
| 33 |
(setf array 'array) |
| 34 |
t) |
| 35 |
((null (rest array)) |
| 36 |
t) |
| 37 |
(t |
| 38 |
(let ((x (second array))) |
| 39 |
(if (eq x '*) t x)))) |
| 40 |
array)) |
| 41 |
|
| 42 |
(def-type-propagator si::aset (fname array-type &rest indices-and-object) |
| 43 |
(multiple-value-bind (elt-type array-type) |
| 44 |
(type-from-array-elt array-type) |
| 45 |
(values (cons array-type |
| 46 |
(nconc (make-list (1- (length indices-and-object)) |
| 47 |
:initial-element 'si::index) |
| 48 |
(list elt-type))) |
| 49 |
elt-type))) |
| 50 |
|
| 51 |
(def-type-propagator aref (fname array-type &rest indices) |
| 52 |
(multiple-value-bind (elt-type array-type) |
| 53 |
(type-from-array-elt array-type) |
| 54 |
(values (list* array-type (make-list (length indices) |
| 55 |
:initial-element 'si::index)) |
| 56 |
elt-type))) |
| 57 |
|
| 58 |
(def-type-propagator si::row-major-aset (fname array-type index obj) |
| 59 |
(declare (ignore index obj)) |
| 60 |
(multiple-value-bind (elt-type array-type) |
| 61 |
(type-from-array-elt array-type) |
| 62 |
(values (list array-type 'si::index elt-type) |
| 63 |
elt-type))) |
| 64 |
|
| 65 |
(def-type-propagator row-major-aref (fname array-type index) |
| 66 |
(declare (ignore index)) |
| 67 |
(multiple-value-bind (elt-type array-type) |
| 68 |
(type-from-array-elt array-type) |
| 69 |
(values (list array-type 'si::index) elt-type))) |