Class: CodeTools::AST::Define
- Inherits:
-
ClosedScope
- Object
- Node
- ClosedScope
- CodeTools::AST::Define
- Defined in:
- lib/rubinius/code/ast/definitions.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from ClosedScope
Attributes inherited from Node
Instance Method Summary collapse
- #bytecode(g) ⇒ Object
- #compile_body(g) ⇒ Object
-
#initialize(line, name, block) ⇒ Define
constructor
A new instance of Define.
- #to_sexp ⇒ Object
Methods inherited from ClosedScope
#assign_local_reference, #attach_and_call, #module?, #nest_scope, #new_local, #new_nested_local, #search_local
Methods inherited from Node
#ascii_graph, #attributes, #children, #defined, 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, name, block) ⇒ Define
Returns a new instance of Define.
242 243 244 245 246 247 248 |
# File 'lib/rubinius/code/ast/definitions.rb', line 242 def initialize(line, name, block) @line = line @name = name @arguments = block.extract_parameters block.array << NilLiteral.new(line) if block.array.empty? @body = block end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
240 241 242 |
# File 'lib/rubinius/code/ast/definitions.rb', line 240 def arguments @arguments end |
#name ⇒ Object
Returns the value of attribute name.
240 241 242 |
# File 'lib/rubinius/code/ast/definitions.rb', line 240 def name @name end |
Instance Method Details
#bytecode(g) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/rubinius/code/ast/definitions.rb', line 274 def bytecode(g) pos(g) g.push_rubinius g.push_literal @name g.push_generator compile_body(g) g.push_scope g.push_variables g.send :method_visibility, 0 g.send :add_defn_method, 4 end |
#compile_body(g) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/rubinius/code/ast/definitions.rb', line 250 def compile_body(g) meth = new_generator(g, @name, @arguments) meth.push_state self meth.state.push_super self meth.definition_line(@line) meth.state.push_name @name @arguments.bytecode(meth) @body.bytecode(meth) meth.state.pop_name meth.local_count = local_count meth.local_names = local_names meth.ret meth.close meth.pop_state return meth end |
#to_sexp ⇒ Object
287 288 289 |
# File 'lib/rubinius/code/ast/definitions.rb', line 287 def to_sexp [:defn, @name, @arguments.to_sexp, [:scope, @body.to_sexp]] end |