Class: SyntaxTree::YARV::DupArray

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

Overview

### Summary

duparray dups an Array literal and pushes it onto the stack.

### Usage

~~~ruby

true

~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(object) ⇒ DupArray

Returns a new instance of DupArray.



1195
1196
1197
# File 'lib/syntax_tree/yarv/instructions.rb', line 1195

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



1193
1194
1195
# File 'lib/syntax_tree/yarv/instructions.rb', line 1193

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



1211
1212
1213
# File 'lib/syntax_tree/yarv/instructions.rb', line 1211

def ==(other)
  other.is_a?(DupArray) && other.object == object
end

#call(vm) ⇒ Object



1223
1224
1225
# File 'lib/syntax_tree/yarv/instructions.rb', line 1223

def call(vm)
  vm.push(object.dup)
end

#deconstruct_keys(_keys) ⇒ Object



1207
1208
1209
# File 'lib/syntax_tree/yarv/instructions.rb', line 1207

def deconstruct_keys(_keys)
  { object: object }
end

#disasm(fmt) ⇒ Object



1199
1200
1201
# File 'lib/syntax_tree/yarv/instructions.rb', line 1199

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

#lengthObject



1215
1216
1217
# File 'lib/syntax_tree/yarv/instructions.rb', line 1215

def length
  2
end

#pushesObject



1219
1220
1221
# File 'lib/syntax_tree/yarv/instructions.rb', line 1219

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1203
1204
1205
# File 'lib/syntax_tree/yarv/instructions.rb', line 1203

def to_a(_iseq)
  [:duparray, object]
end