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.



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

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



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

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

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  { number: number }
end

#disasm(fmt) ⇒ Object



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

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

#lengthObject



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

def length
  2
end

#popsObject



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

def pops
  number
end

#pushesObject



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

def pushes
  1
end

#to_a(_iseq) ⇒ Object



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

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