1.0.13.50: rename JECXZ to JRCXZ in the x86-64 backend for clarity
[sbcl/simd.git] / tests / mop-4.impure-cload.lisp
blobe4c7d0f4bd90d750d5ca69db304d23039a4f76be
1 ;;;; miscellaneous side-effectful tests of the MOP
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 ;;; This file contains tests for COMPUTE-DISCRIMINATING-FUNCTION on
15 ;;; subclasses of generic functions.
17 (defpackage "MOP-4"
18 (:use "CL" "SB-MOP"))
20 (in-package "MOP-4")
22 ;;; bug 343
23 (defclass my-generic-function1 (standard-generic-function) ()
24 (:metaclass funcallable-standard-class))
26 (defmethod compute-discriminating-function ((gf my-generic-function1))
27 (let ((dfun (call-next-method)))
28 (lambda (&rest args)
29 (1+ (apply dfun args)))))
31 (defgeneric foo (x)
32 (:generic-function-class my-generic-function1))
34 (defmethod foo (x) (+ x x))
36 (assert (= (foo 5) 11))
38 ;;; from PCL sources
40 (defclass my-generic-function-pcl1 (standard-generic-function) ()
41 (:metaclass funcallable-standard-class))
43 (defmethod compute-discriminating-function ((gf my-generic-function-pcl1))
44 (let ((std (call-next-method)))
45 (lambda (arg)
46 (print (list 'call-to-gf gf arg))
47 (funcall std arg))))
49 (defgeneric pcl1 (x)
50 (:generic-function-class my-generic-function-pcl1))
52 (defmethod pcl1 ((x integer)) (1+ x))
54 (let ((output (with-output-to-string (*standard-output*)
55 (pcl1 3))))
56 (assert (search "(CALL-TO-GF #<MY-GENERIC-FUNCTION-PCL1 PCL1 (1)> 3)" output)))
59 (defclass my-generic-function-pcl2 (standard-generic-function) ()
60 (:metaclass funcallable-standard-class))
61 (defmethod compute-discriminating-function ((gf my-generic-function-pcl2))
62 (lambda (arg)
63 (cond (<some condition>
64 <store some info in the generic function>
65 (set-funcallable-instance-function
67 (compute-discriminating-function gf))
68 (funcall gf arg))
70 <call-a-method-of-gf>))))
73 ;;; from clisp's test suite
75 (progn
76 (defclass traced-generic-function (standard-generic-function)
78 (:metaclass funcallable-standard-class))
79 (defvar *last-traced-arguments* nil)
80 (defvar *last-traced-values* nil)
81 (defmethod compute-discriminating-function ((gf traced-generic-function)) (let ((orig-df (call-next-method))
82 (name (generic-function-name gf)))
83 #'(lambda (&rest arguments)
84 (format *trace-output* "~%=> ~S arguments: ~:S" name arguments)
85 (setq *last-traced-arguments* arguments)
86 (let ((values (multiple-value-list (apply orig-df arguments))))
87 (format *trace-output* "~%<= ~S values: ~:S" name values)
88 (setq *last-traced-values* values)
89 (values-list values)))))
90 (defgeneric testgf15 (x) (:generic-function-class traced-generic-function)
91 (:method ((x number)) (values x (- x) (* x x) (/ x))))
92 (testgf15 5)
93 (assert (equal (list *last-traced-arguments* *last-traced-values*)
94 '((5) (5 -5 25 1/5)))))
96 ;;; also we might be in a position to run the "application example"
97 ;;; from mop.tst in clisp's test suite