Class: SyntaxTree::YARV::OptSize

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

Overview

### Summary

‘opt_size` is a specialization of `opt_send_without_block`, when the `size` method is called. There are fast paths when the receiver is either a string, hash, or array. It pops the receiver off the stack and pushes on the result.

### Usage

~~~ruby “”.size ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(calldata) ⇒ OptSize

Returns a new instance of OptSize.



4284
4285
4286
# File 'lib/syntax_tree/yarv/instructions.rb', line 4284

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4282
4283
4284
# File 'lib/syntax_tree/yarv/instructions.rb', line 4282

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



4300
4301
4302
# File 'lib/syntax_tree/yarv/instructions.rb', line 4300

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

#call(vm) ⇒ Object



4320
4321
4322
# File 'lib/syntax_tree/yarv/instructions.rb', line 4320

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

#canonicalObject



4316
4317
4318
# File 'lib/syntax_tree/yarv/instructions.rb', line 4316

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



4296
4297
4298
# File 'lib/syntax_tree/yarv/instructions.rb', line 4296

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



4288
4289
4290
# File 'lib/syntax_tree/yarv/instructions.rb', line 4288

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

#lengthObject



4304
4305
4306
# File 'lib/syntax_tree/yarv/instructions.rb', line 4304

def length
  2
end

#popsObject



4308
4309
4310
# File 'lib/syntax_tree/yarv/instructions.rb', line 4308

def pops
  1
end

#pushesObject



4312
4313
4314
# File 'lib/syntax_tree/yarv/instructions.rb', line 4312

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4292
4293
4294
# File 'lib/syntax_tree/yarv/instructions.rb', line 4292

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