Class: CodeTools::AST::ToplevelConstant
- Inherits:
-
Node
- Object
- Node
- CodeTools::AST::ToplevelConstant
show all
- Defined in:
- lib/rubinius/code/ast/constants.rb
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, #visit, #walk
Constructor Details
Returns a new instance of ToplevelConstant.
116
117
118
119
|
# File 'lib/rubinius/code/ast/constants.rb', line 116
def initialize(line, name)
@line = line
@name = name
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
114
115
116
|
# File 'lib/rubinius/code/ast/constants.rb', line 114
def name
@name
end
|
Instance Method Details
#assign_bytecode(g, value) ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/rubinius/code/ast/constants.rb', line 128
def assign_bytecode(g, value)
pos(g)
g.push_cpath_top
g.push_literal @name
value.bytecode(g)
end
|
#bytecode(g) ⇒ Object
121
122
123
124
125
126
|
# File 'lib/rubinius/code/ast/constants.rb', line 121
def bytecode(g)
pos(g)
g.push_cpath_top
g.find_const @name
end
|
#defined(g) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/rubinius/code/ast/constants.rb', line 144
def defined(g)
f = g.new_label
done = g.new_label
value_defined(g, f)
g.pop
g.push_literal "constant"
g.goto done
f.set!
g.push_nil
done.set!
end
|
#masgn_bytecode(g) ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/rubinius/code/ast/constants.rb', line 136
def masgn_bytecode(g)
pos(g)
g.push_cpath_top
g.swap
g.push_literal @name
end
|
#to_sexp ⇒ Object
Also known as:
assign_sexp
189
190
191
|
# File 'lib/rubinius/code/ast/constants.rb', line 189
def to_sexp
[:colon3, @name]
end
|
#value_defined(g, f) ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/rubinius/code/ast/constants.rb', line 160
def value_defined(g, f)
g.push_exception_state
outer_exc_state = g.new_stack_local
g.set_stack_local outer_exc_state
g.pop
ex = g.new_label
ok = g.new_label
g.setup_unwind ex, RescueType
g.push_type
g.push_cpath_top
g.push_literal @name
g.send :constant_path_defined?, 2
g.dup
g.goto_if_not_undefined ok
g.pop
g.goto f
ex.set!
g.clear_exception
g.push_stack_local outer_exc_state
g.restore_exception_state
g.goto f
ok.set!
end
|