-(defmethod from-alien-form (location (class proxy-class) &rest args)
- (declare (ignore args))
- `(ensure-proxy-instance ',(class-name class) ,location))
-
-(defmethod from-alien-function ((class proxy-class) &rest args)
- (declare (ignore args))
- #'(lambda (location)
- (ensure-proxy-instance class location)))
-
-(defmethod to-alien-form (instance (class proxy-class) &rest args)
- (declare (ignore class args))
- `(proxy-location ,instance))
-
-(defmethod to-alien-function ((class proxy-class) &rest args)
- (declare (ignore class args))
- #'proxy-location)
-
-(defmethod copy-from-alien-form (location (class proxy-class) &rest args)
- (declare (ignore args))
- (let ((class-name (class-name class)))
- `(ensure-proxy-instance ',class-name
- (reference-foreign ',class-name ,location))))
-
-(defmethod copy-from-alien-function ((class proxy-class) &rest args)
- (declare (ignore args))
- #'(lambda (location)
- (ensure-proxy-instance class (reference-foreign class location))))
-
-(defmethod copy-to-alien-form (instance (class proxy-class) &rest args)
- (declare (ignore args))
- `(reference-foreign ',(class-name class) (proxy-location ,instance)))
-
-(defmethod copy-to-alien-function ((class proxy-class) &rest args)
- (declare (ignore class args))
- #'(lambda (instance)
- (reference-foreign class (proxy-location instance))))
-
-(defmethod writer-function ((class proxy-class) &rest args)
- (declare (ignore args))
- #'(lambda (instance location &optional (offset 0))
- (assert (null-pointer-p (sap-ref-sap location offset)))
- (setf
- (sap-ref-sap location offset)
- (reference-foreign class (proxy-location instance)))))
-
-(defmethod reader-function ((class proxy-class) &rest args)
- (declare (ignore args))
- #'(lambda (location &optional (offset 0))
- (let ((instance (sap-ref-sap location offset)))
- (unless (null-pointer-p instance)
- (ensure-proxy-instance class (reference-foreign class instance))))))
-
-(defmethod destroy-function ((class proxy-class) &rest args)
- (declare (ignore args))
- #'(lambda (location &optional (offset 0))
- (unreference-foreign class (sap-ref-sap location offset))))
-
-(defmethod unbound-value ((class proxy-class) &rest args)
- (declare (ignore args))
- (values t nil))
-
-(defgeneric ensure-proxy-instance (class location)
- (:documentation "Returns a proxy object representing the foreign object at the give location."))
+(define-type-method from-alien-form ((type proxy) location)
+ (let ((class (type-expand type)))
+ `(ensure-proxy-instance ',class ,location)))
+
+(define-type-method from-alien-function ((type proxy))
+ (let ((class (type-expand type)))
+ #'(lambda (location)
+ (ensure-proxy-instance class location))))
+
+(define-type-method to-alien-form ((type proxy) instance)
+ (declare (ignore type))
+ `(foreign-location ,instance))
+
+(define-type-method to-alien-function ((type proxy))
+ (declare (ignore type))
+ #'foreign-location)
+
+(define-type-method copy-from-alien-form ((type proxy) location)
+ (let ((class (type-expand type)))
+ `(ensure-proxy-instance ',class (reference-foreign ',class ,location))))
+
+(define-type-method copy-from-alien-function ((type proxy))
+ (let ((class (type-expand type)))
+ #'(lambda (location)
+ (ensure-proxy-instance class (reference-foreign class location)))))
+
+(define-type-method copy-to-alien-form ((type proxy) instance)
+ (let ((class (type-expand type)))
+ `(reference-foreign ',class (foreign-location ,instance))))
+
+(define-type-method copy-to-alien-function ((type proxy))
+ (let ((class (type-expand type)))
+ #'(lambda (instance)
+ (reference-foreign class (foreign-location instance)))))
+
+(define-type-method writer-function ((type proxy))
+ (let ((class (type-expand type)))
+ #'(lambda (instance location &optional (offset 0))
+ (assert (null-pointer-p (sap-ref-sap location offset)))
+ (setf
+ (sap-ref-sap location offset)
+ (reference-foreign class (foreign-location instance))))))
+
+(define-type-method reader-function ((type proxy))
+ (let ((class (type-expand type)))
+ #'(lambda (location &optional (offset 0) weak-p)
+ (declare (ignore weak-p))
+ (let ((instance (sap-ref-sap location offset)))
+ (unless (null-pointer-p instance)
+ (ensure-proxy-instance class (reference-foreign class instance)))))))
+
+(define-type-method destroy-function ((type proxy))
+ (let ((class (type-expand type)))
+ #'(lambda (location &optional (offset 0))
+ (unreference-foreign class (sap-ref-sap location offset)))))
+
+(define-type-method unbound-value ((type proxy))
+ (declare (ignore type))
+ nil)