2003/06/07 09:37:13
[org.ibex.core.git] / src / org / xwt / js / ForthBlock.java
index 43607be..0cc4ed2 100644 (file)
@@ -39,7 +39,7 @@ class ForthBlock implements OpCodes, Tokens {
            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 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 +48,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());
@@ -101,7 +101,9 @@ class ForthBlock implements OpCodes, Tokens {
            case PUT: {
                Object val = t.pop();
                Object key = t.pop();
-               ((JS)t.peek()).put(key, val);
+               JS target = (JS)t.peek();
+               if (target == null) 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;
            }
@@ -137,6 +139,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 +238,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() {