Class: SyntaxTree::YARV::OptStrUMinus

Inherits:
Instruction 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

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?

Constructor Details

#initialize(object, calldata) ⇒ OptStrUMinus

Returns a new instance of OptStrUMinus.



4393
4394
4395
4396
# File 'lib/syntax_tree/yarv/instructions.rb', line 4393

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

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4391
4392
4393
# File 'lib/syntax_tree/yarv/instructions.rb', line 4391

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



4391
4392
4393
# File 'lib/syntax_tree/yarv/instructions.rb', line 4391

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



4413
4414
4415
4416
# File 'lib/syntax_tree/yarv/instructions.rb', line 4413

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

#call(vm) ⇒ Object



4426
4427
4428
# File 'lib/syntax_tree/yarv/instructions.rb', line 4426

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

#deconstruct_keys(_keys) ⇒ Object



4409
4410
4411
# File 'lib/syntax_tree/yarv/instructions.rb', line 4409

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

#disasm(fmt) ⇒ Object



4398
4399
4400
4401
4402
4403
# File 'lib/syntax_tree/yarv/instructions.rb', line 4398

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

#lengthObject



4418
4419
4420
# File 'lib/syntax_tree/yarv/instructions.rb', line 4418

def length
  3
end

#pushesObject



4422
4423
4424
# File 'lib/syntax_tree/yarv/instructions.rb', line 4422

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4405
4406
4407
# File 'lib/syntax_tree/yarv/instructions.rb', line 4405

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