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.



1335
1336
1337
# File 'lib/syntax_tree/yarv/instructions.rb', line 1335

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



1333
1334
1335
# File 'lib/syntax_tree/yarv/instructions.rb', line 1333

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



1351
1352
1353
# File 'lib/syntax_tree/yarv/instructions.rb', line 1351

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

#call(vm) ⇒ Object



1371
1372
1373
# File 'lib/syntax_tree/yarv/instructions.rb', line 1371

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

#canonicalObject



1367
1368
1369
# File 'lib/syntax_tree/yarv/instructions.rb', line 1367

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



1347
1348
1349
# File 'lib/syntax_tree/yarv/instructions.rb', line 1347

def deconstruct_keys(_keys)
  { object: object }
end

#disasm(fmt) ⇒ Object



1339
1340
1341
# File 'lib/syntax_tree/yarv/instructions.rb', line 1339

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

#lengthObject



1355
1356
1357
# File 'lib/syntax_tree/yarv/instructions.rb', line 1355

def length
  2
end

#popsObject



1359
1360
1361
# File 'lib/syntax_tree/yarv/instructions.rb', line 1359

def pops
  0
end

#pushesObject



1363
1364
1365
# File 'lib/syntax_tree/yarv/instructions.rb', line 1363

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1343
1344
1345
# File 'lib/syntax_tree/yarv/instructions.rb', line 1343

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