Class: SyntaxTree::YARV::NewArray

Inherits:
Object
  • Object
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

Constructor Details

#initialize(number) ⇒ NewArray



2186
2187
2188
# File 'lib/syntax_tree/yarv/instructions.rb', line 2186

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



2184
2185
2186
# File 'lib/syntax_tree/yarv/instructions.rb', line 2184

def number
  @number
end

Instance Method Details

#call(vm) ⇒ Object



2214
2215
2216
# File 'lib/syntax_tree/yarv/instructions.rb', line 2214

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

#canonicalObject



2210
2211
2212
# File 'lib/syntax_tree/yarv/instructions.rb', line 2210

def canonical
  self
end

#disasm(fmt) ⇒ Object



2190
2191
2192
# File 'lib/syntax_tree/yarv/instructions.rb', line 2190

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

#lengthObject



2198
2199
2200
# File 'lib/syntax_tree/yarv/instructions.rb', line 2198

def length
  2
end

#popsObject



2202
2203
2204
# File 'lib/syntax_tree/yarv/instructions.rb', line 2202

def pops
  number
end

#pushesObject



2206
2207
2208
# File 'lib/syntax_tree/yarv/instructions.rb', line 2206

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2194
2195
2196
# File 'lib/syntax_tree/yarv/instructions.rb', line 2194

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