lib/rubinius/compiler/compiled_file.rb
##
# Process a stream object +stream+ as as marshalled data and
# return an object representation of it.
Process a stream object +stream+ as as marshalled data and
return an object representation of it.
Process a stream object + stream + as as marshalled data and return an object representation of it .
def unmarshal_data
        kind = next_type
        case kind
        when 116 
          return true
        when 102 
          return false
        when 110 
          return nil
        when 73  
          return next_string.to_i(16)
        when 100 
          str = next_string.chop
          if str[0] == ?\     
            x = str.to_f
            e = str[-5..-1].to_i
            if e == 1024
              return x * 2 ** 512 * 2 ** 512
            else
              return x * 2 ** e
            end
          else
            case str.downcase
            when "infinity"
              return 1.0 / 0.0
            when "-infinity"
              return -1.0 / 0.0
            when "nan"
              return 0.0 / 0.0
            else
              raise TypeError, "Invalid Float format: #{str}"
            end
          end
        when 115 
          enc = unmarshal_data
          count = next_string.to_i
          str = next_bytes count
          str.force_encoding enc if enc
          return str
        when 120 
          enc = unmarshal_data
          count = next_string.to_i
          str = next_bytes count
          str.force_encoding enc if enc
          return str.to_sym
        when 99  
          count = next_string.to_i
          str = next_bytes count
          return str.split("::").inject(Object) { |a,n| a.const_get(n) }
        when 112 
          count = next_string.to_i
          obj = Rubinius::Tuple.new(count)
          i = 0
          while i < count
            obj[i] = unmarshal_data
            i += 1
          end
          return obj
        when 105 
          count = next_string.to_i
          seq = Rubinius::InstructionSequence.new(count)
          i = 0
          while i < count
            seq[i] = next_string.to_i
            i += 1
          end
          return seq
        when 69  
          count = next_string.to_i
          name = next_bytes count
          return Encoding.find(name)
        when 77  
          version = next_string.to_i
          if version != 1
            raise "Unknown CompiledCode version #{version}"
          end
          code = Rubinius::CompiledCode.new
          code.metadata      = unmarshal_data
          code.primitive     = unmarshal_data
          code.name          = unmarshal_data
          code.iseq          = unmarshal_data
          code.stack_size    = unmarshal_data
          code.local_count   = unmarshal_data
          code.required_args = unmarshal_data
          code.post_args     = unmarshal_data
          code.total_args    = unmarshal_data
          code.splat         = unmarshal_data
          code.literals      = unmarshal_data
          code.lines         = unmarshal_data
          code.file          = unmarshal_data
          code.local_names   = unmarshal_data
          return code
        else
          raise "Unknown type '#{kind.chr}'"
        end
      end
def unmarshal_data kind = next_type case kind when 116 return true when 102 return false when 110 return nil when 73 return next_string . to_i ( 16 ) when 100 str = next_string . chop if str [ 0 ] == ?\ x = str . to_f e = str [ - 5 .. - 1 ] . to_i if e == 1024 return x * 2 ** 512 * 2 ** 512 else return x * 2 ** e end else case str . downcase when "infinity" return 1.0 / 0.0 when "-infinity" return - 1.0 / 0.0 when "nan" return 0.0 / 0.0 else raise TypeError , "Invalid Float format: #{str}" end end when 115 enc = unmarshal_data count = next_string . to_i str = next_bytes count str . force_encoding enc if enc return str when 120 enc = unmarshal_data count = next_string . to_i str = next_bytes count str . force_encoding enc if enc return str . to_sym when 99 count = next_string . to_i str = next_bytes count return str . split ( "::" ) . inject ( Object ) { | a , n | a . const_get ( n ) } when 112 count = next_string . to_i obj = Rubinius :: Tuple . new ( count ) i = 0 while i < count obj [ i ] = unmarshal_data i += 1 end return obj when 105 count = next_string . to_i seq = Rubinius :: InstructionSequence . new ( count ) i = 0 while i < count seq [ i ] = next_string . to_i i += 1 end return seq when 69 count = next_string . to_i name = next_bytes count return Encoding . find ( name ) when 77 version = next_string . to_i if version != 1 raise "Unknown CompiledCode version #{version}" end code = Rubinius :: CompiledCode . new code . metadata = unmarshal_data code . primitive = unmarshal_data code . name = unmarshal_data code . iseq = unmarshal_data code . stack_size = unmarshal_data code . local_count = unmarshal_data code . required_args = unmarshal_data code . post_args = unmarshal_data code . total_args = unmarshal_data code . splat = unmarshal_data code . literals = unmarshal_data code . lines = unmarshal_data code . file = unmarshal_data code . local_names = unmarshal_data return code else raise "Unknown type '#{kind.chr}'" end end
Process a stream object +stream+ as as marshalled data and
return an object representation of it.
Process a stream object + stream + as as marshalled data and return an object representation of it .
# ?t # ?f # ?n # ?I # ?d # handle the special NaN, Infinity and -Infinity differently # leading space # This is necessary because (2**1024).to_f yields Infinity # ?s # ?x # ?c # ?p # ?i # ?E # ?M