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.
5061 5062 5063 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5061 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5059 5060 5061 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5059 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5077 5078 5079 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5077 def ==(other) other.is_a?(SetConstant) && other.name == name end |
#call(vm) ⇒ Object
5089 5090 5091 5092 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5089 def call(vm) value, parent = vm.pop(2) parent.const_set(name, value) end |
#deconstruct_keys(_keys) ⇒ Object
5073 5074 5075 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5073 def deconstruct_keys(_keys) { name: name } end |
#disasm(fmt) ⇒ Object
5065 5066 5067 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5065 def disasm(fmt) fmt.instruction("setconstant", [fmt.object(name)]) end |
#length ⇒ Object
5081 5082 5083 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5081 def length 2 end |
#pops ⇒ Object
5085 5086 5087 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5085 def pops 2 end |
#to_a(_iseq) ⇒ Object
5069 5070 5071 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5069 def to_a(_iseq) [:setconstant, name] end |