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.



4231
4232
4233
# File 'lib/syntax_tree/yarv/instructions.rb', line 4231

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4229
4230
4231
# File 'lib/syntax_tree/yarv/instructions.rb', line 4229

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



4247
4248
4249
# File 'lib/syntax_tree/yarv/instructions.rb', line 4247

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

#call(vm) ⇒ Object



4267
4268
4269
# File 'lib/syntax_tree/yarv/instructions.rb', line 4267

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

#canonicalObject



4263
4264
4265
# File 'lib/syntax_tree/yarv/instructions.rb', line 4263

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



4243
4244
4245
# File 'lib/syntax_tree/yarv/instructions.rb', line 4243

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



4235
4236
4237
# File 'lib/syntax_tree/yarv/instructions.rb', line 4235

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

#lengthObject



4251
4252
4253
# File 'lib/syntax_tree/yarv/instructions.rb', line 4251

def length
  2
end

#popsObject



4255
4256
4257
# File 'lib/syntax_tree/yarv/instructions.rb', line 4255

def pops
  1
end

#pushesObject



4259
4260
4261
# File 'lib/syntax_tree/yarv/instructions.rb', line 4259

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4239
4240
4241
# File 'lib/syntax_tree/yarv/instructions.rb', line 4239

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