Class: SyntaxTree::YARV::NewRange

Inherits:
Instruction show all
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

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.



2475
2476
2477
# File 'lib/syntax_tree/yarv/instructions.rb', line 2475

def initialize(exclude_end)
  @exclude_end = exclude_end
end

Instance Attribute Details

#exclude_endObject (readonly)

Returns the value of attribute exclude_end.



2473
2474
2475
# File 'lib/syntax_tree/yarv/instructions.rb', line 2473

def exclude_end
  @exclude_end
end

Instance Method Details

#==(other) ⇒ Object



2491
2492
2493
# File 'lib/syntax_tree/yarv/instructions.rb', line 2491

def ==(other)
  other.is_a?(NewRange) && other.exclude_end == exclude_end
end

#call(vm) ⇒ Object



2507
2508
2509
# File 'lib/syntax_tree/yarv/instructions.rb', line 2507

def call(vm)
  vm.push(Range.new(*vm.pop(2), exclude_end == 1))
end

#deconstruct_keys(_keys) ⇒ Object



2487
2488
2489
# File 'lib/syntax_tree/yarv/instructions.rb', line 2487

def deconstruct_keys(_keys)
  { exclude_end: exclude_end }
end

#disasm(fmt) ⇒ Object



2479
2480
2481
# File 'lib/syntax_tree/yarv/instructions.rb', line 2479

def disasm(fmt)
  fmt.instruction("newrange", [fmt.object(exclude_end)])
end

#lengthObject



2495
2496
2497
# File 'lib/syntax_tree/yarv/instructions.rb', line 2495

def length
  2
end

#popsObject



2499
2500
2501
# File 'lib/syntax_tree/yarv/instructions.rb', line 2499

def pops
  2
end

#pushesObject



2503
2504
2505
# File 'lib/syntax_tree/yarv/instructions.rb', line 2503

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2483
2484
2485
# File 'lib/syntax_tree/yarv/instructions.rb', line 2483

def to_a(_iseq)
  [:newrange, exclude_end]
end