2003/10/31 10:57:24
[org.ibex.core.git] / src / org / xwt / js / Parser.java
index cf0fdec..7360876 100644 (file)
@@ -248,12 +248,13 @@ class Parser extends Lexer implements ByteCodes {
             b2.add(parserLine, PUT);
 
             while(peekToken() != RP) {                                    // run through the list of argument names
+                numArgs++;
                 if (peekToken() == NAME) {
                     consume(NAME);                                        // a named argument
                     String varName = string;
                     
                     b2.add(parserLine, DUP);                              // dup the args array 
-                    b2.add(parserLine, GET, new Integer(numArgs));   // retrieve it from the arguments array
+                    b2.add(parserLine, GET, new Integer(numArgs - 1));   // retrieve it from the arguments array
                     b2.add(parserLine, TOPSCOPE);
                     b2.add(parserLine, SWAP);
                     b2.add(parserLine, DECLARE, varName);                  // declare the name
@@ -264,10 +265,10 @@ class Parser extends Lexer implements ByteCodes {
                 }
                 if (peekToken() == RP) break;
                 consume(COMMA);
-                numArgs++;
             }
             consume(RP);
 
+            b2.numFormalArgs = numArgs;
             b2.add(parserLine, POP);                                      // pop off the arguments array
             b2.add(parserLine, POP);                                      // pop off TOPSCOPE
             
@@ -309,14 +310,19 @@ class Parser extends Lexer implements ByteCodes {
             tok = -1;
         switch(tok) {
         case ASSIGN_BITOR: case ASSIGN_BITXOR: case ASSIGN_BITAND: case ASSIGN_LSH: case ASSIGN_RSH: case ASSIGN_URSH:
-        case ASSIGN_ADD: case ASSIGN_SUB: case ASSIGN_MUL: case ASSIGN_DIV: case ASSIGN_MOD: {
+        case ASSIGN_MUL: case ASSIGN_DIV: case ASSIGN_MOD: case ASSIGN_ADD: case ASSIGN_SUB: {
             b.add(parserLine, GET_PRESERVE);
             startExpr(b,  precedence[tok]);
+            int size = b.size();
+            if (tok == ASSIGN_ADD || tok == ASSIGN_SUB) {
+                b.add(parserLine, tok);
+            }
             // tok-1 is always s/^ASSIGN_// (0 is BITOR, 1 is ASSIGN_BITOR, etc) 
             b.add(parserLine, tok - 1, tok-1==ADD ? new Integer(2) : null);
             b.add(parserLine, PUT);
             b.add(parserLine, SWAP);
             b.add(parserLine, POP);
+            if (tok == ASSIGN_ADD || tok == ASSIGN_SUB) b.set(size, tok, new Integer(b.size() - size));
             break;
         }
         case INC: case DEC: { // postfix
@@ -408,7 +414,12 @@ class Parser extends Lexer implements ByteCodes {
             break;
         }
         case DOT: {
-            consume(NAME);
+            // support foo..bar syntax for foo[""].bar
+            if (peekToken() == DOT) {
+                string = "";
+            } else {
+                consume(NAME);
+            }
             b.add(parserLine, LITERAL, string);
             continueExprAfterAssignable(b,minPrecedence);
             break;