Module: internal Author: Jonathan Bachrach Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND define method slot-allocation (descriptor :: ) => (result :: ); #"instance" end method slot-allocation; define method as-slot-descriptor-class (symbol == #"constant") end method as-slot-descriptor-class; define method add-setter-method (class :: , slot-setter :: , descriptor :: , override-sealing? :: ) values(#f, #f) end method add-setter-method; // define method remove-setter-method // (class :: , // slot-setter :: , // descriptor :: ) // #f // end method remove-setter-method; define method initialize (descriptor :: , #rest all-keys, #key init-value = $not-found, init-function, init-keyword, required-init-keyword, setter: setter-var) next-method(); if (init-value == $not-found & ~init-function) error(make(, format-string: "Must specify init-value or init-function for a constant slot %=", format-arguments: list(descriptor))) end if; if (init-keyword | required-init-keyword | setter-var) error(make(, format-string: "Illegal slot-definition for constant slot %=.", format-arguments: list(all-keys))) end if; descriptor end method initialize; define method as-slot-descriptor-class (symbol == #"class") end method as-slot-descriptor-class; define method as-slot-descriptor-class (symbol == #"each-subclass") end method as-slot-descriptor-class; define method slot-allocation (descriptor :: ) => (result :: ); #"virtual" end method slot-allocation; define method as-slot-descriptor-class (symbol == #"repeated") end method as-slot-descriptor-class; define method initialize (descriptor :: , #rest all-keys, #key init-value = $not-found, init-function = $not-found, #all-keys) => () next-method(); apply(initialize-packed-slots, descriptor, all-keys); let init-value? = init-value ~== $not-found; let init-function? = init-function ~== $not-found; if (init-value? & init-function?) error(make(, format-string: "Init-value: may not be specified with init-function: %=", format-arguments: list(descriptor))) end if; if (init-value?) descriptor.init-evaluated? := #t; descriptor.init-supplied? := #t; descriptor.init-value? := #t; descriptor.init-data-slot := init-value; elseif (init-function?) descriptor.init-evaluated? := #t; descriptor.init-supplied? := #t; descriptor.init-data-slot := init-function; end; end method initialize; define method initialize (descriptor :: , #key required-init-keyword, init-keyword, init-value = $not-found, init-function = $not-found, #all-keys) => () next-method(); if (init-keyword & ~instance?(init-keyword, )) error(make(, format-string: "Init-keyword: must be a : %=", format-arguments: list(init-keyword))) end if; let init-value? = init-value ~== $not-found; let init-function? = init-function ~== $not-found; if (required-init-keyword & (init-keyword | init-value? | init-function?)) error(make(, format-string: "Required-init-keyword: may not be specified with " "init-keyword, init-value, or init-function: %=", format-arguments: list(descriptor))) end if; if (required-init-keyword) descriptor.init-keyword-required? := #t; descriptor.init-keyword := required-init-keyword end if; end method initialize; //// //// SLOTS-COMPATIBLE? //// //// determines whether a slot-descriptor is compatible with an inherited one. //// // define method slots-compatible? // (new-descriptor :: , old-descriptor :: ) // local method eqv (a, b, default) // (~(a == default) & ~(b == default)) | (a == default & b == default) // end method eqv; // eqv(new-descriptor.slot-type, old-descriptor.slot-type, ) // & subtype?(new-descriptor.slot-type, old-descriptor.slot-type) // & new-descriptor.init-supplied? == old-descriptor.init-supplied? // & new-descriptor.init-value? == old-descriptor.init-value? // & eqv(new-descriptor.init-keyword, old-descriptor.init-keyword, #f) // & eqv(new-descriptor.slot-allocation, // old-descriptor.slot-allocation, // #"instance") // & eqv(new-descriptor.slot-setter, old-descriptor.slot-setter, #f) // // @@@@ getter ??? // end method slots-compatible?; /* xep: xep slot-descriptor: method-slot-descriptor */ define method initialize (m :: , #rest initargs, #key slot-descriptor :: ) => () primitive-set-accessor-method-xep(m, if (instance?(slot-descriptor, )) 0 else 2 end if); // The next-method() is deliberately after the above initializations; // the xep because I feel better with it being initialized as early as possible. next-method(); end method; define method initialize (m :: , #rest initargs, #key slot-descriptor :: ) => () primitive-set-accessor-method-xep(m, if (instance?(slot-descriptor, )) 1 else 3 end if); // The next-method() is deliberately after the above initializations; // the xep because I feel better with it being initialized as early as possible. next-method(); end method; define method initialize (m :: , #rest initargs, #key slot-descriptor :: ) => () primitive-set-accessor-method-xep(m, 4); // The next-method() is deliberately after the above initializations; // the xep because I feel better with it being initialized as early as possible. next-method(); end method; define method initialize (m :: , #rest initargs, #key slot-descriptor :: ) => () primitive-set-accessor-method-xep(m, 5); // The next-method() is deliberately after the above initializations; // the xep because I feel better with it being initialized as early as possible. next-method(); end method; define generic slot-accessor-method-classes (sd :: ) => (getter-class :: false-or(), setter-class :: false-or()); // Default. define method slot-accessor-method-classes (sd :: ) => (getter-class :: , setter-class :: ); values(, ) end method; define method slot-accessor-method-classes (sd :: ) => (false == #f, false == #f); values(#f, #f) end method; define method slot-accessor-method-classes (sd :: ) => (getter-class :: , setter-class :: ); values(, ) end method; //define function make-a-slot-method (sd :: , setter?) // let owner :: = slot-owner(sd); // let type :: = slot-type(sd); // select (sd by instance?) // => #f; // => // if (setter?) // method (value :: type, object :: owner, idx :: ) // repeated-slot-value(object, sd, idx) := value // end method // else // method (object :: owner, idx :: ) repeated-slot-value(object, sd, idx) end // end if; // otherwise => // if (setter?) // method (value :: type, object :: owner) slot-value(object, sd) := value end // else // method (object :: owner) slot-value(object, sd) end // end if; // end select; //end function; define function make-a-slot-method (sd :: , setter?) let (gtype, stype) = slot-accessor-method-classes(sd); let thetype = if(setter?) stype else gtype end; thetype & make(thetype, slot-descriptor: sd) end function; // define function batch-create-slot-methods (slot-descriptors :: ) // map(method (sd :: ) // let g = slot-getter(sd); // let s = slot-setter(sd); // let (gtype, stype) = slot-accessor-method-classes(sd); // vector(gtype & g & make(gtype, slot-descriptor: sd), // stype & s & make(stype, slot-descriptor: sd)) // end method, // slot-descriptors) // end function; define method add-getter-method (class-NOT :: , slot-getter :: , descriptor :: , override-sealing? :: ) let new-method = make-a-slot-method(descriptor, #f); %add-a-method(slot-getter, new-method, home-library(class-module(class-NOT)), #t, ~ override-sealing?, slot-method-sealed?(descriptor)) end method add-getter-method; define method add-setter-method (class-NOT :: , slot-setter :: , descriptor :: , override-sealing? :: ) let new-method = make-a-slot-method(descriptor, #t); %add-a-method(slot-setter, new-method, home-library(class-module(class-NOT)), #t, ~ override-sealing?, slot-method-sealed?(descriptor)) end method add-setter-method; // define method remove-getter-method // (class :: , // slot-getter :: , // descriptor :: ) // let getter-method = find-method(slot-getter, class.list); // if (instance?(getter-method, )) // let getter-method :: = getter-method; // // remove-method(slot-getter, getter-method) // end if // end method remove-getter-method; // define method remove-setter-method // (class :: , // slot-setter :: , // descriptor :: ) // let setter-method // = find-method(slot-setter, list(descriptor /* .slot-type */, class)); // if (setter-method) // %remove-method(slot-setter, setter-method) // end if // end method remove-setter-method; define method add-getter-method (class :: , slot-getter :: , descriptor :: , override-sealing? :: ) values(#f, #f) end method add-getter-method; define method add-setter-method (class :: , slot-setter :: , descriptor :: , override-sealing? :: ) values(#f, #f) end method add-setter-method; // define method remove-getter-method // (class :: , // slot-getter :: , // descriptor :: ) // #f // end method remove-getter-method; // define method remove-setter-method // (class :: , // slot-setter :: , // descriptor :: ) // #f // end method remove-setter-method; // eof