Class: SyntaxTree::YARV::OptNilP

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

Overview

### Summary

opt_nil_p is an optimization applied when the method nil? is called. It returns true immediately when the receiver is nil and defers to the nil? method in other cases. It pops the receiver off the stack and pushes on the result.

### Usage

~~~ruby “”.nil? ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calldata) ⇒ OptNilP

Returns a new instance of OptNilP.



3642
3643
3644
# File 'lib/syntax_tree/yarv/instructions.rb', line 3642

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3640
3641
3642
# File 'lib/syntax_tree/yarv/instructions.rb', line 3640

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



3670
3671
3672
# File 'lib/syntax_tree/yarv/instructions.rb', line 3670

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

#canonicalObject



3666
3667
3668
# File 'lib/syntax_tree/yarv/instructions.rb', line 3666

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



3646
3647
3648
# File 'lib/syntax_tree/yarv/instructions.rb', line 3646

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

#lengthObject



3654
3655
3656
# File 'lib/syntax_tree/yarv/instructions.rb', line 3654

def length
  2
end

#popsObject



3658
3659
3660
# File 'lib/syntax_tree/yarv/instructions.rb', line 3658

def pops
  1
end

#pushesObject



3662
3663
3664
# File 'lib/syntax_tree/yarv/instructions.rb', line 3662

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3650
3651
3652
# File 'lib/syntax_tree/yarv/instructions.rb', line 3650

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