stklos.scm 3.1 KB

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