Class: Rubinius::ToolSet.current::TS::AST::State

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_flopsObject

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_localsObject

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

#evalObject (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

#scopeObject (readonly)

Returns the value of attribute scope.



263
264
265
# File 'lib/rubinius/ast/node.rb', line 263

def scope
  @scope
end

#superObject (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

Returns:

  • (Boolean)


341
342
343
# File 'lib/rubinius/ast/node.rb', line 341

def block?
  @block > 0
end

#ensure?Boolean

Returns:

  • (Boolean)


317
318
319
# File 'lib/rubinius/ast/node.rb', line 317

def ensure?
  @ensure > 0
end

#flip_flopsObject



345
346
347
# File 'lib/rubinius/ast/node.rb', line 345

def flip_flops
  State.flip_flops
end

#loop?Boolean

Returns:

  • (Boolean)


397
398
399
# File 'lib/rubinius/ast/node.rb', line 397

def loop?
  @loop > 0
end

#masgn?Boolean

Returns:

  • (Boolean)


361
362
363
# File 'lib/rubinius/ast/node.rb', line 361

def masgn?
  @masgn > 0
end

#nameObject



293
294
295
# File 'lib/rubinius/ast/node.rb', line 293

def name
  @name.last
end

#op_asgn?Boolean

Returns:

  • (Boolean)


373
374
375
# File 'lib/rubinius/ast/node.rb', line 373

def op_asgn?
  @op_asgn > 0
end

#pop_blockObject



337
338
339
# File 'lib/rubinius/ast/node.rb', line 337

def pop_block
  @block -= 1 if block?
end

#pop_ensureObject



313
314
315
# File 'lib/rubinius/ast/node.rb', line 313

def pop_ensure
  @ensure -= 1 if ensure?
end

#pop_inside_ensureObject



325
326
327
# File 'lib/rubinius/ast/node.rb', line 325

def pop_inside_ensure
  @ensure_level = nil
end

#pop_loopObject



393
394
395
# File 'lib/rubinius/ast/node.rb', line 393

def pop_loop
  @loop -= 1 if loop?
end

#pop_masgnObject



357
358
359
# File 'lib/rubinius/ast/node.rb', line 357

def pop_masgn
  @masgn -= 1 if masgn?
end

#pop_nameObject



289
290
291
# File 'lib/rubinius/ast/node.rb', line 289

def pop_name
  @name.pop
end

#pop_op_asgnObject



369
370
371
# File 'lib/rubinius/ast/node.rb', line 369

def pop_op_asgn
  @op_asgn -= 1 if op_asgn?
end

#pop_rescueObject



301
302
303
# File 'lib/rubinius/ast/node.rb', line 301

def pop_rescue
  @rescue.pop if rescue?
end

#push_blockObject



333
334
335
# File 'lib/rubinius/ast/node.rb', line 333

def push_block
  @block += 1
end

#push_ensureObject



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_flopObject



349
350
351
# File 'lib/rubinius/ast/node.rb', line 349

def push_flip_flop
  State.flip_flops += 1
end

#push_inside_ensureObject



321
322
323
# File 'lib/rubinius/ast/node.rb', line 321

def push_inside_ensure
  @ensure_level = @loop
end

#push_loopObject



389
390
391
# File 'lib/rubinius/ast/node.rb', line 389

def push_loop
  @loop += 1
end

#push_masgnObject



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_asgnObject



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

Returns:

  • (Boolean)


305
306
307
# File 'lib/rubinius/ast/node.rb', line 305

def rescue?
  @rescue.last
end

#top_level_ensure?Boolean

Returns:

  • (Boolean)


329
330
331
# File 'lib/rubinius/ast/node.rb', line 329

def top_level_ensure?
  @ensure_level && @ensure_level == @loop
end