Class: YTLJit::TypeUtil::KlassTree
Instance Method Summary collapse
- #add(key, value) ⇒ Object
-
#initialize(defkey = [], defval = [[], []]) ⇒ KlassTree
constructor
A new instance of KlassTree.
- #search(key) ⇒ Object
- #search_valid_node ⇒ Object
Constructor Details
#initialize(defkey = [], defval = [[], []]) ⇒ KlassTree
Returns a new instance of KlassTree.
4 5 6 |
# File 'lib/ytljit/vm_type.rb', line 4 def initialize(defkey = [], defval = [[], []]) @node = KlassTreeNode.new(defkey, defval) end |
Instance Method Details
#add(key, value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ytljit/vm_type.rb', line 8 def add(key, value) cnode = @node ocnode = nil while cnode ocnode = cnode if key == cnode.key then return cnode end if false and key.zip(cnode.key).all? {|k, n| k.is_a?(n.class)} then cnode = cnode.same_klass if cnode == nil then ocnode.same_klass = KlassTreeNode.new(key, value) return ocnode.same_klass end else cnode = cnode.next_klass if cnode == nil then ocnode.next_klass = KlassTreeNode.new(key, value) return ocnode.next_klass end end end end |
#search(key) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ytljit/vm_type.rb', line 33 def search(key) cnode = @node while cnode if key == cnode.key then return cnode end if false and key.zip(cnode.key).all? {|a, b| if a then atype = a.ruby_type if b then btype = b.ruby_type btype.is_a?(atype.class) else nil end else raise "foo" return !b end } then cnode = cnode.same_klass else cnode = cnode.next_klass end end nil end |
#search_valid_node ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ytljit/vm_type.rb', line 65 def search_valid_node cnode = @node while cnode if cnode.value != [[], []] then return cnode end cnode = cnode.next_klass end nil end |