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.



4277
4278
4279
# File 'lib/syntax_tree/yarv/instructions.rb', line 4277

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4275
4276
4277
# File 'lib/syntax_tree/yarv/instructions.rb', line 4275

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



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

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

#canonicalObject



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

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



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

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

#lengthObject



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

def length
  2
end

#popsObject



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

def pops
  1
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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