Class: SyntaxTree::YARV::CheckKeyword
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
def evaluate(value: rand)
value
end
evaluate(value: 3)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?
Constructor Details
#initialize(keyword_bits_index, keyword_index) ⇒ CheckKeyword
Returns a new instance of CheckKeyword.
362
363
364
365
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 362
def initialize(keyword_bits_index, keyword_index)
@keyword_bits_index = keyword_bits_index
@keyword_index = keyword_index
end
|
Instance Attribute Details
#keyword_bits_index ⇒ Object
Returns the value of attribute keyword_bits_index.
360
361
362
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 360
def keyword_bits_index
@keyword_bits_index
end
|
#keyword_index ⇒ Object
Returns the value of attribute keyword_index.
360
361
362
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 360
def keyword_index
@keyword_index
end
|
Instance Method Details
#==(other) ⇒ Object
386
387
388
389
390
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 386
def ==(other)
other.is_a?(CheckKeyword) &&
other.keyword_bits_index == keyword_bits_index &&
other.keyword_index == keyword_index
end
|
#call(vm) ⇒ Object
400
401
402
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 400
def call(vm)
vm.push(vm.local_get(keyword_bits_index, 0)[keyword_index])
end
|
#deconstruct_keys(_keys) ⇒ Object
382
383
384
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 382
def deconstruct_keys(_keys)
{ keyword_bits_index: keyword_bits_index, keyword_index: keyword_index }
end
|
#disasm(fmt) ⇒ Object
367
368
369
370
371
372
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 367
def disasm(fmt)
fmt.instruction(
"checkkeyword",
[fmt.object(keyword_bits_index), fmt.object(keyword_index)]
)
end
|
#length ⇒ Object
392
393
394
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 392
def length
3
end
|
#pushes ⇒ Object
396
397
398
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 396
def pushes
1
end
|
#to_a(iseq) ⇒ Object
374
375
376
377
378
379
380
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 374
def to_a(iseq)
[
:checkkeyword,
iseq.local_table.offset(keyword_bits_index),
keyword_index
]
end
|