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.



2308
2309
2310
# File 'lib/syntax_tree/yarv/instructions.rb', line 2308

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



2306
2307
2308
# File 'lib/syntax_tree/yarv/instructions.rb', line 2306

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



2324
2325
2326
# File 'lib/syntax_tree/yarv/instructions.rb', line 2324

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

#call(vm) ⇒ Object



2340
2341
2342
# File 'lib/syntax_tree/yarv/instructions.rb', line 2340

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

#deconstruct_keys(_keys) ⇒ Object



2320
2321
2322
# File 'lib/syntax_tree/yarv/instructions.rb', line 2320

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



2312
2313
2314
# File 'lib/syntax_tree/yarv/instructions.rb', line 2312

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

#lengthObject



2328
2329
2330
# File 'lib/syntax_tree/yarv/instructions.rb', line 2328

def length
  2
end

#popsObject



2332
2333
2334
# File 'lib/syntax_tree/yarv/instructions.rb', line 2332

def pops
  number
end

#pushesObject



2336
2337
2338
# File 'lib/syntax_tree/yarv/instructions.rb', line 2336

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2316
2317
2318
# File 'lib/syntax_tree/yarv/instructions.rb', line 2316

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