mojoshader_compiler.c
changeset 983 665e2d8bd7de
parent 982 97d3ff546b26
child 985 bea4dafa2782
equal deleted inserted replaced
982:97d3ff546b26 983:665e2d8bd7de
  1954 
  1954 
  1955 static void require_numeric_datatype(Context *ctx,
  1955 static void require_numeric_datatype(Context *ctx,
  1956                                      const MOJOSHADER_astDataType *datatype)
  1956                                      const MOJOSHADER_astDataType *datatype)
  1957 {
  1957 {
  1958     datatype = reduce_datatype(ctx, datatype);
  1958     datatype = reduce_datatype(ctx, datatype);
       
  1959     if (datatype->type == MOJOSHADER_AST_DATATYPE_VECTOR)
       
  1960         datatype = reduce_datatype(ctx, datatype->vector.base);
       
  1961     else if (datatype->type == MOJOSHADER_AST_DATATYPE_MATRIX)
       
  1962         datatype = reduce_datatype(ctx, datatype->matrix.base);
       
  1963 
  1959     switch (datatype->type)
  1964     switch (datatype->type)
  1960     {
  1965     {
  1961         case MOJOSHADER_AST_DATATYPE_BOOL:
  1966         case MOJOSHADER_AST_DATATYPE_BOOL:
  1962         case MOJOSHADER_AST_DATATYPE_INT:
  1967         case MOJOSHADER_AST_DATATYPE_INT:
  1963         case MOJOSHADER_AST_DATATYPE_UINT:
  1968         case MOJOSHADER_AST_DATATYPE_UINT:
  2086         { MOJOSHADER_AST_DATATYPE_UINT,   32, 1, 0 },
  2091         { MOJOSHADER_AST_DATATYPE_UINT,   32, 1, 0 },
  2087         { MOJOSHADER_AST_DATATYPE_FLOAT,  32, 0, 1 },
  2092         { MOJOSHADER_AST_DATATYPE_FLOAT,  32, 0, 1 },
  2088         { MOJOSHADER_AST_DATATYPE_DOUBLE, 64, 0, 1 },
  2093         { MOJOSHADER_AST_DATATYPE_DOUBLE, 64, 0, 1 },
  2089     };
  2094     };
  2090 
  2095 
       
  2096     int lvector = 0;
       
  2097     int lmatrix = 0;
  2091     int l = STATICARRAYLEN(typeinf);
  2098     int l = STATICARRAYLEN(typeinf);
  2092     if (ldatatype != NULL)
  2099     if (ldatatype != NULL)
  2093     {
  2100     {
       
  2101         MOJOSHADER_astDataTypeType type = ldatatype->type;
       
  2102         if (type == MOJOSHADER_AST_DATATYPE_VECTOR)
       
  2103         {
       
  2104             lvector = 1;
       
  2105             type = ldatatype->vector.base->type;
       
  2106         } // if
       
  2107         else if (type == MOJOSHADER_AST_DATATYPE_MATRIX)
       
  2108         {
       
  2109             lmatrix = 1;
       
  2110             type = ldatatype->matrix.base->type;
       
  2111         } // if
       
  2112 
  2094         for (l = 0; l < STATICARRAYLEN(typeinf); l++)
  2113         for (l = 0; l < STATICARRAYLEN(typeinf); l++)
  2095         {
  2114         {
  2096             if (typeinf[l].type == ldatatype->type)
  2115             if (typeinf[l].type == type)
  2097                 break;
  2116                 break;
  2098         } // for
  2117         } // for
  2099     } // if
  2118     } // if
  2100 
  2119 
       
  2120     int rvector = 0;
       
  2121     int rmatrix = 0;
  2101     int r = STATICARRAYLEN(typeinf);
  2122     int r = STATICARRAYLEN(typeinf);
  2102     if (rdatatype != NULL)
  2123     if (rdatatype != NULL)
  2103     {
  2124     {
       
  2125         MOJOSHADER_astDataTypeType type = rdatatype->type;
       
  2126         if (type == MOJOSHADER_AST_DATATYPE_VECTOR)
       
  2127         {
       
  2128             rvector = 1;
       
  2129             type = rdatatype->vector.base->type;
       
  2130         } // if
       
  2131         else if (type == MOJOSHADER_AST_DATATYPE_MATRIX)
       
  2132         {
       
  2133             rmatrix = 1;
       
  2134             type = rdatatype->matrix.base->type;
       
  2135         } // if
       
  2136 
  2104         for (r = 0; r < STATICARRAYLEN(typeinf); r++)
  2137         for (r = 0; r < STATICARRAYLEN(typeinf); r++)
  2105         {
  2138         {
  2106             if (typeinf[r].type == rdatatype->type)
  2139             if (typeinf[r].type == type)
  2107                 break;
  2140                 break;
  2108         } // for
  2141         } // for
  2109     } // if
  2142     } // if
  2110 
  2143 
  2111     enum { CHOOSE_NEITHER, CHOOSE_LEFT, CHOOSE_RIGHT } choice = CHOOSE_NEITHER;
  2144     enum { CHOOSE_NEITHER, CHOOSE_LEFT, CHOOSE_RIGHT } choice = CHOOSE_NEITHER;
  2112     if ((l < STATICARRAYLEN(typeinf)) && (r < STATICARRAYLEN(typeinf)))
  2145     if ((l < STATICARRAYLEN(typeinf)) && (r < STATICARRAYLEN(typeinf)))
  2113     {
  2146     {
  2114         if (left == NULL)
  2147         if (left == NULL)
  2115             choice = CHOOSE_LEFT;  // we need to force to the lvalue.
  2148             choice = CHOOSE_LEFT;  // we need to force to the lvalue.
       
  2149         else if (lmatrix && !rmatrix)
       
  2150             choice = CHOOSE_LEFT;
       
  2151         else if (!lmatrix && rmatrix)
       
  2152             choice = CHOOSE_RIGHT;
       
  2153         else if (lvector && !rvector)
       
  2154             choice = CHOOSE_LEFT;
       
  2155         else if (!lvector && rvector)
       
  2156             choice = CHOOSE_RIGHT;
  2116         else if (typeinf[l].bits > typeinf[r].bits)
  2157         else if (typeinf[l].bits > typeinf[r].bits)
  2117             choice = CHOOSE_LEFT;
  2158             choice = CHOOSE_LEFT;
  2118         else if (typeinf[l].bits < typeinf[r].bits)
  2159         else if (typeinf[l].bits < typeinf[r].bits)
  2119             choice = CHOOSE_RIGHT;
  2160             choice = CHOOSE_RIGHT;
  2120         else if (typeinf[l].floating && !typeinf[r].floating)
  2161         else if (typeinf[l].floating && !typeinf[r].floating)