On Dec 24, 2010, at 12:08 PM, Joe Groff wrote:

> On Dec 24, 2010, at 11:24 AM, beo wulf wrote:
> 
>> Is there a way to merge the TYPED:: and METHOD: declarations into one? I.e. 
>> something like:
>> 
>> METHOD: rotate { quat vec3 } TYPED:: ( q: quat v: vec3 -- v': vec3 ) .... ;
> 
> If the types on the METHOD: are fully specified, you don't need the TYPED: 
> definition, since the compiler already knows all the type information for the 
> input types within that method. If it knows the types of the inputs at the 
> method invocation site, the dynamic dispatch will be eliminated as well.

I should clarify something a bit. TYPED: does in fact perform additional 
optimizations for structs and other unboxable types which a METHOD: will not 
gain on its own. If you want to support multiple dispatch and still reap the 
benefits of TYPED: optimization, you can call a TYPED: function from an inline 
METHOD: as follows:

<PRIVATE

TYPED:: quat-vec3-rotate ( q: quat v: vec3 -- v': vec3 )
        <...implementation of quat-vec3-rotate...> ;

PRIVATE>

METHOD: rotate { quat vec3 } quat-vec3-rotate ; inline

Client code can then use the rotate generic. In the static dispatch case, the 
rotate method will be inlined and the TYPED: function will end up being called 
directly with all type checks optimized away. In the generic dispatch case, the 
type checking within the rotate method will still be optimized away because the 
input types of the method match those expected by the typed word.

-Joe
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to