2003/06/09 03:13:18
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:00:57 +0000 (07:00 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:00:57 +0000 (07:00 +0000)
darcs-hash:20040130070057-2ba56-67b417ce5f450471eaf95c4bad2f9226d79a0046.gz

src/org/xwt/js/ByteCodeBlock.java
src/org/xwt/js/JS.java
src/org/xwt/js/Parser.java

index 057a3ca..2da760d 100644 (file)
@@ -40,7 +40,9 @@ public class ByteCodeBlock implements ByteCodes, Tokens {
     }
         
     public Object eval(final JS.Scope s, Vec t) throws ControlTransferException {
-        for(int i=0; i<size; i++) switch(op[i]) {
+
+        for(int i=0; i<size; i++) {
+           switch(op[i]) {
             case LABEL: break;
             case LITERAL: t.push(arg[i]); break;
             case OBJECT: t.push(new JS.Obj()); break;
@@ -107,7 +109,7 @@ public class ByteCodeBlock implements ByteCodes, Tokens {
                 Object key = t.pop();
                 JS target = (JS)t.peek();
                 if (target == null)
-                   throw new EvaluatorException(line, sourceName, "tried to put a value to the " + key + " property on the null value");
+                   throw new JS.Exn("tried to put a value to the " + key + " property on the null value");
                 target.put(key, val);
                 t.push(val);
                 break;
@@ -134,7 +136,7 @@ public class ByteCodeBlock implements ByteCodes, Tokens {
                 arguments.setSize(numArgs);
                 for(int j=numArgs - 1; j >= 0; j--) arguments.setElementAt(t.pop(), j);
                 JS.Function f = (JS.Function)t.pop();
-                if (f == null) throw new JS.Exn(new EvaluatorException(line, sourceName, "attempted to call null"));
+                if (f == null) throw new JS.Exn("attempted to call null");
                 t.push(f.call(arguments));
                 break;
             }
@@ -205,14 +207,14 @@ public class ByteCodeBlock implements ByteCodes, Tokens {
                 default: throw new Error("unknown opcode " + op[i]);
                 } }
             }
-       System.out.println("returning");
+       }
         if (t.size() != 1) throw new Error("eval() terminated with " + t.size() + " elements on the stack; one expected");
         return t.pop();
     }
 
     public Object doGet(final Object o, final Object v) {
         if (o == null)
-            throw new EvaluatorException(line, sourceName, "tried to get property \"" + v + "\" from the null value");
+            throw new JS.Exn("tried to get property \"" + v + "\" from the null value");
         if (o instanceof String) {
             if (v.equals("length")) return new Integer(((String)o).length());
             else if (v.equals("substring")) return new JS.Function() {
index 6c9448d..b0d54e5 100644 (file)
@@ -73,7 +73,7 @@ public abstract class JS {
     public static class Exn extends RuntimeException { 
        private Object js = null; 
        public Exn(Object js) { this.js = js; } 
-       public String toString() { return "JS.Exn: " + js.toString(); }
+       public String toString() { return "JS.Exn: " + js; }
        public String getMessage() { return toString(); }
        public Object getObject() { return js; } 
     } 
index cd665f2..addf0f0 100644 (file)
@@ -135,8 +135,7 @@ class Parser extends Lexer implements ByteCodes {
        }
        case LC: {
            b.add(OBJECT, null);
-           if (peekToken() == RC) { consume(RC); continueExpr(b, minPrecedence); return; }
-           while(true) {
+           if (peekToken() != RC) while(true) {
                if (peekToken() != NAME && peekToken() != STRING) throw new Error("expected NAME or STRING");
                getToken();
                b.add(LITERAL, string);
@@ -144,10 +143,13 @@ class Parser extends Lexer implements ByteCodes {
                startExpr(b);
                b.add(PUT);
                b.add(POP);
-               if (peekToken() == RC) { consume(RC); continueExpr(b, minPrecedence); return; }
+               if (peekToken() == RC) break;
                consume(COMMA);
-               if (peekToken() == RC) { consume(RC); continueExpr(b, minPrecedence); return; }
+               if (peekToken() == RC) break;
            }
+           consume(RC);
+           continueExpr(b, minPrecedence);
+           return;
        }
        case NAME: {
            String name = string;
@@ -262,8 +264,8 @@ class Parser extends Lexer implements ByteCodes {
            // invocation
            int i = 0;
            while(peekToken() != RP) {
-               startExpr(b);
                i++;
+               startExpr(b);
                if (peekToken() == RP) break;
                consume(COMMA);
            }