compiler/codegen/symbol.cpp
// Supports the creation of a python module with --library-python
Supports the creation of a python module with --library-python
Supports the creation of a python module with -- library - python
GenRet FnSymbol::codegenPYXType() {
  GenRet ret;
  ret.chplType = typeInfo();
  std::string header = "def ";
  header += cname;
  header += "(";
  std::string argTranslate = "";
  std::string funcCall = "\t";
  std::string returnStmt = "";
  if (retType != dtVoid) {
    if (retType == dtExternalArray &&
        exportedArrayElementType[this] != NULL) {
      funcCall += "cdef chpl_external_array ret_arr = ";
      returnStmt += getPythonArrayReturnStmts();
    } else {
      funcCall += "ret = ";
    }
    returnStmt += "\treturn ret\n";
  }
  funcCall += "chpl_";
  funcCall += cname;
  funcCall += "(";
  if (numFormals() != 0) {
    int count = 0;
    for_formals(formal, this) {
      if (formal->hasFlag(FLAG_NO_CODEGEN))
        continue; 
      if (count > 0) {
        header += ", ";
        funcCall += ", ";
      }
      std::string argType = formal->getPythonType(C_PYX);
      header += argType;
      header += formal->cname;
      if (fGenIDS) {
        header += " ";
        header += idCommentTemp(formal);
      }
      std::string curArgTranslate = formal->getPythonArgTranslation();
      if (curArgTranslate != "") {
        argTranslate += curArgTranslate;
        if (argType == "") {
          funcCall += "&";
          std::string oldRetStmt = returnStmt;
          returnStmt = "\tchpl_free_external_array(chpl_";
          returnStmt += formal->cname;
          returnStmt += ")\n" + oldRetStmt;
        }
        funcCall += "chpl_";
      }
      funcCall += formal->cname;
      count++;
    }
  } 
  header += "):\n";
  funcCall += ")\n";
  ret.c = header + argTranslate + funcCall + returnStmt;
  return ret;
}
GenRet FnSymbol :: codegenPYXType ( ) { GenRet ret ; ret . chplType = typeInfo ( ) ; std :: string header = " " ; header += cname ; header += " " ; std :: string argTranslate = " " ; std :: string funcCall = " \t " ; std :: string returnStmt = " " ; if ( retType != dtVoid ) { if ( retType == dtExternalArray && exportedArrayElementType [ this ] != NULL ) { funcCall += " " ; returnStmt += getPythonArrayReturnStmts ( ) ; } else { funcCall += " " ; } returnStmt += " \t \n " ; } funcCall += " " ; funcCall += cname ; funcCall += " " ; if ( numFormals ( ) != 0 ) { int count = 0 ; for_formals ( formal , this ) { if ( formal -> hasFlag ( FLAG_NO_CODEGEN ) ) continue ; if ( count > 0 ) { header += " " ; funcCall += " " ; } std :: string argType = formal -> getPythonType ( C_PYX ) ; header += argType ; header += formal -> cname ; if ( fGenIDS ) { header += " " ; header += idCommentTemp ( formal ) ; } std :: string curArgTranslate = formal -> getPythonArgTranslation ( ) ; if ( curArgTranslate != " " ) { argTranslate += curArgTranslate ; if ( argType == " " ) { funcCall += " " ; std :: string oldRetStmt = returnStmt ; returnStmt = " \t " ; returnStmt += formal -> cname ; returnStmt += " \n " + oldRetStmt ; } funcCall += " " ; } funcCall += formal -> cname ; count ++ ; } } header += " \n " ; funcCall += " \n " ; ret . c = header + argTranslate + funcCall + returnStmt ; return ret ; }
Supports the creation of a python module with --library-python
Supports the creation of a python module with -- library - python
// Function header // Translation of any arguments with Python-specific types // Call to the wrapped function // Return statement, if applicable // do not print locale argument, end count, dummy class // Happens when the argument type is an array // We need to send in the wrapper we created by reference // And we need to clean it up when we are done with it // pyx files do not take void as an argument list, just close the parens