Class: SyntaxTree::YARV::NewArrayKwSplat

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

Overview

### Summary

‘newarraykwsplat` is a specialized version of `newarray` that takes a ** splat argument. It pops `number` values off the stack and pushes the array onto the stack.

### Usage

~~~ruby

“string”, **{ foo: “bar” }

~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(number) ⇒ NewArrayKwSplat

Returns a new instance of NewArrayKwSplat.



2419
2420
2421
# File 'lib/syntax_tree/yarv/instructions.rb', line 2419

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



2417
2418
2419
# File 'lib/syntax_tree/yarv/instructions.rb', line 2417

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



2435
2436
2437
# File 'lib/syntax_tree/yarv/instructions.rb', line 2435

def ==(other)
  other.is_a?(NewArrayKwSplat) && other.number == number
end

#call(vm) ⇒ Object



2451
2452
2453
# File 'lib/syntax_tree/yarv/instructions.rb', line 2451

def call(vm)
  vm.push(vm.pop(number))
end

#deconstruct_keys(_keys) ⇒ Object



2431
2432
2433
# File 'lib/syntax_tree/yarv/instructions.rb', line 2431

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



2423
2424
2425
# File 'lib/syntax_tree/yarv/instructions.rb', line 2423

def disasm(fmt)
  fmt.instruction("newarraykwsplat", [fmt.object(number)])
end

#lengthObject



2439
2440
2441
# File 'lib/syntax_tree/yarv/instructions.rb', line 2439

def length
  2
end

#popsObject



2443
2444
2445
# File 'lib/syntax_tree/yarv/instructions.rb', line 2443

def pops
  number
end

#pushesObject



2447
2448
2449
# File 'lib/syntax_tree/yarv/instructions.rb', line 2447

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2427
2428
2429
# File 'lib/syntax_tree/yarv/instructions.rb', line 2427

def to_a(_iseq)
  [:newarraykwsplat, number]
end