Class: SyntaxTree::YARV::DupHash

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

Overview

### Summary

duphash dups a Hash literal and pushes it onto the stack.

### Usage

~~~ruby { a: 1 } ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ DupHash

Returns a new instance of DupHash.



1201
1202
1203
# File 'lib/syntax_tree/yarv/instructions.rb', line 1201

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

Instance Method Details

#call(vm) ⇒ Object



1229
1230
1231
# File 'lib/syntax_tree/yarv/instructions.rb', line 1229

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

#canonicalObject



1225
1226
1227
# File 'lib/syntax_tree/yarv/instructions.rb', line 1225

def canonical
  self
end

#disasm(fmt) ⇒ Object



1205
1206
1207
# File 'lib/syntax_tree/yarv/instructions.rb', line 1205

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

#lengthObject



1213
1214
1215
# File 'lib/syntax_tree/yarv/instructions.rb', line 1213

def length
  2
end

#popsObject



1217
1218
1219
# File 'lib/syntax_tree/yarv/instructions.rb', line 1217

def pops
  0
end

#pushesObject



1221
1222
1223
# File 'lib/syntax_tree/yarv/instructions.rb', line 1221

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1209
1210
1211
# File 'lib/syntax_tree/yarv/instructions.rb', line 1209

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