Fix make-array transforms.
[sbcl.git] / src / code / cross-sap.lisp
1 ;;;; support and placeholders for System Area Pointers (SAPs) in the host
2 ;;;; Common Lisp at cross-compile time
3
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
12
13 (in-package "SB!SYS")
14
15 ;;; SYSTEM-AREA-POINTER is not a primitive type in ANSI Common Lisp,
16 ;;; so we need a compound type to represent it in the host Common Lisp
17 ;;; at cross-compile time:
18 (defstruct (system-area-pointer (:constructor make-sap)
19                                 (:conc-name "SAP-"))
20   ;; the integer representation of the address
21   (int (error "missing SAP-INT argument") :type sap-int :read-only t))
22
23 ;;; cross-compilation-host analogues of target-CMU CL primitive SAP operations
24 (defun int-sap (int)
25   (make-sap :int int))
26 (defun sap+ (sap offset)
27   (declare (type system-area-pointer sap) (type sap-int offset))
28   (make-sap :int (+ (sap-int sap) offset)))
29 #.`(progn
30      ,@(mapcar (lambda (info)
31                  (destructuring-bind (sap-fun int-fun) info
32                    `(defun ,sap-fun (x y)
33                       (,int-fun (sap-int x) (sap-int y)))))
34                '((sap< <) (sap<= <=) (sap= =) (sap>= >=) (sap> >) (sap- -))))
35
36 ;;; dummies, defined so that we can declare they never return and
37 ;;; thereby eliminate a thundering herd of optimization notes along
38 ;;; the lines of "can't optimize this expression because we don't know
39 ;;; the return type of SAP-REF-8"
40 (defun sap-ref-stub (name)
41   (error "~S doesn't make sense on cross-compilation host." name))
42 #.`(progn
43      ,@(mapcan (lambda (name)
44                  `((declaim (ftype (function (system-area-pointer fixnum) nil)
45                                    ,name))
46                    (defun ,name (sap offset)
47                      (declare (ignore sap offset))
48                      (sap-ref-stub ',name))
49                    ,@(let ((setter-stub (gensym "SETTER-STUB-")))
50                        `((defun ,setter-stub (foo sap offset)
51                            (declare (ignore foo sap offset))
52                            (sap-ref-stub '(setf ,name)))
53                          (defsetf ,name ,setter-stub)))))
54                '(sap-ref-8
55                  sap-ref-16
56                  sap-ref-32
57                  sap-ref-64
58                  sap-ref-sap
59                  sap-ref-word
60                  sap-ref-single
61                  sap-ref-double
62                  signed-sap-ref-8
63                  signed-sap-ref-16
64                  signed-sap-ref-32
65                  signed-sap-ref-64
66                  signed-sap-ref-word)))