2003/11/16 02:40:44
[org.ibex.core.git] / src / org / xwt / js / Parser.java
index b3c1742..4b288a8 100644 (file)
@@ -204,7 +204,7 @@ class Parser extends Lexer implements ByteCodes {
                 throw pe("prefixed increment/decrement can only be performed on a valid assignment target");
             b.add(parserLine, GET_PRESERVE, Boolean.TRUE);
             b.add(parserLine, LITERAL, new Integer(1));
-            b.add(parserLine, tok == INC ? ADD : SUB, null);
+            b.add(parserLine, tok == INC ? ADD : SUB, new Integer(2));
             b.add(parserLine, PUT, null);
             b.add(parserLine, SWAP, null);
             b.add(parserLine, POP, null);
@@ -334,7 +334,7 @@ class Parser extends Lexer implements ByteCodes {
         case INC: case DEC: { // postfix
             b.add(parserLine, GET_PRESERVE, Boolean.TRUE);
             b.add(parserLine, LITERAL, new Integer(1));
-            b.add(parserLine, tok == INC ? ADD : SUB, null);
+            b.add(parserLine, tok == INC ? ADD : SUB, new Integer(2));
             b.add(parserLine, PUT, null);
             b.add(parserLine, SWAP, null);
             b.add(parserLine, POP, null);
@@ -350,12 +350,9 @@ class Parser extends Lexer implements ByteCodes {
             break;
         }
         case LP: {
-            int n = parseArgs(b);
-
-            // if the object supports CALLMETHOD, we use this, and jump over the following two instructions
-            b.add(parserLine,CALLMETHOD,new Integer(n));
-            b.add(parserLine,GET);
-            b.add(parserLine,CALL,new Integer(n));
+            int n = parseArgs(b, 2);
+            b.add(parserLine, GET_PRESERVE);
+            b.add(parserLine, CALLMETHOD, new Integer(n));
             break;
         }
         default: {
@@ -397,7 +394,7 @@ class Parser extends Lexer implements ByteCodes {
 
         switch (tok) {
         case LP: {  // invocation (not grouping)
-            int n = parseArgs(b);
+            int n = parseArgs(b, 1);
             b.add(parserLine, CALL, new Integer(n));
             break;
         }
@@ -476,13 +473,13 @@ class Parser extends Lexer implements ByteCodes {
     
     // parse a set of comma separated function arguments, assume LP has already been consumed
     // if swap is true, (because the function is already on the stack) we will SWAP after each argument to keep it on top
-    private int parseArgs(JSFunction b) throws IOException {
+    private int parseArgs(JSFunction b, int pushdown) throws IOException {
         int i = 0;
         while(peekToken() != RP) {
             i++;
             if (peekToken() != COMMA) {
                 startExpr(b, NO_COMMA);
-                b.add(parserLine, SWAP, new Integer(2));
+                b.add(parserLine, SWAP, new Integer(pushdown));
                 if (peekToken() == RP) break;
             }
             consume(COMMA);