Class: SyntaxTree::YARV::CheckKeyword

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

Overview

### Summary

checkkeyword checks if a keyword was passed at the callsite that called into the method represented by the instruction sequence. It has two arguments: the index of the local variable that stores the keywords metadata and the index of the keyword within that metadata. It pushes a boolean onto the stack indicating whether or not the keyword was given.

### Usage

~~~ruby def evaluate(value: rand)

value

end

evaluate(value: 3) ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword_bits_index, keyword_index) ⇒ CheckKeyword



348
349
350
351
# File 'lib/syntax_tree/yarv/instructions.rb', line 348

def initialize(keyword_bits_index, keyword_index)
  @keyword_bits_index = keyword_bits_index
  @keyword_index = keyword_index
end

Instance Attribute Details

#keyword_bits_indexObject (readonly)

Returns the value of attribute keyword_bits_index.



346
347
348
# File 'lib/syntax_tree/yarv/instructions.rb', line 346

def keyword_bits_index
  @keyword_bits_index
end

#keyword_indexObject (readonly)

Returns the value of attribute keyword_index.



346
347
348
# File 'lib/syntax_tree/yarv/instructions.rb', line 346

def keyword_index
  @keyword_index
end

Instance Method Details

#call(vm) ⇒ Object



384
385
386
# File 'lib/syntax_tree/yarv/instructions.rb', line 384

def call(vm)
  vm.push(vm.local_get(keyword_bits_index, 0)[keyword_index])
end

#canonicalObject



380
381
382
# File 'lib/syntax_tree/yarv/instructions.rb', line 380

def canonical
  self
end

#disasm(fmt) ⇒ Object



353
354
355
356
357
358
# File 'lib/syntax_tree/yarv/instructions.rb', line 353

def disasm(fmt)
  fmt.instruction(
    "checkkeyword",
    [fmt.object(keyword_bits_index), fmt.object(keyword_index)]
  )
end

#lengthObject



368
369
370
# File 'lib/syntax_tree/yarv/instructions.rb', line 368

def length
  3
end

#popsObject



372
373
374
# File 'lib/syntax_tree/yarv/instructions.rb', line 372

def pops
  0
end

#pushesObject



376
377
378
# File 'lib/syntax_tree/yarv/instructions.rb', line 376

def pushes
  1
end

#to_a(iseq) ⇒ Object



360
361
362
363
364
365
366
# File 'lib/syntax_tree/yarv/instructions.rb', line 360

def to_a(iseq)
  [
    :checkkeyword,
    iseq.local_table.offset(keyword_bits_index),
    keyword_index
  ]
end