2000-10-25 14:51:33 +00:00
|
|
|
|
;;; installed-scm-file
|
|
|
|
|
|
|
2011-05-21 13:12:44 +02:00
|
|
|
|
;;;; Copyright (C) 1998,1999,2000,2001,2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; This library is free software; you can redistribute it and/or
|
|
|
|
|
|
;;;; modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License as published by the Free Software Foundation; either
|
2009-06-17 00:22:09 +01:00
|
|
|
|
;;;; version 3 of the License, or (at your option) any later version.
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; This library is distributed in the hope that it will be useful,
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
;;;; Lesser General Public License for more details.
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License along with this library; if not, write to the Free Software
|
2005-05-23 19:57:22 +00:00
|
|
|
|
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; This software is a derivative work of other copyrighted softwares; the
|
|
|
|
|
|
;;;; copyright notices of these softwares are placed in the file COPYRIGHTS
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This file is based upon stklos.stk from the STk distribution by
|
|
|
|
|
|
;;;; Erick Gallesio <eg@unice.fr>.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (oop goops)
|
2008-10-23 14:03:51 +02:00
|
|
|
|
:use-module (srfi srfi-1)
|
2005-03-24 10:23:17 +00:00
|
|
|
|
:export-syntax (define-class class standard-define-class
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
define-generic define-accessor define-method
|
2003-03-10 23:18:05 +00:00
|
|
|
|
define-extended-generic define-extended-generics
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
method)
|
2010-10-02 16:10:56 +01:00
|
|
|
|
:export (is-a? class-of
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
ensure-metaclass ensure-metaclass-with-supers
|
|
|
|
|
|
make-class
|
|
|
|
|
|
make-generic ensure-generic
|
2003-01-08 13:24:41 +00:00
|
|
|
|
make-extended-generic
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
make-accessor ensure-accessor
|
don't re-enter the compiler during method dispatch
* libguile/goops.c (scm_make): In the pre-inst `make', default
`procedure' to #f, and read a `make-procedure' instead of
`compile-env'.
* libguile/goops.h (scm_si_make_procedure): This instead of
scm_si_compile_env.
* module/oop/goops.scm (make-method): Remove this unused function. Users
should use (make <method> ...) directly.
(method): Capture `make-procedure' instead of `procedure' in the case
that the body calls a next-method. Allows for the kind of
"recompilation" that we were using before, but with closures instead of
re-entering the compiler. Type-specific compilation is still
interesting, but probably should be implemented in another way.
(initialize): Default #:procedure to #f, and
s/compile-env/make-procedure/.
* module/oop/goops/compile.scm (code-table-lookup): Just return the
cmethod, not the entry -- since the entry is now just (append types
cmethod).
(compile-make-procedure): New procedure, returns a form that, when
evaluated/compiled, will yield a procedure of one argument, the
next-method. When called with a next-method, the procedure returns an
actual method implementation. compile-make-procedure returns #f if the
body doesn't call next-method.
(compile-method): Unify to always return procedures. Much cleaner and
*much* faster in the compiled case. In the interpreted case, there
might be a slight slowdown, but if there is one it should be slight.
* module/oop/goops/dispatch.scm (method-cache-install!): Adapt to removal
of compute-entry-with-cmethod.
2009-02-13 23:30:20 +01:00
|
|
|
|
add-method!
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
class-slot-ref class-slot-set! slot-unbound slot-missing
|
|
|
|
|
|
slot-definition-name slot-definition-options
|
|
|
|
|
|
slot-definition-allocation
|
|
|
|
|
|
slot-definition-getter slot-definition-setter
|
|
|
|
|
|
slot-definition-accessor
|
|
|
|
|
|
slot-definition-init-value slot-definition-init-form
|
|
|
|
|
|
slot-definition-init-thunk slot-definition-init-keyword
|
|
|
|
|
|
slot-init-function class-slot-definition
|
|
|
|
|
|
method-source
|
|
|
|
|
|
compute-cpl compute-std-cpl compute-get-n-set compute-slots
|
|
|
|
|
|
compute-getter-method compute-setter-method
|
|
|
|
|
|
allocate-instance initialize make-instance make
|
|
|
|
|
|
no-next-method no-applicable-method no-method
|
|
|
|
|
|
change-class update-instance-for-different-class
|
|
|
|
|
|
shallow-clone deep-clone
|
|
|
|
|
|
class-redefinition
|
|
|
|
|
|
apply-generic apply-method apply-methods
|
|
|
|
|
|
compute-applicable-methods %compute-applicable-methods
|
|
|
|
|
|
method-more-specific? sort-applicable-methods
|
|
|
|
|
|
class-subclasses class-methods
|
|
|
|
|
|
goops-error
|
|
|
|
|
|
min-fixnum max-fixnum
|
|
|
|
|
|
;;; *fixme* Should go into goops.c
|
|
|
|
|
|
instance? slot-ref-using-class
|
|
|
|
|
|
slot-set-using-class! slot-bound-using-class?
|
|
|
|
|
|
slot-exists-using-class? slot-ref slot-set! slot-bound?
|
|
|
|
|
|
class-name class-direct-supers class-direct-subclasses
|
|
|
|
|
|
class-direct-methods class-direct-slots class-precedence-list
|
2009-11-27 20:50:40 +01:00
|
|
|
|
class-slots
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
generic-function-name
|
2009-03-20 12:06:10 +01:00
|
|
|
|
generic-function-methods method-generic-function
|
|
|
|
|
|
method-specializers method-formals
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
primitive-generic-generic enable-primitive-generic!
|
|
|
|
|
|
method-procedure accessor-method-slot-definition
|
|
|
|
|
|
slot-exists? make find-method get-keyword)
|
2001-05-19 00:19:25 +00:00
|
|
|
|
:no-backtrace)
|
|
|
|
|
|
|
2008-09-30 20:29:35 +02:00
|
|
|
|
(define *goops-module* (current-module))
|
|
|
|
|
|
|
2001-05-19 00:19:25 +00:00
|
|
|
|
;; First initialize the builtin part of GOOPS
|
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
2009-03-06 13:29:13 +01:00
|
|
|
|
(eval-when (eval load compile)
|
|
|
|
|
|
(%init-goops-builtins))
|
2001-05-19 00:19:25 +00:00
|
|
|
|
|
2009-11-06 12:40:20 +01:00
|
|
|
|
(eval-when (eval load compile)
|
|
|
|
|
|
(use-modules ((language tree-il primitives) :select (add-interesting-primitive!)))
|
|
|
|
|
|
(add-interesting-primitive! 'class-of)
|
2009-11-28 01:19:31 +01:00
|
|
|
|
(define (@slot-ref o n)
|
|
|
|
|
|
(struct-ref o n))
|
|
|
|
|
|
(define (@slot-set! o n v)
|
|
|
|
|
|
(struct-set! o n v))
|
2009-11-06 12:40:20 +01:00
|
|
|
|
(add-interesting-primitive! '@slot-ref)
|
|
|
|
|
|
(add-interesting-primitive! '@slot-set!))
|
|
|
|
|
|
|
2001-05-19 00:19:25 +00:00
|
|
|
|
;; Then load the rest of GOOPS
|
|
|
|
|
|
(use-modules (oop goops util)
|
|
|
|
|
|
(oop goops dispatch)
|
2001-05-19 22:58:29 +00:00
|
|
|
|
(oop goops compile))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
2009-03-06 13:29:13 +01:00
|
|
|
|
(eval-when (eval load compile)
|
2009-02-14 00:24:32 +01:00
|
|
|
|
(define min-fixnum (- (expt 2 29)))
|
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
2009-03-06 13:29:13 +01:00
|
|
|
|
(define max-fixnum (- (expt 2 29) 1)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; goops-error
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (goops-error format-string . args)
|
|
|
|
|
|
(scm-error 'goops-error #f format-string args '()))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; is-a?
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (is-a? obj class)
|
|
|
|
|
|
(and (memq class (class-precedence-list (class-of obj))) #t))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Meta classes}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define ensure-metaclass-with-supers
|
|
|
|
|
|
(let ((table-of-metas '()))
|
|
|
|
|
|
(lambda (meta-supers)
|
|
|
|
|
|
(let ((entry (assoc meta-supers table-of-metas)))
|
|
|
|
|
|
(if entry
|
|
|
|
|
|
;; Found a previously created metaclass
|
|
|
|
|
|
(cdr entry)
|
|
|
|
|
|
;; Create a new meta-class which inherit from "meta-supers"
|
|
|
|
|
|
(let ((new (make <class> #:dsupers meta-supers
|
|
|
|
|
|
#:slots '()
|
|
|
|
|
|
#:name (gensym "metaclass"))))
|
|
|
|
|
|
(set! table-of-metas (cons (cons meta-supers new) table-of-metas))
|
|
|
|
|
|
new))))))
|
|
|
|
|
|
|
2009-11-27 20:50:40 +01:00
|
|
|
|
(define (ensure-metaclass supers)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(if (null? supers)
|
|
|
|
|
|
<class>
|
|
|
|
|
|
(let* ((all-metas (map (lambda (x) (class-of x)) supers))
|
2009-02-05 00:31:38 +01:00
|
|
|
|
(all-cpls (append-map (lambda (m)
|
|
|
|
|
|
(cdr (class-precedence-list m)))
|
|
|
|
|
|
all-metas))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(needed-metas '()))
|
|
|
|
|
|
;; Find the most specific metaclasses. The new metaclass will be
|
|
|
|
|
|
;; a subclass of these.
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (meta)
|
|
|
|
|
|
(if (and (not (member meta all-cpls))
|
|
|
|
|
|
(not (member meta needed-metas)))
|
|
|
|
|
|
(set! needed-metas (append needed-metas (list meta)))))
|
|
|
|
|
|
all-metas)
|
|
|
|
|
|
;; Now return a subclass of the metaclasses we found.
|
|
|
|
|
|
(if (null? (cdr needed-metas))
|
|
|
|
|
|
(car needed-metas) ; If there's only one, just use it.
|
|
|
|
|
|
(ensure-metaclass-with-supers needed-metas)))))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Classes}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; (define-class NAME (SUPER ...) SLOT-DEFINITION ... OPTION ...)
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; SLOT-DEFINITION ::= SLOT-NAME | (SLOT-NAME OPTION ...)
|
|
|
|
|
|
;;; OPTION ::= KEYWORD VALUE
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2008-10-23 14:03:51 +02:00
|
|
|
|
(define (kw-do-map mapper f kwargs)
|
|
|
|
|
|
(define (keywords l)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? l) '())
|
|
|
|
|
|
((or (null? (cdr l)) (not (keyword? (car l))))
|
|
|
|
|
|
(goops-error "malformed keyword arguments: ~a" kwargs))
|
|
|
|
|
|
(else (cons (car l) (keywords (cddr l))))))
|
|
|
|
|
|
(define (args l)
|
|
|
|
|
|
(if (null? l) '() (cons (cadr l) (args (cddr l)))))
|
|
|
|
|
|
;; let* to check keywords first
|
|
|
|
|
|
(let* ((k (keywords kwargs))
|
|
|
|
|
|
(a (args kwargs)))
|
|
|
|
|
|
(mapper f k a)))
|
2003-03-17 13:53:58 +00:00
|
|
|
|
|
2009-04-25 14:10:08 +02:00
|
|
|
|
(define (make-class supers slots . options)
|
2009-11-27 20:50:40 +01:00
|
|
|
|
(let* ((name (get-keyword #:name options (make-unbound)))
|
|
|
|
|
|
(supers (if (not (or-map (lambda (class)
|
|
|
|
|
|
(memq <object>
|
|
|
|
|
|
(class-precedence-list class)))
|
|
|
|
|
|
supers))
|
|
|
|
|
|
(append supers (list <object>))
|
|
|
|
|
|
supers))
|
|
|
|
|
|
(metaclass (or (get-keyword #:metaclass options #f)
|
|
|
|
|
|
(ensure-metaclass supers))))
|
|
|
|
|
|
|
|
|
|
|
|
;; Verify that all direct slots are different and that we don't inherit
|
|
|
|
|
|
;; several time from the same class
|
|
|
|
|
|
(let ((tmp1 (find-duplicate supers))
|
|
|
|
|
|
(tmp2 (find-duplicate (map slot-definition-name slots))))
|
|
|
|
|
|
(if tmp1
|
|
|
|
|
|
(goops-error "make-class: super class ~S is duplicate in class ~S"
|
|
|
|
|
|
tmp1 name))
|
|
|
|
|
|
(if tmp2
|
|
|
|
|
|
(goops-error "make-class: slot ~S is duplicate in class ~S"
|
|
|
|
|
|
tmp2 name)))
|
|
|
|
|
|
|
|
|
|
|
|
;; Everything seems correct, build the class
|
|
|
|
|
|
(apply make metaclass
|
|
|
|
|
|
#:dsupers supers
|
|
|
|
|
|
#:slots slots
|
|
|
|
|
|
#:name name
|
|
|
|
|
|
options)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;; (class (SUPER ...) SLOT-DEFINITION ... OPTION ...)
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; SLOT-DEFINITION ::= SLOT-NAME | (SLOT-NAME OPTION ...)
|
|
|
|
|
|
;;; OPTION ::= KEYWORD VALUE
|
|
|
|
|
|
;;;
|
2008-10-23 14:03:51 +02:00
|
|
|
|
(define-macro (class supers . slots)
|
|
|
|
|
|
(define (make-slot-definition-forms slots)
|
|
|
|
|
|
(map
|
|
|
|
|
|
(lambda (def)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((pair? def)
|
|
|
|
|
|
`(list ',(car def)
|
|
|
|
|
|
,@(kw-do-map append-map
|
|
|
|
|
|
(lambda (kw arg)
|
|
|
|
|
|
(case kw
|
|
|
|
|
|
((#:init-form)
|
|
|
|
|
|
`(#:init-form ',arg
|
|
|
|
|
|
#:init-thunk (lambda () ,arg)))
|
|
|
|
|
|
(else (list kw arg))))
|
|
|
|
|
|
(cdr def))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
`(list ',def))))
|
|
|
|
|
|
slots))
|
|
|
|
|
|
(if (not (list? supers))
|
|
|
|
|
|
(goops-error "malformed superclass list: ~S" supers))
|
2009-09-21 00:10:28 +02:00
|
|
|
|
(let ((slots (take-while (lambda (x) (not (keyword? x))) slots))
|
2008-10-23 14:03:51 +02:00
|
|
|
|
(options (or (find-tail keyword? slots) '())))
|
|
|
|
|
|
`(make-class
|
|
|
|
|
|
;; evaluate super class variables
|
|
|
|
|
|
(list ,@supers)
|
|
|
|
|
|
;; evaluate slot definitions, except the slot name!
|
|
|
|
|
|
(list ,@(make-slot-definition-forms slots))
|
|
|
|
|
|
;; evaluate class options
|
|
|
|
|
|
,@options)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
2009-04-25 14:10:08 +02:00
|
|
|
|
(define-syntax define-class-pre-definition
|
|
|
|
|
|
(lambda (x)
|
|
|
|
|
|
(syntax-case x ()
|
|
|
|
|
|
((_ (k arg rest ...) out ...)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(keyword? (syntax->datum #'k))
|
|
|
|
|
|
(case (syntax->datum #'k)
|
2009-04-25 14:10:08 +02:00
|
|
|
|
((#:getter #:setter)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(define-class-pre-definition (rest ...)
|
|
|
|
|
|
out ...
|
|
|
|
|
|
(if (or (not (defined? 'arg))
|
|
|
|
|
|
(not (is-a? arg <generic>)))
|
|
|
|
|
|
(toplevel-define!
|
|
|
|
|
|
'arg
|
|
|
|
|
|
(ensure-generic (if (defined? 'arg) arg #f) 'arg)))))
|
2009-04-25 14:10:08 +02:00
|
|
|
|
((#:accessor)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(define-class-pre-definition (rest ...)
|
|
|
|
|
|
out ...
|
|
|
|
|
|
(if (or (not (defined? 'arg))
|
|
|
|
|
|
(not (is-a? arg <accessor>)))
|
|
|
|
|
|
(toplevel-define!
|
|
|
|
|
|
'arg
|
|
|
|
|
|
(ensure-accessor (if (defined? 'arg) arg #f) 'arg)))))
|
2009-04-25 14:10:08 +02:00
|
|
|
|
(else
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(define-class-pre-definition (rest ...) out ...))))
|
2009-04-25 14:10:08 +02:00
|
|
|
|
((_ () out ...)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(begin out ...)))))
|
2009-04-25 14:10:08 +02:00
|
|
|
|
|
|
|
|
|
|
;; Some slot options require extra definitions to be made. In
|
|
|
|
|
|
;; particular, we want to make sure that the generic function objects
|
|
|
|
|
|
;; which represent accessors exist before `make-class' tries to add
|
|
|
|
|
|
;; methods to them.
|
|
|
|
|
|
(define-syntax define-class-pre-definitions
|
|
|
|
|
|
(lambda (x)
|
|
|
|
|
|
(syntax-case x ()
|
|
|
|
|
|
((_ () out ...)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(begin out ...))
|
2009-04-25 14:10:08 +02:00
|
|
|
|
((_ (slot rest ...) out ...)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(keyword? (syntax->datum #'slot))
|
|
|
|
|
|
#'(begin out ...))
|
2009-04-25 14:10:08 +02:00
|
|
|
|
((_ (slot rest ...) out ...)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(identifier? #'slot)
|
|
|
|
|
|
#'(define-class-pre-definitions (rest ...)
|
|
|
|
|
|
out ...))
|
2009-04-25 14:10:08 +02:00
|
|
|
|
((_ ((slotname slotopt ...) rest ...) out ...)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(define-class-pre-definitions (rest ...)
|
|
|
|
|
|
out ... (define-class-pre-definition (slotopt ...)))))))
|
2009-04-25 14:10:08 +02:00
|
|
|
|
|
|
|
|
|
|
(define-syntax define-class
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ name supers slot ...)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(define-class-pre-definitions (slot ...))
|
|
|
|
|
|
(if (and (defined? 'name)
|
|
|
|
|
|
(is-a? name <class>)
|
|
|
|
|
|
(memq <object> (class-precedence-list name)))
|
|
|
|
|
|
(class-redefinition name
|
|
|
|
|
|
(class supers slot ... #:name 'name))
|
|
|
|
|
|
(toplevel-define! 'name (class supers slot ... #:name 'name)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax standard-define-class
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ arg ...) (define-class arg ...))))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Generic functions and accessors}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2008-10-23 14:24:57 +02:00
|
|
|
|
;; Apparently the desired semantics are that we extend previous
|
|
|
|
|
|
;; procedural definitions, but that if `name' was already a generic, we
|
|
|
|
|
|
;; overwrite its definition.
|
|
|
|
|
|
(define-macro (define-generic name)
|
|
|
|
|
|
(if (not (symbol? name))
|
|
|
|
|
|
(goops-error "bad generic function name: ~S" name))
|
|
|
|
|
|
`(define ,name
|
|
|
|
|
|
(if (and (defined? ',name) (is-a? ,name <generic>))
|
|
|
|
|
|
(make <generic> #:name ',name)
|
|
|
|
|
|
(ensure-generic (if (defined? ',name) ,name #f) ',name))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (define-extended-generic name val)
|
|
|
|
|
|
(if (not (symbol? name))
|
|
|
|
|
|
(goops-error "bad generic function name: ~S" name))
|
|
|
|
|
|
`(define ,name (make-extended-generic ,val ',name)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (define-extended-generics names . args)
|
|
|
|
|
|
(let ((prefixes (get-keyword #:prefix args #f)))
|
|
|
|
|
|
(if prefixes
|
|
|
|
|
|
`(begin
|
|
|
|
|
|
,@(map (lambda (name)
|
|
|
|
|
|
`(define-extended-generic ,name
|
|
|
|
|
|
(list ,@(map (lambda (prefix)
|
|
|
|
|
|
(symbol-append prefix name))
|
|
|
|
|
|
prefixes))))
|
|
|
|
|
|
names))
|
|
|
|
|
|
(goops-error "no prefixes supplied"))))
|
2003-01-08 13:24:41 +00:00
|
|
|
|
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(define (make-generic . name)
|
|
|
|
|
|
(let ((name (and (pair? name) (car name))))
|
|
|
|
|
|
(make <generic> #:name name)))
|
|
|
|
|
|
|
2003-01-08 13:24:41 +00:00
|
|
|
|
(define (make-extended-generic gfs . name)
|
|
|
|
|
|
(let* ((name (and (pair? name) (car name)))
|
|
|
|
|
|
(gfs (if (pair? gfs) gfs (list gfs)))
|
|
|
|
|
|
(gws? (any (lambda (gf) (is-a? gf <generic-with-setter>)) gfs)))
|
|
|
|
|
|
(let ((ans (if gws?
|
|
|
|
|
|
(let* ((sname (and name (make-setter-name name)))
|
|
|
|
|
|
(setters
|
2009-02-05 00:31:38 +01:00
|
|
|
|
(append-map (lambda (gf)
|
2003-01-08 13:24:41 +00:00
|
|
|
|
(if (is-a? gf <generic-with-setter>)
|
|
|
|
|
|
(list (ensure-generic (setter gf)
|
|
|
|
|
|
sname))
|
|
|
|
|
|
'()))
|
2009-02-05 00:31:38 +01:00
|
|
|
|
gfs))
|
2003-01-08 13:24:41 +00:00
|
|
|
|
(es (make <extended-generic-with-setter>
|
|
|
|
|
|
#:name name
|
|
|
|
|
|
#:extends gfs
|
|
|
|
|
|
#:setter (make <extended-generic>
|
|
|
|
|
|
#:name sname
|
|
|
|
|
|
#:extends setters))))
|
|
|
|
|
|
(extended-by! setters (setter es))
|
|
|
|
|
|
es)
|
|
|
|
|
|
(make <extended-generic>
|
|
|
|
|
|
#:name name
|
|
|
|
|
|
#:extends gfs))))
|
|
|
|
|
|
(extended-by! gfs ans)
|
|
|
|
|
|
ans)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (extended-by! gfs eg)
|
|
|
|
|
|
(for-each (lambda (gf)
|
|
|
|
|
|
(slot-set! gf 'extended-by
|
|
|
|
|
|
(cons eg (slot-ref gf 'extended-by))))
|
|
|
|
|
|
gfs))
|
|
|
|
|
|
|
|
|
|
|
|
(define (not-extended-by! gfs eg)
|
|
|
|
|
|
(for-each (lambda (gf)
|
|
|
|
|
|
(slot-set! gf 'extended-by
|
|
|
|
|
|
(delq! eg (slot-ref gf 'extended-by))))
|
|
|
|
|
|
gfs))
|
|
|
|
|
|
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(define (ensure-generic old-definition . name)
|
|
|
|
|
|
(let ((name (and (pair? name) (car name))))
|
|
|
|
|
|
(cond ((is-a? old-definition <generic>) old-definition)
|
|
|
|
|
|
((procedure-with-setter? old-definition)
|
|
|
|
|
|
(make <generic-with-setter>
|
|
|
|
|
|
#:name name
|
|
|
|
|
|
#:default (procedure old-definition)
|
|
|
|
|
|
#:setter (setter old-definition)))
|
|
|
|
|
|
((procedure? old-definition)
|
2011-02-12 05:43:17 -05:00
|
|
|
|
(if (generic-capability? old-definition) old-definition
|
|
|
|
|
|
(make <generic> #:name name #:default old-definition)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(else (make <generic> #:name name)))))
|
|
|
|
|
|
|
2008-10-23 14:24:57 +02:00
|
|
|
|
;; same semantics as <generic>
|
2009-04-25 12:50:53 +02:00
|
|
|
|
(define-syntax define-accessor
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ name)
|
|
|
|
|
|
(define name
|
|
|
|
|
|
(cond ((not (defined? 'name)) (ensure-accessor #f 'name))
|
|
|
|
|
|
((is-a? name <accessor>) (make <accessor> #:name 'name))
|
|
|
|
|
|
(else (ensure-accessor name 'name)))))))
|
2003-03-17 13:53:58 +00:00
|
|
|
|
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(define (make-setter-name name)
|
|
|
|
|
|
(string->symbol (string-append "setter:" (symbol->string name))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-accessor . name)
|
|
|
|
|
|
(let ((name (and (pair? name) (car name))))
|
2003-03-11 14:50:08 +00:00
|
|
|
|
(make <accessor>
|
2000-10-25 14:51:33 +00:00
|
|
|
|
#:name name
|
|
|
|
|
|
#:setter (make <generic>
|
|
|
|
|
|
#:name (and name (make-setter-name name))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (ensure-accessor proc . name)
|
|
|
|
|
|
(let ((name (and (pair? name) (car name))))
|
2003-03-11 14:50:08 +00:00
|
|
|
|
(cond ((and (is-a? proc <accessor>)
|
|
|
|
|
|
(is-a? (setter proc) <generic>))
|
|
|
|
|
|
proc)
|
|
|
|
|
|
((is-a? proc <generic-with-setter>)
|
|
|
|
|
|
(upgrade-accessor proc (setter proc)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
((is-a? proc <generic>)
|
2003-03-11 14:50:08 +00:00
|
|
|
|
(upgrade-accessor proc (make-generic name)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
((procedure-with-setter? proc)
|
2003-03-11 14:50:08 +00:00
|
|
|
|
(make <accessor>
|
2000-10-25 14:51:33 +00:00
|
|
|
|
#:name name
|
|
|
|
|
|
#:default (procedure proc)
|
|
|
|
|
|
#:setter (ensure-generic (setter proc) name)))
|
|
|
|
|
|
((procedure? proc)
|
2011-02-12 05:43:17 -05:00
|
|
|
|
(ensure-accessor (if (generic-capability? proc)
|
|
|
|
|
|
(make <generic> #:name name #:default proc)
|
|
|
|
|
|
(ensure-generic proc name))
|
|
|
|
|
|
name))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(else
|
|
|
|
|
|
(make-accessor name)))))
|
|
|
|
|
|
|
2003-03-11 14:50:08 +00:00
|
|
|
|
(define (upgrade-accessor generic setter)
|
2003-01-08 13:24:41 +00:00
|
|
|
|
(let ((methods (slot-ref generic 'methods))
|
|
|
|
|
|
(gws (make (if (is-a? generic <extended-generic>)
|
|
|
|
|
|
<extended-generic-with-setter>
|
2003-03-11 14:50:08 +00:00
|
|
|
|
<accessor>)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
#:name (generic-function-name generic)
|
2003-01-08 13:24:41 +00:00
|
|
|
|
#:extended-by (slot-ref generic 'extended-by)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
#:setter setter)))
|
2003-01-08 13:24:41 +00:00
|
|
|
|
(if (is-a? generic <extended-generic>)
|
|
|
|
|
|
(let ((gfs (slot-ref generic 'extends)))
|
|
|
|
|
|
(not-extended-by! gfs generic)
|
|
|
|
|
|
(slot-set! gws 'extends gfs)
|
|
|
|
|
|
(extended-by! gfs gws)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;; Steal old methods
|
|
|
|
|
|
(for-each (lambda (method)
|
|
|
|
|
|
(slot-set! method 'generic-function gws))
|
|
|
|
|
|
methods)
|
|
|
|
|
|
(slot-set! gws 'methods methods)
|
|
|
|
|
|
gws))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Methods}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2009-04-25 12:50:53 +02:00
|
|
|
|
(define (toplevel-define! name val)
|
|
|
|
|
|
(module-define! (current-module) name val))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax define-method
|
|
|
|
|
|
(syntax-rules (setter)
|
|
|
|
|
|
((_ ((setter name) . args) body ...)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(if (or (not (defined? 'name))
|
|
|
|
|
|
(not (is-a? name <accessor>)))
|
|
|
|
|
|
(toplevel-define! 'name
|
|
|
|
|
|
(ensure-accessor
|
|
|
|
|
|
(if (defined? 'name) name #f) 'name)))
|
|
|
|
|
|
(add-method! (setter name) (method args body ...))))
|
|
|
|
|
|
((_ (name . args) body ...)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
;; FIXME: this code is how it always was, but it's quite cracky:
|
|
|
|
|
|
;; it will only define the generic function if it was undefined
|
|
|
|
|
|
;; before (ok), or *was defined to #f*. The latter is crack. But
|
|
|
|
|
|
;; there are bootstrap issues about fixing this -- change it to
|
|
|
|
|
|
;; (is-a? name <generic>) and see.
|
|
|
|
|
|
(if (or (not (defined? 'name))
|
|
|
|
|
|
(not name))
|
|
|
|
|
|
(toplevel-define! 'name (make <generic> #:name 'name)))
|
|
|
|
|
|
(add-method! name (method args body ...))))))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(define-syntax method
|
|
|
|
|
|
(lambda (x)
|
2009-05-21 15:34:29 +02:00
|
|
|
|
(define (parse-args args)
|
|
|
|
|
|
(let lp ((ls args) (formals '()) (specializers '()))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(syntax-case ls ()
|
2009-05-21 15:34:29 +02:00
|
|
|
|
(((f s) . rest)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(and (identifier? #'f) (identifier? #'s))
|
|
|
|
|
|
(lp #'rest
|
|
|
|
|
|
(cons #'f formals)
|
|
|
|
|
|
(cons #'s specializers)))
|
2009-05-21 15:34:29 +02:00
|
|
|
|
((f . rest)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(identifier? #'f)
|
|
|
|
|
|
(lp #'rest
|
|
|
|
|
|
(cons #'f formals)
|
|
|
|
|
|
(cons #'<top> specializers)))
|
2009-05-21 15:34:29 +02:00
|
|
|
|
(()
|
|
|
|
|
|
(list (reverse formals)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(reverse (cons #''() specializers))))
|
2009-05-21 15:34:29 +02:00
|
|
|
|
(tail
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(identifier? #'tail)
|
|
|
|
|
|
(list (append (reverse formals) #'tail)
|
|
|
|
|
|
(reverse (cons #'<top> specializers)))))))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
|
|
|
|
|
|
(define (find-free-id exp referent)
|
|
|
|
|
|
(syntax-case exp ()
|
|
|
|
|
|
((x . y)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(or (find-free-id #'x referent)
|
|
|
|
|
|
(find-free-id #'y referent)))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(x
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(identifier? #'x)
|
|
|
|
|
|
(let ((id (datum->syntax #'x referent)))
|
|
|
|
|
|
(and (free-identifier=? #'x id) id)))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(_ #f)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (compute-procedure formals body)
|
|
|
|
|
|
(syntax-case body ()
|
|
|
|
|
|
((body0 ...)
|
|
|
|
|
|
(with-syntax ((formals formals))
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(lambda formals body0 ...)))))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
|
|
|
|
|
|
(define (->proper args)
|
|
|
|
|
|
(let lp ((ls args) (out '()))
|
|
|
|
|
|
(syntax-case ls ()
|
2011-05-21 13:12:44 +02:00
|
|
|
|
((x . xs) (lp #'xs (cons #'x out)))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(() (reverse out))
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(tail (reverse (cons #'tail out))))))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
|
|
|
|
|
|
(define (compute-make-procedure formals body next-method)
|
|
|
|
|
|
(syntax-case body ()
|
|
|
|
|
|
((body ...)
|
|
|
|
|
|
(with-syntax ((next-method next-method))
|
|
|
|
|
|
(syntax-case formals ()
|
|
|
|
|
|
((formal ...)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(lambda (real-next-method)
|
|
|
|
|
|
(lambda (formal ...)
|
|
|
|
|
|
(let ((next-method (lambda args
|
|
|
|
|
|
(if (null? args)
|
|
|
|
|
|
(real-next-method formal ...)
|
|
|
|
|
|
(apply real-next-method args)))))
|
|
|
|
|
|
body ...))))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(formals
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(with-syntax (((formal ...) (->proper #'formals)))
|
|
|
|
|
|
#'(lambda (real-next-method)
|
|
|
|
|
|
(lambda formals
|
|
|
|
|
|
(let ((next-method (lambda args
|
|
|
|
|
|
(if (null? args)
|
|
|
|
|
|
(apply real-next-method formal ...)
|
|
|
|
|
|
(apply real-next-method args)))))
|
|
|
|
|
|
body ...))))))))))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
|
|
|
|
|
|
(define (compute-procedures formals body)
|
|
|
|
|
|
;; So, our use of this is broken, because it operates on the
|
|
|
|
|
|
;; pre-expansion source code. It's equivalent to just searching
|
|
|
|
|
|
;; for referent in the datums. Ah well.
|
|
|
|
|
|
(let ((id (find-free-id body 'next-method)))
|
|
|
|
|
|
(if id
|
|
|
|
|
|
;; return a make-procedure
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(values #'#f
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(compute-make-procedure formals body id))
|
|
|
|
|
|
(values (compute-procedure formals body)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'#f))))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
|
|
|
|
|
|
(syntax-case x ()
|
2011-05-21 13:12:44 +02:00
|
|
|
|
((_ args) #'(method args (if #f #f)))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
((_ args body0 body1 ...)
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(with-syntax (((formals (specializer ...)) (parse-args #'args)))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(call-with-values
|
|
|
|
|
|
(lambda ()
|
2011-05-21 13:12:44 +02:00
|
|
|
|
(compute-procedures #'formals #'(body0 body1 ...)))
|
2009-05-21 13:49:00 +02:00
|
|
|
|
(lambda (procedure make-procedure)
|
|
|
|
|
|
(with-syntax ((procedure procedure)
|
|
|
|
|
|
(make-procedure make-procedure))
|
2011-05-21 13:12:44 +02:00
|
|
|
|
#'(make <method>
|
|
|
|
|
|
#:specializers (cons* specializer ...)
|
|
|
|
|
|
#:formals 'formals
|
|
|
|
|
|
#:body '(body0 body1 ...)
|
|
|
|
|
|
#:make-procedure make-procedure
|
|
|
|
|
|
#:procedure procedure)))))))))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {add-method!}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (add-method-in-classes! m)
|
|
|
|
|
|
;; Add method in all the classes which appears in its specializers list
|
|
|
|
|
|
(for-each* (lambda (x)
|
|
|
|
|
|
(let ((dm (class-direct-methods x)))
|
2009-02-14 00:47:56 +01:00
|
|
|
|
(if (not (memq m dm))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(slot-set! x 'direct-methods (cons m dm)))))
|
|
|
|
|
|
(method-specializers m)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (remove-method-in-classes! m)
|
|
|
|
|
|
;; Remove method in all the classes which appears in its specializers list
|
|
|
|
|
|
(for-each* (lambda (x)
|
|
|
|
|
|
(slot-set! x
|
|
|
|
|
|
'direct-methods
|
|
|
|
|
|
(delv! m (class-direct-methods x))))
|
|
|
|
|
|
(method-specializers m)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (compute-new-list-of-methods gf new)
|
|
|
|
|
|
(let ((new-spec (method-specializers new))
|
2003-01-08 13:24:41 +00:00
|
|
|
|
(methods (slot-ref gf 'methods)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let loop ((l methods))
|
|
|
|
|
|
(if (null? l)
|
|
|
|
|
|
(cons new methods)
|
|
|
|
|
|
(if (equal? (method-specializers (car l)) new-spec)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
;; This spec. list already exists. Remove old method from dependents
|
|
|
|
|
|
(remove-method-in-classes! (car l))
|
|
|
|
|
|
(set-car! l new)
|
|
|
|
|
|
methods)
|
|
|
|
|
|
(loop (cdr l)))))))
|
|
|
|
|
|
|
2008-10-31 00:07:04 +01:00
|
|
|
|
(define internal-add-method!
|
|
|
|
|
|
(method ((gf <generic>) (m <method>))
|
|
|
|
|
|
(slot-set! m 'generic-function gf)
|
|
|
|
|
|
(slot-set! gf 'methods (compute-new-list-of-methods gf m))
|
|
|
|
|
|
(let ((specializers (slot-ref m 'specializers)))
|
|
|
|
|
|
(slot-set! gf 'n-specialized
|
|
|
|
|
|
(max (length* specializers)
|
|
|
|
|
|
(slot-ref gf 'n-specialized))))
|
|
|
|
|
|
(%invalidate-method-cache! gf)
|
|
|
|
|
|
(add-method-in-classes! m)
|
|
|
|
|
|
*unspecified*))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
(define-generic add-method!)
|
|
|
|
|
|
|
2008-10-31 00:07:04 +01:00
|
|
|
|
((method-procedure internal-add-method!) add-method! internal-add-method!)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (add-method! (proc <procedure>) (m <method>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(if (generic-capability? proc)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(enable-primitive-generic! proc)
|
|
|
|
|
|
(add-method! proc m))
|
|
|
|
|
|
(next-method)))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (add-method! (pg <primitive-generic>) (m <method>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(add-method! (primitive-generic-generic pg) m))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (add-method! obj (m <method>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "~S is not a valid generic function" obj))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Access to meta objects}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Methods
|
|
|
|
|
|
;;;
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (method-source (m <method>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let* ((spec (map* class-name (slot-ref m 'specializers)))
|
2009-03-20 12:06:10 +01:00
|
|
|
|
(src (procedure-source (slot-ref m 'procedure))))
|
|
|
|
|
|
(and src
|
|
|
|
|
|
(let ((args (cadr src))
|
|
|
|
|
|
(body (cddr src)))
|
|
|
|
|
|
(cons 'method
|
|
|
|
|
|
(cons (map* list args spec)
|
|
|
|
|
|
body))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-method (method-formals (m <method>))
|
|
|
|
|
|
(slot-ref m 'formals))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Slots
|
|
|
|
|
|
;;;
|
|
|
|
|
|
(define slot-definition-name car)
|
|
|
|
|
|
|
|
|
|
|
|
(define slot-definition-options cdr)
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-definition-allocation s)
|
|
|
|
|
|
(get-keyword #:allocation (cdr s) #:instance))
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-definition-getter s)
|
|
|
|
|
|
(get-keyword #:getter (cdr s) #f))
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-definition-setter s)
|
|
|
|
|
|
(get-keyword #:setter (cdr s) #f))
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-definition-accessor s)
|
|
|
|
|
|
(get-keyword #:accessor (cdr s) #f))
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-definition-init-value s)
|
|
|
|
|
|
;; can be #f, so we can't use #f as non-value
|
|
|
|
|
|
(get-keyword #:init-value (cdr s) (make-unbound)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-definition-init-form s)
|
|
|
|
|
|
(get-keyword #:init-form (cdr s) (make-unbound)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-definition-init-thunk s)
|
|
|
|
|
|
(get-keyword #:init-thunk (cdr s) #f))
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-definition-init-keyword s)
|
|
|
|
|
|
(get-keyword #:init-keyword (cdr s) #f))
|
|
|
|
|
|
|
|
|
|
|
|
(define (class-slot-definition class slot-name)
|
|
|
|
|
|
(assq slot-name (class-slots class)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (slot-init-function class slot-name)
|
|
|
|
|
|
(cadr (assq slot-name (slot-ref class 'getters-n-setters))))
|
|
|
|
|
|
|
limn goops flags, remove foreign objs, rename entity to applicable-struct
* libguile/goops.c (scm_class_applicable_struct)
(scm_class_applicable_struct_with_setter)
(scm_class_applicable_struct_class): Rename from
scm_class_entity, scm_class_entity_with_setter, and
scm_class_entity_class.
(scm_class_simple_method): Removed; this abstraction is not used.
(scm_class_foreign_class, scm_class_foreign_object): Remove these,
they are undocumented and unused. They might come back later.
(scm_sys_inherit_magic_x): Simply inherit the vtable flags from the
class's class. Flags are about layout, and it is the class that
determines the layout of the instance.
(scm_basic_basic_make_class): Don't bother setting GOOPS_OR_VALID,
inherit-magic will do that.
(scm_basic_make_class): Inherit magic after setting the layout. Allows
the struct magic checker to do its job.
(scm_accessor_method_slot_definition): Move implementation to Scheme.
Removes the need for the accessor flag.
(scm_sys_allocate_instance): Adapt to scm_i_alloc_struct name change,
and that alloc-struct will handle finalization.
(scm_compute_applicable_methods): Remove accessor check, as it's
unnecessary.
(scm_make): Adapt to new generic slot order, and no more
simple-method.
(create_standard_classes): What was the GF slot "dispatch-procedure"
is now the applicable-struct slot "procedure". No more foreign class,
foreign object, or simple method. Rename <entity> and friends to
<applicable-struct> and friends. No more entity-with-setter -- though
perhaps it will come back too. Instead generic-with-setter is its own
thing.
* libguile/goops.h (SCM_CLASSF_METACLASS): "A goops class that is a
vtable" -- no need for a separate flag.
(SCM_CLASSF_FOREIGN, SCM_CLASSF_SIMPLE_METHOD)
(SCM_CLASSF_ACCESSOR_METHOD): Removed these unused flags.
(SCM_ACCESSORP): Removed.
Renumber generic slots, rename entity classes, and remove the foreign
class, foreign object, and simple method classes.
* libguile/struct.c (scm_i_struct_inherit_vtable_magic): New function,
called when making new vtables.applicable structs
(scm_i_alloc_struct): Remove 8-bit alignment check, as libGC
guarantees this for us. Handle finalizer registration here.
(scm_make_struct): Factor some things to scm_i_alloc_struct and
scm_i_struct_inherit_vtable_magic.
(scm_make_vtable_vtable): Adapt to scm_i_alloc_struct name change.
* libguile/struct.h (scm_i_alloc_struct): Change name from
scm_alloc_struct, and make internal.
* module/oop/goops.scm (oop): Don't declare #:replace <class> et al,
because <class> isn't defined in the core any more.
(accessor-method-slot-definition): Defined in Scheme now.
Remove <foreign-object> methods.
(initialize on <class>): Prep layout before inheriting magic, as in
scm_basic_make_class.
* module/oop/goops/dispatch.scm (delayed-compile)
(memoize-effective-method!): Adapt to 'procedure slot name change.
2009-11-08 11:24:23 +01:00
|
|
|
|
(define (accessor-method-slot-definition obj)
|
|
|
|
|
|
"Return the slot definition of the accessor @var{obj}."
|
|
|
|
|
|
(slot-ref obj 'slot-definition))
|
|
|
|
|
|
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Standard methods used by the C runtime}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; Methods to compare objects
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2009-11-08 11:49:06 +01:00
|
|
|
|
;; Have to do this in a strange order because equal? is used in the
|
|
|
|
|
|
;; add-method! implementation; we need to make sure that when the
|
|
|
|
|
|
;; primitive is extended, that the generic has a method. =
|
|
|
|
|
|
(define g-equal? (make-generic 'equal?))
|
|
|
|
|
|
;; When this generic gets called, we will have already checked eq? and
|
|
|
|
|
|
;; eqv? -- the purpose of this generic is to extend equality. So by
|
|
|
|
|
|
;; default, there is no extension, thus the #f return.
|
|
|
|
|
|
(add-method! g-equal? (method (x y) #f))
|
|
|
|
|
|
(set-primitive-generic! equal? g-equal?)
|
2003-03-06 12:51:57 +00:00
|
|
|
|
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; methods to display/write an object
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
; Code for writing objects must test that the slots they use are
|
|
|
|
|
|
; bound. Otherwise a slot-unbound method will be called and will
|
|
|
|
|
|
; conduct to an infinite loop.
|
|
|
|
|
|
|
|
|
|
|
|
;; Write
|
|
|
|
|
|
(define (display-address o file)
|
|
|
|
|
|
(display (number->string (object-address o) 16) file))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (write o file)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(display "#<instance " file)
|
|
|
|
|
|
(display-address o file)
|
|
|
|
|
|
(display #\> file))
|
|
|
|
|
|
|
|
|
|
|
|
(define write-object (primitive-generic-generic write))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (write (o <object>) file)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((class (class-of o)))
|
|
|
|
|
|
(if (slot-bound? class 'name)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display "#<" file)
|
|
|
|
|
|
(display (class-name class) file)
|
|
|
|
|
|
(display #\space file)
|
|
|
|
|
|
(display-address o file)
|
|
|
|
|
|
(display #\> file))
|
|
|
|
|
|
(next-method))))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (write (class <class>) file)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((meta (class-of class)))
|
|
|
|
|
|
(if (and (slot-bound? class 'name)
|
|
|
|
|
|
(slot-bound? meta 'name))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display "#<" file)
|
|
|
|
|
|
(display (class-name meta) file)
|
|
|
|
|
|
(display #\space file)
|
|
|
|
|
|
(display (class-name class) file)
|
|
|
|
|
|
(display #\space file)
|
|
|
|
|
|
(display-address class file)
|
|
|
|
|
|
(display #\> file))
|
|
|
|
|
|
(next-method))))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (write (gf <generic>) file)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((meta (class-of gf)))
|
|
|
|
|
|
(if (and (slot-bound? meta 'name)
|
|
|
|
|
|
(slot-bound? gf 'methods))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display "#<" file)
|
|
|
|
|
|
(display (class-name meta) file)
|
|
|
|
|
|
(let ((name (generic-function-name gf)))
|
|
|
|
|
|
(if name
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display #\space file)
|
|
|
|
|
|
(display name file))))
|
|
|
|
|
|
(display " (" file)
|
|
|
|
|
|
(display (length (generic-function-methods gf)) file)
|
|
|
|
|
|
(display ")>" file))
|
|
|
|
|
|
(next-method))))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (write (o <method>) file)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((meta (class-of o)))
|
|
|
|
|
|
(if (and (slot-bound? meta 'name)
|
|
|
|
|
|
(slot-bound? o 'specializers))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display "#<" file)
|
|
|
|
|
|
(display (class-name meta) file)
|
|
|
|
|
|
(display #\space file)
|
|
|
|
|
|
(display (map* (lambda (spec)
|
|
|
|
|
|
(if (slot-bound? spec 'name)
|
|
|
|
|
|
(slot-ref spec 'name)
|
|
|
|
|
|
spec))
|
|
|
|
|
|
(method-specializers o))
|
|
|
|
|
|
file)
|
|
|
|
|
|
(display #\space file)
|
|
|
|
|
|
(display-address o file)
|
|
|
|
|
|
(display #\> file))
|
|
|
|
|
|
(next-method))))
|
|
|
|
|
|
|
|
|
|
|
|
;; Display (do the same thing as write by default)
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (display o file)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(write-object o file))
|
|
|
|
|
|
|
2003-03-07 13:12:47 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; Handling of duplicate bindings in the module system
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define-method (merge-generics (module <module>)
|
|
|
|
|
|
(name <symbol>)
|
|
|
|
|
|
(int1 <module>)
|
|
|
|
|
|
(val1 <top>)
|
|
|
|
|
|
(int2 <module>)
|
|
|
|
|
|
(val2 <top>)
|
|
|
|
|
|
(var <top>)
|
|
|
|
|
|
(val <top>))
|
|
|
|
|
|
#f)
|
|
|
|
|
|
|
|
|
|
|
|
(define-method (merge-generics (module <module>)
|
|
|
|
|
|
(name <symbol>)
|
|
|
|
|
|
(int1 <module>)
|
|
|
|
|
|
(val1 <generic>)
|
|
|
|
|
|
(int2 <module>)
|
|
|
|
|
|
(val2 <generic>)
|
|
|
|
|
|
(var <top>)
|
|
|
|
|
|
(val <boolean>))
|
2003-03-12 18:41:44 +00:00
|
|
|
|
(and (not (eq? val1 val2))
|
|
|
|
|
|
(make-variable (make-extended-generic (list val2 val1) name))))
|
2003-03-07 13:12:47 +00:00
|
|
|
|
|
|
|
|
|
|
(define-method (merge-generics (module <module>)
|
|
|
|
|
|
(name <symbol>)
|
|
|
|
|
|
(int1 <module>)
|
|
|
|
|
|
(val1 <generic>)
|
|
|
|
|
|
(int2 <module>)
|
|
|
|
|
|
(val2 <generic>)
|
|
|
|
|
|
(var <top>)
|
|
|
|
|
|
(gf <extended-generic>))
|
2003-03-12 18:41:44 +00:00
|
|
|
|
(and (not (memq val2 (slot-ref gf 'extends)))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(slot-set! gf
|
|
|
|
|
|
'extends
|
|
|
|
|
|
(cons val2 (delq! val2 (slot-ref gf 'extends))))
|
|
|
|
|
|
(slot-set! val2
|
|
|
|
|
|
'extended-by
|
|
|
|
|
|
(cons gf (delq! gf (slot-ref val2 'extended-by))))
|
|
|
|
|
|
var)))
|
2003-03-07 13:12:47 +00:00
|
|
|
|
|
|
|
|
|
|
(module-define! duplicate-handlers 'merge-generics merge-generics)
|
|
|
|
|
|
|
2003-03-11 14:50:08 +00:00
|
|
|
|
(define-method (merge-accessors (module <module>)
|
|
|
|
|
|
(name <symbol>)
|
|
|
|
|
|
(int1 <module>)
|
|
|
|
|
|
(val1 <top>)
|
|
|
|
|
|
(int2 <module>)
|
|
|
|
|
|
(val2 <top>)
|
|
|
|
|
|
(var <top>)
|
|
|
|
|
|
(val <top>))
|
|
|
|
|
|
#f)
|
|
|
|
|
|
|
|
|
|
|
|
(define-method (merge-accessors (module <module>)
|
|
|
|
|
|
(name <symbol>)
|
|
|
|
|
|
(int1 <module>)
|
|
|
|
|
|
(val1 <accessor>)
|
|
|
|
|
|
(int2 <module>)
|
|
|
|
|
|
(val2 <accessor>)
|
|
|
|
|
|
(var <top>)
|
|
|
|
|
|
(val <top>))
|
|
|
|
|
|
(merge-generics module name int1 val1 int2 val2 var val))
|
|
|
|
|
|
|
|
|
|
|
|
(module-define! duplicate-handlers 'merge-accessors merge-accessors)
|
|
|
|
|
|
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; slot access
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (class-slot-g-n-s class slot-name)
|
|
|
|
|
|
(let* ((this-slot (assq slot-name (slot-ref class 'slots)))
|
|
|
|
|
|
(g-n-s (cddr (or (assq slot-name (slot-ref class 'getters-n-setters))
|
|
|
|
|
|
(slot-missing class slot-name)))))
|
|
|
|
|
|
(if (not (memq (slot-definition-allocation this-slot)
|
|
|
|
|
|
'(#:class #:each-subclass)))
|
|
|
|
|
|
(slot-missing class slot-name))
|
|
|
|
|
|
g-n-s))
|
|
|
|
|
|
|
|
|
|
|
|
(define (class-slot-ref class slot)
|
|
|
|
|
|
(let ((x ((car (class-slot-g-n-s class slot)) #f)))
|
|
|
|
|
|
(if (unbound? x)
|
|
|
|
|
|
(slot-unbound class slot)
|
|
|
|
|
|
x)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (class-slot-set! class slot value)
|
|
|
|
|
|
((cadr (class-slot-g-n-s class slot)) #f value))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (slot-unbound (c <class>) (o <object>) s)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "Slot `~S' is unbound in object ~S" s o))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (slot-unbound (c <class>) s)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "Slot `~S' is unbound in class ~S" s c))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (slot-unbound (o <object>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "Unbound slot in object ~S" o))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (slot-missing (c <class>) (o <object>) s)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "No slot with name `~S' in object ~S" s o))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (slot-missing (c <class>) s)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "No class slot with name `~S' in class ~S" s c))
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (slot-missing (c <class>) (o <object>) s value)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(slot-missing c o s))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Methods for the possible error we can encounter when calling a gf
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (no-next-method (gf <generic>) args)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "No next method when calling ~S\nwith arguments ~S" gf args))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (no-applicable-method (gf <generic>) args)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "No applicable method for ~S in call ~S"
|
|
|
|
|
|
gf (cons (generic-function-name gf) args)))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (no-method (gf <generic>) args)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "No method defined for ~S" gf))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Cloning functions (from rdeline@CS.CMU.EDU)}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (shallow-clone (self <object>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((clone (%allocate-instance (class-of self) '()))
|
|
|
|
|
|
(slots (map slot-definition-name
|
|
|
|
|
|
(class-slots (class-of self)))))
|
|
|
|
|
|
(for-each (lambda (slot)
|
|
|
|
|
|
(if (slot-bound? self slot)
|
|
|
|
|
|
(slot-set! clone slot (slot-ref self slot))))
|
|
|
|
|
|
slots)
|
|
|
|
|
|
clone))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (deep-clone (self <object>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((clone (%allocate-instance (class-of self) '()))
|
|
|
|
|
|
(slots (map slot-definition-name
|
|
|
|
|
|
(class-slots (class-of self)))))
|
|
|
|
|
|
(for-each (lambda (slot)
|
|
|
|
|
|
(if (slot-bound? self slot)
|
|
|
|
|
|
(slot-set! clone slot
|
|
|
|
|
|
(let ((value (slot-ref self slot)))
|
|
|
|
|
|
(if (instance? value)
|
|
|
|
|
|
(deep-clone value)
|
|
|
|
|
|
value)))))
|
|
|
|
|
|
slots)
|
|
|
|
|
|
clone))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Class redefinition utilities}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; (class-redefinition OLD NEW)
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; Has correct the following conditions:
|
|
|
|
|
|
|
|
|
|
|
|
;;; Methods
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; 1. New accessor specializers refer to new header
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Classes
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; 1. New class cpl refers to the new class header
|
|
|
|
|
|
;;; 2. Old class header exists on old super classes direct-subclass lists
|
|
|
|
|
|
;;; 3. New class header exists on new super classes direct-subclass lists
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (class-redefinition (old <class>) (new <class>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;; Work on direct methods:
|
|
|
|
|
|
;; 1. Remove accessor methods from the old class
|
|
|
|
|
|
;; 2. Patch the occurences of new in the specializers by old
|
|
|
|
|
|
;; 3. Displace the methods from old to new
|
|
|
|
|
|
(remove-class-accessors! old) ;; -1-
|
|
|
|
|
|
(let ((methods (class-direct-methods new)))
|
|
|
|
|
|
(for-each (lambda (m)
|
|
|
|
|
|
(update-direct-method! m new old)) ;; -2-
|
|
|
|
|
|
methods)
|
|
|
|
|
|
(slot-set! new
|
|
|
|
|
|
'direct-methods
|
|
|
|
|
|
(append methods (class-direct-methods old))))
|
|
|
|
|
|
|
|
|
|
|
|
;; Substitute old for new in new cpl
|
|
|
|
|
|
(set-car! (slot-ref new 'cpl) old)
|
|
|
|
|
|
|
|
|
|
|
|
;; Remove the old class from the direct-subclasses list of its super classes
|
|
|
|
|
|
(for-each (lambda (c) (slot-set! c 'direct-subclasses
|
|
|
|
|
|
(delv! old (class-direct-subclasses c))))
|
|
|
|
|
|
(class-direct-supers old))
|
|
|
|
|
|
|
|
|
|
|
|
;; Replace the new class with the old in the direct-subclasses of the supers
|
|
|
|
|
|
(for-each (lambda (c)
|
|
|
|
|
|
(slot-set! c 'direct-subclasses
|
|
|
|
|
|
(cons old (delv! new (class-direct-subclasses c)))))
|
|
|
|
|
|
(class-direct-supers new))
|
|
|
|
|
|
|
|
|
|
|
|
;; Swap object headers
|
|
|
|
|
|
(%modify-class old new)
|
|
|
|
|
|
|
|
|
|
|
|
;; Now old is NEW!
|
|
|
|
|
|
|
|
|
|
|
|
;; Redefine all the subclasses of old to take into account modification
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (c)
|
|
|
|
|
|
(update-direct-subclass! c new old))
|
|
|
|
|
|
(class-direct-subclasses new))
|
|
|
|
|
|
|
|
|
|
|
|
;; Invalidate class so that subsequent instances slot accesses invoke
|
|
|
|
|
|
;; change-object-class
|
|
|
|
|
|
(slot-set! new 'redefined old)
|
|
|
|
|
|
(%invalidate-class new) ;must come after slot-set!
|
|
|
|
|
|
|
|
|
|
|
|
old)
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; remove-class-accessors!
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (remove-class-accessors! (c <class>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(for-each (lambda (m)
|
|
|
|
|
|
(if (is-a? m <accessor-method>)
|
2003-04-15 01:17:36 +00:00
|
|
|
|
(let ((gf (slot-ref m 'generic-function)))
|
|
|
|
|
|
;; remove the method from its GF
|
|
|
|
|
|
(slot-set! gf 'methods
|
|
|
|
|
|
(delq1! m (slot-ref gf 'methods)))
|
|
|
|
|
|
(%invalidate-method-cache! gf)
|
|
|
|
|
|
;; remove the method from its specializers
|
|
|
|
|
|
(remove-method-in-classes! m))))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(class-direct-methods c)))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; update-direct-method!
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (update-direct-method! (m <method>)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(old <class>)
|
|
|
|
|
|
(new <class>))
|
|
|
|
|
|
(let loop ((l (method-specializers m)))
|
|
|
|
|
|
;; Note: the <top> in dotted list is never used.
|
|
|
|
|
|
;; So we can work as if we had only proper lists.
|
|
|
|
|
|
(if (pair? l)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(if (eqv? (car l) old)
|
|
|
|
|
|
(set-car! l new))
|
|
|
|
|
|
(loop (cdr l))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; update-direct-subclass!
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (update-direct-subclass! (c <class>)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(old <class>)
|
|
|
|
|
|
(new <class>))
|
|
|
|
|
|
(class-redefinition c
|
|
|
|
|
|
(make-class (class-direct-supers c)
|
|
|
|
|
|
(class-direct-slots c)
|
|
|
|
|
|
#:name (class-name c)
|
|
|
|
|
|
#:metaclass (class-of c))))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Utilities for INITIALIZE methods}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; compute-slot-accessors
|
|
|
|
|
|
;;;
|
2009-11-27 20:50:40 +01:00
|
|
|
|
(define (compute-slot-accessors class slots)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (s g-n-s)
|
2009-09-21 00:10:28 +02:00
|
|
|
|
(let ((getter-function (slot-definition-getter s))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(setter-function (slot-definition-setter s))
|
|
|
|
|
|
(accessor (slot-definition-accessor s)))
|
|
|
|
|
|
(if getter-function
|
|
|
|
|
|
(add-method! getter-function
|
|
|
|
|
|
(compute-getter-method class g-n-s)))
|
|
|
|
|
|
(if setter-function
|
|
|
|
|
|
(add-method! setter-function
|
|
|
|
|
|
(compute-setter-method class g-n-s)))
|
|
|
|
|
|
(if accessor
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(add-method! accessor
|
|
|
|
|
|
(compute-getter-method class g-n-s))
|
|
|
|
|
|
(add-method! (setter accessor)
|
|
|
|
|
|
(compute-setter-method class g-n-s))))))
|
|
|
|
|
|
slots (slot-ref class 'getters-n-setters)))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (compute-getter-method (class <class>) slotdef)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((init-thunk (cadr slotdef))
|
|
|
|
|
|
(g-n-s (cddr slotdef)))
|
|
|
|
|
|
(make <accessor-method>
|
|
|
|
|
|
#:specializers (list class)
|
|
|
|
|
|
#:procedure (cond ((pair? g-n-s)
|
2003-04-15 01:17:36 +00:00
|
|
|
|
(make-generic-bound-check-getter (car g-n-s)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(init-thunk
|
|
|
|
|
|
(standard-get g-n-s))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(bound-check-get g-n-s)))
|
|
|
|
|
|
#:slot-definition slotdef)))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (compute-setter-method (class <class>) slotdef)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((g-n-s (cddr slotdef)))
|
|
|
|
|
|
(make <accessor-method>
|
|
|
|
|
|
#:specializers (list class <top>)
|
|
|
|
|
|
#:procedure (if (pair? g-n-s)
|
|
|
|
|
|
(cadr g-n-s)
|
|
|
|
|
|
(standard-set g-n-s))
|
|
|
|
|
|
#:slot-definition slotdef)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-generic-bound-check-getter proc)
|
2009-11-26 22:11:40 +01:00
|
|
|
|
(lambda (o) (assert-bound (proc o) o)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
2008-10-31 18:30:27 +01:00
|
|
|
|
;; the idea is to compile the index into the procedure, for fastest
|
|
|
|
|
|
;; lookup. Also, @slot-ref and @slot-set! have their own bytecodes.
|
2008-09-30 20:29:35 +02:00
|
|
|
|
|
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
2009-03-06 13:29:13 +01:00
|
|
|
|
(eval-when (eval load compile)
|
|
|
|
|
|
(define num-standard-pre-cache 20))
|
2009-02-14 00:24:32 +01:00
|
|
|
|
|
|
|
|
|
|
(define-macro (define-standard-accessor-method form . body)
|
|
|
|
|
|
(let ((name (caar form))
|
|
|
|
|
|
(n-var (cadar form))
|
|
|
|
|
|
(args (cdr form)))
|
|
|
|
|
|
(define (make-one x)
|
|
|
|
|
|
(define (body-trans form)
|
|
|
|
|
|
(cond ((not (pair? form)) form)
|
|
|
|
|
|
((eq? (car form) '@slot-ref)
|
|
|
|
|
|
`(,(car form) ,(cadr form) ,x))
|
|
|
|
|
|
((eq? (car form) '@slot-set!)
|
|
|
|
|
|
`(,(car form) ,(cadr form) ,x ,(cadddr form)))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(map body-trans form))))
|
|
|
|
|
|
`(lambda ,args ,@(map body-trans body)))
|
|
|
|
|
|
`(define ,name
|
|
|
|
|
|
(let ((cache (vector ,@(map make-one (iota num-standard-pre-cache)))))
|
|
|
|
|
|
(lambda (n)
|
|
|
|
|
|
(if (< n ,num-standard-pre-cache)
|
|
|
|
|
|
(vector-ref cache n)
|
|
|
|
|
|
((lambda (,n-var) (lambda ,args ,@body)) n)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-standard-accessor-method ((bound-check-get n) o)
|
|
|
|
|
|
(let ((x (@slot-ref o n)))
|
|
|
|
|
|
(if (unbound? x)
|
2009-10-22 22:42:45 +02:00
|
|
|
|
(slot-unbound o)
|
2009-02-14 00:24:32 +01:00
|
|
|
|
x)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-standard-accessor-method ((standard-get n) o)
|
|
|
|
|
|
(@slot-ref o n))
|
|
|
|
|
|
|
|
|
|
|
|
(define-standard-accessor-method ((standard-set n) o v)
|
|
|
|
|
|
(@slot-set! o n v))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;; compute-getters-n-setters
|
2003-04-20 17:35:41 +00:00
|
|
|
|
;;;
|
2009-11-27 20:50:40 +01:00
|
|
|
|
(define (compute-getters-n-setters class slots)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
2003-04-17 17:37:11 +00:00
|
|
|
|
(define (compute-slot-init-function name s)
|
|
|
|
|
|
(or (let ((thunk (slot-definition-init-thunk s)))
|
|
|
|
|
|
(and thunk
|
eval.c closures are now applicable smobs, not tc3s
* libguile/debug.c (scm_procedure_name): Remove a SCM_CLOSUREP case and
some dead code.
(scm_procedure_module): Remove. This was introduced a few months ago
for the hygienic expander, but now it is no longer needed, as the
expander keeps track of this information itself.
* libguile/debug.h: Remove scm_procedure_module.
* libguile/eval.c: Instead of using tc3 closures, define a "boot
closure" applicable smob type, and represent closures with that. The
advantage is that after eval.scm is compiled, boot closures take up no
address space (besides a smob number) in the runtime, and require no
special cases in procedure dispatch.
* libguile/eval.h: Remove the internal functions scm_i_call_closure_0
and scm_closure_apply, and the public function scm_closure.
* libguile/gc.c (scm_storage_prehistory): No tc3_closure displacement
registration.
(scm_i_tag_name): Remove closure case, and a dead cclo case.
* libguile/vm.c (apply_foreign):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_procedure_documentation);
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of): Remove tc3_closure/tcs_closure cases.
* libguile/hash.c (scm_hasher):
* libguile/hooks.c (scm_add_hook_x): Use new scm_i_procedure_arity.
* libguile/macros.c (macro_print): Print all macros using the same code.
(scm_macro_transformer): Return any procedure, not just programs.
* libguile/procprop.h:
* libguile/procprop.c (scm_i_procedure_arity): Instead of returning a
list that the caller has to parse, have the same prototype as
scm_i_program_arity. An incompatible change, but it's an internal
function anyway.
(scm_procedure_properties, scm_set_procedure_properties)
(scm_procedure_property, scm_set_procedure_property): Remove closure
cases, and use scm_i_program_arity for arity.
* libguile/procs.h (SCM_CLOSUREP, SCM_CLOSCAR, SCM_CODE)
(SCM_CLOSURE_NUM_REQUIRED_ARGS, SCM_CLOSURE_HAS_REST_ARGS)
(SCM_CLOSURE_BODY, SCM_PROCPROPS, SCM_SETPROCPROPS, SCM_ENV)
(SCM_TOP_LEVEL): Remove these macros that pertain to boot closures
only. Only eval.c should know abut boot closures.
* libguile/procs.c (scm_closure_p): Remove this function. There is a
simple stub in deprecated.scm now.
(scm_thunk_p): Use scm_i_program_arity.
* libguile/tags.h (scm_tc3_closure): Remove. Yay, another tc3 to play
with!
(scm_tcs_closures): Remove.
* libguile/validate.h (SCM_VALIDATE_CLOSURE): Remove.
* module/ice-9/deprecated.scm (closure?): Add stub.
* module/ice-9/documentation.scm (object-documentation)
* module/ice-9/session.scm (help-doc, arity)
* module/oop/goops.scm (compute-getters-n-setters)
* module/oop/goops/describe.scm (describe)
* module/system/repl/describe.scm (display-object, display-type):
Remove calls to closure?.
2009-12-04 19:20:11 +01:00
|
|
|
|
(if (thunk? thunk)
|
|
|
|
|
|
thunk
|
|
|
|
|
|
(goops-error "Bad init-thunk for slot `~S' in ~S: ~S"
|
|
|
|
|
|
name class thunk))))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((init (slot-definition-init-value s)))
|
|
|
|
|
|
(and (not (unbound? init))
|
|
|
|
|
|
(lambda () init)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (verify-accessors slot l)
|
2003-04-13 14:48:35 +00:00
|
|
|
|
(cond ((integer? l))
|
|
|
|
|
|
((not (and (list? l) (= (length l) 2)))
|
|
|
|
|
|
(goops-error "Bad getter and setter for slot `~S' in ~S: ~S"
|
|
|
|
|
|
slot class l))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(let ((get (car l))
|
|
|
|
|
|
(set (cadr l)))
|
eval.c closures are now applicable smobs, not tc3s
* libguile/debug.c (scm_procedure_name): Remove a SCM_CLOSUREP case and
some dead code.
(scm_procedure_module): Remove. This was introduced a few months ago
for the hygienic expander, but now it is no longer needed, as the
expander keeps track of this information itself.
* libguile/debug.h: Remove scm_procedure_module.
* libguile/eval.c: Instead of using tc3 closures, define a "boot
closure" applicable smob type, and represent closures with that. The
advantage is that after eval.scm is compiled, boot closures take up no
address space (besides a smob number) in the runtime, and require no
special cases in procedure dispatch.
* libguile/eval.h: Remove the internal functions scm_i_call_closure_0
and scm_closure_apply, and the public function scm_closure.
* libguile/gc.c (scm_storage_prehistory): No tc3_closure displacement
registration.
(scm_i_tag_name): Remove closure case, and a dead cclo case.
* libguile/vm.c (apply_foreign):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_procedure_documentation);
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of): Remove tc3_closure/tcs_closure cases.
* libguile/hash.c (scm_hasher):
* libguile/hooks.c (scm_add_hook_x): Use new scm_i_procedure_arity.
* libguile/macros.c (macro_print): Print all macros using the same code.
(scm_macro_transformer): Return any procedure, not just programs.
* libguile/procprop.h:
* libguile/procprop.c (scm_i_procedure_arity): Instead of returning a
list that the caller has to parse, have the same prototype as
scm_i_program_arity. An incompatible change, but it's an internal
function anyway.
(scm_procedure_properties, scm_set_procedure_properties)
(scm_procedure_property, scm_set_procedure_property): Remove closure
cases, and use scm_i_program_arity for arity.
* libguile/procs.h (SCM_CLOSUREP, SCM_CLOSCAR, SCM_CODE)
(SCM_CLOSURE_NUM_REQUIRED_ARGS, SCM_CLOSURE_HAS_REST_ARGS)
(SCM_CLOSURE_BODY, SCM_PROCPROPS, SCM_SETPROCPROPS, SCM_ENV)
(SCM_TOP_LEVEL): Remove these macros that pertain to boot closures
only. Only eval.c should know abut boot closures.
* libguile/procs.c (scm_closure_p): Remove this function. There is a
simple stub in deprecated.scm now.
(scm_thunk_p): Use scm_i_program_arity.
* libguile/tags.h (scm_tc3_closure): Remove. Yay, another tc3 to play
with!
(scm_tcs_closures): Remove.
* libguile/validate.h (SCM_VALIDATE_CLOSURE): Remove.
* module/ice-9/deprecated.scm (closure?): Add stub.
* module/ice-9/documentation.scm (object-documentation)
* module/ice-9/session.scm (help-doc, arity)
* module/oop/goops.scm (compute-getters-n-setters)
* module/oop/goops/describe.scm (describe)
* module/system/repl/describe.scm (display-object, display-type):
Remove calls to closure?.
2009-12-04 19:20:11 +01:00
|
|
|
|
(if (not (procedure? get))
|
|
|
|
|
|
(goops-error "Bad getter closure for slot `~S' in ~S: ~S"
|
2003-04-13 14:48:35 +00:00
|
|
|
|
slot class get))
|
eval.c closures are now applicable smobs, not tc3s
* libguile/debug.c (scm_procedure_name): Remove a SCM_CLOSUREP case and
some dead code.
(scm_procedure_module): Remove. This was introduced a few months ago
for the hygienic expander, but now it is no longer needed, as the
expander keeps track of this information itself.
* libguile/debug.h: Remove scm_procedure_module.
* libguile/eval.c: Instead of using tc3 closures, define a "boot
closure" applicable smob type, and represent closures with that. The
advantage is that after eval.scm is compiled, boot closures take up no
address space (besides a smob number) in the runtime, and require no
special cases in procedure dispatch.
* libguile/eval.h: Remove the internal functions scm_i_call_closure_0
and scm_closure_apply, and the public function scm_closure.
* libguile/gc.c (scm_storage_prehistory): No tc3_closure displacement
registration.
(scm_i_tag_name): Remove closure case, and a dead cclo case.
* libguile/vm.c (apply_foreign):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_procedure_documentation);
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of): Remove tc3_closure/tcs_closure cases.
* libguile/hash.c (scm_hasher):
* libguile/hooks.c (scm_add_hook_x): Use new scm_i_procedure_arity.
* libguile/macros.c (macro_print): Print all macros using the same code.
(scm_macro_transformer): Return any procedure, not just programs.
* libguile/procprop.h:
* libguile/procprop.c (scm_i_procedure_arity): Instead of returning a
list that the caller has to parse, have the same prototype as
scm_i_program_arity. An incompatible change, but it's an internal
function anyway.
(scm_procedure_properties, scm_set_procedure_properties)
(scm_procedure_property, scm_set_procedure_property): Remove closure
cases, and use scm_i_program_arity for arity.
* libguile/procs.h (SCM_CLOSUREP, SCM_CLOSCAR, SCM_CODE)
(SCM_CLOSURE_NUM_REQUIRED_ARGS, SCM_CLOSURE_HAS_REST_ARGS)
(SCM_CLOSURE_BODY, SCM_PROCPROPS, SCM_SETPROCPROPS, SCM_ENV)
(SCM_TOP_LEVEL): Remove these macros that pertain to boot closures
only. Only eval.c should know abut boot closures.
* libguile/procs.c (scm_closure_p): Remove this function. There is a
simple stub in deprecated.scm now.
(scm_thunk_p): Use scm_i_program_arity.
* libguile/tags.h (scm_tc3_closure): Remove. Yay, another tc3 to play
with!
(scm_tcs_closures): Remove.
* libguile/validate.h (SCM_VALIDATE_CLOSURE): Remove.
* module/ice-9/deprecated.scm (closure?): Add stub.
* module/ice-9/documentation.scm (object-documentation)
* module/ice-9/session.scm (help-doc, arity)
* module/oop/goops.scm (compute-getters-n-setters)
* module/oop/goops/describe.scm (describe)
* module/system/repl/describe.scm (display-object, display-type):
Remove calls to closure?.
2009-12-04 19:20:11 +01:00
|
|
|
|
(if (not (procedure? set))
|
|
|
|
|
|
(goops-error "Bad setter closure for slot `~S' in ~S: ~S"
|
2003-04-13 14:48:35 +00:00
|
|
|
|
slot class set))))))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
(map (lambda (s)
|
2003-04-13 14:48:35 +00:00
|
|
|
|
;; The strange treatment of nfields is due to backward compatibility.
|
|
|
|
|
|
(let* ((index (slot-ref class 'nfields))
|
|
|
|
|
|
(g-n-s (compute-get-n-set class s))
|
|
|
|
|
|
(size (- (slot-ref class 'nfields) index))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(name (slot-definition-name s)))
|
2003-04-13 14:48:35 +00:00
|
|
|
|
;; NOTE: The following is interdependent with C macros
|
|
|
|
|
|
;; defined above goops.c:scm_sys_prep_layout_x.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; For simple instance slots, we have the simplest form
|
|
|
|
|
|
;; '(name init-function . index)
|
|
|
|
|
|
;; For other slots we have
|
|
|
|
|
|
;; '(name init-function getter setter . alloc)
|
|
|
|
|
|
;; where alloc is:
|
|
|
|
|
|
;; '(index size) for instance allocated slots
|
|
|
|
|
|
;; '() for other slots
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(verify-accessors name g-n-s)
|
|
|
|
|
|
(cons name
|
2003-04-17 17:37:11 +00:00
|
|
|
|
(cons (compute-slot-init-function name s)
|
2003-04-13 14:48:35 +00:00
|
|
|
|
(if (or (integer? g-n-s)
|
|
|
|
|
|
(zero? size))
|
|
|
|
|
|
g-n-s
|
2003-04-14 20:12:40 +00:00
|
|
|
|
(append g-n-s (list index size)))))))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
slots))
|
|
|
|
|
|
|
|
|
|
|
|
;;; compute-cpl
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Correct behaviour:
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (define-class food ())
|
|
|
|
|
|
;;; (define-class fruit (food))
|
|
|
|
|
|
;;; (define-class spice (food))
|
|
|
|
|
|
;;; (define-class apple (fruit))
|
|
|
|
|
|
;;; (define-class cinnamon (spice))
|
|
|
|
|
|
;;; (define-class pie (apple cinnamon))
|
|
|
|
|
|
;;; => cpl (pie) = pie apple fruit cinnamon spice food object top
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (define-class d ())
|
|
|
|
|
|
;;; (define-class e ())
|
|
|
|
|
|
;;; (define-class f ())
|
|
|
|
|
|
;;; (define-class b (d e))
|
|
|
|
|
|
;;; (define-class c (e f))
|
|
|
|
|
|
;;; (define-class a (b c))
|
|
|
|
|
|
;;; => cpl (a) = a b d c e f object top
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (compute-cpl (class <class>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(compute-std-cpl class class-direct-supers))
|
|
|
|
|
|
|
|
|
|
|
|
;; Support
|
|
|
|
|
|
|
|
|
|
|
|
(define (only-non-null lst)
|
|
|
|
|
|
(filter (lambda (l) (not (null? l))) lst))
|
|
|
|
|
|
|
|
|
|
|
|
(define (compute-std-cpl c get-direct-supers)
|
|
|
|
|
|
(let ((c-direct-supers (get-direct-supers c)))
|
|
|
|
|
|
(merge-lists (list c)
|
|
|
|
|
|
(only-non-null (append (map class-precedence-list
|
|
|
|
|
|
c-direct-supers)
|
|
|
|
|
|
(list c-direct-supers))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (merge-lists reversed-partial-result inputs)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((every null? inputs)
|
|
|
|
|
|
(reverse! reversed-partial-result))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(let* ((candidate (lambda (c)
|
|
|
|
|
|
(and (not (any (lambda (l)
|
|
|
|
|
|
(memq c (cdr l)))
|
|
|
|
|
|
inputs))
|
|
|
|
|
|
c)))
|
|
|
|
|
|
(candidate-car (lambda (l)
|
|
|
|
|
|
(and (not (null? l))
|
|
|
|
|
|
(candidate (car l)))))
|
|
|
|
|
|
(next (any candidate-car inputs)))
|
|
|
|
|
|
(if (not next)
|
|
|
|
|
|
(goops-error "merge-lists: Inconsistent precedence graph"))
|
|
|
|
|
|
(let ((remove-next (lambda (l)
|
|
|
|
|
|
(if (eq? (car l) next)
|
|
|
|
|
|
(cdr l)
|
|
|
|
|
|
l))))
|
|
|
|
|
|
(merge-lists (cons next reversed-partial-result)
|
|
|
|
|
|
(only-non-null (map remove-next inputs))))))))
|
|
|
|
|
|
|
|
|
|
|
|
;; Modified from TinyClos:
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; A simple topological sort.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; It's in this file so that both TinyClos and Objects can use it.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; This is a fairly modified version of code I originally got from Anurag
|
|
|
|
|
|
;; Mendhekar <anurag@moose.cs.indiana.edu>.
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (compute-clos-cpl c get-direct-supers)
|
|
|
|
|
|
(top-sort ((build-transitive-closure get-direct-supers) c)
|
|
|
|
|
|
((build-constraints get-direct-supers) c)
|
|
|
|
|
|
(std-tie-breaker get-direct-supers)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (top-sort elements constraints tie-breaker)
|
|
|
|
|
|
(let loop ((elements elements)
|
|
|
|
|
|
(constraints constraints)
|
|
|
|
|
|
(result '()))
|
|
|
|
|
|
(if (null? elements)
|
|
|
|
|
|
result
|
|
|
|
|
|
(let ((can-go-in-now
|
|
|
|
|
|
(filter
|
|
|
|
|
|
(lambda (x)
|
|
|
|
|
|
(every (lambda (constraint)
|
|
|
|
|
|
(or (not (eq? (cadr constraint) x))
|
|
|
|
|
|
(memq (car constraint) result)))
|
|
|
|
|
|
constraints))
|
|
|
|
|
|
elements)))
|
|
|
|
|
|
(if (null? can-go-in-now)
|
|
|
|
|
|
(goops-error "top-sort: Invalid constraints")
|
|
|
|
|
|
(let ((choice (if (null? (cdr can-go-in-now))
|
|
|
|
|
|
(car can-go-in-now)
|
|
|
|
|
|
(tie-breaker result
|
|
|
|
|
|
can-go-in-now))))
|
|
|
|
|
|
(loop
|
|
|
|
|
|
(filter (lambda (x) (not (eq? x choice)))
|
2003-03-11 19:55:00 +00:00
|
|
|
|
elements)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
constraints
|
|
|
|
|
|
(append result (list choice)))))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (std-tie-breaker get-supers)
|
|
|
|
|
|
(lambda (partial-cpl min-elts)
|
|
|
|
|
|
(let loop ((pcpl (reverse partial-cpl)))
|
|
|
|
|
|
(let ((current-elt (car pcpl)))
|
|
|
|
|
|
(let ((ds-of-ce (get-supers current-elt)))
|
|
|
|
|
|
(let ((common (filter (lambda (x)
|
|
|
|
|
|
(memq x ds-of-ce))
|
|
|
|
|
|
min-elts)))
|
|
|
|
|
|
(if (null? common)
|
|
|
|
|
|
(if (null? (cdr pcpl))
|
|
|
|
|
|
(goops-error "std-tie-breaker: Nothing valid")
|
|
|
|
|
|
(loop (cdr pcpl)))
|
|
|
|
|
|
(car common))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (build-transitive-closure get-follow-ons)
|
|
|
|
|
|
(lambda (x)
|
|
|
|
|
|
(let track ((result '())
|
|
|
|
|
|
(pending (list x)))
|
|
|
|
|
|
(if (null? pending)
|
|
|
|
|
|
result
|
|
|
|
|
|
(let ((next (car pending)))
|
|
|
|
|
|
(if (memq next result)
|
|
|
|
|
|
(track result (cdr pending))
|
|
|
|
|
|
(track (cons next result)
|
|
|
|
|
|
(append (get-follow-ons next)
|
|
|
|
|
|
(cdr pending)))))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (build-constraints get-follow-ons)
|
|
|
|
|
|
(lambda (x)
|
|
|
|
|
|
(let loop ((elements ((build-transitive-closure get-follow-ons) x))
|
|
|
|
|
|
(this-one '())
|
|
|
|
|
|
(result '()))
|
|
|
|
|
|
(if (or (null? this-one) (null? (cdr this-one)))
|
|
|
|
|
|
(if (null? elements)
|
|
|
|
|
|
result
|
|
|
|
|
|
(loop (cdr elements)
|
|
|
|
|
|
(cons (car elements)
|
|
|
|
|
|
(get-follow-ons (car elements)))
|
|
|
|
|
|
result))
|
|
|
|
|
|
(loop elements
|
|
|
|
|
|
(cdr this-one)
|
|
|
|
|
|
(cons (list (car this-one) (cadr this-one))
|
|
|
|
|
|
result))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; compute-get-n-set
|
|
|
|
|
|
;;;
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (compute-get-n-set (class <class>) s)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(case (slot-definition-allocation s)
|
|
|
|
|
|
((#:instance) ;; Instance slot
|
|
|
|
|
|
;; get-n-set is just its offset
|
|
|
|
|
|
(let ((already-allocated (slot-ref class 'nfields)))
|
|
|
|
|
|
(slot-set! class 'nfields (+ already-allocated 1))
|
|
|
|
|
|
already-allocated))
|
|
|
|
|
|
|
|
|
|
|
|
((#:class) ;; Class slot
|
|
|
|
|
|
;; Class-slots accessors are implemented as 2 closures around
|
|
|
|
|
|
;; a Scheme variable. As instance slots, class slots must be
|
|
|
|
|
|
;; unbound at init time.
|
|
|
|
|
|
(let ((name (slot-definition-name s)))
|
|
|
|
|
|
(if (memq name (map slot-definition-name (class-direct-slots class)))
|
|
|
|
|
|
;; This slot is direct; create a new shared variable
|
|
|
|
|
|
(make-closure-variable class)
|
|
|
|
|
|
;; Slot is inherited. Find its definition in superclass
|
|
|
|
|
|
(let loop ((l (cdr (class-precedence-list class))))
|
|
|
|
|
|
(let ((r (assoc name (slot-ref (car l) 'getters-n-setters))))
|
|
|
|
|
|
(if r
|
|
|
|
|
|
(cddr r)
|
|
|
|
|
|
(loop (cdr l))))))))
|
|
|
|
|
|
|
|
|
|
|
|
((#:each-subclass) ;; slot shared by instances of direct subclass.
|
|
|
|
|
|
;; (Thomas Buerger, April 1998)
|
|
|
|
|
|
(make-closure-variable class))
|
|
|
|
|
|
|
|
|
|
|
|
((#:virtual) ;; No allocation
|
|
|
|
|
|
;; slot-ref and slot-set! function must be given by the user
|
|
|
|
|
|
(let ((get (get-keyword #:slot-ref (slot-definition-options s) #f))
|
2009-09-21 00:10:28 +02:00
|
|
|
|
(set (get-keyword #:slot-set! (slot-definition-options s) #f)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(if (not (and get set))
|
2004-01-12 17:28:30 +00:00
|
|
|
|
(goops-error "You must supply a #:slot-ref and a #:slot-set! in ~S"
|
2000-10-25 14:51:33 +00:00
|
|
|
|
s))
|
|
|
|
|
|
(list get set)))
|
|
|
|
|
|
(else (next-method))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-closure-variable class)
|
|
|
|
|
|
(let ((shared-variable (make-unbound)))
|
|
|
|
|
|
(list (lambda (o) shared-variable)
|
|
|
|
|
|
(lambda (o v) (set! shared-variable v)))))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (compute-get-n-set (o <object>) s)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(goops-error "Allocation \"~S\" is unknown" (slot-definition-allocation s)))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (compute-slots (class <class>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(%compute-slots class))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Initialize}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (initialize (object <object>) initargs)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(%initialize-object object initargs))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (initialize (class <class>) initargs)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(next-method)
|
|
|
|
|
|
(let ((dslots (get-keyword #:slots initargs '()))
|
2009-11-27 20:50:40 +01:00
|
|
|
|
(supers (get-keyword #:dsupers initargs '())))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(slot-set! class 'name (get-keyword #:name initargs '???))
|
|
|
|
|
|
(slot-set! class 'direct-supers supers)
|
|
|
|
|
|
(slot-set! class 'direct-slots dslots)
|
|
|
|
|
|
(slot-set! class 'direct-subclasses '())
|
|
|
|
|
|
(slot-set! class 'direct-methods '())
|
|
|
|
|
|
(slot-set! class 'cpl (compute-cpl class))
|
|
|
|
|
|
(slot-set! class 'redefined #f)
|
|
|
|
|
|
(let ((slots (compute-slots class)))
|
|
|
|
|
|
(slot-set! class 'slots slots)
|
|
|
|
|
|
(slot-set! class 'nfields 0)
|
|
|
|
|
|
(slot-set! class 'getters-n-setters (compute-getters-n-setters class
|
2009-11-27 20:50:40 +01:00
|
|
|
|
slots))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
;; Build getters - setters - accessors
|
2009-11-27 20:50:40 +01:00
|
|
|
|
(compute-slot-accessors class slots))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;; Update the "direct-subclasses" of each inherited classes
|
|
|
|
|
|
(for-each (lambda (x)
|
|
|
|
|
|
(slot-set! x
|
|
|
|
|
|
'direct-subclasses
|
|
|
|
|
|
(cons class (slot-ref x 'direct-subclasses))))
|
|
|
|
|
|
supers)
|
|
|
|
|
|
|
|
|
|
|
|
;; Support for the underlying structs:
|
|
|
|
|
|
|
|
|
|
|
|
;; Set the layout slot
|
limn goops flags, remove foreign objs, rename entity to applicable-struct
* libguile/goops.c (scm_class_applicable_struct)
(scm_class_applicable_struct_with_setter)
(scm_class_applicable_struct_class): Rename from
scm_class_entity, scm_class_entity_with_setter, and
scm_class_entity_class.
(scm_class_simple_method): Removed; this abstraction is not used.
(scm_class_foreign_class, scm_class_foreign_object): Remove these,
they are undocumented and unused. They might come back later.
(scm_sys_inherit_magic_x): Simply inherit the vtable flags from the
class's class. Flags are about layout, and it is the class that
determines the layout of the instance.
(scm_basic_basic_make_class): Don't bother setting GOOPS_OR_VALID,
inherit-magic will do that.
(scm_basic_make_class): Inherit magic after setting the layout. Allows
the struct magic checker to do its job.
(scm_accessor_method_slot_definition): Move implementation to Scheme.
Removes the need for the accessor flag.
(scm_sys_allocate_instance): Adapt to scm_i_alloc_struct name change,
and that alloc-struct will handle finalization.
(scm_compute_applicable_methods): Remove accessor check, as it's
unnecessary.
(scm_make): Adapt to new generic slot order, and no more
simple-method.
(create_standard_classes): What was the GF slot "dispatch-procedure"
is now the applicable-struct slot "procedure". No more foreign class,
foreign object, or simple method. Rename <entity> and friends to
<applicable-struct> and friends. No more entity-with-setter -- though
perhaps it will come back too. Instead generic-with-setter is its own
thing.
* libguile/goops.h (SCM_CLASSF_METACLASS): "A goops class that is a
vtable" -- no need for a separate flag.
(SCM_CLASSF_FOREIGN, SCM_CLASSF_SIMPLE_METHOD)
(SCM_CLASSF_ACCESSOR_METHOD): Removed these unused flags.
(SCM_ACCESSORP): Removed.
Renumber generic slots, rename entity classes, and remove the foreign
class, foreign object, and simple method classes.
* libguile/struct.c (scm_i_struct_inherit_vtable_magic): New function,
called when making new vtables.applicable structs
(scm_i_alloc_struct): Remove 8-bit alignment check, as libGC
guarantees this for us. Handle finalizer registration here.
(scm_make_struct): Factor some things to scm_i_alloc_struct and
scm_i_struct_inherit_vtable_magic.
(scm_make_vtable_vtable): Adapt to scm_i_alloc_struct name change.
* libguile/struct.h (scm_i_alloc_struct): Change name from
scm_alloc_struct, and make internal.
* module/oop/goops.scm (oop): Don't declare #:replace <class> et al,
because <class> isn't defined in the core any more.
(accessor-method-slot-definition): Defined in Scheme now.
Remove <foreign-object> methods.
(initialize on <class>): Prep layout before inheriting magic, as in
scm_basic_make_class.
* module/oop/goops/dispatch.scm (delayed-compile)
(memoize-effective-method!): Adapt to 'procedure slot name change.
2009-11-08 11:24:23 +01:00
|
|
|
|
(%prep-layout! class)
|
|
|
|
|
|
;; Inherit class flags (invisible on scheme level) from supers
|
|
|
|
|
|
(%inherit-magic! class supers)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
(define (initialize-object-procedure object initargs)
|
|
|
|
|
|
(let ((proc (get-keyword #:procedure initargs #f)))
|
|
|
|
|
|
(cond ((not proc))
|
|
|
|
|
|
((pair? proc)
|
2010-06-29 09:14:33 +01:00
|
|
|
|
(apply slot-set! object 'procedure proc))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(else
|
2010-06-29 09:14:33 +01:00
|
|
|
|
(slot-set! object 'procedure proc)))))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
limn goops flags, remove foreign objs, rename entity to applicable-struct
* libguile/goops.c (scm_class_applicable_struct)
(scm_class_applicable_struct_with_setter)
(scm_class_applicable_struct_class): Rename from
scm_class_entity, scm_class_entity_with_setter, and
scm_class_entity_class.
(scm_class_simple_method): Removed; this abstraction is not used.
(scm_class_foreign_class, scm_class_foreign_object): Remove these,
they are undocumented and unused. They might come back later.
(scm_sys_inherit_magic_x): Simply inherit the vtable flags from the
class's class. Flags are about layout, and it is the class that
determines the layout of the instance.
(scm_basic_basic_make_class): Don't bother setting GOOPS_OR_VALID,
inherit-magic will do that.
(scm_basic_make_class): Inherit magic after setting the layout. Allows
the struct magic checker to do its job.
(scm_accessor_method_slot_definition): Move implementation to Scheme.
Removes the need for the accessor flag.
(scm_sys_allocate_instance): Adapt to scm_i_alloc_struct name change,
and that alloc-struct will handle finalization.
(scm_compute_applicable_methods): Remove accessor check, as it's
unnecessary.
(scm_make): Adapt to new generic slot order, and no more
simple-method.
(create_standard_classes): What was the GF slot "dispatch-procedure"
is now the applicable-struct slot "procedure". No more foreign class,
foreign object, or simple method. Rename <entity> and friends to
<applicable-struct> and friends. No more entity-with-setter -- though
perhaps it will come back too. Instead generic-with-setter is its own
thing.
* libguile/goops.h (SCM_CLASSF_METACLASS): "A goops class that is a
vtable" -- no need for a separate flag.
(SCM_CLASSF_FOREIGN, SCM_CLASSF_SIMPLE_METHOD)
(SCM_CLASSF_ACCESSOR_METHOD): Removed these unused flags.
(SCM_ACCESSORP): Removed.
Renumber generic slots, rename entity classes, and remove the foreign
class, foreign object, and simple method classes.
* libguile/struct.c (scm_i_struct_inherit_vtable_magic): New function,
called when making new vtables.applicable structs
(scm_i_alloc_struct): Remove 8-bit alignment check, as libGC
guarantees this for us. Handle finalizer registration here.
(scm_make_struct): Factor some things to scm_i_alloc_struct and
scm_i_struct_inherit_vtable_magic.
(scm_make_vtable_vtable): Adapt to scm_i_alloc_struct name change.
* libguile/struct.h (scm_i_alloc_struct): Change name from
scm_alloc_struct, and make internal.
* module/oop/goops.scm (oop): Don't declare #:replace <class> et al,
because <class> isn't defined in the core any more.
(accessor-method-slot-definition): Defined in Scheme now.
Remove <foreign-object> methods.
(initialize on <class>): Prep layout before inheriting magic, as in
scm_basic_make_class.
* module/oop/goops/dispatch.scm (delayed-compile)
(memoize-effective-method!): Adapt to 'procedure slot name change.
2009-11-08 11:24:23 +01:00
|
|
|
|
(define-method (initialize (applicable-struct <applicable-struct>) initargs)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(next-method)
|
limn goops flags, remove foreign objs, rename entity to applicable-struct
* libguile/goops.c (scm_class_applicable_struct)
(scm_class_applicable_struct_with_setter)
(scm_class_applicable_struct_class): Rename from
scm_class_entity, scm_class_entity_with_setter, and
scm_class_entity_class.
(scm_class_simple_method): Removed; this abstraction is not used.
(scm_class_foreign_class, scm_class_foreign_object): Remove these,
they are undocumented and unused. They might come back later.
(scm_sys_inherit_magic_x): Simply inherit the vtable flags from the
class's class. Flags are about layout, and it is the class that
determines the layout of the instance.
(scm_basic_basic_make_class): Don't bother setting GOOPS_OR_VALID,
inherit-magic will do that.
(scm_basic_make_class): Inherit magic after setting the layout. Allows
the struct magic checker to do its job.
(scm_accessor_method_slot_definition): Move implementation to Scheme.
Removes the need for the accessor flag.
(scm_sys_allocate_instance): Adapt to scm_i_alloc_struct name change,
and that alloc-struct will handle finalization.
(scm_compute_applicable_methods): Remove accessor check, as it's
unnecessary.
(scm_make): Adapt to new generic slot order, and no more
simple-method.
(create_standard_classes): What was the GF slot "dispatch-procedure"
is now the applicable-struct slot "procedure". No more foreign class,
foreign object, or simple method. Rename <entity> and friends to
<applicable-struct> and friends. No more entity-with-setter -- though
perhaps it will come back too. Instead generic-with-setter is its own
thing.
* libguile/goops.h (SCM_CLASSF_METACLASS): "A goops class that is a
vtable" -- no need for a separate flag.
(SCM_CLASSF_FOREIGN, SCM_CLASSF_SIMPLE_METHOD)
(SCM_CLASSF_ACCESSOR_METHOD): Removed these unused flags.
(SCM_ACCESSORP): Removed.
Renumber generic slots, rename entity classes, and remove the foreign
class, foreign object, and simple method classes.
* libguile/struct.c (scm_i_struct_inherit_vtable_magic): New function,
called when making new vtables.applicable structs
(scm_i_alloc_struct): Remove 8-bit alignment check, as libGC
guarantees this for us. Handle finalizer registration here.
(scm_make_struct): Factor some things to scm_i_alloc_struct and
scm_i_struct_inherit_vtable_magic.
(scm_make_vtable_vtable): Adapt to scm_i_alloc_struct name change.
* libguile/struct.h (scm_i_alloc_struct): Change name from
scm_alloc_struct, and make internal.
* module/oop/goops.scm (oop): Don't declare #:replace <class> et al,
because <class> isn't defined in the core any more.
(accessor-method-slot-definition): Defined in Scheme now.
Remove <foreign-object> methods.
(initialize on <class>): Prep layout before inheriting magic, as in
scm_basic_make_class.
* module/oop/goops/dispatch.scm (delayed-compile)
(memoize-effective-method!): Adapt to 'procedure slot name change.
2009-11-08 11:24:23 +01:00
|
|
|
|
(initialize-object-procedure applicable-struct initargs))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (initialize (generic <generic>) initargs)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((previous-definition (get-keyword #:default initargs #f))
|
|
|
|
|
|
(name (get-keyword #:name initargs #f)))
|
|
|
|
|
|
(next-method)
|
|
|
|
|
|
(slot-set! generic 'methods (if (is-a? previous-definition <procedure>)
|
2008-10-31 00:07:04 +01:00
|
|
|
|
(list (method args
|
|
|
|
|
|
(apply previous-definition args)))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
'()))
|
|
|
|
|
|
(if name
|
|
|
|
|
|
(set-procedure-property! generic 'name name))
|
|
|
|
|
|
))
|
|
|
|
|
|
|
limn goops flags, remove foreign objs, rename entity to applicable-struct
* libguile/goops.c (scm_class_applicable_struct)
(scm_class_applicable_struct_with_setter)
(scm_class_applicable_struct_class): Rename from
scm_class_entity, scm_class_entity_with_setter, and
scm_class_entity_class.
(scm_class_simple_method): Removed; this abstraction is not used.
(scm_class_foreign_class, scm_class_foreign_object): Remove these,
they are undocumented and unused. They might come back later.
(scm_sys_inherit_magic_x): Simply inherit the vtable flags from the
class's class. Flags are about layout, and it is the class that
determines the layout of the instance.
(scm_basic_basic_make_class): Don't bother setting GOOPS_OR_VALID,
inherit-magic will do that.
(scm_basic_make_class): Inherit magic after setting the layout. Allows
the struct magic checker to do its job.
(scm_accessor_method_slot_definition): Move implementation to Scheme.
Removes the need for the accessor flag.
(scm_sys_allocate_instance): Adapt to scm_i_alloc_struct name change,
and that alloc-struct will handle finalization.
(scm_compute_applicable_methods): Remove accessor check, as it's
unnecessary.
(scm_make): Adapt to new generic slot order, and no more
simple-method.
(create_standard_classes): What was the GF slot "dispatch-procedure"
is now the applicable-struct slot "procedure". No more foreign class,
foreign object, or simple method. Rename <entity> and friends to
<applicable-struct> and friends. No more entity-with-setter -- though
perhaps it will come back too. Instead generic-with-setter is its own
thing.
* libguile/goops.h (SCM_CLASSF_METACLASS): "A goops class that is a
vtable" -- no need for a separate flag.
(SCM_CLASSF_FOREIGN, SCM_CLASSF_SIMPLE_METHOD)
(SCM_CLASSF_ACCESSOR_METHOD): Removed these unused flags.
(SCM_ACCESSORP): Removed.
Renumber generic slots, rename entity classes, and remove the foreign
class, foreign object, and simple method classes.
* libguile/struct.c (scm_i_struct_inherit_vtable_magic): New function,
called when making new vtables.applicable structs
(scm_i_alloc_struct): Remove 8-bit alignment check, as libGC
guarantees this for us. Handle finalizer registration here.
(scm_make_struct): Factor some things to scm_i_alloc_struct and
scm_i_struct_inherit_vtable_magic.
(scm_make_vtable_vtable): Adapt to scm_i_alloc_struct name change.
* libguile/struct.h (scm_i_alloc_struct): Change name from
scm_alloc_struct, and make internal.
* module/oop/goops.scm (oop): Don't declare #:replace <class> et al,
because <class> isn't defined in the core any more.
(accessor-method-slot-definition): Defined in Scheme now.
Remove <foreign-object> methods.
(initialize on <class>): Prep layout before inheriting magic, as in
scm_basic_make_class.
* module/oop/goops/dispatch.scm (delayed-compile)
(memoize-effective-method!): Adapt to 'procedure slot name change.
2009-11-08 11:24:23 +01:00
|
|
|
|
(define-method (initialize (gws <generic-with-setter>) initargs)
|
|
|
|
|
|
(next-method)
|
|
|
|
|
|
(%set-object-setter! gws (get-keyword #:setter initargs #f)))
|
|
|
|
|
|
|
2003-01-08 13:24:41 +00:00
|
|
|
|
(define-method (initialize (eg <extended-generic>) initargs)
|
|
|
|
|
|
(next-method)
|
|
|
|
|
|
(slot-set! eg 'extends (get-keyword #:extends initargs '())))
|
|
|
|
|
|
|
2001-03-04 20:46:34 +00:00
|
|
|
|
(define dummy-procedure (lambda args *unspecified*))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (initialize (method <method>) initargs)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(next-method)
|
|
|
|
|
|
(slot-set! method 'generic-function (get-keyword #:generic-function initargs #f))
|
|
|
|
|
|
(slot-set! method 'specializers (get-keyword #:specializers initargs '()))
|
2001-03-04 20:46:34 +00:00
|
|
|
|
(slot-set! method 'procedure
|
don't re-enter the compiler during method dispatch
* libguile/goops.c (scm_make): In the pre-inst `make', default
`procedure' to #f, and read a `make-procedure' instead of
`compile-env'.
* libguile/goops.h (scm_si_make_procedure): This instead of
scm_si_compile_env.
* module/oop/goops.scm (make-method): Remove this unused function. Users
should use (make <method> ...) directly.
(method): Capture `make-procedure' instead of `procedure' in the case
that the body calls a next-method. Allows for the kind of
"recompilation" that we were using before, but with closures instead of
re-entering the compiler. Type-specific compilation is still
interesting, but probably should be implemented in another way.
(initialize): Default #:procedure to #f, and
s/compile-env/make-procedure/.
* module/oop/goops/compile.scm (code-table-lookup): Just return the
cmethod, not the entry -- since the entry is now just (append types
cmethod).
(compile-make-procedure): New procedure, returns a form that, when
evaluated/compiled, will yield a procedure of one argument, the
next-method. When called with a next-method, the procedure returns an
actual method implementation. compile-make-procedure returns #f if the
body doesn't call next-method.
(compile-method): Unify to always return procedures. Much cleaner and
*much* faster in the compiled case. In the interpreted case, there
might be a slight slowdown, but if there is one it should be slight.
* module/oop/goops/dispatch.scm (method-cache-install!): Adapt to removal
of compute-entry-with-cmethod.
2009-02-13 23:30:20 +01:00
|
|
|
|
(get-keyword #:procedure initargs #f))
|
2008-10-24 11:56:31 +02:00
|
|
|
|
(slot-set! method 'formals (get-keyword #:formals initargs '()))
|
|
|
|
|
|
(slot-set! method 'body (get-keyword #:body initargs '()))
|
don't re-enter the compiler during method dispatch
* libguile/goops.c (scm_make): In the pre-inst `make', default
`procedure' to #f, and read a `make-procedure' instead of
`compile-env'.
* libguile/goops.h (scm_si_make_procedure): This instead of
scm_si_compile_env.
* module/oop/goops.scm (make-method): Remove this unused function. Users
should use (make <method> ...) directly.
(method): Capture `make-procedure' instead of `procedure' in the case
that the body calls a next-method. Allows for the kind of
"recompilation" that we were using before, but with closures instead of
re-entering the compiler. Type-specific compilation is still
interesting, but probably should be implemented in another way.
(initialize): Default #:procedure to #f, and
s/compile-env/make-procedure/.
* module/oop/goops/compile.scm (code-table-lookup): Just return the
cmethod, not the entry -- since the entry is now just (append types
cmethod).
(compile-make-procedure): New procedure, returns a form that, when
evaluated/compiled, will yield a procedure of one argument, the
next-method. When called with a next-method, the procedure returns an
actual method implementation. compile-make-procedure returns #f if the
body doesn't call next-method.
(compile-method): Unify to always return procedures. Much cleaner and
*much* faster in the compiled case. In the interpreted case, there
might be a slight slowdown, but if there is one it should be slight.
* module/oop/goops/dispatch.scm (method-cache-install!): Adapt to removal
of compute-entry-with-cmethod.
2009-02-13 23:30:20 +01:00
|
|
|
|
(slot-set! method 'make-procedure (get-keyword #:make-procedure initargs #f)))
|
2008-10-24 11:56:31 +02:00
|
|
|
|
|
2000-10-25 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Change-class}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (change-object-class old-instance old-class new-class)
|
2001-03-04 05:28:21 +00:00
|
|
|
|
(let ((new-instance (allocate-instance new-class '())))
|
2005-04-24 12:29:14 +00:00
|
|
|
|
;; Initialize the slots of the new instance
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(for-each (lambda (slot)
|
|
|
|
|
|
(if (and (slot-exists-using-class? old-class old-instance slot)
|
|
|
|
|
|
(eq? (slot-definition-allocation
|
|
|
|
|
|
(class-slot-definition old-class slot))
|
|
|
|
|
|
#:instance)
|
|
|
|
|
|
(slot-bound-using-class? old-class old-instance slot))
|
|
|
|
|
|
;; Slot was present and allocated in old instance; copy it
|
|
|
|
|
|
(slot-set-using-class!
|
|
|
|
|
|
new-class
|
|
|
|
|
|
new-instance
|
|
|
|
|
|
slot
|
|
|
|
|
|
(slot-ref-using-class old-class old-instance slot))
|
|
|
|
|
|
;; slot was absent; initialize it with its default value
|
|
|
|
|
|
(let ((init (slot-init-function new-class slot)))
|
|
|
|
|
|
(if init
|
|
|
|
|
|
(slot-set-using-class!
|
|
|
|
|
|
new-class
|
|
|
|
|
|
new-instance
|
|
|
|
|
|
slot
|
|
|
|
|
|
(apply init '()))))))
|
|
|
|
|
|
(map slot-definition-name (class-slots new-class)))
|
|
|
|
|
|
;; Exchange old and new instance in place to keep pointers valid
|
|
|
|
|
|
(%modify-instance old-instance new-instance)
|
|
|
|
|
|
;; Allow class specific updates of instances (which now are swapped)
|
|
|
|
|
|
(update-instance-for-different-class new-instance old-instance)
|
|
|
|
|
|
old-instance))
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (update-instance-for-different-class (old-instance <object>)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(new-instance
|
|
|
|
|
|
<object>))
|
|
|
|
|
|
;;not really important what we do, we just need a default method
|
|
|
|
|
|
new-instance)
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (change-class (old-instance <object>) (new-class <class>))
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(change-object-class old-instance (class-of old-instance) new-class))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {make}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; A new definition which overwrites the previous one which was built-in
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (allocate-instance (class <class>) initargs)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(%allocate-instance class initargs))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (make-instance (class <class>) . initargs)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((instance (allocate-instance class initargs)))
|
|
|
|
|
|
(initialize instance initargs)
|
|
|
|
|
|
instance))
|
|
|
|
|
|
|
|
|
|
|
|
(define make make-instance)
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {apply-generic}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Protocol for calling standard generic functions. This protocol is
|
|
|
|
|
|
;;; not used for real <generic> functions (in this case we use a
|
|
|
|
|
|
;;; completely C hard-coded protocol). Apply-generic is used by
|
|
|
|
|
|
;;; goops for calls to subclasses of <generic> and <generic-with-setter>.
|
|
|
|
|
|
;;; The code below is similar to the first MOP described in AMOP. In
|
|
|
|
|
|
;;; particular, it doesn't used the currified approach to gf
|
|
|
|
|
|
;;; call. There are 2 reasons for that:
|
|
|
|
|
|
;;; - the protocol below is exposed to mimic completely the one written in C
|
|
|
|
|
|
;;; - the currified protocol would be imho inefficient in C.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (apply-generic (gf <generic>) args)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(if (null? (slot-ref gf 'methods))
|
|
|
|
|
|
(no-method gf args))
|
|
|
|
|
|
(let ((methods (compute-applicable-methods gf args)))
|
|
|
|
|
|
(if methods
|
|
|
|
|
|
(apply-methods gf (sort-applicable-methods gf methods args) args)
|
|
|
|
|
|
(no-applicable-method gf args))))
|
|
|
|
|
|
|
|
|
|
|
|
;; compute-applicable-methods is bound to %compute-applicable-methods.
|
|
|
|
|
|
;; *fixme* use let
|
|
|
|
|
|
(define %%compute-applicable-methods
|
|
|
|
|
|
(make <generic> #:name 'compute-applicable-methods))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (%%compute-applicable-methods (gf <generic>) args)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(%compute-applicable-methods gf args))
|
|
|
|
|
|
|
|
|
|
|
|
(set! compute-applicable-methods %%compute-applicable-methods)
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (sort-applicable-methods (gf <generic>) methods args)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(let ((targs (map class-of args)))
|
|
|
|
|
|
(sort methods (lambda (m1 m2) (method-more-specific? m1 m2 targs)))))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (method-more-specific? (m1 <method>) (m2 <method>) targs)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(%method-more-specific? m1 m2 targs))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (apply-method (gf <generic>) methods build-next args)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(apply (method-procedure (car methods))
|
|
|
|
|
|
(build-next (cdr methods) args)
|
|
|
|
|
|
args))
|
|
|
|
|
|
|
2001-03-10 03:09:50 +00:00
|
|
|
|
(define-method (apply-methods (gf <generic>) (l <list>) args)
|
2000-10-25 14:51:33 +00:00
|
|
|
|
(letrec ((next (lambda (procs args)
|
|
|
|
|
|
(lambda new-args
|
|
|
|
|
|
(let ((a (if (null? new-args) args new-args)))
|
|
|
|
|
|
(if (null? procs)
|
|
|
|
|
|
(no-next-method gf a)
|
|
|
|
|
|
(apply-method gf procs next a)))))))
|
|
|
|
|
|
(apply-method gf l next args)))
|
|
|
|
|
|
|
|
|
|
|
|
;; We don't want the following procedure to turn up in backtraces:
|
|
|
|
|
|
(for-each (lambda (proc)
|
|
|
|
|
|
(set-procedure-property! proc 'system-procedure #t))
|
|
|
|
|
|
(list slot-unbound
|
|
|
|
|
|
slot-missing
|
|
|
|
|
|
no-next-method
|
|
|
|
|
|
no-applicable-method
|
|
|
|
|
|
no-method
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {<composite-metaclass> and <active-metaclass>}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;(autoload "active-slot" <active-metaclass>)
|
|
|
|
|
|
;(autoload "composite-slot" <composite-metaclass>)
|
|
|
|
|
|
;(export <composite-metaclass> <active-metaclass>)
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Tools}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; list2set
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; duplicate the standard list->set function but using eq instead of
|
|
|
|
|
|
;; eqv which really sucks a lot, uselessly here
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (list2set l)
|
|
|
|
|
|
(let loop ((l l)
|
|
|
|
|
|
(res '()))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? l) res)
|
|
|
|
|
|
((memq (car l) res) (loop (cdr l) res))
|
|
|
|
|
|
(else (loop (cdr l) (cons (car l) res))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (class-subclasses c)
|
|
|
|
|
|
(letrec ((allsubs (lambda (c)
|
|
|
|
|
|
(cons c (mapappend allsubs
|
|
|
|
|
|
(class-direct-subclasses c))))))
|
|
|
|
|
|
(list2set (cdr (allsubs c)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (class-methods c)
|
|
|
|
|
|
(list2set (mapappend class-direct-methods
|
|
|
|
|
|
(cons c (class-subclasses c)))))
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; {Final initialization}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; Tell C code that the main bulk of Goops has been loaded
|
|
|
|
|
|
(%goops-loaded)
|