Class: SyntaxTree::YARV::OptEmptyP

Inherits:
Object
  • Object
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

Constructor Details

#initialize(calldata) ⇒ OptEmptyP



2894
2895
2896
# File 'lib/syntax_tree/yarv/instructions.rb', line 2894

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



2892
2893
2894
# File 'lib/syntax_tree/yarv/instructions.rb', line 2892

def calldata
  @calldata
end

Instance Method Details

#call(vm) ⇒ Object



2922
2923
2924
# File 'lib/syntax_tree/yarv/instructions.rb', line 2922

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

#canonicalObject



2918
2919
2920
# File 'lib/syntax_tree/yarv/instructions.rb', line 2918

def canonical
  Send.new(calldata, nil)
end

#disasm(fmt) ⇒ Object



2898
2899
2900
# File 'lib/syntax_tree/yarv/instructions.rb', line 2898

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

#lengthObject



2906
2907
2908
# File 'lib/syntax_tree/yarv/instructions.rb', line 2906

def length
  2
end

#popsObject



2910
2911
2912
# File 'lib/syntax_tree/yarv/instructions.rb', line 2910

def pops
  1
end

#pushesObject



2914
2915
2916
# File 'lib/syntax_tree/yarv/instructions.rb', line 2914

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2902
2903
2904
# File 'lib/syntax_tree/yarv/instructions.rb', line 2902

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