Class: SyntaxTree::YARV::OptSucc

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

Overview

### Summary

‘opt_succ` is a specialization of the `opt_send_without_block` instruction when the method being called is `succ`. Fast paths exist when the receiver is either a String or a Fixnum. It pops the receiver off the stack and pushes on the result.

### Usage

~~~ruby “”.succ ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

#branch_targets, #falls_through?, #leaves?, #side_effects?

Constructor Details

#initialize(calldata) ⇒ OptSucc

Returns a new instance of OptSucc.



4382
4383
4384
# File 'lib/syntax_tree/yarv/instructions.rb', line 4382

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4380
4381
4382
# File 'lib/syntax_tree/yarv/instructions.rb', line 4380

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  other.is_a?(OptSucc) && other.calldata == calldata
end

#call(vm) ⇒ Object



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

def call(vm)
  canonical.call(vm)
end

#canonicalObject



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

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



4386
4387
4388
# File 'lib/syntax_tree/yarv/instructions.rb', line 4386

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

#lengthObject



4402
4403
4404
# File 'lib/syntax_tree/yarv/instructions.rb', line 4402

def length
  2
end

#popsObject



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

def pops
  1
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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