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.



2314
2315
2316
# File 'lib/syntax_tree/yarv/instructions.rb', line 2314

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



2330
2331
2332
# File 'lib/syntax_tree/yarv/instructions.rb', line 2330

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

#call(vm) ⇒ Object



2346
2347
2348
# File 'lib/syntax_tree/yarv/instructions.rb', line 2346

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

#deconstruct_keys(_keys) ⇒ Object



2326
2327
2328
# File 'lib/syntax_tree/yarv/instructions.rb', line 2326

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



2318
2319
2320
# File 'lib/syntax_tree/yarv/instructions.rb', line 2318

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

#lengthObject



2334
2335
2336
# File 'lib/syntax_tree/yarv/instructions.rb', line 2334

def length
  2
end

#popsObject



2338
2339
2340
# File 'lib/syntax_tree/yarv/instructions.rb', line 2338

def pops
  number
end

#pushesObject



2342
2343
2344
# File 'lib/syntax_tree/yarv/instructions.rb', line 2342

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2322
2323
2324
# File 'lib/syntax_tree/yarv/instructions.rb', line 2322

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