Class: YTLJit::TypeUtil::KlassTree

Inherits:
Object
  • Object
show all
Defined in:
lib/ytljit/vm_type.rb

Instance Method Summary collapse

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_nodeObject



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