rewrite_resbody (UnifiedRuby)

    # File lib/unified_ruby.rb, line 139
      def rewrite_resbody(exp) # TODO: clean up and move to unified
        result = s()

        code = result
        while exp and exp.first == :resbody do
          code << exp.shift
          list = exp.shift || s(:array)
          body = exp.empty? ? nil : exp.shift
          exp  = exp.empty? ? nil : exp.shift

          # code may be nil, :lasgn, or :block
          case body.first
          when nil then
            # do nothing
          when :lasgn then
            # TODO: check that it is assigning $!
            list << body
            body = nil
          when :block then
            # TODO: check that it is assigning $!
            list << body.delete_at(1) if body[1].first == :lasgn
          else
            # do nothing (expression form)
          end if body

          code << list << body
          if exp then
            code = s()
            result << code
          end
        end

        if $DEBUG or $TESTING then
          structure = result.structure
          raise "result structure wrong: #{structure[0..1].inspect}" unless
            structure.flatten[0] == :resbody
          raise "result structure wrong: #{structure[0..1].inspect}" unless
            s(:array, :splat, :argscat).include? structure.flatten[1]
          raise "result body wrong: #{structure[2].inspect}" unless
            structure[2].nil? or not structure[2].empty?
        end

        result
      end