Support hints on methods
parent
01129fb9bd
commit
8779784798
|
@ -20,9 +20,24 @@ HELP: specialized-def
|
||||||
{ $description "Outputs the definition of a word after it has been split into specialized branches. This is the definition which will actually be compiled by the compiler." } ;
|
{ $description "Outputs the definition of a word after it has been split into specialized branches. This is the definition which will actually be compiled by the compiler." } ;
|
||||||
|
|
||||||
HELP: HINTS:
|
HELP: HINTS:
|
||||||
{ $values { "word" word } { "hints..." "a list of sequences of classes" } }
|
{ $values { "defspec" "a definition specifier" } { "hints..." "a list of sequences of classes" } }
|
||||||
{ $description "Defines specialization hints for each words. Each sequence of classes in the list will cause a specialized version of the word to be compiled." }
|
{ $description "Defines specialization hints for a word or a method."
|
||||||
|
$nl
|
||||||
|
"Each sequence of classes in the list will cause a specialized version of the word to be compiled." }
|
||||||
{ $examples "The " { $link append } " word has a specializer for the very common case where two strings or two arrays are appended:"
|
{ $examples "The " { $link append } " word has a specializer for the very common case where two strings or two arrays are appended:"
|
||||||
{ $code "HINTS: append { string string } { array array } ;" } } ;
|
{ $code "HINTS: append { string string } { array array } ;" }
|
||||||
|
"Specializers can also be defined on methods:"
|
||||||
|
{ $code
|
||||||
|
"GENERIC: count-occurrences ( elt obj -- n )"
|
||||||
|
""
|
||||||
|
"M: sequence count-occurrences [ = ] with count ;"
|
||||||
|
""
|
||||||
|
"M: assoc count-occurrences"
|
||||||
|
" swap [ = nip ] curry assoc-filter assoc-size ;"
|
||||||
|
""
|
||||||
|
"HINTS: { sequence count-occurrences } { object array } ;"
|
||||||
|
"HINTS: { assoc count-occurrences } { object hashtable } ;"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
ABOUT: "hints"
|
ABOUT: "hints"
|
||||||
|
|
|
@ -42,11 +42,11 @@ IN: hints
|
||||||
|
|
||||||
: specialized-def ( word -- quot )
|
: specialized-def ( word -- quot )
|
||||||
dup def>> swap {
|
dup def>> swap {
|
||||||
{ [ dup standard-method? ] [ specialize-method ] }
|
|
||||||
{
|
{
|
||||||
[ dup "specializer" word-prop ]
|
[ dup "specializer" word-prop ]
|
||||||
[ "specializer" word-prop specialize-quot ]
|
[ "specializer" word-prop specialize-quot ]
|
||||||
}
|
}
|
||||||
|
{ [ dup standard-method? ] [ specialize-method ] }
|
||||||
[ drop ]
|
[ drop ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ IN: hints
|
||||||
dup [ array? ] all? [ first ] when length ;
|
dup [ array? ] all? [ first ] when length ;
|
||||||
|
|
||||||
: HINTS:
|
: HINTS:
|
||||||
scan-word
|
scan-object
|
||||||
|
dup method-spec? [ first2 method ] when
|
||||||
[ redefined ]
|
[ redefined ]
|
||||||
[ parse-definition "specializer" set-word-prop ] bi ;
|
[ parse-definition "specializer" set-word-prop ] bi ;
|
||||||
parsing
|
parsing
|
||||||
|
|
Loading…
Reference in New Issue