Class: CodeTools::AST::Flip2

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/code/ast/control_flow.rb

Direct Known Subclasses

Flip3

Instance Attribute Summary

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph, #attributes, #children, #defined, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk

Constructor Details

#initialize(line, start, finish) ⇒ Flip2

Returns a new instance of Flip2.



225
226
227
228
229
# File 'lib/rubinius/code/ast/control_flow.rb', line 225

def initialize(line, start, finish)
  @line = line
  @start = start
  @finish = finish
end

Instance Method Details

#bytecode(g) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/rubinius/code/ast/control_flow.rb', line 239

def bytecode(g)
  done = g.new_label
  on_label = g.new_label
  index = g.state.flip_flops
  g.state.push_flip_flop

  get_flip_flop(g, index)
  g.goto_if_true on_label

  @start.bytecode(g)
  g.dup
  g.goto_if_false done
  g.pop
  set_flip_flop(g, index, true)

  if exclusive?
    g.goto done
  else
    g.pop
  end

  on_label.set!
  g.push_true
  @finish.bytecode(g)
  g.goto_if_false done
  set_flip_flop(g, index, false)
  g.pop

  done.set!
end

#exclusive?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/rubinius/code/ast/control_flow.rb', line 235

def exclusive?
  false
end

#get_flip_flop(g, index) ⇒ Object



270
271
272
273
274
275
276
# File 'lib/rubinius/code/ast/control_flow.rb', line 270

def get_flip_flop(g, index)
  g.push_rubinius
  g.find_const :Runtime
  g.push_scope
  g.push_int index
  g.send(:get_flip_flop, 2)
end

#set_flip_flop(g, index, value) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/rubinius/code/ast/control_flow.rb', line 278

def set_flip_flop(g, index, value)
  g.push_rubinius
  g.find_const :Runtime
  g.push_scope
  g.push_int index
  if value
    g.push_true
  else
    g.push_false
  end
  g.send(:set_flip_flop, 3)
end

#sexp_nameObject



231
232
233
# File 'lib/rubinius/code/ast/control_flow.rb', line 231

def sexp_name
  :flip2
end

#to_sexpObject



291
292
293
# File 'lib/rubinius/code/ast/control_flow.rb', line 291

def to_sexp
  [sexp_name, @start.to_sexp, @finish.to_sexp]
end