Class: SyntaxTree::YARV::CheckKeyword
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::CheckKeyword
- 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
-
#keyword_bits_index ⇒ Object
readonly
Returns the value of attribute keyword_bits_index.
-
#keyword_index ⇒ Object
readonly
Returns the value of attribute keyword_index.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(keyword_bits_index, keyword_index) ⇒ CheckKeyword
constructor
A new instance of CheckKeyword.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(iseq) ⇒ Object
Constructor Details
#initialize(keyword_bits_index, keyword_index) ⇒ CheckKeyword
388 389 390 391 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 388 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 (readonly)
Returns the value of attribute keyword_bits_index.
386 387 388 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 386 def keyword_bits_index @keyword_bits_index end |
#keyword_index ⇒ Object (readonly)
Returns the value of attribute keyword_index.
386 387 388 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 386 def keyword_index @keyword_index end |
Instance Method Details
#==(other) ⇒ Object
412 413 414 415 416 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 412 def ==(other) other.is_a?(CheckKeyword) && other.keyword_bits_index == keyword_bits_index && other.keyword_index == keyword_index end |
#call(vm) ⇒ Object
434 435 436 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 434 def call(vm) vm.push(vm.local_get(keyword_bits_index, 0)[keyword_index]) end |
#canonical ⇒ Object
430 431 432 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 430 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
408 409 410 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 408 def deconstruct_keys(_keys) { keyword_bits_index: keyword_bits_index, keyword_index: keyword_index } end |
#disasm(fmt) ⇒ Object
393 394 395 396 397 398 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 393 def disasm(fmt) fmt.instruction( "checkkeyword", [fmt.object(keyword_bits_index), fmt.object(keyword_index)] ) end |
#length ⇒ Object
418 419 420 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 418 def length 3 end |
#pops ⇒ Object
422 423 424 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 422 def pops 0 end |
#pushes ⇒ Object
426 427 428 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 426 def pushes 1 end |
#to_a(iseq) ⇒ Object
400 401 402 403 404 405 406 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 400 def to_a(iseq) [ :checkkeyword, iseq.local_table.offset(keyword_bits_index), keyword_index ] end |