Class: SyntaxTree::YARV::SetConstant
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::SetConstant
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
setconstant pops two values off the stack: the value to set the constant to and the constant base to set it in.
### Usage
~~~ruby Constant = 1 ~~~
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name) ⇒ SetConstant
constructor
A new instance of SetConstant.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name) ⇒ SetConstant
5369 5370 5371 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5369 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5367 5368 5369 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5367 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5385 5386 5387 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5385 def ==(other) other.is_a?(SetConstant) && other.name == name end |
#call(vm) ⇒ Object
5405 5406 5407 5408 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5405 def call(vm) value, parent = vm.pop(2) parent.const_set(name, value) end |
#canonical ⇒ Object
5401 5402 5403 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5401 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
5381 5382 5383 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5381 def deconstruct_keys(_keys) { name: name } end |
#disasm(fmt) ⇒ Object
5373 5374 5375 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5373 def disasm(fmt) fmt.instruction("setconstant", [fmt.object(name)]) end |
#length ⇒ Object
5389 5390 5391 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5389 def length 2 end |
#pops ⇒ Object
5393 5394 5395 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5393 def pops 2 end |
#pushes ⇒ Object
5397 5398 5399 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5397 def pushes 0 end |
#to_a(_iseq) ⇒ Object
5377 5378 5379 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5377 def to_a(_iseq) [:setconstant, name] end |