Class: SyntaxTree::YARV::SetConstant

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (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

#canonicalObject



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

#lengthObject



4687
4688
4689
# File 'lib/syntax_tree/yarv/instructions.rb', line 4687

def length
  2
end

#popsObject



4691
4692
4693
# File 'lib/syntax_tree/yarv/instructions.rb', line 4691

def pops
  2
end

#pushesObject



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