compile.scm 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ;;;; Copyright (C) 1999, 2001, 2006, 2009 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 3 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. ;; There are circularities here; you can't import (oop goops compile)
  18. ;; before (oop goops). So when compiling, make sure that things are
  19. ;; kosher.
  20. (eval-when (compile) (resolve-module '(oop goops)))
  21. (define-module (oop goops compile)
  22. :use-module (oop goops)
  23. :use-module (oop goops util)
  24. :export (compute-cmethod)
  25. :no-backtrace
  26. )
  27. ;;;
  28. ;;; Compiling next methods into method bodies
  29. ;;;
  30. ;;; So, for the reader: there basic idea is that, given that the
  31. ;;; semantics of `next-method' depend on the concrete types being
  32. ;;; dispatched, why not compile a specific procedure to handle each type
  33. ;;; combination that we see at runtime.
  34. ;;;
  35. ;;; In theory we can do much better than a bytecode compilation, because
  36. ;;; we know the *exact* types of the arguments. It's ideal for native
  37. ;;; compilation. A task for the future.
  38. ;;;
  39. ;;; I think this whole generic application mess would benefit from a
  40. ;;; strict MOP.
  41. (define (compute-cmethod methods types)
  42. (let ((make-procedure (slot-ref (car methods) 'make-procedure)))
  43. (if make-procedure
  44. (make-procedure
  45. (if (null? (cdr methods))
  46. (lambda args
  47. (no-next-method (method-generic-function (car methods)) args))
  48. (compute-cmethod (cdr methods) types)))
  49. (method-procedure (car methods)))))