Class: SyntaxTree::YARV::NewArray

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

Overview

### Summary

‘newarray` puts a new array initialized with `number` values from the stack. It pops `number` values off the stack and pushes the array onto the stack.

### Usage

~~~ruby

“string”

~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(number) ⇒ NewArray

Returns a new instance of NewArray.



2256
2257
2258
# File 'lib/syntax_tree/yarv/instructions.rb', line 2256

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



2272
2273
2274
# File 'lib/syntax_tree/yarv/instructions.rb', line 2272

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

#call(vm) ⇒ Object



2288
2289
2290
# File 'lib/syntax_tree/yarv/instructions.rb', line 2288

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

#deconstruct_keys(_keys) ⇒ Object



2268
2269
2270
# File 'lib/syntax_tree/yarv/instructions.rb', line 2268

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



2260
2261
2262
# File 'lib/syntax_tree/yarv/instructions.rb', line 2260

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

#lengthObject



2276
2277
2278
# File 'lib/syntax_tree/yarv/instructions.rb', line 2276

def length
  2
end

#popsObject



2280
2281
2282
# File 'lib/syntax_tree/yarv/instructions.rb', line 2280

def pops
  number
end

#pushesObject



2284
2285
2286
# File 'lib/syntax_tree/yarv/instructions.rb', line 2284

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2264
2265
2266
# File 'lib/syntax_tree/yarv/instructions.rb', line 2264

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