Class: SyntaxTree::YARV::NewRange

Inherits:
Object
  • Object
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

Constructor Details

#initialize(exclude_end) ⇒ NewRange

Returns a new instance of NewRange.



2335
2336
2337
# File 'lib/syntax_tree/yarv/instructions.rb', line 2335

def initialize(exclude_end)
  @exclude_end = exclude_end
end

Instance Attribute Details

#exclude_endObject (readonly)

Returns the value of attribute exclude_end.



2333
2334
2335
# File 'lib/syntax_tree/yarv/instructions.rb', line 2333

def exclude_end
  @exclude_end
end

Instance Method Details

#call(vm) ⇒ Object



2363
2364
2365
# File 'lib/syntax_tree/yarv/instructions.rb', line 2363

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

#canonicalObject



2359
2360
2361
# File 'lib/syntax_tree/yarv/instructions.rb', line 2359

def canonical
  self
end

#disasm(fmt) ⇒ Object



2339
2340
2341
# File 'lib/syntax_tree/yarv/instructions.rb', line 2339

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

#lengthObject



2347
2348
2349
# File 'lib/syntax_tree/yarv/instructions.rb', line 2347

def length
  2
end

#popsObject



2351
2352
2353
# File 'lib/syntax_tree/yarv/instructions.rb', line 2351

def pops
  2
end

#pushesObject



2355
2356
2357
# File 'lib/syntax_tree/yarv/instructions.rb', line 2355

def pushes
  1
end

#to_a(_iseq) ⇒ Object



2343
2344
2345
# File 'lib/syntax_tree/yarv/instructions.rb', line 2343

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