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
- #call(vm) ⇒ Object
- #canonical ⇒ 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
4675 4676 4677 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4675 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4673 4674 4675 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4673 def name @name end |
Instance Method Details
#call(vm) ⇒ Object
4703 4704 4705 4706 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4703 def call(vm) value, parent = vm.pop(2) parent.const_set(name, value) end |
#canonical ⇒ Object
4699 4700 4701 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4699 def canonical self end |
#disasm(fmt) ⇒ Object
4679 4680 4681 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4679 def disasm(fmt) fmt.instruction("setconstant", [fmt.object(name)]) end |
#length ⇒ Object
4687 4688 4689 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4687 def length 2 end |
#pops ⇒ Object
4691 4692 4693 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4691 def pops 2 end |
#pushes ⇒ Object
4695 4696 4697 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4695 def pushes 0 end |
#to_a(_iseq) ⇒ Object
4683 4684 4685 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 4683 def to_a(_iseq) [:setconstant, name] end |