Added spec:commit task to commit changes to spec/ruby sources.
[rbx.git] / shotgun / lib / selector.c
blob5834f0f79001ca9bc74e07865e2de873de3e4586
1 #include "shotgun/lib/shotgun.h"
2 #include "shotgun/lib/hash.h"
3 #include "shotgun/lib/lookuptable.h"
4 #include "shotgun/lib/array.h"
5 #include "shotgun/lib/module.h"
6 #include "shotgun/lib/sendsite.h"
8 void selector_init(STATE) {
9 state->global->selectors = lookuptable_new(state);
10 BASIC_CLASS(selector) = _selector_class(state, BASIC_CLASS(object));
11 module_setup(state, BASIC_CLASS(selector), "Selector");
12 class_set_object_type(BASIC_CLASS(selector), I2N(SelectorType));
14 rbs_const_set(state, BASIC_CLASS(selector), "ALL", state->global->selectors);
17 OBJECT selector_new(STATE, OBJECT name) {
18 OBJECT sel = selector_allocate(state);
20 selector_set_name(sel, name);
21 selector_set_send_sites(sel, array_new(state, 1));
23 return sel;
26 OBJECT selector_lookup(STATE, OBJECT name) {
27 OBJECT sel;
28 sel = lookuptable_fetch(state, state->global->selectors, name);
29 if(!NIL_P(sel)) return sel;
31 sel = selector_new(state, name);
32 lookuptable_store(state, state->global->selectors, name, sel);
33 return sel;
36 OBJECT selector_associate(STATE, OBJECT self, OBJECT ss) {
37 OBJECT ary;
39 ary = selector_get_send_sites(self);
40 array_append(state, ary, ss);
42 return ss;
45 void selector_clear(STATE, OBJECT self) {
46 OBJECT ary, ss;
47 int i, sz;
49 ary = selector_get_send_sites(self);
50 sz = N2I(array_get_total(ary));
52 for(i = 0; i < sz; i++) {
53 ss = array_get(state, ary, i);
54 cpu_initialize_sendsite(state, SENDSITE(ss));
58 void selector_clear_by_name(STATE, OBJECT name) {
59 OBJECT sel;
60 sel = lookuptable_fetch(state, state->global->selectors, name);
61 if(NIL_P(sel)) return;
63 selector_clear(state, sel);