Class: SyntaxTree::YARV::OptDiv

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

Overview

### Summary

opt_div is a specialization of the opt_send_without_block instruction that occurs when the / operator is used. There are fast paths for if both operands are integers, or if both operands are floats. It pops both the receiver and the argument off the stack and pushes on the result.

### Usage

~~~ruby 2 / 3 ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calldata) ⇒ OptDiv



3238
3239
3240
# File 'lib/syntax_tree/yarv/instructions.rb', line 3238

def initialize(calldata)
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3236
3237
3238
# File 'lib/syntax_tree/yarv/instructions.rb', line 3236

def calldata
  @calldata
end

Instance Method Details

#==(other) ⇒ Object



3254
3255
3256
# File 'lib/syntax_tree/yarv/instructions.rb', line 3254

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

#call(vm) ⇒ Object



3274
3275
3276
# File 'lib/syntax_tree/yarv/instructions.rb', line 3274

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

#canonicalObject



3270
3271
3272
# File 'lib/syntax_tree/yarv/instructions.rb', line 3270

def canonical
  Send.new(calldata, nil)
end

#deconstruct_keys(_keys) ⇒ Object



3250
3251
3252
# File 'lib/syntax_tree/yarv/instructions.rb', line 3250

def deconstruct_keys(_keys)
  { calldata: calldata }
end

#disasm(fmt) ⇒ Object



3242
3243
3244
# File 'lib/syntax_tree/yarv/instructions.rb', line 3242

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

#lengthObject



3258
3259
3260
# File 'lib/syntax_tree/yarv/instructions.rb', line 3258

def length
  2
end

#popsObject



3262
3263
3264
# File 'lib/syntax_tree/yarv/instructions.rb', line 3262

def pops
  2
end

#pushesObject



3266
3267
3268
# File 'lib/syntax_tree/yarv/instructions.rb', line 3266

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3246
3247
3248
# File 'lib/syntax_tree/yarv/instructions.rb', line 3246

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