More inheritance debugging
parent
7a596ce004
commit
8fde3fb914
|
@ -444,6 +444,7 @@ PRIVATE>
|
||||||
"resource:/core/bootstrap/stage1.factor" run-file
|
"resource:/core/bootstrap/stage1.factor" run-file
|
||||||
build-image
|
build-image
|
||||||
write-image
|
write-image
|
||||||
|
\ word-props target-word
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
||||||
: make-images ( -- )
|
: make-images ( -- )
|
||||||
|
|
|
@ -31,6 +31,7 @@ crossref off
|
||||||
"syntax" vocab vocab-words bootstrap-syntax set
|
"syntax" vocab vocab-words bootstrap-syntax set
|
||||||
H{ } clone dictionary set
|
H{ } clone dictionary set
|
||||||
H{ } clone changed-words set
|
H{ } clone changed-words set
|
||||||
|
H{ } clone forgotten-definitions set
|
||||||
H{ } clone root-cache set
|
H{ } clone root-cache set
|
||||||
H{ } clone source-files set
|
H{ } clone source-files set
|
||||||
H{ } clone update-map set
|
H{ } clone update-map set
|
||||||
|
@ -126,27 +127,49 @@ num-types get f <array> builtins set
|
||||||
: register-builtin ( class -- )
|
: register-builtin ( class -- )
|
||||||
[ dup lookup-type-number "type" set-word-prop ]
|
[ dup lookup-type-number "type" set-word-prop ]
|
||||||
[ dup "type" word-prop builtins get set-nth ]
|
[ dup "type" word-prop builtins get set-nth ]
|
||||||
bi ;
|
[ f f builtin-class define-class ]
|
||||||
|
tri ;
|
||||||
|
|
||||||
: define-builtin-slots ( symbol slotspec -- )
|
: define-builtin-slots ( symbol slotspec -- )
|
||||||
[ drop ] [ 1 simple-slots ] 2bi
|
[ drop ] [ 1 simple-slots ] 2bi
|
||||||
[ "slots" set-word-prop ] [ define-slots ] 2bi ;
|
[ "slots" set-word-prop ] [ define-slots ] 2bi ;
|
||||||
|
|
||||||
: define-builtin ( symbol slotspec -- )
|
: define-builtin ( symbol slotspec -- )
|
||||||
>r
|
>r [ define-builtin-predicate ] keep
|
||||||
{
|
|
||||||
[ register-builtin ]
|
|
||||||
[ f f builtin-class define-class ]
|
|
||||||
[ define-builtin-predicate ]
|
|
||||||
[ ]
|
|
||||||
} cleave
|
|
||||||
r> define-builtin-slots ;
|
r> define-builtin-slots ;
|
||||||
|
|
||||||
! Forward definitions
|
"fixnum" "math" create register-builtin
|
||||||
"object" "kernel" create t "class" set-word-prop
|
"bignum" "math" create register-builtin
|
||||||
"object" "kernel" create union-class "metaclass" set-word-prop
|
"tuple" "kernel" create register-builtin
|
||||||
|
"ratio" "math" create register-builtin
|
||||||
|
"float" "math" create register-builtin
|
||||||
|
"complex" "math" create register-builtin
|
||||||
|
"f" "syntax" lookup register-builtin
|
||||||
|
"array" "arrays" create register-builtin
|
||||||
|
"wrapper" "kernel" create register-builtin
|
||||||
|
"float-array" "float-arrays" create register-builtin
|
||||||
|
"callstack" "kernel" create register-builtin
|
||||||
|
"string" "strings" create register-builtin
|
||||||
|
"bit-array" "bit-arrays" create register-builtin
|
||||||
|
"quotation" "quotations" create register-builtin
|
||||||
|
"dll" "alien" create register-builtin
|
||||||
|
"alien" "alien" create register-builtin
|
||||||
|
"word" "words" create register-builtin
|
||||||
|
"byte-array" "byte-arrays" create register-builtin
|
||||||
|
"tuple-layout" "classes.tuple.private" create register-builtin
|
||||||
|
|
||||||
"null" "kernel" create drop
|
! Catch-all class for providing a default method.
|
||||||
|
"object" "kernel" create [ drop t ] "predicate" set-word-prop
|
||||||
|
"object" "kernel" create
|
||||||
|
f builtins get [ ] subset union-class define-class
|
||||||
|
|
||||||
|
! Class of objects with object tag
|
||||||
|
"hi-tag" "kernel.private" create
|
||||||
|
f builtins get num-tags get tail union-class define-class
|
||||||
|
|
||||||
|
! Empty class with no instances
|
||||||
|
"null" "kernel" create [ drop f ] "predicate" set-word-prop
|
||||||
|
"null" "kernel" create f { } union-class define-class
|
||||||
|
|
||||||
"fixnum" "math" create { } define-builtin
|
"fixnum" "math" create { } define-builtin
|
||||||
"fixnum" "math" create ">fixnum" "math" create 1quotation "coercer" set-word-prop
|
"fixnum" "math" create ">fixnum" "math" create 1quotation "coercer" set-word-prop
|
||||||
|
@ -335,9 +358,11 @@ define-builtin
|
||||||
}
|
}
|
||||||
} define-builtin
|
} define-builtin
|
||||||
|
|
||||||
"tuple" "kernel" create { } define-builtin
|
"tuple" "kernel" create {
|
||||||
|
[ { } define-builtin ]
|
||||||
"tuple" "kernel" lookup
|
[ { "delegate" } "slot-names" set-word-prop ]
|
||||||
|
[ define-tuple-layout ]
|
||||||
|
[
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{ "object" "kernel" }
|
{ "object" "kernel" }
|
||||||
|
@ -347,11 +372,11 @@ define-builtin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[ drop ] [ generate-tuple-slots ] 2bi
|
[ drop ] [ generate-tuple-slots ] 2bi
|
||||||
[ [ name>> ] map "slot-names" set-word-prop ]
|
|
||||||
[ "slots" set-word-prop ]
|
[ "slots" set-word-prop ]
|
||||||
[ define-slots ] 2tri
|
[ define-slots ]
|
||||||
|
2bi
|
||||||
"tuple" "kernel" lookup define-tuple-layout
|
]
|
||||||
|
} cleave
|
||||||
|
|
||||||
! Define general-t type, which is any object that is not f.
|
! Define general-t type, which is any object that is not f.
|
||||||
"general-t" "kernel" create
|
"general-t" "kernel" create
|
||||||
|
@ -359,23 +384,10 @@ f "f" "syntax" lookup builtins get remove [ ] subset union-class
|
||||||
define-class
|
define-class
|
||||||
|
|
||||||
"f" "syntax" create [ not ] "predicate" set-word-prop
|
"f" "syntax" create [ not ] "predicate" set-word-prop
|
||||||
"f?" "syntax" create "syntax" vocab-words delete-at
|
"f?" "syntax" vocab-words delete-at
|
||||||
|
|
||||||
"general-t" "kernel" create [ ] "predicate" set-word-prop
|
"general-t" "kernel" create [ ] "predicate" set-word-prop
|
||||||
"general-t?" "kernel" create "syntax" vocab-words delete-at
|
"general-t?" "kernel" vocab-words delete-at
|
||||||
|
|
||||||
! Catch-all class for providing a default method.
|
|
||||||
"object" "kernel" create [ drop t ] "predicate" set-word-prop
|
|
||||||
"object" "kernel" create
|
|
||||||
f builtins get [ ] subset union-class define-class
|
|
||||||
|
|
||||||
! Class of objects with object tag
|
|
||||||
"hi-tag" "kernel.private" create
|
|
||||||
f builtins get num-tags get tail union-class define-class
|
|
||||||
|
|
||||||
! Null class with no instances.
|
|
||||||
"null" "kernel" create [ drop f ] "predicate" set-word-prop
|
|
||||||
"null" "kernel" create f { } union-class define-class
|
|
||||||
|
|
||||||
! Create special tombstone values
|
! Create special tombstone values
|
||||||
"tombstone" "hashtables.private" create
|
"tombstone" "hashtables.private" create
|
||||||
|
|
|
@ -19,7 +19,6 @@ vocabs.loader system debugger continuations ;
|
||||||
! Rehash hashtables, since bootstrap.image creates them
|
! Rehash hashtables, since bootstrap.image creates them
|
||||||
! using the host image's hashing algorithms
|
! using the host image's hashing algorithms
|
||||||
[ hashtable? ] instances [ rehash ] each
|
[ hashtable? ] instances [ rehash ] each
|
||||||
|
|
||||||
boot
|
boot
|
||||||
] %
|
] %
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel classes combinators accessors sequences arrays
|
USING: kernel classes combinators accessors sequences arrays
|
||||||
vectors assocs namespaces words sorting layouts math hashtables
|
vectors assocs namespaces words sorting layouts math hashtables
|
||||||
;
|
kernel.private ;
|
||||||
IN: classes.algebra
|
IN: classes.algebra
|
||||||
|
|
||||||
: 2cache ( key1 key2 assoc quot -- value )
|
: 2cache ( key1 key2 assoc quot -- value )
|
||||||
|
@ -211,12 +211,6 @@ C: <anonymous-complement> anonymous-complement
|
||||||
: flatten-class ( class -- assoc )
|
: flatten-class ( class -- assoc )
|
||||||
[ (flatten-class) ] H{ } make-assoc ;
|
[ (flatten-class) ] H{ } make-assoc ;
|
||||||
|
|
||||||
: class-hashes ( class -- seq )
|
|
||||||
flatten-class keys [
|
|
||||||
dup builtin-class?
|
|
||||||
[ "type" word-prop ] [ hashcode ] if
|
|
||||||
] map ;
|
|
||||||
|
|
||||||
: flatten-builtin-class ( class -- assoc )
|
: flatten-builtin-class ( class -- assoc )
|
||||||
flatten-class [
|
flatten-class [
|
||||||
dup tuple class< [ 2drop tuple tuple ] when
|
dup tuple class< [ 2drop tuple tuple ] when
|
||||||
|
@ -229,5 +223,5 @@ C: <anonymous-complement> anonymous-complement
|
||||||
: class-tags ( class -- tag/f )
|
: class-tags ( class -- tag/f )
|
||||||
class-types [
|
class-types [
|
||||||
dup num-tags get >=
|
dup num-tags get >=
|
||||||
[ drop object tag-number ] when
|
[ drop \ hi-tag tag-number ] when
|
||||||
] map prune ;
|
] map prune ;
|
||||||
|
|
|
@ -25,9 +25,11 @@ SYMBOL: class-or-cache
|
||||||
class-and-cache get clear-assoc
|
class-and-cache get clear-assoc
|
||||||
class-or-cache get clear-assoc ;
|
class-or-cache get clear-assoc ;
|
||||||
|
|
||||||
PREDICATE: class < word ( obj -- ? ) "class" word-prop ;
|
|
||||||
|
|
||||||
SYMBOL: update-map
|
SYMBOL: update-map
|
||||||
|
|
||||||
|
PREDICATE: class < word
|
||||||
|
"class" word-prop ;
|
||||||
|
|
||||||
SYMBOL: builtins
|
SYMBOL: builtins
|
||||||
|
|
||||||
PREDICATE: builtin-class < class
|
PREDICATE: builtin-class < class
|
||||||
|
@ -58,7 +60,7 @@ PREDICATE: predicate < word "predicating" word-prop >boolean ;
|
||||||
dup class? [ "superclass" word-prop ] [ drop f ] if ;
|
dup class? [ "superclass" word-prop ] [ drop f ] if ;
|
||||||
|
|
||||||
: superclasses ( class -- supers )
|
: superclasses ( class -- supers )
|
||||||
[ dup ] [ dup superclass swap ] [ ] unfold reverse nip ;
|
[ dup ] [ [ superclass ] keep ] [ ] unfold nip reverse ;
|
||||||
|
|
||||||
: members ( class -- seq )
|
: members ( class -- seq )
|
||||||
#! Output f for non-classes to work with algebra code
|
#! Output f for non-classes to work with algebra code
|
||||||
|
@ -72,7 +74,7 @@ M: word reset-class drop ;
|
||||||
|
|
||||||
! update-map
|
! update-map
|
||||||
: class-uses ( class -- seq )
|
: class-uses ( class -- seq )
|
||||||
dup members swap superclass [ suffix ] when* ;
|
[ members ] [ superclass ] bi [ suffix ] when* ;
|
||||||
|
|
||||||
: class-usages ( class -- assoc )
|
: class-usages ( class -- assoc )
|
||||||
[ update-map get at ] closure ;
|
[ update-map get at ] closure ;
|
||||||
|
|
|
@ -394,7 +394,9 @@ test-server-slot-values
|
||||||
! Reshape crash
|
! Reshape crash
|
||||||
TUPLE: test1 a ; TUPLE: test2 < test1 b ;
|
TUPLE: test1 a ; TUPLE: test2 < test1 b ;
|
||||||
|
|
||||||
T{ test2 f "a" "b" } "test" set
|
C: <test2> test2
|
||||||
|
|
||||||
|
"a" "b" <test2> "test" set
|
||||||
|
|
||||||
: test-a/b
|
: test-a/b
|
||||||
[ "a" ] [ "test" get a>> ] unit-test
|
[ "a" ] [ "test" get a>> ] unit-test
|
||||||
|
|
|
@ -37,7 +37,6 @@ $nl
|
||||||
{ $subsection create-method }
|
{ $subsection create-method }
|
||||||
"Method definitions can be looked up:"
|
"Method definitions can be looked up:"
|
||||||
{ $subsection method }
|
{ $subsection method }
|
||||||
{ $subsection methods }
|
|
||||||
"A generic word contains methods; the list of methods specializing on a class can also be obtained:"
|
"A generic word contains methods; the list of methods specializing on a class can also be obtained:"
|
||||||
{ $subsection implementors }
|
{ $subsection implementors }
|
||||||
"Low-level word which rebuilds the generic word after methods are added or removed, or the method combination is changed:"
|
"Low-level word which rebuilds the generic word after methods are added or removed, or the method combination is changed:"
|
||||||
|
@ -120,10 +119,6 @@ HELP: <method>
|
||||||
{ $values { "class" class } { "generic" generic } { "method" "a new method definition" } }
|
{ $values { "class" class } { "generic" generic } { "method" "a new method definition" } }
|
||||||
{ $description "Creates a new method." } ;
|
{ $description "Creates a new method." } ;
|
||||||
|
|
||||||
HELP: methods
|
|
||||||
{ $values { "word" generic } { "assoc" "an association list mapping classes to quotations" } }
|
|
||||||
{ $description "Outputs a sequence of pairs, where the first element of each pair is a class and the second element is the corresponding method quotation. The methods are sorted by class order; see " { $link sort-classes } "." } ;
|
|
||||||
|
|
||||||
HELP: order
|
HELP: order
|
||||||
{ $values { "generic" generic } { "seq" "a sequence of classes" } }
|
{ $values { "generic" generic } { "seq" "a sequence of classes" } }
|
||||||
{ $description "Outputs a sequence of classes for which methods have been defined on this generic word. The sequence is sorted in method dispatch order." } ;
|
{ $description "Outputs a sequence of classes for which methods have been defined on this generic word. The sequence is sorted in method dispatch order." } ;
|
||||||
|
@ -151,4 +146,4 @@ HELP: forget-methods
|
||||||
{ $values { "class" class } }
|
{ $values { "class" class } }
|
||||||
{ $description "Remove all method definitions which specialize on the class." } ;
|
{ $description "Remove all method definitions which specialize on the class." } ;
|
||||||
|
|
||||||
{ sort-classes methods order } related-words
|
{ sort-classes order } related-words
|
||||||
|
|
|
@ -171,37 +171,6 @@ M: f tag-and-f 4 ;
|
||||||
|
|
||||||
[ 3.4 3 ] [ 3.4 tag-and-f ] unit-test
|
[ 3.4 3 ] [ 3.4 tag-and-f ] unit-test
|
||||||
|
|
||||||
! define-class hashing issue
|
|
||||||
TUPLE: debug-combination ;
|
|
||||||
|
|
||||||
M: debug-combination make-default-method
|
|
||||||
2drop [ "Oops" throw ] ;
|
|
||||||
|
|
||||||
M: debug-combination perform-combination
|
|
||||||
drop
|
|
||||||
order [ dup class-hashes ] { } map>assoc sort-keys
|
|
||||||
1quotation ;
|
|
||||||
|
|
||||||
SYMBOL: redefinition-test-generic
|
|
||||||
|
|
||||||
[
|
|
||||||
redefinition-test-generic
|
|
||||||
T{ debug-combination }
|
|
||||||
define-generic
|
|
||||||
] with-compilation-unit
|
|
||||||
|
|
||||||
TUPLE: redefinition-test-tuple ;
|
|
||||||
|
|
||||||
"IN: generic.tests M: redefinition-test-tuple redefinition-test-generic ;" eval
|
|
||||||
|
|
||||||
[ t ] [
|
|
||||||
[
|
|
||||||
redefinition-test-generic ,
|
|
||||||
"IN: generic.tests TUPLE: redefinition-test-tuple ;" eval
|
|
||||||
redefinition-test-generic ,
|
|
||||||
] { } make all-equal?
|
|
||||||
] unit-test
|
|
||||||
|
|
||||||
! Issues with forget
|
! Issues with forget
|
||||||
GENERIC: generic-forget-test-1
|
GENERIC: generic-forget-test-1
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,9 @@ PREDICATE: generic < word
|
||||||
M: generic definition drop f ;
|
M: generic definition drop f ;
|
||||||
|
|
||||||
: make-generic ( word -- )
|
: make-generic ( word -- )
|
||||||
dup { "unannotated-def" } reset-props
|
[ { "unannotated-def" } reset-props ]
|
||||||
dup dup "combination" word-prop perform-combination define ;
|
[ dup "combination" word-prop perform-combination ]
|
||||||
|
bi ;
|
||||||
|
|
||||||
: method ( class generic -- method/f )
|
: method ( class generic -- method/f )
|
||||||
"methods" word-prop at ;
|
"methods" word-prop at ;
|
||||||
|
@ -37,13 +38,6 @@ PREDICATE: method-spec < pair
|
||||||
: order ( generic -- seq )
|
: order ( generic -- seq )
|
||||||
"methods" word-prop keys sort-classes ;
|
"methods" word-prop keys sort-classes ;
|
||||||
|
|
||||||
: sort-methods ( assoc -- assoc' )
|
|
||||||
[ keys sort-classes ]
|
|
||||||
[ [ dupd at ] curry ] bi { } map>assoc ;
|
|
||||||
|
|
||||||
: methods ( word -- assoc )
|
|
||||||
"methods" word-prop sort-methods ;
|
|
||||||
|
|
||||||
TUPLE: check-method class generic ;
|
TUPLE: check-method class generic ;
|
||||||
|
|
||||||
: check-method ( class generic -- class generic )
|
: check-method ( class generic -- class generic )
|
||||||
|
@ -64,6 +58,9 @@ PREDICATE: method-body < word
|
||||||
M: method-body stack-effect
|
M: method-body stack-effect
|
||||||
"method-generic" word-prop stack-effect ;
|
"method-generic" word-prop stack-effect ;
|
||||||
|
|
||||||
|
M: method-body crossref?
|
||||||
|
drop t ;
|
||||||
|
|
||||||
: method-word-props ( class generic -- assoc )
|
: method-word-props ( class generic -- assoc )
|
||||||
[
|
[
|
||||||
"method-generic" set
|
"method-generic" set
|
||||||
|
@ -122,9 +119,12 @@ M: method-body definer
|
||||||
|
|
||||||
M: method-body forget*
|
M: method-body forget*
|
||||||
dup "forgotten" word-prop [ drop ] [
|
dup "forgotten" word-prop [ drop ] [
|
||||||
dup "method-class" word-prop
|
[
|
||||||
over "method-generic" word-prop forget-method
|
[ "method-class" word-prop ]
|
||||||
t "forgotten" set-word-prop
|
[ "method-generic" word-prop ] bi
|
||||||
|
forget-method
|
||||||
|
]
|
||||||
|
[ t "forgotten" set-word-prop ] bi
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: implementors* ( classes -- words )
|
: implementors* ( classes -- words )
|
||||||
|
@ -137,12 +137,13 @@ M: method-body forget*
|
||||||
dup associate implementors* ;
|
dup associate implementors* ;
|
||||||
|
|
||||||
: forget-methods ( class -- )
|
: forget-methods ( class -- )
|
||||||
[ implementors ] keep [ swap 2array ] curry map forget-all ;
|
[ implementors ] [ [ swap 2array ] curry ] bi map forget-all ;
|
||||||
|
|
||||||
M: class forget* ( class -- )
|
M: class forget* ( class -- )
|
||||||
dup forget-methods
|
[ forget-methods ]
|
||||||
dup update-map-
|
[ update-map- ]
|
||||||
forget-word ;
|
[ forget-word ]
|
||||||
|
tri ;
|
||||||
|
|
||||||
M: assoc update-methods ( assoc -- )
|
M: assoc update-methods ( assoc -- )
|
||||||
implementors* [ make-generic ] each ;
|
implementors* [ make-generic ] each ;
|
||||||
|
@ -158,11 +159,15 @@ M: assoc update-methods ( assoc -- )
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
M: generic subwords
|
M: generic subwords
|
||||||
dup "methods" word-prop values
|
[
|
||||||
swap "default-method" word-prop suffix ;
|
[ "default-method" word-prop , ]
|
||||||
|
[ "methods" word-prop values % ]
|
||||||
|
[ "engines" word-prop % ]
|
||||||
|
tri
|
||||||
|
] { } make ;
|
||||||
|
|
||||||
M: generic forget-word
|
M: generic forget-word
|
||||||
dup subwords [ forget ] each (forget-word) ;
|
[ subwords forget-all ] [ (forget-word) ] bi ;
|
||||||
|
|
||||||
: xref-generics ( -- )
|
: xref-generics ( -- )
|
||||||
all-words [ subwords [ xref ] each ] each ;
|
all-words [ subwords [ xref ] each ] each ;
|
||||||
|
|
|
@ -71,13 +71,15 @@ M: math-combination make-default-method
|
||||||
|
|
||||||
M: math-combination perform-combination
|
M: math-combination perform-combination
|
||||||
drop
|
drop
|
||||||
|
dup
|
||||||
\ over [
|
\ over [
|
||||||
dup math-class? [
|
dup math-class? [
|
||||||
\ dup [ >r 2dup r> math-method ] math-vtable
|
\ dup [ >r 2dup r> math-method ] math-vtable
|
||||||
] [
|
] [
|
||||||
over object-method
|
over object-method
|
||||||
] if nip
|
] if nip
|
||||||
] math-vtable nip ;
|
] math-vtable nip
|
||||||
|
define ;
|
||||||
|
|
||||||
PREDICATE: math-generic < generic ( word -- ? )
|
PREDICATE: math-generic < generic ( word -- ? )
|
||||||
"combination" word-prop math-combination? ;
|
"combination" word-prop math-combination? ;
|
||||||
|
|
|
@ -21,6 +21,10 @@ C: <predicate-dispatch-engine> predicate-dispatch-engine
|
||||||
{ [ t ] [ [ first second ] [ 1 tail-slice ] bi ] }
|
{ [ t ] [ [ first second ] [ 1 tail-slice ] bi ] }
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
: sort-methods ( assoc -- assoc' )
|
||||||
|
[ keys sort-classes ]
|
||||||
|
[ [ dupd at ] curry ] bi { } map>assoc ;
|
||||||
|
|
||||||
M: predicate-dispatch-engine engine>quot
|
M: predicate-dispatch-engine engine>quot
|
||||||
methods>> clone
|
methods>> clone
|
||||||
default get object bootstrap-word pick set-at engines>quots
|
default get object bootstrap-word pick set-at engines>quots
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
USING: classes.private generic.standard.engines namespaces
|
USING: classes.private generic.standard.engines namespaces
|
||||||
arrays assocs sequences.private quotations kernel.private
|
arrays assocs sequences.private quotations kernel.private
|
||||||
layouts math slots.private math.private kernel accessors ;
|
math slots.private math.private kernel accessors words
|
||||||
|
layouts ;
|
||||||
IN: generic.standard.engines.tag
|
IN: generic.standard.engines.tag
|
||||||
|
|
||||||
TUPLE: lo-tag-dispatch-engine methods ;
|
TUPLE: lo-tag-dispatch-engine methods ;
|
||||||
|
|
||||||
C: <lo-tag-dispatch-engine> lo-tag-dispatch-engine
|
C: <lo-tag-dispatch-engine> lo-tag-dispatch-engine
|
||||||
|
|
||||||
TUPLE: hi-tag-dispatch-engine methods ;
|
|
||||||
|
|
||||||
C: <hi-tag-dispatch-engine> hi-tag-dispatch-engine
|
|
||||||
|
|
||||||
: convert-hi-tag-methods ( assoc -- assoc' )
|
|
||||||
\ hi-tag \ <hi-tag-dispatch-engine> convert-methods ;
|
|
||||||
|
|
||||||
: direct-dispatch-quot ( alist n -- quot )
|
: direct-dispatch-quot ( alist n -- quot )
|
||||||
default get <array>
|
default get <array>
|
||||||
[ <enum> swap update ] keep
|
[ <enum> swap update ] keep
|
||||||
[ dispatch ] curry >quotation ;
|
[ dispatch ] curry >quotation ;
|
||||||
|
|
||||||
|
: lo-tag-number ( class -- n )
|
||||||
|
dup \ hi-tag bootstrap-word eq? [
|
||||||
|
drop \ hi-tag tag-number
|
||||||
|
] [
|
||||||
|
"type" word-prop
|
||||||
|
] if ;
|
||||||
|
|
||||||
M: lo-tag-dispatch-engine engine>quot
|
M: lo-tag-dispatch-engine engine>quot
|
||||||
methods>> engines>quots* [ >r tag-number r> ] assoc-map
|
methods>> engines>quots* [ >r lo-tag-number r> ] assoc-map
|
||||||
[
|
[
|
||||||
picker % [ tag ] % [
|
picker % [ tag ] % [
|
||||||
linear-dispatch-quot
|
linear-dispatch-quot
|
||||||
|
@ -29,12 +30,21 @@ M: lo-tag-dispatch-engine engine>quot
|
||||||
] if-small? %
|
] if-small? %
|
||||||
] [ ] make ;
|
] [ ] make ;
|
||||||
|
|
||||||
|
TUPLE: hi-tag-dispatch-engine methods ;
|
||||||
|
|
||||||
|
C: <hi-tag-dispatch-engine> hi-tag-dispatch-engine
|
||||||
|
|
||||||
|
: convert-hi-tag-methods ( assoc -- assoc' )
|
||||||
|
\ hi-tag bootstrap-word
|
||||||
|
\ <hi-tag-dispatch-engine> convert-methods ;
|
||||||
|
|
||||||
: num-hi-tags num-types get num-tags get - ;
|
: num-hi-tags num-types get num-tags get - ;
|
||||||
|
|
||||||
: hi-tag-number type-number num-tags get - ;
|
: hi-tag-number ( class -- n )
|
||||||
|
"type" word-prop num-tags get - ;
|
||||||
|
|
||||||
: hi-tag-quot ( -- quot )
|
: hi-tag-quot ( -- quot )
|
||||||
[ 0 slot ] num-tags get [ fixnum- ] curry compose ;
|
[ hi-tag ] num-tags get [ fixnum-fast ] curry compose ;
|
||||||
|
|
||||||
M: hi-tag-dispatch-engine engine>quot
|
M: hi-tag-dispatch-engine engine>quot
|
||||||
methods>> engines>quots* [ >r hi-tag-number r> ] assoc-map
|
methods>> engines>quots* [ >r hi-tag-number r> ] assoc-map
|
||||||
|
|
|
@ -2,7 +2,7 @@ IN: generic.standard.engines.tuple
|
||||||
USING: kernel classes.tuple.private hashtables assocs sorting
|
USING: kernel classes.tuple.private hashtables assocs sorting
|
||||||
accessors combinators sequences slots.private math.parser words
|
accessors combinators sequences slots.private math.parser words
|
||||||
effects namespaces generic generic.standard.engines
|
effects namespaces generic generic.standard.engines
|
||||||
classes.algebra math math.private quotations ;
|
classes.algebra math math.private quotations arrays ;
|
||||||
|
|
||||||
TUPLE: echelon-dispatch-engine n methods ;
|
TUPLE: echelon-dispatch-engine n methods ;
|
||||||
|
|
||||||
|
@ -27,17 +27,25 @@ TUPLE: tuple-dispatch-engine echelons ;
|
||||||
|
|
||||||
: <tuple-dispatch-engine> ( methods -- engine )
|
: <tuple-dispatch-engine> ( methods -- engine )
|
||||||
echelon-sort
|
echelon-sort
|
||||||
[ dupd <echelon-dispatch-engine> ] assoc-map
|
[
|
||||||
|
over zero? [
|
||||||
|
dup assoc-empty?
|
||||||
|
[ drop f ] [ values first ] if
|
||||||
|
] [
|
||||||
|
dupd <echelon-dispatch-engine>
|
||||||
|
] if
|
||||||
|
] assoc-map [ nip ] assoc-subset
|
||||||
\ tuple-dispatch-engine construct-boa ;
|
\ tuple-dispatch-engine construct-boa ;
|
||||||
|
|
||||||
: convert-tuple-methods ( assoc -- assoc' )
|
: convert-tuple-methods ( assoc -- assoc' )
|
||||||
tuple \ <tuple-dispatch-engine> convert-methods ;
|
tuple bootstrap-word
|
||||||
|
\ <tuple-dispatch-engine> convert-methods ;
|
||||||
|
|
||||||
M: trivial-tuple-dispatch-engine engine>quot
|
M: trivial-tuple-dispatch-engine engine>quot
|
||||||
methods>> engines>quots* linear-dispatch-quot ;
|
methods>> engines>quots* linear-dispatch-quot ;
|
||||||
|
|
||||||
: hash-methods ( methods -- buckets )
|
: hash-methods ( methods -- buckets )
|
||||||
>alist V{ } clone [ class-hashes ] distribute-buckets
|
>alist V{ } clone [ hashcode 1array ] distribute-buckets
|
||||||
[ <trivial-tuple-dispatch-engine> ] map ;
|
[ <trivial-tuple-dispatch-engine> ] map ;
|
||||||
|
|
||||||
: class-hash-dispatch-quot ( methods -- quot )
|
: class-hash-dispatch-quot ( methods -- quot )
|
||||||
|
@ -60,12 +68,20 @@ PREDICATE: tuple-dispatch-engine-word < word
|
||||||
M: tuple-dispatch-engine-word stack-effect
|
M: tuple-dispatch-engine-word stack-effect
|
||||||
"tuple-dispatch-generic" word-prop stack-effect ;
|
"tuple-dispatch-generic" word-prop stack-effect ;
|
||||||
|
|
||||||
|
M: tuple-dispatch-engine-word crossref?
|
||||||
|
drop t ;
|
||||||
|
|
||||||
|
: remember-engine ( word -- )
|
||||||
|
generic get "engines" word-prop push ;
|
||||||
|
|
||||||
: <tuple-dispatch-engine-word> ( engine -- word )
|
: <tuple-dispatch-engine-word> ( engine -- word )
|
||||||
tuple-dispatch-engine-word-name f <word>
|
tuple-dispatch-engine-word-name f <word>
|
||||||
|
{
|
||||||
[ t "tuple-dispatch-engine" set-word-prop ]
|
[ t "tuple-dispatch-engine" set-word-prop ]
|
||||||
[ generic get "tuple-dispatch-generic" set-word-prop ]
|
[ generic get "tuple-dispatch-generic" set-word-prop ]
|
||||||
|
[ remember-engine ]
|
||||||
[ ]
|
[ ]
|
||||||
tri ;
|
} cleave ;
|
||||||
|
|
||||||
: define-tuple-dispatch-engine-word ( engine quot -- word )
|
: define-tuple-dispatch-engine-word ( engine quot -- word )
|
||||||
>r <tuple-dispatch-engine-word> dup r> define ;
|
>r <tuple-dispatch-engine-word> dup r> define ;
|
||||||
|
@ -104,6 +120,9 @@ M: tuple-dispatch-engine engine>quot
|
||||||
picker %
|
picker %
|
||||||
[ 1 slot 5 slot ] %
|
[ 1 slot 5 slot ] %
|
||||||
echelons>>
|
echelons>>
|
||||||
[ [ engine>quot dup default set ] assoc-map ] with-scope
|
[
|
||||||
|
tuple assumed set
|
||||||
|
[ engine>quot dup default set ] assoc-map
|
||||||
|
] with-scope
|
||||||
>=-case-quot %
|
>=-case-quot %
|
||||||
] [ ] make ;
|
] [ ] make ;
|
||||||
|
|
|
@ -59,16 +59,18 @@ ERROR: no-method object generic ;
|
||||||
|
|
||||||
: find-default ( methods -- quot )
|
: find-default ( methods -- quot )
|
||||||
#! Side-effects methods.
|
#! Side-effects methods.
|
||||||
object swap delete-at* [
|
object bootstrap-word swap delete-at* [
|
||||||
drop generic get "default-method" word-prop 1quotation
|
drop generic get "default-method" word-prop 1quotation
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
||||||
GENERIC: mangle-method ( method generic -- quot )
|
GENERIC: mangle-method ( method generic -- quot )
|
||||||
|
|
||||||
: single-combination ( words -- quot )
|
: single-combination ( word -- quot )
|
||||||
[
|
[
|
||||||
object bootstrap-word assumed set
|
object bootstrap-word assumed set {
|
||||||
[ generic set ]
|
[ generic set ]
|
||||||
|
[ "engines" word-prop forget-all ]
|
||||||
|
[ V{ } clone "engines" set-word-prop ]
|
||||||
[
|
[
|
||||||
"methods" word-prop
|
"methods" word-prop
|
||||||
[ generic get mangle-method ] assoc-map
|
[ generic get mangle-method ] assoc-map
|
||||||
|
@ -81,7 +83,8 @@ GENERIC: mangle-method ( method generic -- quot )
|
||||||
] if
|
] if
|
||||||
] bi
|
] bi
|
||||||
engine>quot
|
engine>quot
|
||||||
] bi
|
]
|
||||||
|
} cleave
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
||||||
TUPLE: standard-combination # ;
|
TUPLE: standard-combination # ;
|
||||||
|
@ -107,7 +110,7 @@ M: standard-combination make-default-method
|
||||||
[ empty-method ] with-standard ;
|
[ empty-method ] with-standard ;
|
||||||
|
|
||||||
M: standard-combination perform-combination
|
M: standard-combination perform-combination
|
||||||
[ single-combination ] with-standard ;
|
[ drop ] [ [ single-combination ] with-standard ] 2bi define ;
|
||||||
|
|
||||||
TUPLE: hook-combination var ;
|
TUPLE: hook-combination var ;
|
||||||
|
|
||||||
|
@ -128,7 +131,7 @@ M: hook-combination make-default-method
|
||||||
[ error-method ] with-hook ;
|
[ error-method ] with-hook ;
|
||||||
|
|
||||||
M: hook-combination perform-combination
|
M: hook-combination perform-combination
|
||||||
[ single-combination ] with-hook ;
|
[ drop ] [ [ single-combination ] with-hook ] 2bi define ;
|
||||||
|
|
||||||
GENERIC: dispatch# ( word -- n )
|
GENERIC: dispatch# ( word -- n )
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ GENERIC: construct-boa ( ... class -- tuple )
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: hi-tag ( obj -- n ) 0 slot ;
|
: hi-tag ( obj -- n ) 0 slot ; inline
|
||||||
|
|
||||||
: declare ( spec -- ) drop ;
|
: declare ( spec -- ) drop ;
|
||||||
|
|
||||||
|
|
|
@ -63,10 +63,11 @@ SYMBOL: bootstrapping?
|
||||||
: bootstrap-word ( word -- target )
|
: bootstrap-word ( word -- target )
|
||||||
[ target-word ] [ ] if-bootstrapping ;
|
[ target-word ] [ ] if-bootstrapping ;
|
||||||
|
|
||||||
: crossref? ( word -- ? )
|
GENERIC: crossref? ( word -- ? )
|
||||||
|
|
||||||
|
M: word crossref?
|
||||||
{
|
{
|
||||||
{ [ dup "forgotten" word-prop ] [ f ] }
|
{ [ dup "forgotten" word-prop ] [ f ] }
|
||||||
{ [ dup "method-generic" word-prop ] [ t ] }
|
|
||||||
{ [ dup word-vocabulary ] [ t ] }
|
{ [ dup word-vocabulary ] [ t ] }
|
||||||
{ [ t ] [ f ] }
|
{ [ t ] [ f ] }
|
||||||
} cond nip ;
|
} cond nip ;
|
||||||
|
|
Loading…
Reference in New Issue