Ejemplo n.º 1
0
  def _set_literal_value(self, value):
    if type(value) in (_array_type, _extarray_type):

      if self.array_typecode != value.typecode:
        print "Warning: array typecode does not match variable type - I hope you know what you're doing!"
        
      util.vector_from_array(self.code, self, value)

      self.code.add_storage(value)
      self.storage = self.value
      
      # elif type(self.value) is _numeric_type:
      #   raise Exception('Numeric types not yet supported')

    elif type(value) in (int, long):

      if self.array_typecode not in INT_ARRAY_TYPES:
        print "Warning: int does not match variable type - I hope you know what you're doing!"

      util.load_word(self.code, self, value)
    else:
      # print "Warning: unknown type for %s -> %s, defaulting to 'I'" % (str(self.value), str(type(self.value)))
      # self.typecode = 'I'
      raise Exception("Warning: unknown type for %s -> %s, defaulting to 'I'" % (str(self.value), str(type(self.value))))
    
    if self.array_typecode is not None and INT_ARRAY_SIZES[self.array_typecode] != 4:
      print "Warning: Only 4-byte integers are supported for spu variables from arrays"

    self.code.add_storage(self.storage)
    return
Ejemplo n.º 2
0
  def _set_literal_value(self, value):

    # Convert lists and tuples to 'f' arrays
    if isinstance(value, (list, tuple)):
      value = array.array(self.array_typecode, value)
    
    if type(value) in (_array_type, _extarray_type):

      if self.array_typecode != value.typecode:
        print "Warning: array typecode does not match variable type - I hope you know what you're doing!"

      # Convert the float array to an integer array to prevent Python from
      # improperly casting floats to ints
      int_value = array.array('I')
      int_value.fromstring(value.tostring())
      
      util.vector_from_array(self.code, self, int_value)
      

      self.code.add_storage(value)
      self.code.add_storage(int_value)
      self.storage = self.value
      
      # elif type(self.value) is _numeric_type:
      #   raise Exception('Numeric types not yet supported')

    elif type(value) in (float,):

      if self.array_typecode not in FLOAT_ARRAY_TYPES:
        print "Warning: int does not match variable type - I hope you know what you're doing!"

      ## Convert to bits
      #af = array.array('f', (value,))
      #int_value = array.array('I')
      #int_value.fromstring(af.tostring())
      
      #util.load_word(self.code, self, int_value[0])
      util.load_word(self.code, self, value)
    else:
      # print "Warning: unknown type for %s -> %s, defaulting to 'I'" % (str(self.value), str(type(self.value)))
      # self.typecode = 'I'
      raise Exception("Warning: unknown type for %s -> %s, defaulting to 'I'" % (str(self.value), str(type(self.value))))

    return