Class: SyntaxTree::YARV::SetBlockParam

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

setblockparam sets the value of a block local variable on a frame determined by the level and index arguments. The level is the number of frames back to look and the index is the index in the local table. It pops the value it is setting off the stack.

### Usage

~~~ruby def foo(&bar)

bar = baz

end ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, level) ⇒ SetBlockParam

Returns a new instance of SetBlockParam.



5246
5247
5248
5249
# File 'lib/syntax_tree/yarv/instructions.rb', line 5246

def initialize(index, level)
  @index = index
  @level = level
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5244
5245
5246
# File 'lib/syntax_tree/yarv/instructions.rb', line 5244

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



5244
5245
5246
# File 'lib/syntax_tree/yarv/instructions.rb', line 5244

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



5265
5266
5267
5268
# File 'lib/syntax_tree/yarv/instructions.rb', line 5265

def ==(other)
  other.is_a?(SetBlockParam) && other.index == index &&
    other.level == level
end

#call(vm) ⇒ Object



5286
5287
5288
# File 'lib/syntax_tree/yarv/instructions.rb', line 5286

def call(vm)
  vm.local_set(index, level, vm.pop)
end

#canonicalObject



5282
5283
5284
# File 'lib/syntax_tree/yarv/instructions.rb', line 5282

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



5261
5262
5263
# File 'lib/syntax_tree/yarv/instructions.rb', line 5261

def deconstruct_keys(_keys)
  { index: index, level: level }
end

#disasm(fmt) ⇒ Object



5251
5252
5253
# File 'lib/syntax_tree/yarv/instructions.rb', line 5251

def disasm(fmt)
  fmt.instruction("setblockparam", [fmt.local(index, explicit: level)])
end

#lengthObject



5270
5271
5272
# File 'lib/syntax_tree/yarv/instructions.rb', line 5270

def length
  3
end

#popsObject



5274
5275
5276
# File 'lib/syntax_tree/yarv/instructions.rb', line 5274

def pops
  1
end

#pushesObject



5278
5279
5280
# File 'lib/syntax_tree/yarv/instructions.rb', line 5278

def pushes
  0
end

#to_a(iseq) ⇒ Object



5255
5256
5257
5258
5259
# File 'lib/syntax_tree/yarv/instructions.rb', line 5255

def to_a(iseq)
  current = iseq
  level.times { current = current.parent_iseq }
  [:setblockparam, current.local_table.offset(index), level]
end