Class: CodeTools::AST::State
- Inherits:
-
Object
- Object
- CodeTools::AST::State
- Defined in:
- lib/rubinius/code/ast/node.rb
Overview
In a perfect world, each AST node would fully encapsulate its state. But in the real world, some state exists across the AST rather than just in a node. For example, some nodes need to emit different bytecode when in a rescue.
This class maintains state needed as the AST is walked to generate bytecode. An instance of State is pushed onto a stack in the Generator instance as each ClosedScope or Iter is entered, and popped when left.
Class Attribute Summary collapse
-
.flip_flops ⇒ Object
Returns the value of attribute flip_flops.
Instance Attribute Summary collapse
-
#check_for_locals ⇒ Object
Returns the value of attribute check_for_locals.
-
#eval ⇒ Object
(also: #eval?)
readonly
Returns the value of attribute eval.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#super ⇒ Object
(also: #super?)
readonly
Returns the value of attribute super.
Instance Method Summary collapse
- #block? ⇒ Boolean
- #ensure? ⇒ Boolean
- #flip_flops ⇒ Object
-
#initialize(scope) ⇒ State
constructor
A new instance of State.
- #loop? ⇒ Boolean
- #masgn? ⇒ Boolean
- #name ⇒ Object
- #op_asgn? ⇒ Boolean
- #pop_block ⇒ Object
- #pop_ensure ⇒ Object
- #pop_inside_ensure ⇒ Object
- #pop_loop ⇒ Object
- #pop_masgn ⇒ Object
- #pop_name ⇒ Object
- #pop_op_asgn ⇒ Object
- #pop_rescue ⇒ Object
- #push_block ⇒ Object
- #push_ensure ⇒ Object
- #push_eval(scope) ⇒ Object
- #push_flip_flop ⇒ Object
- #push_inside_ensure ⇒ Object
- #push_loop ⇒ Object
- #push_masgn ⇒ Object
- #push_name(name) ⇒ Object
- #push_op_asgn ⇒ Object
- #push_rescue(val) ⇒ Object
- #push_super(scope) ⇒ Object
- #rescue? ⇒ Boolean
- #top_level_ensure? ⇒ Boolean
Constructor Details
#initialize(scope) ⇒ State
Returns a new instance of State.
278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/rubinius/code/ast/node.rb', line 278 def initialize(scope) @scope = scope @ensure = 0 @ensure_level = nil @block = 0 @masgn = 0 @loop = 0 @op_asgn = 0 @rescue = [] @name = [] @check_for_locals = true end |
Class Attribute Details
.flip_flops ⇒ Object
Returns the value of attribute flip_flops.
273 274 275 |
# File 'lib/rubinius/code/ast/node.rb', line 273 def flip_flops @flip_flops end |
Instance Attribute Details
#check_for_locals ⇒ Object
Returns the value of attribute check_for_locals.
270 271 272 |
# File 'lib/rubinius/code/ast/node.rb', line 270 def check_for_locals @check_for_locals end |
#eval ⇒ Object (readonly) Also known as: eval?
Returns the value of attribute eval.
269 270 271 |
# File 'lib/rubinius/code/ast/node.rb', line 269 def eval @eval end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
269 270 271 |
# File 'lib/rubinius/code/ast/node.rb', line 269 def scope @scope end |
#super ⇒ Object (readonly) Also known as: super?
Returns the value of attribute super.
269 270 271 |
# File 'lib/rubinius/code/ast/node.rb', line 269 def super @super end |
Instance Method Details
#block? ⇒ Boolean
347 348 349 |
# File 'lib/rubinius/code/ast/node.rb', line 347 def block? @block > 0 end |
#ensure? ⇒ Boolean
323 324 325 |
# File 'lib/rubinius/code/ast/node.rb', line 323 def ensure? @ensure > 0 end |
#flip_flops ⇒ Object
351 352 353 |
# File 'lib/rubinius/code/ast/node.rb', line 351 def flip_flops State.flip_flops end |
#loop? ⇒ Boolean
403 404 405 |
# File 'lib/rubinius/code/ast/node.rb', line 403 def loop? @loop > 0 end |
#masgn? ⇒ Boolean
367 368 369 |
# File 'lib/rubinius/code/ast/node.rb', line 367 def masgn? @masgn > 0 end |
#name ⇒ Object
299 300 301 |
# File 'lib/rubinius/code/ast/node.rb', line 299 def name @name.last end |
#op_asgn? ⇒ Boolean
379 380 381 |
# File 'lib/rubinius/code/ast/node.rb', line 379 def op_asgn? @op_asgn > 0 end |
#pop_block ⇒ Object
343 344 345 |
# File 'lib/rubinius/code/ast/node.rb', line 343 def pop_block @block -= 1 if block? end |
#pop_ensure ⇒ Object
319 320 321 |
# File 'lib/rubinius/code/ast/node.rb', line 319 def pop_ensure @ensure -= 1 if ensure? end |
#pop_inside_ensure ⇒ Object
331 332 333 |
# File 'lib/rubinius/code/ast/node.rb', line 331 def pop_inside_ensure @ensure_level = nil end |
#pop_loop ⇒ Object
399 400 401 |
# File 'lib/rubinius/code/ast/node.rb', line 399 def pop_loop @loop -= 1 if loop? end |
#pop_masgn ⇒ Object
363 364 365 |
# File 'lib/rubinius/code/ast/node.rb', line 363 def pop_masgn @masgn -= 1 if masgn? end |
#pop_name ⇒ Object
295 296 297 |
# File 'lib/rubinius/code/ast/node.rb', line 295 def pop_name @name.pop end |
#pop_op_asgn ⇒ Object
375 376 377 |
# File 'lib/rubinius/code/ast/node.rb', line 375 def pop_op_asgn @op_asgn -= 1 if op_asgn? end |
#pop_rescue ⇒ Object
307 308 309 |
# File 'lib/rubinius/code/ast/node.rb', line 307 def pop_rescue @rescue.pop if rescue? end |
#push_block ⇒ Object
339 340 341 |
# File 'lib/rubinius/code/ast/node.rb', line 339 def push_block @block += 1 end |
#push_ensure ⇒ Object
315 316 317 |
# File 'lib/rubinius/code/ast/node.rb', line 315 def push_ensure @ensure += 1 end |
#push_eval(scope) ⇒ Object
389 390 391 |
# File 'lib/rubinius/code/ast/node.rb', line 389 def push_eval(scope) @eval = scope end |
#push_flip_flop ⇒ Object
355 356 357 |
# File 'lib/rubinius/code/ast/node.rb', line 355 def push_flip_flop State.flip_flops += 1 end |
#push_inside_ensure ⇒ Object
327 328 329 |
# File 'lib/rubinius/code/ast/node.rb', line 327 def push_inside_ensure @ensure_level = @loop end |
#push_loop ⇒ Object
395 396 397 |
# File 'lib/rubinius/code/ast/node.rb', line 395 def push_loop @loop += 1 end |
#push_masgn ⇒ Object
359 360 361 |
# File 'lib/rubinius/code/ast/node.rb', line 359 def push_masgn @masgn += 1 end |
#push_name(name) ⇒ Object
291 292 293 |
# File 'lib/rubinius/code/ast/node.rb', line 291 def push_name(name) @name.push name end |
#push_op_asgn ⇒ Object
371 372 373 |
# File 'lib/rubinius/code/ast/node.rb', line 371 def push_op_asgn @op_asgn += 1 end |
#push_rescue(val) ⇒ Object
303 304 305 |
# File 'lib/rubinius/code/ast/node.rb', line 303 def push_rescue(val) @rescue.push(val) end |
#push_super(scope) ⇒ Object
383 384 385 |
# File 'lib/rubinius/code/ast/node.rb', line 383 def push_super(scope) @super = scope end |
#rescue? ⇒ Boolean
311 312 313 |
# File 'lib/rubinius/code/ast/node.rb', line 311 def rescue? @rescue.last end |
#top_level_ensure? ⇒ Boolean
335 336 337 |
# File 'lib/rubinius/code/ast/node.rb', line 335 def top_level_ensure? @ensure_level && @ensure_level == @loop end |