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.



2234
2235
2236
# File 'lib/syntax_tree/yarv/instructions.rb', line 2234

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



2232
2233
2234
# File 'lib/syntax_tree/yarv/instructions.rb', line 2232

def number
  @number
end

Instance Method Details

#call(vm) ⇒ Object



2262
2263
2264
# File 'lib/syntax_tree/yarv/instructions.rb', line 2262

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

#canonicalObject



2258
2259
2260
# File 'lib/syntax_tree/yarv/instructions.rb', line 2258

def canonical
  self
end

#disasm(fmt) ⇒ Object



2238
2239
2240
# File 'lib/syntax_tree/yarv/instructions.rb', line 2238

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

#lengthObject



2246
2247
2248
# File 'lib/syntax_tree/yarv/instructions.rb', line 2246

def length
  2
end

#popsObject



2250
2251
2252
# File 'lib/syntax_tree/yarv/instructions.rb', line 2250

def pops
  number
end

#pushesObject



2254
2255
2256
# File 'lib/syntax_tree/yarv/instructions.rb', line 2254

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2242
2243
2244
# File 'lib/syntax_tree/yarv/instructions.rb', line 2242

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