Class: SyntaxTree::YARV::SetConstant
- Inherits:
-
Instruction
- Object
- Instruction
- 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
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name) ⇒ SetConstant
constructor
A new instance of SetConstant.
- #length ⇒ Object
- #pops ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(name) ⇒ SetConstant
Returns a new instance of SetConstant.
5162 5163 5164 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5162 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5160 5161 5162 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5160 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5178 5179 5180 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5178 def ==(other) other.is_a?(SetConstant) && other.name == name end |
#call(vm) ⇒ Object
5190 5191 5192 5193 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5190 def call(vm) value, parent = vm.pop(2) parent.const_set(name, value) end |
#deconstruct_keys(_keys) ⇒ Object
5174 5175 5176 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5174 def deconstruct_keys(_keys) { name: name } end |
#disasm(fmt) ⇒ Object
5166 5167 5168 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5166 def disasm(fmt) fmt.instruction("setconstant", [fmt.object(name)]) end |
#length ⇒ Object
5182 5183 5184 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5182 def length 2 end |
#pops ⇒ Object
5186 5187 5188 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5186 def pops 2 end |
#to_a(_iseq) ⇒ Object
5170 5171 5172 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5170 def to_a(_iseq) [:setconstant, name] end |