compiler/codegen/symbol.cpp
// Some Python type instances need to be translated into C level type instances.
// Generate code to perform that translation when this is the case
Some Python type instances need to be translated into C level type instances.
Generate code to perform that translation when this is the case
Some Python type instances need to be translated into C level type instances . Generate code to perform that translation when this is the case
std::string ArgSymbol::getPythonArgTranslation() {
  Type* t = getArgSymbolCodegenType(this);
  if (t == dtStringC) {
    std::string res = "\tcdef const char* chpl_";
    res += cname;
    res += " = ";
    res += cname;
    res += "\n";
    return res;
  } else if (t->symbol->hasFlag(FLAG_REF) &&
             t->getValType() == dtExternalArray) {
    if (Symbol* eltType = exportedArrayElementType[this]) {
      std::string typeStr = getPythonTypeName(eltType->type, PYTHON_PYX);
      std::string typeStrCDefs = getPythonTypeName(eltType->type, C_PYX);
      std::string res = "\tcdef chpl_external_array chpl_";
      res += cname;
      res += " = chpl_make_external_array(sizeof(";
      res += typeStrCDefs;
      res += "), len(";
      res += cname;
      res += "))\n";
      res += "\tfor i in range(len(";
      res += cname;
      res += ")):\n";
      res += "\t\t(<" + typeStrCDefs + "*>chpl_";
      res += cname;
      res += ".elts)[i] = ";
      res += cname;
      res += "[i]\n";
      return res;
    }
  }
  return "";
}
std :: string ArgSymbol :: getPythonArgTranslation ( ) { Type * t = getArgSymbolCodegenType ( this ) ; if ( t == dtStringC ) { std :: string res = " \t " ; res += cname ; res += " " ; res += cname ; res += " \n " ; return res ; } else if ( t -> symbol -> hasFlag ( FLAG_REF ) && t -> getValType ( ) == dtExternalArray ) { if ( Symbol * eltType = exportedArrayElementType [ this ] ) { std :: string typeStr = getPythonTypeName ( eltType -> type , PYTHON_PYX ) ; std :: string typeStrCDefs = getPythonTypeName ( eltType -> type , C_PYX ) ; std :: string res = " \t " ; res += cname ; res += " " ; res += typeStrCDefs ; res += " " ; res += cname ; res += " \n " ; res += " \t " ; res += cname ; res += " \n " ; res += " \t \t " + typeStrCDefs + " " ; res += cname ; res += " " ; res += cname ; res += " \n " ; return res ; } } return " " ; }
Some Python type instances need to be translated into C level type instances.
Some Python type instances need to be translated into C level type instances .
// Handle arrays // The element type will be recorded in the exportedArrayElementType map // if this arg's type was originally a Chapel array instead of explicitly // an external array.  If we have the element type, that means we need to // do a translation in the python wrapper. // Create the memory needed to store the contents of what was passed to us // E.g. cdef chpl_external_array chpl_foo = //          chpl_make_external_array(sizeof(element type), len(foo)) // Copy the contents over. // E.g. for i in range(len(foo)): //         (<element type*>chpl_foo.elts)[i] = foo[i]