Class: Rubinius::AST::State
- Inherits:
-
Object
- Object
- Rubinius::AST::State
- Defined in:
- lib/compiler/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
-
#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_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_loop ⇒ Object
- #push_masgn ⇒ Object
- #push_name(name) ⇒ Object
- #push_op_asgn ⇒ Object
- #push_rescue(val) ⇒ Object
- #push_super(scope) ⇒ Object
- #rescue? ⇒ Boolean
Constructor Details
#initialize(scope) ⇒ State
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/compiler/ast/node.rb', line 246 def initialize(scope) @scope = scope @ensure = 0 @block = 0 @masgn = 0 @loop = 0 @op_asgn = 0 @rescue = [] @name = [] end |
Class Attribute Details
.flip_flops ⇒ Object
Returns the value of attribute flip_flops.
241 242 243 |
# File 'lib/compiler/ast/node.rb', line 241 def flip_flops @flip_flops end |
Instance Attribute Details
#eval ⇒ Object (readonly) Also known as: eval?
Returns the value of attribute eval.
238 239 240 |
# File 'lib/compiler/ast/node.rb', line 238 def eval @eval end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
238 239 240 |
# File 'lib/compiler/ast/node.rb', line 238 def scope @scope end |
#super ⇒ Object (readonly) Also known as: super?
Returns the value of attribute super.
238 239 240 |
# File 'lib/compiler/ast/node.rb', line 238 def super @super end |
Instance Method Details
#block? ⇒ Boolean
301 302 303 |
# File 'lib/compiler/ast/node.rb', line 301 def block? @block > 0 end |
#ensure? ⇒ Boolean
289 290 291 |
# File 'lib/compiler/ast/node.rb', line 289 def ensure? @ensure > 0 end |
#flip_flops ⇒ Object
305 306 307 |
# File 'lib/compiler/ast/node.rb', line 305 def flip_flops State.flip_flops end |
#loop? ⇒ Boolean
357 358 359 |
# File 'lib/compiler/ast/node.rb', line 357 def loop? @loop > 0 end |
#masgn? ⇒ Boolean
321 322 323 |
# File 'lib/compiler/ast/node.rb', line 321 def masgn? @masgn > 0 end |
#name ⇒ Object
265 266 267 |
# File 'lib/compiler/ast/node.rb', line 265 def name @name.last end |
#op_asgn? ⇒ Boolean
333 334 335 |
# File 'lib/compiler/ast/node.rb', line 333 def op_asgn? @op_asgn > 0 end |
#pop_block ⇒ Object
297 298 299 |
# File 'lib/compiler/ast/node.rb', line 297 def pop_block @block -= 1 if block? end |
#pop_ensure ⇒ Object
285 286 287 |
# File 'lib/compiler/ast/node.rb', line 285 def pop_ensure @ensure -= 1 if ensure? end |
#pop_loop ⇒ Object
353 354 355 |
# File 'lib/compiler/ast/node.rb', line 353 def pop_loop @loop -= 1 if loop? end |
#pop_masgn ⇒ Object
317 318 319 |
# File 'lib/compiler/ast/node.rb', line 317 def pop_masgn @masgn -= 1 if masgn? end |
#pop_name ⇒ Object
261 262 263 |
# File 'lib/compiler/ast/node.rb', line 261 def pop_name @name.pop end |
#pop_op_asgn ⇒ Object
329 330 331 |
# File 'lib/compiler/ast/node.rb', line 329 def pop_op_asgn @op_asgn -= 1 if op_asgn? end |
#pop_rescue ⇒ Object
273 274 275 |
# File 'lib/compiler/ast/node.rb', line 273 def pop_rescue @rescue.pop if rescue? end |
#push_block ⇒ Object
293 294 295 |
# File 'lib/compiler/ast/node.rb', line 293 def push_block @block += 1 end |
#push_ensure ⇒ Object
281 282 283 |
# File 'lib/compiler/ast/node.rb', line 281 def push_ensure @ensure += 1 end |
#push_eval(scope) ⇒ Object
343 344 345 |
# File 'lib/compiler/ast/node.rb', line 343 def push_eval(scope) @eval = scope end |
#push_flip_flop ⇒ Object
309 310 311 |
# File 'lib/compiler/ast/node.rb', line 309 def push_flip_flop State.flip_flops += 1 end |
#push_loop ⇒ Object
349 350 351 |
# File 'lib/compiler/ast/node.rb', line 349 def push_loop @loop += 1 end |
#push_masgn ⇒ Object
313 314 315 |
# File 'lib/compiler/ast/node.rb', line 313 def push_masgn @masgn += 1 end |
#push_name(name) ⇒ Object
257 258 259 |
# File 'lib/compiler/ast/node.rb', line 257 def push_name(name) @name.push name end |
#push_op_asgn ⇒ Object
325 326 327 |
# File 'lib/compiler/ast/node.rb', line 325 def push_op_asgn @op_asgn += 1 end |
#push_rescue(val) ⇒ Object
269 270 271 |
# File 'lib/compiler/ast/node.rb', line 269 def push_rescue(val) @rescue.push(val) end |
#push_super(scope) ⇒ Object
337 338 339 |
# File 'lib/compiler/ast/node.rb', line 337 def push_super(scope) @super = scope end |
#rescue? ⇒ Boolean
277 278 279 |
# File 'lib/compiler/ast/node.rb', line 277 def rescue? @rescue.last end |