Class: SyntaxTree::YARV::NewHash

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

Overview

### Summary

newhash puts a new hash onto the stack, using number elements from the stack. number needs to be even. It pops number elements off the stack and pushes a hash onto the stack.

### Usage

~~~ruby def foo(key, value)

{ key => value }

end ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ NewHash

Returns a new instance of NewHash.



2284
2285
2286
# File 'lib/syntax_tree/yarv/instructions.rb', line 2284

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



2282
2283
2284
# File 'lib/syntax_tree/yarv/instructions.rb', line 2282

def number
  @number
end

Instance Method Details

#call(vm) ⇒ Object



2312
2313
2314
# File 'lib/syntax_tree/yarv/instructions.rb', line 2312

def call(vm)
  vm.push(vm.pop(number).each_slice(2).to_h)
end

#canonicalObject



2308
2309
2310
# File 'lib/syntax_tree/yarv/instructions.rb', line 2308

def canonical
  self
end

#disasm(fmt) ⇒ Object



2288
2289
2290
# File 'lib/syntax_tree/yarv/instructions.rb', line 2288

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

#lengthObject



2296
2297
2298
# File 'lib/syntax_tree/yarv/instructions.rb', line 2296

def length
  2
end

#popsObject



2300
2301
2302
# File 'lib/syntax_tree/yarv/instructions.rb', line 2300

def pops
  number
end

#pushesObject



2304
2305
2306
# File 'lib/syntax_tree/yarv/instructions.rb', line 2304

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2292
2293
2294
# File 'lib/syntax_tree/yarv/instructions.rb', line 2292

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