Class: SyntaxTree::YARV::NewArrayKwSplat

Inherits:
Object
  • Object
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

Constructor Details

#initialize(number) ⇒ NewArrayKwSplat

Returns a new instance of NewArrayKwSplat.



2526
2527
2528
# File 'lib/syntax_tree/yarv/instructions.rb', line 2526

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



2524
2525
2526
# File 'lib/syntax_tree/yarv/instructions.rb', line 2524

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



2542
2543
2544
# File 'lib/syntax_tree/yarv/instructions.rb', line 2542

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

#call(vm) ⇒ Object



2562
2563
2564
# File 'lib/syntax_tree/yarv/instructions.rb', line 2562

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

#canonicalObject



2558
2559
2560
# File 'lib/syntax_tree/yarv/instructions.rb', line 2558

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



2538
2539
2540
# File 'lib/syntax_tree/yarv/instructions.rb', line 2538

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



2530
2531
2532
# File 'lib/syntax_tree/yarv/instructions.rb', line 2530

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

#lengthObject



2546
2547
2548
# File 'lib/syntax_tree/yarv/instructions.rb', line 2546

def length
  2
end

#popsObject



2550
2551
2552
# File 'lib/syntax_tree/yarv/instructions.rb', line 2550

def pops
  number
end

#pushesObject



2554
2555
2556
# File 'lib/syntax_tree/yarv/instructions.rb', line 2554

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2534
2535
2536
# File 'lib/syntax_tree/yarv/instructions.rb', line 2534

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