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



3294
3295
3296
# File 'lib/syntax_tree/yarv/instructions.rb', line 3294

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3292
3293
3294
# File 'lib/syntax_tree/yarv/instructions.rb', line 3292

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3310
3311
3312
# File 'lib/syntax_tree/yarv/instructions.rb', line 3310

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

#call(vm) ⇒ Object



3330
3331
3332
# File 'lib/syntax_tree/yarv/instructions.rb', line 3330

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

#canonicalObject



3326
3327
3328
# File 'lib/syntax_tree/yarv/instructions.rb', line 3326

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3306
3307
3308
# File 'lib/syntax_tree/yarv/instructions.rb', line 3306

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3298
3299
3300
# File 'lib/syntax_tree/yarv/instructions.rb', line 3298

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

#lengthObject



3314
3315
3316
# File 'lib/syntax_tree/yarv/instructions.rb', line 3314

def length
  2
end

#popsObject



3318
3319
3320
# File 'lib/syntax_tree/yarv/instructions.rb', line 3318

def pops
  1
end

#pushesObject



3322
3323
3324
# File 'lib/syntax_tree/yarv/instructions.rb', line 3322

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3302
3303
3304
# File 'lib/syntax_tree/yarv/instructions.rb', line 3302

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