Class: SyntaxTree::YARV::DupHash

Inherits:
Instruction 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

Methods inherited from Instruction

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

Constructor Details

#initialize(object) ⇒ DupHash

Returns a new instance of DupHash.



1299
1300
1301
# File 'lib/syntax_tree/yarv/instructions.rb', line 1299

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



1297
1298
1299
# File 'lib/syntax_tree/yarv/instructions.rb', line 1297

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



1315
1316
1317
# File 'lib/syntax_tree/yarv/instructions.rb', line 1315

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

#call(vm) ⇒ Object



1327
1328
1329
# File 'lib/syntax_tree/yarv/instructions.rb', line 1327

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

#deconstruct_keys(_keys) ⇒ Object



1311
1312
1313
# File 'lib/syntax_tree/yarv/instructions.rb', line 1311

def deconstruct_keys(_keys)
  { object: object }
end

#disasm(fmt) ⇒ Object



1303
1304
1305
# File 'lib/syntax_tree/yarv/instructions.rb', line 1303

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

#lengthObject



1319
1320
1321
# File 'lib/syntax_tree/yarv/instructions.rb', line 1319

def length
  2
end

#pushesObject



1323
1324
1325
# File 'lib/syntax_tree/yarv/instructions.rb', line 1323

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1307
1308
1309
# File 'lib/syntax_tree/yarv/instructions.rb', line 1307

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