kernel libc literals math mirrors namespaces prettyprint
prettyprint.config see sequences specialized-arrays system
tools.test parser lexer eval layouts generic.single classes
-vocabs generic ;
+vocabs generic classes.private ;
FROM: math => float ;
FROM: specialized-arrays.private => specialized-array-vocab ;
QUALIFIED-WITH: alien.c-types c
[ f ] [ \ going-to-redefine \ clone ?lookup-method ] unit-test
[ f ] [ \ going-to-redefine \ struct-slot-values ?lookup-method ] unit-test
+! Test reset-class on structs, which should forget all the accessors, clone, and struct-slot-values
+STRUCT: some-accessors { aaa uint } { bbb int } ;
+[ ] [ [ \ some-accessors reset-class ] with-compilation-unit ] unit-test
+[ f ] [ \ some-accessors \ a>> ?lookup-method ] unit-test
+[ f ] [ \ some-accessors \ a<< ?lookup-method ] unit-test
+[ f ] [ \ some-accessors \ b>> ?lookup-method ] unit-test
+[ f ] [ \ some-accessors \ b<< ?lookup-method ] unit-test
+[ f ] [ \ some-accessors \ clone ?lookup-method ] unit-test
+[ f ] [ \ some-accessors \ struct-slot-values ?lookup-method ] unit-test
+
c-type c-type-boxed-class
dup \ byte-array = [ drop \ c-ptr ] when ;
-: forget-struct-accessors ( class -- )
- dup "c-type" word-prop fields>> [
- name>>
- [ reader-word ?lookup-method forget ]
- [ writer-word ?lookup-method forget ] 2bi
- ] with each ;
-
M: struct-class reset-class
{
- [ forget-struct-accessors ]
+ [ dup "c-type" word-prop fields>> forget-struct-slot-accessors ]
[
[ forget-struct-slot-values-method ]
[ forget-clone-method ] bi
: seeing-implementors ( class -- seq )
dup implementors
[ [ reader? ] [ writer? ] bi or not ] filter
- [ ?lookup-method ] with map
+ [ lookup-method ] with map
natural-sort ;
: seeing-methods ( generic -- seq )
predicate
predicate?
}
-"A predicate word holds a reference to the class it is predicating over in the " { $snippet "\"predicating\"" } " word property." ;
+"A predicate word holds a reference to the class it is predicating over in the " { $snippet "\"predicating\"" } " word property." $nl
+"Implementation of class reloading:"
+{ $subsections reset-class forget-class forget-methods } ;
ARTICLE: "classes" "Classes"
"Conceptually, a " { $snippet "class" } " is a set of objects whose members can be identified with a predicate, and on which generic words can specialize methods. Classes are organized into a general partial order, and an object may be an instance of more than one class."
{ "object" object } { "class" class }
{ "?" "a boolean" } }
{ $description "Tests whether the input object is a member of the class." } ;
+
+HELP: reset-class
+{ $values { "class" class } }
+{ $description "Forgets all of words that the class defines, but not words that are defined on the class. For instance, on a tuple class, this word should reset all of the tuple accessors but not things like " { $link nth } " that may be defined on the class elsewhere." } ;
+
+HELP: forget-class
+{ $values { "class" class } }
+{ $description "Removes a class by forgetting all of the methods defined on that class and all of the methods generated when that class was defined. Also resets any caches that may contain that class." } ;
+
+HELP: forget-methods
+{ $values { "class" class } }
+{ $description "Forgets all methods defined on a class. In contrast to " { $link reset-class } ", this not only forgets accessors but also any methods at all on the class." } ;
+
[ ] [ "IN: classes.tuple.tests TUPLE: final-superclass x ;" eval( -- ) ] unit-test
[ t ] [ \ final-subclass final-class? ] unit-test
+
+! Test reset-class on tuples
+! Should forget all accessors on rclasstest
+TUPLE: rclasstest a b ;
+[ ] [ [ \ rclasstest reset-class ] with-compilation-unit ] unit-test
+[ f ] [ \ rclasstest \ a>> ?lookup-method ] unit-test
+[ f ] [ \ rclasstest \ a<< ?lookup-method ] unit-test
+[ f ] [ \ rclasstest \ b>> ?lookup-method ] unit-test
+[ f ] [ \ rclasstest \ b<< ?lookup-method ] unit-test
+
: define-boa-word ( word class -- )
[ [ boa ] curry ] [ boa-effect ] bi define-inline ;
+: forget-struct-slot-accessors ( class slots -- )
+ [
+ name>>
+ [ reader-word ?lookup-method forget ]
+ [ writer-word ?lookup-method forget ] 2bi
+ ] with each ;
+
M: tuple-class reset-class
[
- dup "slots" word-prop [
- name>>
- [ reader-word ?lookup-method forget ]
- [ writer-word ?lookup-method forget ] 2bi
- ] with each
+ dup "slots" word-prop forget-struct-slot-accessors
] [
[ call-next-method ]
[ { "layout" "slots" "boa-check" "prototype" "final" } reset-props ]
:: [bind-uniforms] ( superclass uniforms -- quot )
superclass "uniform-tuple-texture-units" word-prop 0 or :> first-texture-unit
- superclass \ (bind-uniforms) method :> next-method
+ superclass \ (bind-uniforms) lookup-method :> next-method
first-texture-unit uniforms "" [bind-uniform-tuple] nip :> bind-quot
{ 2dup next-method } bind-quot [ ] append-as ;