Class: Rubinius::AST::State

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_flopsObject

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

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

#scopeObject (readonly)

Returns the value of attribute scope.



238
239
240
# File 'lib/compiler/ast/node.rb', line 238

def scope
  @scope
end

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



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

#nameObject



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_blockObject



297
298
299
# File 'lib/compiler/ast/node.rb', line 297

def pop_block
  @block -= 1 if block?
end

#pop_ensureObject



285
286
287
# File 'lib/compiler/ast/node.rb', line 285

def pop_ensure
  @ensure -= 1 if ensure?
end

#pop_loopObject



353
354
355
# File 'lib/compiler/ast/node.rb', line 353

def pop_loop
  @loop -= 1 if loop?
end

#pop_masgnObject



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

def pop_masgn
  @masgn -= 1 if masgn?
end

#pop_nameObject



261
262
263
# File 'lib/compiler/ast/node.rb', line 261

def pop_name
  @name.pop
end

#pop_op_asgnObject



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

def pop_op_asgn
  @op_asgn -= 1 if op_asgn?
end

#pop_rescueObject



273
274
275
# File 'lib/compiler/ast/node.rb', line 273

def pop_rescue
  @rescue.pop if rescue?
end

#push_blockObject



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

def push_block
  @block += 1
end

#push_ensureObject



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_flopObject



309
310
311
# File 'lib/compiler/ast/node.rb', line 309

def push_flip_flop
  State.flip_flops += 1
end

#push_loopObject



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

def push_loop
  @loop += 1
end

#push_masgnObject



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_asgnObject



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