Class: Optimize::IR::SlotTypeTable

Inherits:
Object
  • Object
show all
Defined in:
lib/optimize/ir/slot_type_table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function, signature, parent, object_table: nil) ⇒ SlotTypeTable

Returns a new instance of SlotTypeTable.



12
13
14
15
16
17
18
# File 'lib/optimize/ir/slot_type_table.rb', line 12

def initialize(function, signature, parent, object_table: nil)
  @slot_types = {}
  @parent = parent
  @local_table_size = (function.misc && function.misc[:local_table_size]) || 0
  seed_from_signature(function, signature)
  scan_for_constructors(function, object_table)
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/optimize/ir/slot_type_table.rb', line 6

def parent
  @parent
end

Class Method Details

.build(function, signature, parent, object_table: nil) ⇒ Object



8
9
10
# File 'lib/optimize/ir/slot_type_table.rb', line 8

def self.build(function, signature, parent, object_table: nil)
  new(function, signature, parent, object_table: object_table)
end

.lindex_to_slot(lindex, size) ⇒ Object

LINDEX ↔ slot-index conversion. LINDEX = VM_ENV_DATA_SIZE(3) + (size - 1 - slot) → slot = size - 1 - (LINDEX - 3).



49
50
51
# File 'lib/optimize/ir/slot_type_table.rb', line 49

def self.lindex_to_slot(lindex, size)
  size - 1 - (lindex - 3)
end

Instance Method Details

#local_table_size_at(level) ⇒ Object

Returns the local_table_size of the table ‘level` parents up. Returns nil if the parent chain ends before reaching `level`.



31
32
33
34
35
36
37
38
# File 'lib/optimize/ir/slot_type_table.rb', line 31

def local_table_size_at(level)
  table = self
  level.times do
    table = table.parent
    return nil unless table
  end
  table.local_table_size
end

#lookup(slot, level) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/optimize/ir/slot_type_table.rb', line 20

def lookup(slot, level)
  table = self
  level.times do
    table = table.parent
    return nil unless table
  end
  table.slot_types[slot]
end

#refresh_local_table_size!(new_size) ⇒ Object

Update the cached size after the function’s local table grew. The cache is what ‘local_table_size_at` walks; after a pass calls Codec::LocalTable.grow!, the slot-table view must be re-synced.



43
44
45
# File 'lib/optimize/ir/slot_type_table.rb', line 43

def refresh_local_table_size!(new_size)
  @local_table_size = new_size
end