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.
5015 5016 5017 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5015 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5013 5014 5015 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5013 def name @name end |
Instance Method Details
#==(other) ⇒ Object
5031 5032 5033 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5031 def ==(other) other.is_a?(SetConstant) && other.name == name end |
#call(vm) ⇒ Object
5043 5044 5045 5046 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5043 def call(vm) value, parent = vm.pop(2) parent.const_set(name, value) end |
#deconstruct_keys(_keys) ⇒ Object
5027 5028 5029 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5027 def deconstruct_keys(_keys) { name: name } end |
#disasm(fmt) ⇒ Object
5019 5020 5021 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5019 def disasm(fmt) fmt.instruction("setconstant", [fmt.object(name)]) end |
#length ⇒ Object
5035 5036 5037 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5035 def length 2 end |
#pops ⇒ Object
5039 5040 5041 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5039 def pops 2 end |
#to_a(_iseq) ⇒ Object
5023 5024 5025 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 5023 def to_a(_iseq) [:setconstant, name] end |