1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: classes.private generic.standard.engines namespaces make
4 arrays assocs sequences.private quotations kernel.private
5 math slots.private math.private kernel accessors words
7 IN: generic.standard.engines.tag
9 TUPLE: lo-tag-dispatch-engine methods ;
11 C: <lo-tag-dispatch-engine> lo-tag-dispatch-engine
13 : direct-dispatch-quot ( alist n -- quot )
15 [ <enum> swap update ] keep
16 [ dispatch ] curry >quotation ;
18 : lo-tag-number ( class -- n )
19 dup \ hi-tag bootstrap-word eq? [
20 drop \ hi-tag tag-number
25 M: lo-tag-dispatch-engine engine>quot
26 methods>> engines>quots* [ >r lo-tag-number r> ] assoc-map
31 num-tags get direct-dispatch-quot
35 TUPLE: hi-tag-dispatch-engine methods ;
37 C: <hi-tag-dispatch-engine> hi-tag-dispatch-engine
39 : convert-hi-tag-methods ( assoc -- assoc' )
40 \ hi-tag bootstrap-word
41 \ <hi-tag-dispatch-engine> convert-methods ;
43 : num-hi-tags ( -- n ) num-types get num-tags get - ;
45 : hi-tag-number ( class -- n )
46 "type" word-prop num-tags get - ;
48 : hi-tag-quot ( -- quot )
49 [ 0 slot ] num-tags get [ fixnum-fast ] curry compose ;
51 M: hi-tag-dispatch-engine engine>quot
52 methods>> engines>quots* [ >r hi-tag-number r> ] assoc-map
54 picker % hi-tag-quot % [
57 num-hi-tags direct-dispatch-quot