Class: Rubinius::ToolSet.current::TS::AST::State
- Inherits:
-
Object
- Object
- Rubinius::ToolSet.current::TS::AST::State
- Defined in:
- lib/rubinius/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.
272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/rubinius/ast/node.rb', line 272 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.
267 268 269 |
# File 'lib/rubinius/ast/node.rb', line 267 def flip_flops @flip_flops end |
Instance Attribute Details
#check_for_locals ⇒ Object
Returns the value of attribute check_for_locals.
264 265 266 |
# File 'lib/rubinius/ast/node.rb', line 264 def check_for_locals @check_for_locals end |
#eval ⇒ Object (readonly) Also known as: eval?
Returns the value of attribute eval.
263 264 265 |
# File 'lib/rubinius/ast/node.rb', line 263 def eval @eval end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
263 264 265 |
# File 'lib/rubinius/ast/node.rb', line 263 def scope @scope end |
#super ⇒ Object (readonly) Also known as: super?
Returns the value of attribute super.
263 264 265 |
# File 'lib/rubinius/ast/node.rb', line 263 def super @super end |
Instance Method Details
#block? ⇒ Boolean
341 342 343 |
# File 'lib/rubinius/ast/node.rb', line 341 def block? @block > 0 end |
#ensure? ⇒ Boolean
317 318 319 |
# File 'lib/rubinius/ast/node.rb', line 317 def ensure? @ensure > 0 end |
#flip_flops ⇒ Object
345 346 347 |
# File 'lib/rubinius/ast/node.rb', line 345 def flip_flops State.flip_flops end |
#loop? ⇒ Boolean
397 398 399 |
# File 'lib/rubinius/ast/node.rb', line 397 def loop? @loop > 0 end |
#masgn? ⇒ Boolean
361 362 363 |
# File 'lib/rubinius/ast/node.rb', line 361 def masgn? @masgn > 0 end |
#name ⇒ Object
293 294 295 |
# File 'lib/rubinius/ast/node.rb', line 293 def name @name.last end |
#op_asgn? ⇒ Boolean
373 374 375 |
# File 'lib/rubinius/ast/node.rb', line 373 def op_asgn? @op_asgn > 0 end |
#pop_block ⇒ Object
337 338 339 |
# File 'lib/rubinius/ast/node.rb', line 337 def pop_block @block -= 1 if block? end |
#pop_ensure ⇒ Object
313 314 315 |
# File 'lib/rubinius/ast/node.rb', line 313 def pop_ensure @ensure -= 1 if ensure? end |
#pop_inside_ensure ⇒ Object
325 326 327 |
# File 'lib/rubinius/ast/node.rb', line 325 def pop_inside_ensure @ensure_level = nil end |
#pop_loop ⇒ Object
393 394 395 |
# File 'lib/rubinius/ast/node.rb', line 393 def pop_loop @loop -= 1 if loop? end |
#pop_masgn ⇒ Object
357 358 359 |
# File 'lib/rubinius/ast/node.rb', line 357 def pop_masgn @masgn -= 1 if masgn? end |
#pop_name ⇒ Object
289 290 291 |
# File 'lib/rubinius/ast/node.rb', line 289 def pop_name @name.pop end |
#pop_op_asgn ⇒ Object
369 370 371 |
# File 'lib/rubinius/ast/node.rb', line 369 def pop_op_asgn @op_asgn -= 1 if op_asgn? end |
#pop_rescue ⇒ Object
301 302 303 |
# File 'lib/rubinius/ast/node.rb', line 301 def pop_rescue @rescue.pop if rescue? end |
#push_block ⇒ Object
333 334 335 |
# File 'lib/rubinius/ast/node.rb', line 333 def push_block @block += 1 end |
#push_ensure ⇒ Object
309 310 311 |
# File 'lib/rubinius/ast/node.rb', line 309 def push_ensure @ensure += 1 end |
#push_eval(scope) ⇒ Object
383 384 385 |
# File 'lib/rubinius/ast/node.rb', line 383 def push_eval(scope) @eval = scope end |
#push_flip_flop ⇒ Object
349 350 351 |
# File 'lib/rubinius/ast/node.rb', line 349 def push_flip_flop State.flip_flops += 1 end |
#push_inside_ensure ⇒ Object
321 322 323 |
# File 'lib/rubinius/ast/node.rb', line 321 def push_inside_ensure @ensure_level = @loop end |
#push_loop ⇒ Object
389 390 391 |
# File 'lib/rubinius/ast/node.rb', line 389 def push_loop @loop += 1 end |
#push_masgn ⇒ Object
353 354 355 |
# File 'lib/rubinius/ast/node.rb', line 353 def push_masgn @masgn += 1 end |
#push_name(name) ⇒ Object
285 286 287 |
# File 'lib/rubinius/ast/node.rb', line 285 def push_name(name) @name.push name end |
#push_op_asgn ⇒ Object
365 366 367 |
# File 'lib/rubinius/ast/node.rb', line 365 def push_op_asgn @op_asgn += 1 end |
#push_rescue(val) ⇒ Object
297 298 299 |
# File 'lib/rubinius/ast/node.rb', line 297 def push_rescue(val) @rescue.push(val) end |
#push_super(scope) ⇒ Object
377 378 379 |
# File 'lib/rubinius/ast/node.rb', line 377 def push_super(scope) @super = scope end |
#rescue? ⇒ Boolean
305 306 307 |
# File 'lib/rubinius/ast/node.rb', line 305 def rescue? @rescue.last end |
#top_level_ensure? ⇒ Boolean
329 330 331 |
# File 'lib/rubinius/ast/node.rb', line 329 def top_level_ensure? @ensure_level && @ensure_level == @loop end |