*** empty log message ***
[bpt/guile.git] / oop / goops / stklos.scm
1 ;;;; Copyright (C) 1999 Free Software Foundation, Inc.
2 ;;;;
3 ;;;; This program is free software; you can redistribute it and/or modify
4 ;;;; it under the terms of the GNU General Public License as published by
5 ;;;; the Free Software Foundation; either version 2, or (at your option)
6 ;;;; any later version.
7 ;;;;
8 ;;;; This program is distributed in the hope that it will be useful,
9 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;;;; GNU General Public License for more details.
12 ;;;;
13 ;;;; You should have received a copy of the GNU General Public License
14 ;;;; along with this software; see the file COPYING. If not, write to
15 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 ;;;; Boston, MA 02111-1307 USA
17 ;;;;
18 \f
19
20 (define-module (oop goops stklos)
21 :use-module (oop goops internal)
22 :no-backtrace
23 )
24
25 ;;;
26 ;;; This is the stklos compatibility module.
27 ;;;
28 ;;; WARNING: This module is under construction. While we expect to be able
29 ;;; to run most stklos code without problems in the future, this is not the
30 ;;; case now. The current compatibility is only superficial.
31 ;;;
32 ;;; Any comments/complaints/patches are welcome. Tell us about
33 ;;; your incompatibility problems (bug-guile@gnu.org).
34 ;;;
35
36 ;; Export all bindings that are exported from (oop goops)...
37 (module-for-each (lambda (sym var)
38 (module-add! %module-public-interface sym var))
39 (nested-ref the-root-module '(app modules oop goops
40 %module-public-interface)))
41
42 ;; ...but replace the following bindings:
43 (export define-class define-method)
44
45 ;; Also export the following
46 (export write-object)
47
48 ;;; Enable keyword support (*fixme*---currently this has global effect)
49 (read-set! keywords 'prefix)
50
51 (define standard-define-class-transformer
52 (macro-transformer standard-define-class))
53
54 (define define-class
55 ;; Syntax
56 (let ((name cadr)
57 (supers caddr)
58 (slots cadddr)
59 (rest cddddr))
60 (procedure->macro
61 (lambda (exp env)
62 (standard-define-class-transformer
63 `(define-class ,(name exp) ,(supers exp) ,@(slots exp)
64 ,@(rest exp))
65 env)))))
66
67 (define define-method
68 (procedure->memoizing-macro
69 (lambda (exp env)
70 (let ((name (cadr exp)))
71 (if (and (pair? name)
72 (eq? (car name) 'setter)
73 (pair? (cdr name))
74 (null? (cddr name)))
75 (let ((name (cadr name)))
76 (cond ((not (symbol? name))
77 (goops-error "bad method name: ~S" name))
78 ((defined? name env)
79 `(begin
80 (if (not (is-a? ,name <generic-with-setter>))
81 (define-accessor ,name))
82 (add-method! (setter ,name) (method ,@(cddr exp)))))
83 (else
84 `(begin
85 (define-accessor ,name)
86 (add-method! (setter ,name) (method ,@(cddr exp)))))))
87 (cond ((not (symbol? name))
88 (goops-error "bad method name: ~S" name))
89 ((defined? name env)
90 `(begin
91 (if (not (or (is-a? ,name <generic>)
92 (is-a? ,name <primitive-generic>)))
93 (define-generic ,name))
94 (add-method! ,name (method ,@(cddr exp)))))
95 (else
96 `(begin
97 (define-generic ,name)
98 (add-method! ,name (method ,@(cddr exp)))))))))))