r2741: Start migration to pathname-less asd files, remove .system files
[clsql.git] / base / cmucl-compat.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          cmucl-compat.sql
6 ;;;; Purpose:       Compatiblity library for CMUCL functions
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id: cmucl-compat.cl,v 1.3 2002/09/17 17:16:43 kevin Exp $
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
20 (in-package :cl-user)
21
22 (defpackage :cmucl-compat
23   (:export
24    #:shrink-vector
25    #:make-sequence-of-type
26    #:result-type-or-lose
27    #:required-argument
28    ))
29 (in-package :cmucl-compat)
30
31 #+cmu
32 (defmacro required-argument ()
33   `(ext:required-argument))
34
35 #-cmu
36 (defun required-argument ()
37   (error "~&A required keyword argument was not supplied"))
38
39 #+cmu
40 (defmacro shrink-vector (vec len)
41   `(lisp::shrink-vector ,vec ,len))
42
43 #-cmu
44 (defmacro shrink-vector (vec len)
45   "Shrinks a vector. Optimized if vector has a fill pointer.
46 Needs to be a macro to overwrite value of VEC."
47   (let ((new-vec (gensym)))
48     `(cond
49       ((adjustable-array-p ,vec)
50        (adjust-array ,vec ,len))
51       ((typep ,vec 'simple-array)
52        (let ((,new-vec (make-array ,len :element-type
53                                    (array-element-type ,vec))))
54          (dotimes (i ,len)
55            (declare (fixnum i))
56            (setf (aref ,new-vec i) (aref ,vec i)))
57          (setq ,vec ,new-vec)))
58       ((typep ,vec 'vector)
59         (setf (fill-pointer ,vec) ,len)
60         ,vec)
61       (t
62        (error "Unable to shrink vector ~S which is type-of ~S" ,vec (type-of ,vec))) 
63        )))
64
65
66
67 #-cmu
68 (defun make-sequence-of-type (type length)
69   "Returns a sequence of the given TYPE and LENGTH."
70   (declare (fixnum length))
71   (case type
72     (list 
73      (make-list length))
74     ((bit-vector simple-bit-vector) 
75      (make-array length :element-type '(mod 2)))
76     ((string simple-string base-string simple-base-string)
77      (make-string length))
78     (simple-vector 
79      (make-array length))
80     ((array simple-array vector)
81      (if (listp type)
82          (make-array length :element-type (cadr type))
83        (make-array length)))
84     (t
85      (make-sequence-of-type (result-type-or-lose type t) length))))
86
87
88 #+cmu
89 (if (fboundp 'lisp::make-sequence-of-type)
90     (defun make-sequence-of-type (type len)
91       (lisp::make-sequence-of-type type len))
92   (defun make-sequence-of-type (type len)
93     (system::make-sequence-of-type type len)))
94   
95
96 #-cmu
97 (defun result-type-or-lose (type nil-ok)
98   (unless (or type nil-ok)
99     (error "NIL output type invalid for this sequence function"))
100   (case type
101     ((list cons)
102      'list)
103     ((string simple-string base-string simple-base-string)
104      'string)
105     (simple-vector
106      'simple-vector)
107     (vector
108      'vector)
109     (t
110      (error "~S is a bad type specifier for sequence functions." type))
111     ))
112
113 #+cmu
114 (defun result-type-or-lose (type nil-ok)
115   (lisp::result-type-or-lose type nil-ok))