2003/06/07 08:21:30
[org.ibex.core.git] / src / org / xwt / js / ForthBlock.java
index 43607be..f1f1e0a 100644 (file)
@@ -38,8 +38,15 @@ class ForthBlock implements OpCodes, Tokens {
            case LITERAL: t.push(arg[i]); break;
            case OBJECT: t.push(new JS.Obj()); break;
            case ARRAY: t.push(new JS.Array(JS.toNumber(arg[i]).intValue())); break;
-           case DECLARE: s.declare((String)t.pop()); break;
-           case OpCodes.THIS: t.push(s); break;   // FIXME: transparents
+           case DECLARE: {
+               String st = (String)t.pop();
+               if (st.equals("sel")) {
+                   System.out.println("**** SEL!");
+                   for(int j=0; j<4; j++) System.out.println(op[i+j] + " " + arg[i+j]);
+               }
+               s.declare(st); break;
+           }
+           case THIS: t.push(s); break;   // FIXME: transparents
            case JT: if (JS.toBoolean(t.pop())) i += JS.toNumber(arg[i]).intValue() - 1; break;
            case JF: if (!JS.toBoolean(t.pop())) i += JS.toNumber(arg[i]).intValue() - 1; break;
            case JMP: i += JS.toNumber(arg[i]).intValue() - 1; break;
@@ -48,7 +55,7 @@ class ForthBlock implements OpCodes, Tokens {
            case DUP: t.push(t.peek()); break;
            case NOP: break;
            case EXPR: t.push(((ForthBlock)arg[i]).eval(s)); break;
-           case SCOPE: t.push(((ForthBlock)arg[i]).eval(new JS.Scope(s), t)); break;
+           case SCOPE: t.push(((ForthBlock)arg[i]).eval(new JS.Scope(s))); break;
 
            case ASSERT: if (!JS.toBoolean(t.pop())) throw new EvaluatorException(line, sourceName, "assertion failed"); break;
            case RETURN: throw new ReturnException(t.pop());
@@ -137,6 +144,7 @@ class ForthBlock implements OpCodes, Tokens {
                t.push(new JS.Function() {
                        public String toString() { return sourceName + ":" + line; }
                        public String getSourceName() throws JS.Exn { return sourceName; }
+                       public int getLine() throws JS.Exn { return line; }
                        public Object _call(final JS.Array args) throws JS.Exn {
                            Function save = JS.getCurrentFunction();
                            JS.currentFunction.put(java.lang.Thread.currentThread(), this);
@@ -235,13 +243,18 @@ class ForthBlock implements OpCodes, Tokens {
                } }
            }
        if (t.size() != 1) {
+           for(int i=0; i<size; i++) {
+               System.out.println((op[i] >= 0 ? codeToString[op[i]] : "" + op[i]) + " [" + arg[i] + "]");
+           }
            throw new EvaluatorException(line, sourceName, "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");
+       if (o == null) {
+           throw new EvaluatorException(line, sourceName, "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() {