Class: SyntaxTree::YARV::NewRange
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::NewRange
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
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
-
#exclude_end ⇒ Object
readonly
Returns the value of attribute exclude_end.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(exclude_end) ⇒ NewRange
constructor
A new instance of NewRange.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(exclude_end) ⇒ NewRange
Returns a new instance of NewRange.
2643 2644 2645 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2643 def initialize(exclude_end) @exclude_end = exclude_end end |
Instance Attribute Details
#exclude_end ⇒ Object (readonly)
Returns the value of attribute exclude_end.
2641 2642 2643 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2641 def exclude_end @exclude_end end |
Instance Method Details
#==(other) ⇒ Object
2659 2660 2661 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2659 def ==(other) other.is_a?(NewRange) && other.exclude_end == exclude_end end |
#call(vm) ⇒ Object
2679 2680 2681 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2679 def call(vm) vm.push(Range.new(*vm.pop(2), exclude_end == 1)) end |
#canonical ⇒ Object
2675 2676 2677 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2675 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
2655 2656 2657 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2655 def deconstruct_keys(_keys) { exclude_end: exclude_end } end |
#disasm(fmt) ⇒ Object
2647 2648 2649 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2647 def disasm(fmt) fmt.instruction("newrange", [fmt.object(exclude_end)]) end |
#length ⇒ Object
2663 2664 2665 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2663 def length 2 end |
#pops ⇒ Object
2667 2668 2669 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2667 def pops 2 end |
#pushes ⇒ Object
2671 2672 2673 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2671 def pushes 1 end |
#to_a(_iseq) ⇒ Object
2651 2652 2653 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 2651 def to_a(_iseq) [:newrange, exclude_end] end |