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.



2366
2367
2368
# File 'lib/syntax_tree/yarv/instructions.rb', line 2366

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



2364
2365
2366
# File 'lib/syntax_tree/yarv/instructions.rb', line 2364

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



2382
2383
2384
# File 'lib/syntax_tree/yarv/instructions.rb', line 2382

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

#call(vm) ⇒ Object



2398
2399
2400
# File 'lib/syntax_tree/yarv/instructions.rb', line 2398

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

#deconstruct_keys(_keys) ⇒ Object



2378
2379
2380
# File 'lib/syntax_tree/yarv/instructions.rb', line 2378

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



2370
2371
2372
# File 'lib/syntax_tree/yarv/instructions.rb', line 2370

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

#lengthObject



2386
2387
2388
# File 'lib/syntax_tree/yarv/instructions.rb', line 2386

def length
  2
end

#popsObject



2390
2391
2392
# File 'lib/syntax_tree/yarv/instructions.rb', line 2390

def pops
  number
end

#pushesObject



2394
2395
2396
# File 'lib/syntax_tree/yarv/instructions.rb', line 2394

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2374
2375
2376
# File 'lib/syntax_tree/yarv/instructions.rb', line 2374

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