Class: SyntaxTree::YARV::NewRange
Overview
### Summary
newrange creates a new range object from the top two values on the stack. It pops both of them off, and then pushes on the new range. It takes one argument which is 0 if the end is included or 1 if the end value is excluded.
### Usage
~~~ruby x = 0 y = 1 p (x..y), (x…y) ~~~
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(exclude_end) ⇒ NewRange
Returns a new instance of NewRange.
2417
2418
2419
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2417
def initialize(exclude_end)
@exclude_end = exclude_end
end
|
Instance Attribute Details
#exclude_end ⇒ Object
Returns the value of attribute exclude_end.
2415
2416
2417
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2415
def exclude_end
@exclude_end
end
|
Instance Method Details
#==(other) ⇒ Object
2433
2434
2435
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2433
def ==(other)
other.is_a?(NewRange) && other.exclude_end == exclude_end
end
|
#call(vm) ⇒ Object
2449
2450
2451
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2449
def call(vm)
vm.push(Range.new(*vm.pop(2), exclude_end == 1))
end
|
#deconstruct_keys(_keys) ⇒ Object
2429
2430
2431
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2429
def deconstruct_keys(_keys)
{ exclude_end: exclude_end }
end
|
#disasm(fmt) ⇒ Object
2421
2422
2423
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2421
def disasm(fmt)
fmt.instruction("newrange", [fmt.object(exclude_end)])
end
|
#length ⇒ Object
2437
2438
2439
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2437
def length
2
end
|
#pops ⇒ Object
2441
2442
2443
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2441
def pops
2
end
|
#pushes ⇒ Object
2445
2446
2447
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2445
def pushes
1
end
|
#to_a(_iseq) ⇒ Object
2425
2426
2427
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 2425
def to_a(_iseq)
[:newrange, exclude_end]
end
|