Changeset 150

Show
Ignore:
Timestamp:
11/29/07 03:11:11 (4 years ago)
Author:
Don Clugston
Message:

Strided array accesses are now parsed OK, and dimensionality errors are detected. (But there's no codegen support yet).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/blade/BladeDemo.d

    r148 r150  
    3434    //mixin(vectorize("dot(q,q*dot(q,q))"));     
    3535    // should simplify to: dot(q.q) * dot(q,q) 
    36 /*     
     36    
    3737    mixin(vectorize(` a += (d[2..$-1]*2.01*a[2]-another[][1])["abc".length-3..$]`)); 
    3838     
    3939    mixin(vectorize(" a-= 2.01*(        3.04+k)*r")); 
    4040    mixin(vectorize("q+= q*2.01")); 
    41 */     
    42 //    mixin(vectorize("a+=d[2,[1,$]]")); 
     41   
     42    // This parses OK, but isn't get supported at the codegen step.   
     43//    mixin(vectorize("a+=another[1,[1,$]]")); 
    4344    writefln("a=", a); 
    4445} 
  • trunk/blade/BladeRank.d

    r148 r150  
    11//  Written in the D programming language 1.0 
     2//  Part of BLADE : Basic Linear Algebra D Expressions 
    23/** 
    3 * Part of BLADE : Basic Linear Algebra D Expressions 
     4* Determine the tensor rank of an expression. 
    45* 
    56*/ 
     
    100101    RankMismatch = -8, 
    101102    RankMismatchConcatenation = -9, 
    102     RankMismatchDotProduct = -10 
     103    RankMismatchDotProduct = -10, 
     104    ExtraCharsAfterArrayLiteral = -11, 
     105    ArrayLiteralRankMismatch = -12 
    103106} 
    104107 
     
    114117            "Dimensionality mismatch (addition or subtraction)", 
    115118            "Dimensionality mismatch in concatenation", 
    116             "Dimenionality error in dot product"][-err-1]; 
     119            "Dimenionality error in dot product" 
     120            "Extra characters after array literal" 
     121            "Rank mismatch in array literal" 
     122            ][-err-1]; 
    117123} 
    118124 
     
    153159    // Deal with unary operators 
    154160    if (expr[0]=='+' || expr[0]=='-') return subexprRank(expr[1..$], rank); 
    155 //    if (expr[0]=='~' || expr[0]=='*') { return 0; } 
    156161     
    157162    int x = exprLength(expr); 
     163    if (expr[0]=='[') { // array literal 
     164        if (x!=expr.length-1) return RankError.ExtraCharsAfterArrayLiteral; 
     165        expr = expr[1..$-1]; 
     166        x = exprLength(expr); 
     167        int lrank = subexprRank(expr[0..x+1], rank); 
     168        while (x<expr.length-1) { 
     169            if (expr[x+1]!=',') return RankError.CommaExpected; 
     170            expr = expr[x+2.. $]; 
     171            x = exprLength(expr); 
     172            int rrank = subexprRank(expr[0..x+1], rank); 
     173            if (lrank!=rrank) return RankError.ArrayLiteralRankMismatch; 
     174        } 
     175        return lrank+1; 
     176    } 
    158177    int y = x+1; 
    159178    // Deal with shifts, op=, and NCEG operators 
     
    163182    char [] left = expr[0..x+1]; 
    164183    char [] right = expr[y+1..$]; 
    165     if (expr[0]=='[') { // array literal 
    166         assert(0, expr); 
    167     } 
    168184    if (expr[x+1]=='[') right = expr[y+1..$-1]; // drop off the ']'. 
    169185    int lrank = subexprRank(left, rank); 
     
    185201                // allow rank of 1 to be a slice operation 
    186202                // (so A[1,[2,$-1], $] is possible). 
     203//                if (z>1) assert(0, right[0..z+1]); 
    187204                int rrank = subexprRank(right[0..z+1], rank); 
    188205                if (rrank<0) return rrank; 
    189206                if (rrank>1) return RankError.NonScalarIndex; 
    190207                if (rrank==0) --totrank; 
    191                 if (rrank==1) assert(0, right); 
    192                  
     208                                 
    193209                if (z==right.length-1) return totrank; 
    194210                right = right[z+2..$]; 
     
    239255 
    240256unittest {     
    241 //    assert(exprRank("A[B,[B,C],B]", "600")==4); 
    242 //    const y = exprRank("A+=(B[C,$])", "1100"); 
    243257    assert(exprRank("A+((((++B)+D)--)*C)", "1010")==1); 
    244258    assert(exprRank("A+(B*C)", "000")==0); 
     
    255269    assert(exprRank("d(A)", "1")==RankError.CommaExpected); 
    256270    assert(exprRank("d(A,B)", "10")==RankError.RankMismatchDotProduct); 
    257     assert(exprRank("d(B,(A*(d(B,B))))", "11")==0); 
    258      
    259     assert(exprRank("A[B,B,B]", "6034")==3); 
    260 
    261  
    262 // Return true if the entire expression contains a multiplucation by a scalar 
     271    assert(exprRank("d(B,(A*(d(B,B))))", "11")==0);     
     272    assert(exprRank("A[B,B,B]", "60")==3); 
     273    assert(exprRank("A[B,B,C,B]", "600")==2); 
     274    assert(exprRank("A[B,([B,C]),B]", "600")==4); 
     275    assert(exprRank("A[B,(([B,C])[B]),B]", "600")==3); 
     276    assert(exprRank("A+=(B[C..$])", "110")==1); 
     277
     278 
     279// Return true if the entire expression contains a multiplication by a scalar 
    263280bool hasScalarMultiply(char [] expr, char [] rank) 
    264281{ 
  • trunk/blade/BladeSimplify.d

    r148 r150  
    6161    else { 
    6262        char [] expr2 = removeDuplicates(tree); 
    63         assert(0, ranks); 
    6463        // Check for rank errors 
    6564        int wholerank = exprRank(expr2, ranks); 
  • trunk/blade/BladeUtil.d

    r145 r150  
    11//  Written in the D programming language 1.0 
    22/** 
    3 * General CTFE string utility functions 
     3* General CTFE functions 
    44* BLADE 0.3Alpha -- Basic Linear Algebra D Expressions 
    55*/ 
     
    4242    for(int i=0; i<instr.length; ++i) { 
    4343        if (instr[i]=='"' || instr[i]=='\\') { 
    44             char [] str=instr[0..i] ~ escape; 
     44            char [] str = instr[0..i] ~ escape; 
    4545            int m = i; 
    4646            foreach(int k, char c; instr[i+1..$]) { 
  • trunk/blade/SyntaxTree.d

    r149 r150  
    344344//  ==== SEMANTIC PASS ==== 
    345345 
    346 // Returns typeof(sym).stringof, with workarounds for compiler bugs 
     346// Returns typeof(sym).stringof. 
    347347char [] mixin_typeOf(char [] sym) 
    348348{ 
    349     // typeof(x).stringof doesn't compile if x is a function. 
    350     // If it doesn't compile at all, return an empty string. 
     349    // If sym is a function, we take its address, since 
     350    //   typeof(x).stringof doesn't compile if x is a function. 
     351    // If sym doesn't compile at all, return an empty string. 
    351352    return `mixin(!is(typeof(` ~ sym ~ `))?"\"\"" : is(typeof(` ~ sym ~ `)==function)?"` ~ enquote("typeof(&" ~ sym ~ ").stringof")~`":"` ~ enquote("typeof(" ~ sym ~ ").stringof") ~ `")`; 
    352353}