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.



3090
3091
3092
# File 'lib/syntax_tree/yarv/instructions.rb', line 3090

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3088
3089
3090
# File 'lib/syntax_tree/yarv/instructions.rb', line 3088

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3106
3107
3108
# File 'lib/syntax_tree/yarv/instructions.rb', line 3106

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

#call(vm) ⇒ Object



3126
3127
3128
# File 'lib/syntax_tree/yarv/instructions.rb', line 3126

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

#canonicalObject



3122
3123
3124
# File 'lib/syntax_tree/yarv/instructions.rb', line 3122

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3102
3103
3104
# File 'lib/syntax_tree/yarv/instructions.rb', line 3102

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3094
3095
3096
# File 'lib/syntax_tree/yarv/instructions.rb', line 3094

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

#lengthObject



3110
3111
3112
# File 'lib/syntax_tree/yarv/instructions.rb', line 3110

def length
  2
end

#popsObject



3114
3115
3116
# File 'lib/syntax_tree/yarv/instructions.rb', line 3114

def pops
  1
end

#pushesObject



3118
3119
3120
# File 'lib/syntax_tree/yarv/instructions.rb', line 3118

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3098
3099
3100
# File 'lib/syntax_tree/yarv/instructions.rb', line 3098

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