Class: SyntaxTree::YARV::OptStrUMinus

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

opt_str_uminus pushes a frozen known string value with no interpolation onto the stack. If the method gets overridden, this will fall back to a send.

### Usage

~~~ruby -“string” ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, calldata) ⇒ OptStrUMinus



4618
4619
4620
4621
# File 'lib/syntax_tree/yarv/instructions.rb', line 4618

def initialize(object, calldata)
  @object = object
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4616
4617
4618
# File 'lib/syntax_tree/yarv/instructions.rb', line 4616

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



4616
4617
4618
# File 'lib/syntax_tree/yarv/instructions.rb', line 4616

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



4638
4639
4640
4641
# File 'lib/syntax_tree/yarv/instructions.rb', line 4638

def ==(other)
  other.is_a?(OptStrUMinus) && other.object == object &&
    other.calldata == calldata
end

#call(vm) ⇒ Object



4659
4660
4661
# File 'lib/syntax_tree/yarv/instructions.rb', line 4659

def call(vm)
  vm.push(-object)
end

#canonicalObject



4655
4656
4657
# File 'lib/syntax_tree/yarv/instructions.rb', line 4655

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



4634
4635
4636
# File 'lib/syntax_tree/yarv/instructions.rb', line 4634

def deconstruct_keys(_keys)
  { object: object, calldata: calldata }
end

#disasm(fmt) ⇒ Object



4623
4624
4625
4626
4627
4628
# File 'lib/syntax_tree/yarv/instructions.rb', line 4623

def disasm(fmt)
  fmt.instruction(
    "opt_str_uminus",
    [fmt.object(object), fmt.calldata(calldata)]
  )
end

#lengthObject



4643
4644
4645
# File 'lib/syntax_tree/yarv/instructions.rb', line 4643

def length
  3
end

#popsObject



4647
4648
4649
# File 'lib/syntax_tree/yarv/instructions.rb', line 4647

def pops
  0
end

#pushesObject



4651
4652
4653
# File 'lib/syntax_tree/yarv/instructions.rb', line 4651

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4630
4631
4632
# File 'lib/syntax_tree/yarv/instructions.rb', line 4630

def to_a(_iseq)
  [:opt_str_uminus, object, calldata.to_h]
end