Class: TempExpander

Inherits:
SexpProcessor
  • Object
show all
Defined in:
lib/bud/rewrite.rb

Overview

Look for temp declarations and remove the “temp” keyword, yielding code that we can safely eval. We also record the set of “temp” collections we've seen, and provide a helper method that returns the AST of a state block that contains declarations for all those temp tables.

Constant Summary

TEMP_KEYWORD =
:temp

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (TempExpander) initialize

Returns a new instance of TempExpander



568
569
570
571
572
573
574
# File 'lib/bud/rewrite.rb', line 568

def initialize
  super()
  self.require_empty = false
  self.expected = Sexp
  @tmp_tables = []
  @did_work = false
end

Instance Attribute Details

- (Object) did_work

Returns the value of attribute did_work



564
565
566
# File 'lib/bud/rewrite.rb', line 564

def did_work
  @did_work
end

- (Object) tmp_tables (readonly)

:nodoc: all



563
564
565
# File 'lib/bud/rewrite.rb', line 563

def tmp_tables
  @tmp_tables
end

Instance Method Details

- (Object) process_defn(exp)



576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/bud/rewrite.rb', line 576

def process_defn(exp)
  tag, name, args, *body = exp
  return exp unless name.to_s =~ /^__bloom__.+/

  body.each_with_index do |n,i|
    # temp declarations are misparsed if the RHS contains certain constructs
    # (e.g., group, "do |f| ... end" rather than "{|f| ... }").  Rewrite to
    # correct the misparsing.
    if n.sexp_type == :iter
      iter_body = n.sexp_body
      new_n = fix_temp_decl(iter_body)
      unless new_n.nil?
        body[i] = n = new_n
        @did_work = true
      end
    end

    _, recv, meth, meth_args = n
    if meth == TEMP_KEYWORD and recv.nil?
      body[i] = rewrite_temp(n)
      @did_work = true
    end
  end
  s(tag, name, args, *body)
end