Class: SyntaxTree::YARV::OptEmptyP

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

Overview

### Summary

opt_empty_p is an optimization applied when the method empty? is called. It pops the receiver off the stack and pushes on the result of the method call.

### Usage

~~~ruby “”.empty? ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(calldata) ⇒ OptEmptyP

Returns a new instance of OptEmptyP.



3032
3033
3034
# File 'lib/syntax_tree/yarv/instructions.rb', line 3032

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3030
3031
3032
# File 'lib/syntax_tree/yarv/instructions.rb', line 3030

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3048
3049
3050
# File 'lib/syntax_tree/yarv/instructions.rb', line 3048

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

#call(vm) ⇒ Object



3068
3069
3070
# File 'lib/syntax_tree/yarv/instructions.rb', line 3068

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

#canonicalObject



3064
3065
3066
# File 'lib/syntax_tree/yarv/instructions.rb', line 3064

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3044
3045
3046
# File 'lib/syntax_tree/yarv/instructions.rb', line 3044

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3036
3037
3038
# File 'lib/syntax_tree/yarv/instructions.rb', line 3036

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

#lengthObject



3052
3053
3054
# File 'lib/syntax_tree/yarv/instructions.rb', line 3052

def length
  2
end

#popsObject



3056
3057
3058
# File 'lib/syntax_tree/yarv/instructions.rb', line 3056

def pops
  1
end

#pushesObject



3060
3061
3062
# File 'lib/syntax_tree/yarv/instructions.rb', line 3060

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3040
3041
3042
# File 'lib/syntax_tree/yarv/instructions.rb', line 3040

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