Class: CodeTools::AST::NthRef

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/code/ast/variables.rb

Constant Summary collapse

Mode =
5

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk

Constructor Details

#initialize(line, ref) ⇒ NthRef

Returns a new instance of NthRef.



66
67
68
69
# File 'lib/rubinius/code/ast/variables.rb', line 66

def initialize(line, ref)
  @line = line
  @which = ref
end

Instance Attribute Details

#whichObject

Returns the value of attribute which.



64
65
66
# File 'lib/rubinius/code/ast/variables.rb', line 64

def which
  @which
end

Instance Method Details

#bytecode(g) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/rubinius/code/ast/variables.rb', line 73

def bytecode(g)
  pos(g)

  # These are for $1, $2, etc. We subtract 1 because
  # we start numbering the captures from 0.
  g.last_match Mode, @which - 1
end

#defined(g) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rubinius/code/ast/variables.rb', line 81

def defined(g)
  f = g.new_label
  done = g.new_label

  g.last_match Mode, @which - 1
  g.goto_if_nil f

  g.push_literal "global-variable"
  g.string_dup

  g.goto done

  f.set!
  g.push_nil

  done.set!
end

#to_sexpObject



99
100
101
# File 'lib/rubinius/code/ast/variables.rb', line 99

def to_sexp
  [:nth_ref, @which]
end