Class: SyntaxTree::YARV::Instruction

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

This is a base class for all YARV instructions. It provides a few convenience methods for working with instructions.

Instance Method Summary collapse

Instance Method Details

#branch_targetsObject

This returns an array of labels.



33
34
35
# File 'lib/syntax_tree/yarv/instructions.rb', line 33

def branch_targets
  []
end

#canonicalObject

This method creates an instruction that represents the canonical (non-specialized) form of this instruction. If this instruction is not a specialized instruction, then this method returns ‘self`.



11
12
13
# File 'lib/syntax_tree/yarv/instructions.rb', line 11

def canonical
  self
end

#falls_through?Boolean

Whether or not this instruction falls through to the next instruction if its branching fails.

Returns:

  • (Boolean)


44
45
46
# File 'lib/syntax_tree/yarv/instructions.rb', line 44

def falls_through?
  false
end

#leaves?Boolean

Whether or not this instruction leaves the current frame.

Returns:

  • (Boolean)


38
39
40
# File 'lib/syntax_tree/yarv/instructions.rb', line 38

def leaves?
  false
end

#lengthObject

This returns the size of the instruction in terms of the number of slots it occupies in the instruction sequence. Effectively this is 1 plus the number of operands.



18
19
20
# File 'lib/syntax_tree/yarv/instructions.rb', line 18

def length
  1
end

#popsObject

This returns the number of values that are popped off the stack.



28
29
30
# File 'lib/syntax_tree/yarv/instructions.rb', line 28

def pops
  0
end

#pushesObject

This returns the number of values that are pushed onto the stack.



23
24
25
# File 'lib/syntax_tree/yarv/instructions.rb', line 23

def pushes
  0
end

#side_effects?Boolean

Does the instruction have side effects? Control-flow counts as a side-effect, as do some special-case instructions like Leave. By default every instruction is marked as having side effects.

Returns:

  • (Boolean)


51
52
53
# File 'lib/syntax_tree/yarv/instructions.rb', line 51

def side_effects?
  true
end