1 ;;;; support and placeholders for System Area Pointers (SAPs) in the host
2 ;;;; Common Lisp at cross-compile time
4 ;;;; This software is part of the SBCL system. See the README file for
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.
18 ;;; SYSTEM-AREA-POINTER is not a primitive type in ANSI Common Lisp, so we
19 ;;; need a compound type to represent it in the host Common Lisp at
20 ;;; cross-compile time:
21 (defstruct (system-area-pointer (:constructor make-sap) (:conc-name "SAP-"))
22 ;; the integer representation of the address
23 (int (error "missing SAP-INT argument") :type sap-int-type :read-only t))
25 ;;; cross-compilation-host analogues of target-CMU CL primitive SAP operations
28 (defun sap+ (sap offset)
29 (declare (type system-area-pointer sap) (type sap-int-type offset))
30 (make-sap :int (+ (sap-int sap) offset)))
32 ,@(mapcar (lambda (info)
33 (destructuring-bind (sap-fun int-fun) info
34 `(defun ,sap-fun (x y)
35 (,int-fun (sap-int x) (sap-int y)))))
36 '((sap< <) (sap<= <=) (sap= =) (sap>= >=) (sap> >) (sap- -))))
38 ;;; dummies, defined so that we can declare they never return and thereby
39 ;;; eliminate a thundering herd of optimization notes a la "can't optimize this
40 ;;; expression because we don't know the return type of SAP-REF-8"
41 (defun sap-ref-stub (name)
42 (error "~S doesn't make sense on cross-compilation host." name))
44 ,@(mapcan (lambda (name)
45 `((declaim (ftype (function (system-area-pointer fixnum) nil)
47 (defun ,name (sap offset)
48 (declare (ignore sap offset))
49 (sap-ref-stub ',name))
50 ,@(let ((setter-stub (gensym "SAP-SETTER-STUB-")))
51 `((defun ,setter-stub (foo sap offset)
52 (declare (ignore foo sap offset))
53 (sap-ref-stub '(setf ,name)))
54 (defsetf ,name ,setter-stub)))))