renamed Script to JSU
authoradam <adam@megacz.com>
Fri, 7 Jan 2005 04:04:02 +0000 (04:04 +0000)
committeradam <adam@megacz.com>
Fri, 7 Jan 2005 04:04:02 +0000 (04:04 +0000)
darcs-hash:20050107040402-5007d-42d23a4ebcfbe5753cdd2f4a9847536f046d0451.gz

17 files changed:
src/org/ibex/js/Directory.java
src/org/ibex/js/Interpreter.java
src/org/ibex/js/JS.java
src/org/ibex/js/JSArray.java
src/org/ibex/js/JSDate.java
src/org/ibex/js/JSExn.java
src/org/ibex/js/JSFunction.java
src/org/ibex/js/JSMath.java
src/org/ibex/js/JSPrimitive.java
src/org/ibex/js/JSReflection.java
src/org/ibex/js/JSRegexp.java
src/org/ibex/js/JSScope.java
src/org/ibex/js/JSU.java [moved from src/org/ibex/js/Script.java with 99% similarity]
src/org/ibex/js/Parser.java
src/org/ibex/js/SOAP.java
src/org/ibex/js/Test.java
src/org/ibex/js/XMLRPC.java

index 0c0fc73..9bcc7f6 100644 (file)
@@ -65,14 +65,14 @@ public class Directory extends JS.Immutable {
     public void put(JS key0, JS val) throws JSExn {
         try {
             if (key0 == null) return;
-            String key = Script.toString(key0);
+            String key = JSU.toString(key0);
             File f2 = new File(f.getAbsolutePath() + File.separatorChar + Encode.toFilename(key));
             destroy(f2);
             if (val == null) return;
             if (val instanceof JSPrimitive) {
                 OutputStream out = new FileOutputStream(f2);
                 Writer w = new OutputStreamWriter(out);
-                w.write(Script.toString(val));
+                w.write(JSU.toString(val));
                 w.flush();
                 out.close();
             } else {
@@ -92,7 +92,7 @@ public class Directory extends JS.Immutable {
     public JS get(JS key0) throws JSExn {
         try {
             if (key0 == null) return null;
-            String key = Script.toString(key0);
+            String key = JSU.toString(key0);
             File f2 = new File(f.getAbsolutePath() + File.separatorChar + Encode.toFilename(key));
             if (!f2.exists()) return null;
             if (f2.isDirectory()) return new Directory(f2);
@@ -101,7 +101,7 @@ public class Directory extends JS.Immutable {
             Reader r = new InputStreamReader(new FileInputStream(f2));
             while(true) {
                 int numread = r.read(chars, numchars, chars.length - numchars);
-                if (numread == -1) return Script.S(new String(chars, 0, numchars));
+                if (numread == -1) return JSU.S(new String(chars, 0, numchars));
                 numchars += numread;
             }
         } catch (IOException ioe) {
@@ -114,7 +114,7 @@ public class Directory extends JS.Immutable {
         return new JS.Enumeration(null) {
                 int i = 0;
                 public boolean _hasNext() { return i < elements.length; }
-                public JS _next() { return Script.S(Encode.fromFilename(elements[i++])); }
+                public JS _next() { return JSU.S(Encode.fromFilename(elements[i++])); }
             };
     }
 }
index b0eb602..693ad9c 100644 (file)
@@ -107,16 +107,16 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
             switch(op) {
             case LITERAL: stack.push((JS)arg); break;
             case OBJECT: stack.push(new JS.Obj()); break;
-            case ARRAY: stack.push(new JSArray(Script.toInt((JS)arg))); break;
+            case ARRAY: stack.push(new JSArray(JSU.toInt((JS)arg))); break;
             //case DECLARE: scope.declare((JS)(arg==null ? stack.peek() : arg)); if(arg != null) stack.push((JS)arg); break;
-            case JT: if (Script.toBoolean((JS)stack.pop())) pc += Script.toInt((JS)arg) - 1; break;
-            case JF: if (!Script.toBoolean((JS)stack.pop())) pc += Script.toInt((JS)arg) - 1; break;
-            case JMP: pc += Script.toInt((JS)arg) - 1; break;
+            case JT: if (JSU.toBoolean((JS)stack.pop())) pc += JSU.toInt((JS)arg) - 1; break;
+            case JF: if (!JSU.toBoolean((JS)stack.pop())) pc += JSU.toInt((JS)arg) - 1; break;
+            case JMP: pc += JSU.toInt((JS)arg) - 1; break;
             case POP: stack.pop(); break;
             case SWAP: stack.swap(); break;
             case DUP: stack.push(stack.peek()); break;
             case NEWSCOPE: {
-                int n = Script.toInt((JS)arg);
+                int n = JSU.toInt((JS)arg);
                 scope = new JSScope(scope,(n>>>16)&0xffff,(n>>>0)&0xffff);
                 break;
             }
@@ -124,19 +124,19 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
             case GLOBALSCOPE: stack.push(scope.getGlobal()); break;
             case SCOPEGET: stack.push(scope.get((JS)arg)); break;
             case SCOPEPUT: scope.put((JS)arg, (JS)stack.peek()); break;
-            case ASSERT: if (!Script.toBoolean((JS)stack.pop())) throw je("ibex.assertion.failed"); break;
-            case BITNOT: stack.push(Script.N(~Script.toLong((JS)stack.pop()))); break;
-            case BANG: stack.push(Script.B(!Script.toBoolean((JS)stack.pop()))); break;
+            case ASSERT: if (!JSU.toBoolean((JS)stack.pop())) throw je("ibex.assertion.failed"); break;
+            case BITNOT: stack.push(JSU.N(~JSU.toLong((JS)stack.pop()))); break;
+            case BANG: stack.push(JSU.B(!JSU.toBoolean((JS)stack.pop()))); break;
             case NEWFUNCTION: stack.push(((JSFunction)arg)._cloneWithNewParentScope(scope)); break;
             case LABEL: break;
 
             case TYPEOF: {
                 Object o = stack.pop();
                 if (o == null) stack.push(null);
-                else if (o instanceof JSString) stack.push(Script.S("string"));
-                else if (o instanceof JSNumber.B) stack.push(Script.S("boolean"));
-                else if (o instanceof JSNumber) stack.push(Script.S("number"));
-                else stack.push(Script.S("object"));
+                else if (o instanceof JSString) stack.push(JSU.S("string"));
+                else if (o instanceof JSNumber.B) stack.push(JSU.S("boolean"));
+                else if (o instanceof JSNumber) stack.push(JSU.S("number"));
+                else stack.push(JSU.S("object"));
                 break;
             }
 
@@ -148,7 +148,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
 
             case LOOP:
                 stack.push(new LoopMarker(pc, (String)(pc > 0 && f.op[pc - 1] == LABEL ? f.arg[pc - 1] : null), scope));
-                stack.push(Script.T);
+                stack.push(JSU.T);
                 break;
 
             case BREAK:
@@ -166,9 +166,9 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                     if (o instanceof LoopMarker) {
                         if (arg == null || arg.equals(((LoopMarker)o).label)) {
                             int loopInstructionLocation = ((LoopMarker)o).location;
-                            int endOfLoop = Script.toInt((JS)f.arg[loopInstructionLocation]) + loopInstructionLocation;
+                            int endOfLoop = JSU.toInt((JS)f.arg[loopInstructionLocation]) + loopInstructionLocation;
                             scope = ((LoopMarker)o).scope;
-                            if (op == CONTINUE) { stack.push(o); stack.push(Script.F); }
+                            if (op == CONTINUE) { stack.push(o); stack.push(JSU.F); }
                             pc = op == BREAK ? endOfLoop - 1 : loopInstructionLocation;
                             continue OUTER;
                         }
@@ -200,7 +200,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                         boolean didTrapPut = false;
                         if (o instanceof TrapMarker) { // handles return component of a write trap
                             TrapMarker tm = (TrapMarker) o;
-                            boolean cascade = tm.t.isWriteTrap() && !tm.cascadeHappened && !Script.toBoolean(retval);
+                            boolean cascade = tm.t.isWriteTrap() && !tm.cascadeHappened && !JSU.toBoolean(retval);
                             if(cascade) {
                                 JS.Trap t = tm.t.nextWrite();
                                 if(t == null && tm.t.target() instanceof JS.Clone) {
@@ -236,7 +236,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
             }
                 
             case CASCADE: {
-                boolean write = Script.toBoolean((JS)arg);
+                boolean write = JSU.toBoolean((JS)arg);
                 JS val = write ? (JS)stack.pop() : null;
                 CallMarker o = stack.findCall();
                 if(!(o instanceof TrapMarker)) throw new JSExn("tried to CASCADE while not in a trap");
@@ -276,8 +276,8 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                 JS val = (JS)stack.pop();
                 JS key = (JS)stack.pop();
                 JS target = (JS)stack.peek();
-                if (target == null) throw je("tried to put " + Script.str(val) + " to the " + Script.str(key) + " property on the null value");
-                if (key == null) throw je("tried to assign \"" + Script.str(val) + "\" to the null key");
+                if (target == null) throw je("tried to put " + JSU.str(val) + " to the " + JSU.str(key) + " property on the null value");
+                if (key == null) throw je("tried to assign \"" + JSU.str(val) + "\" to the null key");
                 
                 JS.Trap t = target.getTrap(key);
                 if(t != null) t = t.write();
@@ -312,8 +312,8 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                     stack.push(key);
                 }
                 JS ret = null;
-                if (key == null) throw je("tried to get the null key from " + Script.str(target));
-                if (target == null) throw je("tried to get property \"" + Script.str(key) + "\" from the null object");
+                if (key == null) throw je("tried to get the null key from " + JSU.str(target));
+                if (target == null) throw je("tried to get property \"" + JSU.str(key) + "\" from the null object");
                 
                 JS.Trap t = target.getTrap(key);
                 if(t != null) t = t.read();
@@ -354,7 +354,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                     if (object == null) {
                         method = (JS)stack.pop();
                         object = (JS)stack.pop();
-                        throw new JSExn("function '"+Script.str(method)+"' not found in " + object.getClass().getName());
+                        throw new JSExn("function '"+JSU.str(method)+"' not found in " + object.getClass().getName());
                     } else if (object instanceof JS.Method) {
                         method = (JS)stack.pop();
                         object = (JS)stack.pop();
@@ -427,13 +427,13 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                     JS left = (JS)stack.pop();
                     JS ret;
                     if(left instanceof JSString || right instanceof JSString)
-                        ret = Script.S(Script.toString(left).concat(Script.toString(right)));
+                        ret = JSU.S(JSU.toString(left).concat(JSU.toString(right)));
                     else if(left instanceof JSNumber.D || right instanceof JSNumber.D)
-                        ret = Script.N(Script.toDouble(left) + Script.toDouble(right));
+                        ret = JSU.N(JSU.toDouble(left) + JSU.toDouble(right));
                     else {
-                        long l = Script.toLong(left) + Script.toLong(right);
-                        if(l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) ret = Script.N(l);
-                        ret = Script.N((int)l);
+                        long l = JSU.toLong(left) + JSU.toLong(right);
+                        if(l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) ret = JSU.N(l);
+                        ret = JSU.N((int)l);
                     }
                     stack.push(ret);
                 } else {
@@ -441,27 +441,27 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                     while(--count >= 0) args[count] = (JS)stack.pop();
                     if(args[0] instanceof JSString) {
                         StringBuffer sb = new StringBuffer(64);
-                        for(int i=0;i<args.length;i++) sb.append(Script.toString(args[i]));
-                        stack.push(Script.S(sb.toString()));
+                        for(int i=0;i<args.length;i++) sb.append(JSU.toString(args[i]));
+                        stack.push(JSU.S(sb.toString()));
                     } else {
                         int numStrings = 0;
                         for(int i=0;i<args.length;i++) if(args[i] instanceof JSString) numStrings++;
                         if(numStrings == 0) {
                             double d = 0.0;
-                            for(int i=0;i<args.length;i++) d += Script.toDouble(args[i]);
-                            stack.push(Script.N(d));
+                            for(int i=0;i<args.length;i++) d += JSU.toDouble(args[i]);
+                            stack.push(JSU.N(d));
                         } else {
                             int i=0;
                             StringBuffer sb = new StringBuffer(64);
                             if(!(args[0] instanceof JSString || args[1] instanceof JSString)) {
                                 double d=0.0;
                                 do {
-                                    d += Script.toDouble(args[i++]);
+                                    d += JSU.toDouble(args[i++]);
                                 } while(!(args[i] instanceof JSString));
-                                sb.append(Script.toString(Script.N(d)));
+                                sb.append(JSU.toString(JSU.N(d)));
                             }
-                            while(i < args.length) sb.append(Script.toString(args[i++]));
-                            stack.push(Script.S(sb.toString()));
+                            while(i < args.length) sb.append(JSU.toString(args[i++]));
+                            stack.push(JSU.S(sb.toString()));
                         }
                     }
                 }
@@ -473,25 +473,25 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                 JS left = (JS)stack.pop();
                 switch(op) {
                         
-                case BITOR: stack.push(Script.N(Script.toLong(left) | Script.toLong(right))); break;
-                case BITXOR: stack.push(Script.N(Script.toLong(left) ^ Script.toLong(right))); break;
-                case BITAND: stack.push(Script.N(Script.toLong(left) & Script.toLong(right))); break;
-
-                case SUB: stack.push(Script.N(Script.toDouble(left) - Script.toDouble(right))); break;
-                case MUL: stack.push(Script.N(Script.toDouble(left) * Script.toDouble(right))); break;
-                case DIV: stack.push(Script.N(Script.toDouble(left) / Script.toDouble(right))); break;
-                case MOD: stack.push(Script.N(Script.toDouble(left) % Script.toDouble(right))); break;
+                case BITOR: stack.push(JSU.N(JSU.toLong(left) | JSU.toLong(right))); break;
+                case BITXOR: stack.push(JSU.N(JSU.toLong(left) ^ JSU.toLong(right))); break;
+                case BITAND: stack.push(JSU.N(JSU.toLong(left) & JSU.toLong(right))); break;
+
+                case SUB: stack.push(JSU.N(JSU.toDouble(left) - JSU.toDouble(right))); break;
+                case MUL: stack.push(JSU.N(JSU.toDouble(left) * JSU.toDouble(right))); break;
+                case DIV: stack.push(JSU.N(JSU.toDouble(left) / JSU.toDouble(right))); break;
+                case MOD: stack.push(JSU.N(JSU.toDouble(left) % JSU.toDouble(right))); break;
                         
-                case LSH: stack.push(Script.N(Script.toLong(left) << Script.toLong(right))); break;
-                case RSH: stack.push(Script.N(Script.toLong(left) >> Script.toLong(right))); break;
-                case URSH: stack.push(Script.N(Script.toLong(left) >>> Script.toLong(right))); break;
+                case LSH: stack.push(JSU.N(JSU.toLong(left) << JSU.toLong(right))); break;
+                case RSH: stack.push(JSU.N(JSU.toLong(left) >> JSU.toLong(right))); break;
+                case URSH: stack.push(JSU.N(JSU.toLong(left) >>> JSU.toLong(right))); break;
                         
                 //#repeat </<=/>/>= LT/LE/GT/GE
                 case LT: {
                     if(left instanceof JSString && right instanceof JSString)
-                        stack.push(Script.B(Script.toString(left).compareTo(Script.toString(right)) < 0));
+                        stack.push(JSU.B(JSU.toString(left).compareTo(JSU.toString(right)) < 0));
                     else
-                        stack.push(Script.B(Script.toDouble(left) < Script.toDouble(right)));
+                        stack.push(JSU.B(JSU.toDouble(left) < JSU.toDouble(right)));
                 }
                 //#end
                     
@@ -501,7 +501,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                     if(left == null && right == null) ret = true;
                     else if(left == null || right == null) ret = false;
                     else ret = left.equals(right);
-                    stack.push(Script.B(op == EQ ? ret : !ret)); break;
+                    stack.push(JSU.B(op == EQ ? ret : !ret)); break;
                 }
 
                 default: throw new Error("unknown opcode " + op);
@@ -626,12 +626,12 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
         private JS val;
         public TrapArgs(Trap t, JS val) { this.t = t; this.val = val; }
         public JS get(JS key) throws JSExn {
-            if(Script.isInt(key) && Script.toInt(key) == 0) return val;
-            //#switch(Script.str(key))
+            if(JSU.isInt(key) && JSU.toInt(key) == 0) return val;
+            //#switch(JSU.str(key))
             case "trapee": return t.target();
             case "callee": return t.function();
             case "trapname": return t.key();
-            case "length": return t.isWriteTrap() ? Script.ONE : Script.ZERO;
+            case "length": return t.isWriteTrap() ? JSU.ONE : JSU.ZERO;
             //#end
             return super.get(key);
         }
@@ -677,7 +677,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable {
                     if(cm.f == null) break;
                     String s = cm.f.sourceName + ":" + cm.f.line[cm.pc-1];
                     if(cm instanceof Interpreter.TrapMarker) 
-                        s += " (trap on " + Script.str(((Interpreter.TrapMarker)cm).t.key()) + ")";
+                        s += " (trap on " + JSU.str(((Interpreter.TrapMarker)cm).t.key()) + ")";
                     e.addBacktrace(s);
                 }
             }
index a6e64a9..096e8f9 100644 (file)
@@ -101,11 +101,11 @@ public interface JS extends Pausable {
         public JS call(JS[] args) throws JSExn { throw new JSExn(
             "object cannot be called, class ["+ getClass().getName() +"]"); }
         public JS call(JS method, JS[] args) throws JSExn { throw new JSExn(
-            "method not found: " + Script.str(method)); }
+            "method not found: " + JSU.str(method)); }
         public String[] getFormalArgs() { return emptystr; }
 
         public void declare(JS key) throws JSExn { throw new JSExn(
-            "object cannot declare key: "+ Script.str(key)); }
+            "object cannot declare key: "+ JSU.str(key)); }
         public void undeclare(JS key) throws JSExn { } // FIXME throw error?
 
         public JS putAndTriggerTraps(JS key, JS val) throws JSExn { throw new JSExn(
@@ -193,7 +193,7 @@ public interface JS extends Pausable {
         public JS call(JS[] args) throws JSExn { throw new JSExn(
             "object cannot be called, class ["+ getClass().getName() +"]"); }
         public JS call(JS method, JS[] args) throws JSExn { throw new JSExn(
-            "method not found: " + Script.str(method)); }
+            "method not found: " + JSU.str(method)); }
         public String[] getFormalArgs() { return emptystr; }
 
         public Enumeration keys() throws JSExn {
@@ -339,8 +339,8 @@ public interface JS extends Pausable {
         }
 
         public JS get(JS key) throws JSExn {
-            //#switch(Script.str(key))
-            case "hasNext": return Script.B(hasNext());
+            //#switch(JSU.str(key))
+            case "hasNext": return JSU.B(hasNext());
             case "next": return next();
             //#end
             return super.get(key);
index ae2478f..8e2fdd2 100644 (file)
@@ -22,12 +22,12 @@ class JSArray extends Basket.Array implements JS, Basket.CompareFunc {
         return new Enumeration(null) {
             private int n = 0;
             public boolean _hasNext() { return n < size(); }
-            public JS _next() { return Script.N(n++); }
+            public JS _next() { return JSU.N(n++); }
         };
     }
     public JS get(JS key) throws JSExn {
         if (key == null || !(key instanceof JSNumber.I)) {
-            //#switch(Script.str(key))
+            //#switch(JSU.str(key))
             case "pop": return METHOD;
             case "reverse": return METHOD;
             case "toString": return METHOD;
@@ -38,17 +38,17 @@ class JSArray extends Basket.Array implements JS, Basket.CompareFunc {
             case "push": return METHOD;
             case "unshift": return METHOD;
             case "splice": return METHOD;
-            case "length": return Script.N(size());
+            case "length": return JSU.N(size());
             //#end
-            throw new JSExn("arrays only support positive integer keys, can not use: "+Script.str(key));
+            throw new JSExn("arrays only support positive integer keys, can not use: "+JSU.str(key));
         }
         return (JS)get(((JSNumber.I)key).toInt());
     }
     public void put(JS key, JS val) throws JSExn {
-        if (Script.str(key).equals("length")) { setSize(Script.toInt(val)); }
+        if (JSU.str(key).equals("length")) { setSize(JSU.toInt(val)); }
 
         if (key == null || !(key instanceof JSNumber.I)) throw new JSExn(
-            "arrays only support positive integer keys, can not use: "+Script.str(key));
+            "arrays only support positive integer keys, can not use: "+JSU.str(key));
         int i = ((JSNumber.I)key).toInt();
         if (i < 0) throw new JSExn("arrays can not use negative integer keys "+i);
         size(i + 1); while (size() < i) add(null);
@@ -69,25 +69,25 @@ class JSArray extends Basket.Array implements JS, Basket.CompareFunc {
     public void pause() throws NotPausableException { throw new NotPausableException(); }
     public JS call(JS[] args) throws JSExn { throw new JSExn("can not call an array as a function"); }
     public JS call(JS method, JS[] args) throws JSExn {
-        //#switch(Script.str(method))
+        //#switch(JSU.str(method))
         case "pop": return size() == 0 ? null : (JS)remove(size() - 1);
-        case "push": addAll(args); return Script.N(size());
+        case "push": addAll(args); return JSU.N(size());
         case "reverse": reverse(); return this;
         case "toString": return join(",");
         case "shift": return size() == 0 ? null : (JS)remove(0);
-        case "join": return join(args.length == 0 ? "," : Script.str(args[0]));
+        case "join": return join(args.length == 0 ? "," : JSU.str(args[0]));
         case "sort": return sort(args.length == 0 ? null : args[0]);
         case "slice":
-            int start = Script.toInt(args.length < 1 ? null : args[0]);
-            int end = args.length < 2 ? size() : Script.toInt(args[1]);
+            int start = JSU.toInt(args.length < 1 ? null : args[0]);
+            int end = args.length < 2 ? size() : JSU.toInt(args[1]);
             return slice(start, end);
         case "unshift":
             for (int i=0; i < args.length; i++) add(i, args[i]);
-            return Script.N(size());
+            return JSU.N(size());
         case "splice": return splice(args);
         //#end
 
-        throw new JSExn("arrays have no function: "+Script.str(method));
+        throw new JSExn("arrays have no function: "+JSU.str(method));
     }
 
     public JS putAndTriggerTraps(JS key, JS val) throws JSExn { put(key, val); return val; }
@@ -112,16 +112,16 @@ class JSArray extends Basket.Array implements JS, Basket.CompareFunc {
 
     private JS join(String sep) throws JSExn {
         int length = size();
-        if(length == 0) return Script.S("");
+        if(length == 0) return JSU.S("");
         StringBuffer sb = new StringBuffer(64);
         int i=0;
         while(true) {
             JS o = (JS)get(i);
-            if(o != null) sb.append(Script.toString(o));
+            if(o != null) sb.append(JSU.toString(o));
             if(++i == length) break;
             sb.append(sep);
         }
-        return Script.S(sb.toString());
+        return JSU.S(sb.toString());
     }
  
     private JS slice(int start, int end) {
@@ -140,8 +140,8 @@ class JSArray extends Basket.Array implements JS, Basket.CompareFunc {
 
     private JS splice(JS[] args) throws JSExn {
         int oldLength = size();
-        int start = Script.toInt(args.length < 1 ? null : args[0]);
-        int deleteCount = Script.toInt(args.length < 2 ? null : args[1]);
+        int start = JSU.toInt(args.length < 1 ? null : args[0]);
+        int deleteCount = JSU.toInt(args.length < 2 ? null : args[1]);
         int newCount = args.length - 2;
         if(newCount < 0) newCount = 0;
         if(start < 0) start = oldLength+start;
@@ -170,7 +170,7 @@ class JSArray extends Basket.Array implements JS, Basket.CompareFunc {
 
     private static final Basket.CompareFunc defaultSort = new Basket.CompareFunc() {
         public int compare(Object a, Object b) {
-            try { return Script.toString((JS)a).compareTo(Script.toString((JS)b)); }
+            try { return JSU.toString((JS)a).compareTo(JSU.toString((JS)b)); }
             catch (JSExn e) { throw new JSExn.Wrapper(e); }
         }
     };
@@ -188,7 +188,7 @@ class JSArray extends Basket.Array implements JS, Basket.CompareFunc {
     public int compare(Object a, Object b) throws JSExn.Wrapper {
         try {
             sortargs[0] = (JS)a; sortargs[1] = (JS)b;
-            return Script.toInt(sort.call(sortargs));
+            return JSU.toInt(sort.call(sortargs));
         } catch (JSExn e) { throw new JSExn.Wrapper(e);
         } finally { sortargs[0] = null; sortargs[1] = null; }
     }
index 5e5eaaf..19e4fc6 100644 (file)
@@ -61,60 +61,60 @@ public class JSDate extends JS.Immutable {
     public JS call(JS method, JS[] args) throws JSExn {
         switch(args.length) {
             case 0: {
-                //#switch(Script.toString(method))
-                case "toString": return Script.S(date_format(date, FORMATSPEC_FULL));
-                case "toTimeString": return Script.S(date_format(date, FORMATSPEC_TIME));
-                case "toDateString": return Script.S(date_format(date, FORMATSPEC_DATE));
-                case "toLocaleString": return Script.S(toLocaleString(date));
-                case "toLocaleTimeString": return Script.S(toLocaleTimeString(date));
-                case "toLocaleDateString": return Script.S(toLocaleDateString(date));
-                case "toUTCString": return Script.S(toUTCString(date));
-                case "valueOf": return Script.N(this.date);
-                case "getTime": return Script.N(this.date);
-                case "getYear": return Script.N(getYear(date));
-                case "getFullYear": return Script.N(YearFromTime(LocalTime(date)));
-                case "getUTCFullYear": return Script.N(YearFromTime(date));
-                case "getMonth": return Script.N(MonthFromTime(LocalTime(date)));
-                case "getUTCMonth": return Script.N(MonthFromTime(date));
-                case "getDate": return Script.N(DateFromTime(LocalTime(date)));
-                case "getUTCDate": return Script.N(DateFromTime(date));
-                case "getDay": return Script.N(WeekDay(LocalTime(date)));
-                case "getUTCDay": return Script.N(WeekDay(date));
-                case "getHours": return Script.N(HourFromTime(LocalTime(date)));
-                case "getUTCHours": return Script.N(HourFromTime(date));
-                case "getMinutes": return Script.N(MinFromTime(LocalTime(date)));
-                case "getUTCMinutes": return Script.N(MinFromTime(date));
-                case "getSeconds": return Script.N(SecFromTime(LocalTime(date)));
-                case "getUTCSeconds": return Script.N(SecFromTime(date));
-                case "getMilliseconds": return Script.N(msFromTime(LocalTime(date)));
-                case "getUTCMilliseconds": return Script.N(msFromTime(date));
-                case "getTimezoneOffset": return Script.N(getTimezoneOffset(date));
+                //#switch(JSU.toString(method))
+                case "toString": return JSU.S(date_format(date, FORMATSPEC_FULL));
+                case "toTimeString": return JSU.S(date_format(date, FORMATSPEC_TIME));
+                case "toDateString": return JSU.S(date_format(date, FORMATSPEC_DATE));
+                case "toLocaleString": return JSU.S(toLocaleString(date));
+                case "toLocaleTimeString": return JSU.S(toLocaleTimeString(date));
+                case "toLocaleDateString": return JSU.S(toLocaleDateString(date));
+                case "toUTCString": return JSU.S(toUTCString(date));
+                case "valueOf": return JSU.N(this.date);
+                case "getTime": return JSU.N(this.date);
+                case "getYear": return JSU.N(getYear(date));
+                case "getFullYear": return JSU.N(YearFromTime(LocalTime(date)));
+                case "getUTCFullYear": return JSU.N(YearFromTime(date));
+                case "getMonth": return JSU.N(MonthFromTime(LocalTime(date)));
+                case "getUTCMonth": return JSU.N(MonthFromTime(date));
+                case "getDate": return JSU.N(DateFromTime(LocalTime(date)));
+                case "getUTCDate": return JSU.N(DateFromTime(date));
+                case "getDay": return JSU.N(WeekDay(LocalTime(date)));
+                case "getUTCDay": return JSU.N(WeekDay(date));
+                case "getHours": return JSU.N(HourFromTime(LocalTime(date)));
+                case "getUTCHours": return JSU.N(HourFromTime(date));
+                case "getMinutes": return JSU.N(MinFromTime(LocalTime(date)));
+                case "getUTCMinutes": return JSU.N(MinFromTime(date));
+                case "getSeconds": return JSU.N(SecFromTime(LocalTime(date)));
+                case "getUTCSeconds": return JSU.N(SecFromTime(date));
+                case "getMilliseconds": return JSU.N(msFromTime(LocalTime(date)));
+                case "getUTCMilliseconds": return JSU.N(msFromTime(date));
+                case "getTimezoneOffset": return JSU.N(getTimezoneOffset(date));
                 //#end
                 return super.call(method, args);
             }
             case 1: {
-                //#switch(Script.toString(method))
-                case "setTime": return Script.N(this.setTime(Script.toDouble(args[0])));
-                case "setYear": return Script.N(this.setYear(Script.toDouble(args[0])));
+                //#switch(JSU.toString(method))
+                case "setTime": return JSU.N(this.setTime(JSU.toDouble(args[0])));
+                case "setYear": return JSU.N(this.setYear(JSU.toDouble(args[0])));
                 //#end
                 // fall through
             }
             default: {
-                //#switch(Script.toString(method))
-                case "setMilliseconds": return Script.N(this.makeTime(args, 1, true));
-                case "setUTCMilliseconds": return Script.N(this.makeTime(args, 1, false));
-                case "setSeconds": return Script.N(this.makeTime(args, 2, true));
-                case "setUTCSeconds": return Script.N(this.makeTime(args, 2, false));
-                case "setMinutes": return Script.N(this.makeTime(args, 3, true));
-                case "setUTCMinutes": return Script.N(this.makeTime(args, 3, false));
-                case "setHours": return Script.N(this.makeTime(args, 4, true));
-                case "setUTCHours": return Script.N(this.makeTime(args, 4, false));
-                case "setDate": return Script.N(this.makeDate(args, 1, true));
-                case "setUTCDate": return Script.N(this.makeDate(args, 1, false));
-                case "setMonth": return Script.N(this.makeDate(args, 2, true));
-                case "setUTCMonth": return Script.N(this.makeDate(args, 2, false));
-                case "setFullYear": return Script.N(this.makeDate(args, 3, true));
-                case "setUTCFullYear": return Script.N(this.makeDate(args, 3, false));
+                //#switch(JSU.toString(method))
+                case "setMilliseconds": return JSU.N(this.makeTime(args, 1, true));
+                case "setUTCMilliseconds": return JSU.N(this.makeTime(args, 1, false));
+                case "setSeconds": return JSU.N(this.makeTime(args, 2, true));
+                case "setUTCSeconds": return JSU.N(this.makeTime(args, 2, false));
+                case "setMinutes": return JSU.N(this.makeTime(args, 3, true));
+                case "setUTCMinutes": return JSU.N(this.makeTime(args, 3, false));
+                case "setHours": return JSU.N(this.makeTime(args, 4, true));
+                case "setUTCHours": return JSU.N(this.makeTime(args, 4, false));
+                case "setDate": return JSU.N(this.makeDate(args, 1, true));
+                case "setUTCDate": return JSU.N(this.makeDate(args, 1, false));
+                case "setMonth": return JSU.N(this.makeDate(args, 2, true));
+                case "setUTCMonth": return JSU.N(this.makeDate(args, 2, false));
+                case "setFullYear": return JSU.N(this.makeDate(args, 3, true));
+                case "setUTCFullYear": return JSU.N(this.makeDate(args, 3, false));
                 //#end
             }
         }
@@ -122,7 +122,7 @@ public class JSDate extends JS.Immutable {
     }
 
     public JS get(JS key) throws JSExn {
-        //#switch(Script.toString(key))
+        //#switch(JSU.toString(key))
         case "toString": return METHOD;
         case "toTimeString": return METHOD;
         case "toDateString": return METHOD;
@@ -538,7 +538,7 @@ public class JSDate extends JS.Immutable {
                 if (d != d || Double.isInfinite(d)) {
                     return Double.NaN;
                 }
-                array[loop] = Script.toDouble(args[loop]);
+                array[loop] = JSU.toDouble(args[loop]);
             } else {
                 array[loop] = 0;
             }
@@ -557,7 +557,7 @@ public class JSDate extends JS.Immutable {
                               array[3], array[4], array[5], array[6]);
         d = TimeClip(d);
         return d;
-        //        return Script.N(d);
+        //        return JSU.N(d);
     }
 
     /*
@@ -887,8 +887,8 @@ public class JSDate extends JS.Immutable {
         return result.toString();
     }
 
-    private static double _toNumber(JS o) throws JSExn { return Script.toDouble(o); }
-    private static double _toNumber(JS[] o, int index) throws JSExn { return Script.toDouble(o[index]); }
+    private static double _toNumber(JS o) throws JSExn { return JSU.toDouble(o); }
+    private static double _toNumber(JS[] o, int index) throws JSExn { return JSU.toDouble(o[index]); }
 
     public JSDate(JS[] args) throws JSExn {
 
@@ -900,8 +900,8 @@ public class JSDate extends JS.Immutable {
             }
             case 1: {
                 double date;
-                if(Script.isString(args[0]))
-                    date = date_parseString(Script.toString(args[0]));
+                if(JSU.isString(args[0]))
+                    date = date_parseString(JSU.toString(args[0]));
                 else
                     date = _toNumber(args[0]);
                 obj.date = TimeClip(date);
@@ -910,9 +910,9 @@ public class JSDate extends JS.Immutable {
             default: {
                 // multiple arguments; year, month, day etc.
                 double array[] = new double[MAXARGS];
-                array[0] = Script.toDouble(args[0]);
-                array[1] = Script.toDouble(args[1]);
-                if (args.length >= 2) array[2] = Script.toDouble(args[2]);
+                array[0] = JSU.toDouble(args[0]);
+                array[1] = JSU.toDouble(args[1]);
+                if (args.length >= 2) array[2] = JSU.toDouble(args[2]);
                 for (int i=0; i < args.length; i++) {
                     double d = _toNumber(args[i]);
                     if (d != d || Double.isInfinite(d)) {
index 3880858..af72ce4 100644 (file)
@@ -11,7 +11,7 @@ import java.io.*;
 public class JSExn extends Exception { 
     private Basket.List backtrace = new Basket.Array();
     private JS js; 
-    public JSExn(String s) { this(Script.S(s)); }
+    public JSExn(String s) { this(JSU.S(s)); }
     public JSExn(JS js) { this(js,null); }
     public JSExn(JS js, Interpreter cx) { this.js = js; fill(cx); }
     
@@ -30,7 +30,7 @@ public class JSExn extends Exception {
         for(int i=0; i<backtrace.size(); i++) ps.println("    at " + (String) backtrace.get(i));
         super.printStackTrace(ps);
     }
-    public String toString() { return "JSExn: " + Script.str(js); }
+    public String toString() { return "JSExn: " + JSU.str(js); }
     public String getMessage() { return toString(); }
     public JS getObject() { return js; } 
     
@@ -49,7 +49,7 @@ public class JSExn extends Exception {
     public static class IO extends JSExn {
         public IO(java.io.IOException ioe) {
             super("ibex.io: " + ioe.toString());
-            Script.warn(ioe);
+            JSU.warn(ioe);
         }
     }
 } 
index 03508b7..681e03e 100644 (file)
@@ -97,7 +97,7 @@ class JSFunction extends JS.Immutable implements ByteCodes, Tokens {
             if (op[i] < 0) sb.append(bytecodeToString[-op[i]]);
             else sb.append(codeToString[op[i]]);
             sb.append(" ");
-            sb.append(arg[i] == null ? "(no arg)" : arg[i] instanceof JS ? Script.str((JS)arg[i]) : arg[i]);
+            sb.append(arg[i] == null ? "(no arg)" : arg[i] instanceof JS ? JSU.str((JS)arg[i]) : arg[i]);
             if((op[i] == JF || op[i] == JT || op[i] == JMP) && arg[i] != null && arg[i] instanceof Number) {
                 sb.append(" jump to ").append(i+((Number) arg[i]).intValue());
             } else  if(op[i] == TRY) {
index 6e4e231..7a805e7 100644 (file)
@@ -8,47 +8,47 @@ package org.ibex.js;
 class JSMath extends JS.Immutable {
     private static final JS.Method METHOD = new JS.Method();
 
-    private static final JS E       = Script.N(java.lang.Math.E);
-    private static final JS PI      = Script.N(java.lang.Math.PI);
-    private static final JS LN10    = Script.N(java.lang.Math.log(10));
-    private static final JS LN2     = Script.N(java.lang.Math.log(2));
-    private static final JS LOG10E  = Script.N(1/java.lang.Math.log(10));
-    private static final JS LOG2E   = Script.N(1/java.lang.Math.log(2));
-    private static final JS SQRT1_2 = Script.N(1/java.lang.Math.sqrt(2));
-    private static final JS SQRT2   = Script.N(java.lang.Math.sqrt(2));
+    private static final JS E       = JSU.N(java.lang.Math.E);
+    private static final JS PI      = JSU.N(java.lang.Math.PI);
+    private static final JS LN10    = JSU.N(java.lang.Math.log(10));
+    private static final JS LN2     = JSU.N(java.lang.Math.log(2));
+    private static final JS LOG10E  = JSU.N(1/java.lang.Math.log(10));
+    private static final JS LOG2E   = JSU.N(1/java.lang.Math.log(2));
+    private static final JS SQRT1_2 = JSU.N(1/java.lang.Math.sqrt(2));
+    private static final JS SQRT2   = JSU.N(java.lang.Math.sqrt(2));
 
     public JS call(JS method, JS[] args) throws JSExn {
         switch(args.length) {
             case 0: {
-                //#switch(Script.toString(method))
-                case "random": return Script.N(java.lang.Math.random());
+                //#switch(JSU.toString(method))
+                case "random": return JSU.N(java.lang.Math.random());
                 //#end
                 break;
             }
             case 1: {
-                //#switch(Script.toString(method))
-                case "ceil": return Script.N((long)java.lang.Math.ceil(Script.toDouble(args[0])));
-                case "floor": return Script.N((long)java.lang.Math.floor(Script.toDouble(args[0])));
-                case "round": return Script.N((long)java.lang.Math.round(Script.toDouble(args[0])));
-                case "abs": return Script.N(java.lang.Math.abs(Script.toDouble(args[0])));
-                case "sin": return Script.N(java.lang.Math.sin(Script.toDouble(args[0])));
-                case "cos": return Script.N(java.lang.Math.cos(Script.toDouble(args[0])));
-                case "tan": return Script.N(java.lang.Math.tan(Script.toDouble(args[0])));
-                case "asin": return Script.N(java.lang.Math.asin(Script.toDouble(args[0])));
-                case "acos": return Script.N(java.lang.Math.acos(Script.toDouble(args[0])));
-                case "atan": return Script.N(java.lang.Math.atan(Script.toDouble(args[0])));
-                case "sqrt": return Script.N(java.lang.Math.sqrt(Script.toDouble(args[0])));
-                case "exp": return Script.N(java.lang.Math.exp(Script.toDouble(args[0])));
-                case "log": return Script.N(java.lang.Math.log(Script.toDouble(args[0])));
+                //#switch(JSU.toString(method))
+                case "ceil": return JSU.N((long)java.lang.Math.ceil(JSU.toDouble(args[0])));
+                case "floor": return JSU.N((long)java.lang.Math.floor(JSU.toDouble(args[0])));
+                case "round": return JSU.N((long)java.lang.Math.round(JSU.toDouble(args[0])));
+                case "abs": return JSU.N(java.lang.Math.abs(JSU.toDouble(args[0])));
+                case "sin": return JSU.N(java.lang.Math.sin(JSU.toDouble(args[0])));
+                case "cos": return JSU.N(java.lang.Math.cos(JSU.toDouble(args[0])));
+                case "tan": return JSU.N(java.lang.Math.tan(JSU.toDouble(args[0])));
+                case "asin": return JSU.N(java.lang.Math.asin(JSU.toDouble(args[0])));
+                case "acos": return JSU.N(java.lang.Math.acos(JSU.toDouble(args[0])));
+                case "atan": return JSU.N(java.lang.Math.atan(JSU.toDouble(args[0])));
+                case "sqrt": return JSU.N(java.lang.Math.sqrt(JSU.toDouble(args[0])));
+                case "exp": return JSU.N(java.lang.Math.exp(JSU.toDouble(args[0])));
+                case "log": return JSU.N(java.lang.Math.log(JSU.toDouble(args[0])));
                 //#end
                 break;
             }
             case 2: {
-                //#switch(Script.toString(method))
-                case "min": return Script.N(java.lang.Math.min(Script.toDouble(args[0]), Script.toDouble(args[1])));
-                case "max": return Script.N(java.lang.Math.max(Script.toDouble(args[0]), Script.toDouble(args[1])));
-                case "pow": return Script.N(java.lang.Math.pow(Script.toDouble(args[0]), Script.toDouble(args[1])));
-                case "atan2": return Script.N(java.lang.Math.atan2(Script.toDouble(args[0]), Script.toDouble(args[1])));
+                //#switch(JSU.toString(method))
+                case "min": return JSU.N(java.lang.Math.min(JSU.toDouble(args[0]), JSU.toDouble(args[1])));
+                case "max": return JSU.N(java.lang.Math.max(JSU.toDouble(args[0]), JSU.toDouble(args[1])));
+                case "pow": return JSU.N(java.lang.Math.pow(JSU.toDouble(args[0]), JSU.toDouble(args[1])));
+                case "atan2": return JSU.N(java.lang.Math.atan2(JSU.toDouble(args[0]), JSU.toDouble(args[1])));
                 //#end
                 break;
             }
@@ -57,7 +57,7 @@ class JSMath extends JS.Immutable {
     }
 
     public JS get(JS key) throws JSExn {
-        //#switch(Script.toString(key))
+        //#switch(JSU.toString(key))
         case "E": return E;
         case "LN10": return LN10;
         case "LN2": return LN2;
index be81749..57f9c9e 100644 (file)
@@ -8,89 +8,89 @@ class JSPrimitive extends JS.Immutable {
     private static final JS.Method METHOD = new JS.Method();
 
     public JS callMethod(JS method, JS[] args) throws JSExn {
-        //#switch(Script.str(method))
+        //#switch(JSU.str(method))
         case "toFixed": throw new JSExn("toFixed() not implemented");
         case "toExponential": throw new JSExn("toExponential() not implemented");
         case "toPrecision": throw new JSExn("toPrecision() not implemented");
-        case "toString": return this instanceof JSString ? this : Script.S(Script.toString(this));
+        case "toString": return this instanceof JSString ? this : JSU.S(JSU.toString(this));
         //#end
             
         String s = coerceToString();
         int slength = s.length();
             
-        //#switch(Script.toString(method))
+        //#switch(JSU.toString(method))
         case "substring": {
-            int a = args.length >= 1 ? Script.toInt(args[0]) : 0;
-            int b = args.length >= 2 ? Script.toInt(args[1]) : slength;
+            int a = args.length >= 1 ? JSU.toInt(args[0]) : 0;
+            int b = args.length >= 2 ? JSU.toInt(args[1]) : slength;
             if (a > slength) a = slength;
             if (b > slength) b = slength;
             if (a < 0) a = 0;
             if (b < 0) b = 0;
             if (a > b) { int tmp = a; a = b; b = tmp; }
-            return Script.S(s.substring(a,b));
+            return JSU.S(s.substring(a,b));
         }
         case "substr": {
-            int start = args.length >= 1 ? Script.toInt(args[0]) : 0;
-            int len = args.length >= 2 ? Script.toInt(args[1]) : Integer.MAX_VALUE;
+            int start = args.length >= 1 ? JSU.toInt(args[0]) : 0;
+            int len = args.length >= 2 ? JSU.toInt(args[1]) : Integer.MAX_VALUE;
             if (start < 0) start = slength + start;
             if (start < 0) start = 0;
             if (len < 0) len = 0;
             if (len > slength - start) len = slength - start;
-            if (len <= 0) return Script.S("");
-            return Script.S(s.substring(start,start+len));
+            if (len <= 0) return JSU.S("");
+            return JSU.S(s.substring(start,start+len));
         }
         case "charAt": {
-            int p = args.length >= 1 ? Script.toInt(args[0]) : 0;
-            if (p < 0 || p >= slength) return Script.S("");
-            return Script.S(s.substring(p,p+1));
+            int p = args.length >= 1 ? JSU.toInt(args[0]) : 0;
+            if (p < 0 || p >= slength) return JSU.S("");
+            return JSU.S(s.substring(p,p+1));
         }
         case "charCodeAt": {
-            int p = args.length >= 1 ? Script.toInt(args[0]) : 0;
-            if (p < 0 || p >= slength) return Script.N(Double.NaN);
-            return Script.N(s.charAt(p));
+            int p = args.length >= 1 ? JSU.toInt(args[0]) : 0;
+            if (p < 0 || p >= slength) return JSU.N(Double.NaN);
+            return JSU.N(s.charAt(p));
         }
         case "concat": {
             StringBuffer sb = new StringBuffer(slength*2).append(s);
             for (int i=0; i < args.length; i++) sb.append(args[i]);
-            return Script.S(sb.toString());
+            return JSU.S(sb.toString());
         }
         case "indexOf": {
-            String search = args.length >= 1 ? Script.toString(args[0]) : "null";
-            int start = args.length >= 2 ? Script.toInt(args[1]) : 0;
+            String search = args.length >= 1 ? JSU.toString(args[0]) : "null";
+            int start = args.length >= 2 ? JSU.toInt(args[1]) : 0;
             // Java's indexOf handles an out of bounds start index, it'll return -1
-            return Script.N(s.indexOf(search,start));
+            return JSU.N(s.indexOf(search,start));
         }
         case "lastIndexOf": {
-            String search = args.length >= 1 ? Script.toString(args[0]) : "null";
-            int start = args.length >= 2 ? Script.toInt(args[1]) : 0;
+            String search = args.length >= 1 ? JSU.toString(args[0]) : "null";
+            int start = args.length >= 2 ? JSU.toInt(args[1]) : 0;
             // Java's indexOf handles an out of bounds start index, it'll return -1
-            return Script.N(s.lastIndexOf(search,start));            
+            return JSU.N(s.lastIndexOf(search,start));            
         }
         case "match": return JSRegexp.stringMatch(this,args[0]);
         case "replace": return JSRegexp.stringReplace(this,args[0],args[1]);
         case "search": return JSRegexp.stringSearch(this,args[0]);
         case "split": return JSRegexp.stringSplit(this,args[0],args[1],args.length);
-        case "toLowerCase": return Script.S(s.toLowerCase());
-        case "toUpperCase": return Script.S(s.toUpperCase());
+        case "toLowerCase": return JSU.S(s.toLowerCase());
+        case "toUpperCase": return JSU.S(s.toUpperCase());
         case "slice": {
-            int a = args.length >= 1 ? Script.toInt(args[0]) : 0;
-            int b = args.length >= 2 ? Script.toInt(args[1]) : slength;
+            int a = args.length >= 1 ? JSU.toInt(args[0]) : 0;
+            int b = args.length >= 2 ? JSU.toInt(args[1]) : slength;
             if (a < 0) a = slength + a;
             if (b < 0) b = slength + b;
             if (a < 0) a = 0;
             if (b < 0) b = 0;
             if (a > slength) a = slength;
             if (b > slength) b = slength;
-            if (a > b) return Script.S("");
-            return Script.S(s.substring(a,b));
+            if (a > b) return JSU.S("");
+            return JSU.S(s.substring(a,b));
         }
         //#end
         return super.call(method, args);
     }
     
     public JS get(JS key) throws JSExn {
-        //#switch(Script.toString(key))
-        case "length": return Script.N(Script.toString(this).length());
+        //#switch(JSU.toString(key))
+        case "length": return JSU.N(JSU.toString(this).length());
         case "substring": return METHOD;
         case "charAt": return METHOD;
         case "charCodeAt": return METHOD;
index d6ecd75..9c23830 100644 (file)
@@ -12,9 +12,9 @@ public class JSReflection extends JS.Immutable {
 
     public static JS wrap(Object o) throws JSExn {
         if (o == null) return null;
-        if (o instanceof String) return Script.S((String)o);
-        if (o instanceof Boolean) return Script.B(((Boolean)o).booleanValue());
-        if (o instanceof Number) return Script.N((Number)o);
+        if (o instanceof String) return JSU.S((String)o);
+        if (o instanceof Boolean) return JSU.B(((Boolean)o).booleanValue());
+        if (o instanceof Number) return JSU.N((Number)o);
         if (o instanceof JS) return (JS)o;
         if (o instanceof Object[]) {
             // FIXME: get element type here
@@ -30,17 +30,17 @@ public class JSReflection extends JS.Immutable {
             return new Enumeration(null) {
                 private int n = 0;
                 public boolean _hasNext() { return n < arr.length; }
-                public JS _next() { return Script.N(n++); }
+                public JS _next() { return JSU.N(n++); }
             };
         }
-        public JS get(JS key) throws JSExn { return wrap(arr[Script.toInt(key)]); }
+        public JS get(JS key) throws JSExn { return wrap(arr[JSU.toInt(key)]); }
     }
 
     // FIXME public static class Hash { }
     // FIXME public Enumeration keys() throws JSExn {  }
 
     public JS get(JS key) throws JSExn {
-        String k = Script.toString(key);
+        String k = JSU.toString(key);
         try {
             Field f = this.getClass().getField(k);
             return wrap(f.get(this));
@@ -60,7 +60,7 @@ public class JSReflection extends JS.Immutable {
     }
 
     public JS call(JS method, JS[] args) throws JSExn {
-        String k = Script.toString(method);
+        String k = JSU.toString(method);
         try {
             java.lang.reflect.Method[] methods = this.getClass().getMethods();
             for(int j=0; j<methods.length; j++) {
@@ -73,7 +73,7 @@ public class JSReflection extends JS.Immutable {
         } catch (InvocationTargetException it) {
             Throwable ite = it.getTargetException();
             if (ite instanceof JSExn) throw ((JSExn)ite);
-            Script.warn(ite);
+            JSU.warn(ite);
             throw new JSExn("unhandled reflected exception: " + ite.toString());
         } catch (SecurityException nfe) { }
         throw new JSExn("called a reflection method with the wrong number of arguments");
index 3353b1d..aa68c2f 100644 (file)
@@ -24,10 +24,10 @@ public class JSRegexp extends JS.Immutable {
             this.pattern = r.pattern;
             this.flags = r.flags;
         } else {
-            String pattern = Script.toString(arg0);
+            String pattern = JSU.toString(arg0);
             String sFlags = null;
             int flags = 0;
-            if(arg1 != null) sFlags = Script.toString(arg1);
+            if(arg1 != null) sFlags = JSU.toString(arg1);
             if(sFlags == null) sFlags = "";
             for(int i=0;i<sFlags.length();i++) {
                 switch(sFlags.charAt(i)) {
@@ -38,7 +38,7 @@ public class JSRegexp extends JS.Immutable {
                 }
             }
             re = newRE(pattern,flags);
-            this.pattern = Script.S(pattern);
+            this.pattern = JSU.S(pattern);
             this.flags = flags;
         }
     }
@@ -46,9 +46,9 @@ public class JSRegexp extends JS.Immutable {
     public JS call(JS method, JS[] args) throws JSExn {
         switch(args.length) {
             case 1: {
-                //#switch(Script.str(method))
+                //#switch(JSU.str(method))
                 case "exec": {
-                    String s = Script.toString(args[0]);
+                    String s = JSU.toString(args[0]);
                     int start = global ? lastIndex : 0;
                     if(start < 0 || start >= s.length()) { lastIndex = 0; return null; }
                     GnuRegexp.REMatch match = re.getMatch(s,start);
@@ -56,27 +56,27 @@ public class JSRegexp extends JS.Immutable {
                     return match == null ? null : matchToExecResult(match,re,s);
                 }
                 case "test": {
-                    String s = Script.toString(args[0]);
-                    if (!global) return Script.B(re.getMatch(s) != null);
+                    String s = JSU.toString(args[0]);
+                    if (!global) return JSU.B(re.getMatch(s) != null);
                     int start = global ? lastIndex : 0;
                     if(start < 0 || start >= s.length()) { lastIndex = 0; return null; }
                     GnuRegexp.REMatch match = re.getMatch(s,start);
                     lastIndex = match != null ? s.length() : match.getEndIndex();
-                    return Script.B(match != null);
+                    return JSU.B(match != null);
                 }
-                case "toString": return Script.S(args[0].coerceToString());
+                case "toString": return JSU.S(args[0].coerceToString());
                 //#end
                 break;
             }
             case 2: {
-                //#switch(Script.str(method))
+                //#switch(JSU.str(method))
                 case "stringMatch": return stringMatch(args[0], args[1]);
                 case "stringSearch": return stringSearch(args[0], args[1]);
                 //#end
                 break;
             }
             case 3: {
-                //#switch(Script.str(method))
+                //#switch(JSU.str(method))
                 case "stringReplace": return stringReplace(args[0], args[1], args[2]);
                 //#end
                 break;
@@ -86,23 +86,23 @@ public class JSRegexp extends JS.Immutable {
     }
     
     public JS get(JS key) throws JSExn {
-        //#switch(Script.str(key))
+        //#switch(JSU.str(key))
         case "exec": return METHOD;
         case "test": return METHOD;
         case "toString": return METHOD;
-        case "lastIndex": return Script.N(lastIndex);
+        case "lastIndex": return JSU.N(lastIndex);
         case "source": return pattern;
-        case "global": return Script.B(global);
-        case "ignoreCase": return Script.B(flags & GnuRegexp.RE.REG_ICASE);
-        case "multiline": return Script.B(flags & GnuRegexp.RE.REG_MULTILINE);
+        case "global": return JSU.B(global);
+        case "ignoreCase": return JSU.B(flags & GnuRegexp.RE.REG_ICASE);
+        case "multiline": return JSU.B(flags & GnuRegexp.RE.REG_MULTILINE);
         //#end
         return super.get(key);
     }
     
     public void put(JS key, JS value) throws JSExn {
-        if(Script.isString(key)) {
-            if(Script.toString(key).equals("lastIndex")) {
-                lastIndex = Script.toInt(value);
+        if(JSU.isString(key)) {
+            if(JSU.toString(key).equals("lastIndex")) {
+                lastIndex = JSU.toInt(value);
                 return;
             }
         }
@@ -112,12 +112,12 @@ public class JSRegexp extends JS.Immutable {
     private static JS matchToExecResult(GnuRegexp.REMatch match, GnuRegexp.RE re, String s) {
         try {
             JS ret = new JS.Obj();
-            ret.put(Script.S("index"), Script.N(match.getStartIndex()));
-            ret.put(Script.S("input"), Script.S(s));
+            ret.put(JSU.S("index"), JSU.N(match.getStartIndex()));
+            ret.put(JSU.S("input"), JSU.S(s));
             int n = re.getNumSubs();
-            ret.put(Script.S("length"), Script.N(n+1));
-            ret.put(Script.ZERO, Script.S(match.toString()));
-            for(int i=1;i<=n;i++) ret.put(Script.N(i),Script.S(match.toString(i)));
+            ret.put(JSU.S("length"), JSU.N(n+1));
+            ret.put(JSU.ZERO, JSU.S(match.toString()));
+            for(int i=1;i<=n;i++) ret.put(JSU.N(i),JSU.S(match.toString(i)));
             return ret;
         } catch (JSExn e) {
             throw new Error("this should never happen");
@@ -137,14 +137,14 @@ public class JSRegexp extends JS.Immutable {
     
     private static final JS[] execarg = new JS[1];
     static JS stringMatch(JS o, JS arg0) throws JSExn {
-        String s = Script.toString(o);
+        String s = JSU.toString(o);
         GnuRegexp.RE re;
         JSRegexp regexp = null;
         if(arg0 instanceof JSRegexp) {
             regexp = (JSRegexp) arg0;
             re = regexp.re;
         } else {
-            re = newRE(Script.toString(arg0),0);
+            re = newRE(JSU.toString(arg0),0);
         }
         
         if(regexp == null) {
@@ -153,25 +153,25 @@ public class JSRegexp extends JS.Immutable {
         }
         try {
             execarg[0] = o;
-            if(!regexp.global) return regexp.call(Script.S("exec"), execarg);
+            if(!regexp.global) return regexp.call(JSU.S("exec"), execarg);
         } finally { execarg[0] = null; }
 
         GnuRegexp.REMatch[] matches = re.getAllMatches(s);
         JSArray ret = new JSArray(matches.length);
-        for(int i=0;i<matches.length;i++) ret.add(Script.S(matches[i].toString()));
+        for(int i=0;i<matches.length;i++) ret.add(JSU.S(matches[i].toString()));
         regexp.lastIndex = matches.length > 0 ? matches[matches.length-1].getEndIndex() : s.length();
         return ret;
     }
     
     static JS stringSearch(JS o, JS arg0) throws JSExn  {
-        String s = Script.toString(o);
-        GnuRegexp.RE re = arg0 instanceof JSRegexp ? ((JSRegexp)arg0).re : newRE(Script.toString(arg0),0);
+        String s = JSU.toString(o);
+        GnuRegexp.RE re = arg0 instanceof JSRegexp ? ((JSRegexp)arg0).re : newRE(JSU.toString(arg0),0);
         GnuRegexp.REMatch match = re.getMatch(s);
-        return match == null ? Script.N(-1) : Script.N(match.getStartIndex());
+        return match == null ? JSU.N(-1) : JSU.N(match.getStartIndex());
     }
     
     static JS stringReplace(JS o, JS arg0, JS arg1) throws JSExn {
-        String s = Script.toString(o);
+        String s = JSU.toString(o);
         GnuRegexp.RE re;
         JSFunction replaceFunc = null;
         String replaceString = null;
@@ -185,7 +185,7 @@ public class JSRegexp extends JS.Immutable {
         if(arg1 instanceof JSFunction)
             replaceFunc = (JSFunction) arg1;
         else
-            replaceString = Script.toString(arg1);
+            replaceString = JSU.toString(arg1);
         GnuRegexp.REMatch[] matches;
         if(regexp != null && regexp.global) {
             matches = re.getAllMatches(s);
@@ -214,15 +214,15 @@ public class JSRegexp extends JS.Immutable {
                 int n = (regexp == null ? 0 : re.getNumSubs());
                 int numArgs = 3 + n;
                 JS[] args = new JS[3 + n];
-                args[0] = Script.S(match.toString());
+                args[0] = JSU.S(match.toString());
                 args[1] = null;
                 args[2] = null;
-                for(int j=1;j<=n;j++) args[j] = Script.S(match.toString(j));
-                args[args.length - 2] = Script.N(match.getStartIndex());
-                args[args.length - 1] = Script.S(s);
+                for(int j=1;j<=n;j++) args[j] = JSU.S(match.toString(j));
+                args[args.length - 2] = JSU.N(match.getStartIndex());
+                args[args.length - 1] = JSU.S(s);
 
                 // note: can't perform pausing operations in here
-                sb.append(Script.toString(replaceFunc.call(args)));
+                sb.append(JSU.toString(replaceFunc.call(args)));
 
             } else {
                 sb.append(mySubstitute(match,replaceString,s));
@@ -230,7 +230,7 @@ public class JSRegexp extends JS.Immutable {
         }
         int end = matches.length == 0 ? 0 : matches[matches.length-1].getEndIndex();
         sb.append(sa,end,sa.length-end);
-        return Script.S(sb.toString());
+        return JSU.S(sb.toString());
     }
     
     private static String mySubstitute(GnuRegexp.REMatch match, String s, String source) {
@@ -276,8 +276,8 @@ public class JSRegexp extends JS.Immutable {
                     
     
     static JS stringSplit(JS s_, JS arg0, JS arg1, int nargs) throws JSExn {
-        String s = Script.toString(s_);
-        int limit = nargs < 2 ? Integer.MAX_VALUE : Script.toInt(arg1);
+        String s = JSU.toString(s_);
+        int limit = nargs < 2 ? Integer.MAX_VALUE : JSU.toInt(arg1);
         if(limit < 0) limit = Integer.MAX_VALUE;
         if(limit == 0) return new JSArray(0);
         
@@ -291,7 +291,7 @@ public class JSRegexp extends JS.Immutable {
             regexp = (JSRegexp) arg0;
             re = regexp.re;
         } else {
-            sep = Script.toString(arg0);
+            sep = JSU.toString(arg0);
         }
         
         // special case this for speed. additionally, the code below doesn't properly handle
@@ -299,7 +299,7 @@ public class JSRegexp extends JS.Immutable {
         if(sep != null && sep.length()==0) {
             int len = s.length();
             for(int i=0;i<len;i++)
-                ret.add(Script.S(s.substring(i,i+1)));
+                ret.add(JSU.S(s.substring(i,i+1)));
             return ret;
         }
         
@@ -308,24 +308,24 @@ public class JSRegexp extends JS.Immutable {
                 GnuRegexp.REMatch m = re.getMatch(s,p);
                 if(m == null) break OUTER;
                 boolean zeroLength = m.getStartIndex() == m.getEndIndex();
-                ret.add(Script.S(s.substring(p,zeroLength ? m.getStartIndex()+1 : m.getStartIndex())));
+                ret.add(JSU.S(s.substring(p,zeroLength ? m.getStartIndex()+1 : m.getStartIndex())));
                 p = zeroLength ? p + 1 : m.getEndIndex();
                 if(!zeroLength) {
                     for(int i=1;i<=re.getNumSubs();i++) {
-                        ret.add(Script.S(m.toString(i)));
+                        ret.add(JSU.S(m.toString(i)));
                         if(ret.size() == limit) break OUTER;
                     }
                 }
             } else {
                 int x = s.indexOf(sep,p);
                 if(x == -1) break OUTER;
-                ret.add(Script.S(s.substring(p,x)));
+                ret.add(JSU.S(s.substring(p,x)));
                 p = x + sep.length();
             }
             if(ret.size() == limit) break;
         }
         if(p < s.length() && ret.size() != limit)
-            ret.add(Script.S(s.substring(p)));
+            ret.add(JSU.S(s.substring(p)));
         return ret;
     }
    
index 5bd3a76..52dafe1 100644 (file)
@@ -30,7 +30,7 @@ class JSScope {
     final JS get(JS i) throws JSExn {
         if(i==null) throw new NullPointerException();
         try {
-            return get(Script.toInt(i));
+            return get(JSU.toInt(i));
         } catch(ArrayIndexOutOfBoundsException e) { 
             throw new JSExn("scope index out of range");
         }
@@ -38,7 +38,7 @@ class JSScope {
     final void put(JS i, JS o) throws JSExn {
         if(i==null) throw new NullPointerException();
         try {
-            put(Script.toInt(i), o);
+            put(JSU.toInt(i), o);
         } catch(ArrayIndexOutOfBoundsException e) { 
             throw new JSExn("scope index out of range");
         }
similarity index 99%
rename from src/org/ibex/js/Script.java
rename to src/org/ibex/js/JSU.java
index 3fa9671..614114f 100644 (file)
@@ -4,7 +4,7 @@ import java.io.Reader;
 import java.io.IOException;
 import org.ibex.util.*;
 
-public class Script {
+public class JSU {
     /** returns a Pausable which will restart the context;
      *  expects a value to be pushed onto the stack when unpaused. */
     public static Pausable pause() throws Pausable.NotPausableException {
index 6b3f640..81215fc 100644 (file)
@@ -77,7 +77,7 @@ class Parser extends Lexer implements ByteCodes {
 
     /** for debugging */
     public static void main(String[] s) throws IOException {
-        JS block = Script.fromReader("stdin", 0, new InputStreamReader(System.in));
+        JS block = JSU.fromReader("stdin", 0, new InputStreamReader(System.in));
         if (block == null) return;
         System.out.println(block);
     }
@@ -157,7 +157,7 @@ class Parser extends Lexer implements ByteCodes {
     void scopeDeclare(String name) throws IOException {
         ScopeInfo si = (ScopeInfo) scopeStack.peek();
         if(si.mapping.get(name) != null) throw pe("" + name + " already declared in this scope");
-        si.mapping.put(name,Script.N(si.end++));
+        si.mapping.put(name,JSU.N(si.end++));
         globalCache.put(name,null);
     }
     void scopePush(JSFunction b) {
@@ -172,7 +172,7 @@ class Parser extends Lexer implements ByteCodes {
     void scopePop(JSFunction b) {
         ScopeInfo si = (ScopeInfo) scopeStack.pop();
         b.add(parserLine, OLDSCOPE);
-        b.set(si.newScopeInsn,Script.N((si.base<<16)|((si.end-si.base)<<0))); 
+        b.set(si.newScopeInsn,JSU.N((si.base<<16)|((si.end-si.base)<<0))); 
     }
     
     
@@ -232,28 +232,28 @@ class Parser extends Lexer implements ByteCodes {
         case -1: throw pe("expected expression");
 
         // all of these simply push values onto the stack
-        case NUMBER: b.add(parserLine, LITERAL, Script.N(number)); break;
+        case NUMBER: b.add(parserLine, LITERAL, JSU.N(number)); break;
         case STRING: b.add(parserLine, LITERAL, JSString.intern(string)); break;
         case NULL: b.add(parserLine, LITERAL, null); break;
-        case TRUE: case FALSE: b.add(parserLine, LITERAL, tok == TRUE ? Script.T : Script.F); break;
+        case TRUE: case FALSE: b.add(parserLine, LITERAL, tok == TRUE ? JSU.T : JSU.F); break;
 
         // (.foo) syntax
         case DOT: {
             consume(NAME);
             b.add(parserLine, GLOBALSCOPE);
-            b.add(parserLine, GET, Script.S("",true));
-            b.add(parserLine, LITERAL, Script.S(string,true));
+            b.add(parserLine, GET, JSU.S("",true));
+            b.add(parserLine, LITERAL, JSU.S(string,true));
             continueExprAfterAssignable(b,minPrecedence,null);
             break;
         }
 
         case LB: {
-            b.add(parserLine, ARRAY, Script.ZERO);                       // push an array onto the stack
+            b.add(parserLine, ARRAY, JSU.ZERO);                       // push an array onto the stack
             int size0 = b.size;
             int i = 0;
             if (peekToken() != RB)
                 while(true) {                                               // iterate over the initialization values
-                    b.add(parserLine, LITERAL, Script.N(i++));           // push the index in the array to place it into
+                    b.add(parserLine, LITERAL, JSU.N(i++));           // push the index in the array to place it into
                     if (peekToken() == COMMA || peekToken() == RB)
                         b.add(parserLine, LITERAL, null);                   // for stuff like [1,,2,]
                     else
@@ -263,19 +263,19 @@ class Parser extends Lexer implements ByteCodes {
                     if (peekToken() == RB) break;
                     consume(COMMA);
                 }
-            b.set(size0 - 1, Script.N(i));                               // back at the ARRAY instruction, write the size of the array
+            b.set(size0 - 1, JSU.N(i));                               // back at the ARRAY instruction, write the size of the array
             consume(RB);
             break;
         }
         case SUB: case ADD: {
             if(peekToken() == NUMBER) {   // literal
                 consume(NUMBER);
-                b.add(parserLine, LITERAL, Script.N(number.doubleValue() * (tok == SUB ? -1 : 1)));
+                b.add(parserLine, LITERAL, JSU.N(number.doubleValue() * (tok == SUB ? -1 : 1)));
             } else { // unary +/- operator
-                if(tok == SUB) b.add(parserLine, LITERAL, Script.ZERO);
+                if(tok == SUB) b.add(parserLine, LITERAL, JSU.ZERO);
                 // BITNOT has the same precedence as the unary +/- operators
                 startExpr(b,precedence[BITNOT]);
-                if(tok == ADD) b.add(parserLine, LITERAL, Script.ZERO); // HACK to force expr into a numeric context
+                if(tok == ADD) b.add(parserLine, LITERAL, JSU.ZERO); // HACK to force expr into a numeric context
                 b.add(parserLine, SUB);
             }
             break;
@@ -296,8 +296,8 @@ class Parser extends Lexer implements ByteCodes {
             else if(!sg)
                 throw pe("prefixed increment/decrement can only be performed on a valid assignment target");
             if(!sg) b.add(parserLine, GET_PRESERVE, Boolean.TRUE);
-            b.add(parserLine, LITERAL, Script.N(1));
-            b.add(parserLine, tok == INC ? ADD : SUB, Script.N(2));
+            b.add(parserLine, LITERAL, JSU.N(1));
+            b.add(parserLine, tok == INC ? ADD : SUB, JSU.N(2));
             if(sg) {
                 b.add(parserLine, SCOPEPUT, b.getArg(prev));
             } else {
@@ -344,9 +344,9 @@ class Parser extends Lexer implements ByteCodes {
             if(peekToken() == ASSIGN) {
                 consume(ASSIGN);
                 startExpr(b, precedence[ASSIGN]);
-                b.add(parserLine, CASCADE, Script.T);
+                b.add(parserLine, CASCADE, JSU.T);
             } else {
-                b.add(parserLine, CASCADE, Script.F);
+                b.add(parserLine, CASCADE, JSU.F);
             }
             break;
         }
@@ -368,7 +368,7 @@ class Parser extends Lexer implements ByteCodes {
                     consume(NAME);                                        // a named argument
                     
                     b2.add(parserLine, DUP);                              // dup the args array 
-                    b2.add(parserLine, GET, Script.N(numArgs - 1));   // retrieve it from the arguments array
+                    b2.add(parserLine, GET, JSU.N(numArgs - 1));   // retrieve it from the arguments array
                     scopeDeclare(string);
                     b2.add(parserLine, SCOPEPUT, scopeKey(string));
                     b2.add(parserLine, POP);
@@ -473,7 +473,7 @@ class Parser extends Lexer implements ByteCodes {
             
             if (tok != ADD_TRAP && tok != DEL_TRAP) {
                 // tok-1 is always s/^ASSIGN_// (0 is BITOR, 1 is ASSIGN_BITOR, etc) 
-                b.add(parserLine, tok - 1, tok-1==ADD ? Script.N(2) : null);
+                b.add(parserLine, tok - 1, tok-1==ADD ? JSU.N(2) : null);
                 if(varKey == null) {
                     b.add(parserLine, PUT);
                     b.add(parserLine, SWAP);
@@ -490,18 +490,18 @@ class Parser extends Lexer implements ByteCodes {
         case INC: case DEC: { // postfix
             if(varKey == null) {
                 b.add(parserLine, GET_PRESERVE, Boolean.TRUE);
-                b.add(parserLine, LITERAL, Script.N(1));
-                b.add(parserLine, tok == INC ? ADD : SUB, Script.N(2));
+                b.add(parserLine, LITERAL, JSU.N(1));
+                b.add(parserLine, tok == INC ? ADD : SUB, JSU.N(2));
                 b.add(parserLine, PUT, null);
                 b.add(parserLine, SWAP, null);
                 b.add(parserLine, POP, null);
-                b.add(parserLine, LITERAL, Script.N(1));
-                b.add(parserLine, tok == INC ? SUB : ADD, Script.N(2));   // undo what we just did, since this is postfix
+                b.add(parserLine, LITERAL, JSU.N(1));
+                b.add(parserLine, tok == INC ? SUB : ADD, JSU.N(2));   // undo what we just did, since this is postfix
             } else {
                 b.add(parserLine, SCOPEGET, varKey);
                 b.add(parserLine, DUP);
-                b.add(parserLine, LITERAL, Script.ONE);
-                b.add(parserLine, tok == INC ? ADD : SUB, Script.N(2));
+                b.add(parserLine, LITERAL, JSU.ONE);
+                b.add(parserLine, tok == INC ? ADD : SUB, JSU.N(2));
                 b.add(parserLine, SCOPEPUT, varKey);
             }
             break;
@@ -523,7 +523,7 @@ class Parser extends Lexer implements ByteCodes {
             // return JS.METHOD
             b.add(parserLine, varKey == null ? GET_PRESERVE : SCOPEGET, varKey);
             int n = parseArgs(b);
-            b.add(parserLine, varKey == null ? CALLMETHOD : CALL, Script.N(n));
+            b.add(parserLine, varKey == null ? CALLMETHOD : CALL, JSU.N(n));
             break;
         }
         default: {
@@ -568,7 +568,7 @@ class Parser extends Lexer implements ByteCodes {
         switch (tok) {
         case LP: {  // invocation (not grouping)
             int n = parseArgs(b);
-            b.add(parserLine, CALL, Script.N(n));
+            b.add(parserLine, CALL, JSU.N(n));
             break;
         }
         case BITOR: case BITXOR: case BITAND: case SHEQ: case SHNE: case LSH:
@@ -587,17 +587,17 @@ class Parser extends Lexer implements ByteCodes {
                 nextTok = getToken();
             } while(nextTok == tok);
             pushBackToken();
-            b.add(parserLine, tok, Script.N(count));
+            b.add(parserLine, tok, JSU.N(count));
             break;
         }
         case OR: case AND: {
-            b.add(parserLine, tok == AND ? JSFunction.JF : JSFunction.JT, Script.ZERO);       // test to see if we can short-circuit
+            b.add(parserLine, tok == AND ? JSFunction.JF : JSFunction.JT, JSU.ZERO);       // test to see if we can short-circuit
             int size = b.size;
             startExpr(b, precedence[tok]);                                     // otherwise check the second value
-            b.add(parserLine, JMP, Script.N(2));                            // leave the second value on the stack and jump to the end
+            b.add(parserLine, JMP, JSU.N(2));                            // leave the second value on the stack and jump to the end
             b.add(parserLine, LITERAL, tok == AND ?
-                  Script.B(false) : Script.B(true));                     // target of the short-circuit jump is here
-            b.set(size - 1, Script.N(b.size - size));                     // write the target of the short-circuit jump
+                  JSU.B(false) : JSU.B(true));                     // target of the short-circuit jump is here
+            b.set(size - 1, JSU.N(b.size - size));                     // write the target of the short-circuit jump
             break;
         }
         case DOT: {
@@ -618,15 +618,15 @@ class Parser extends Lexer implements ByteCodes {
             break;
         }
         case HOOK: {
-            b.add(parserLine, JF, Script.ZERO);                // jump to the if-false expression
+            b.add(parserLine, JF, JSU.ZERO);                // jump to the if-false expression
             int size = b.size;
             startExpr(b, minPrecedence);                          // write the if-true expression
-            b.add(parserLine, JMP, Script.ZERO);               // if true, jump *over* the if-false expression     
-            b.set(size - 1, Script.N(b.size - size + 1));    // now we know where the target of the jump is
+            b.add(parserLine, JMP, JSU.ZERO);               // if true, jump *over* the if-false expression     
+            b.set(size - 1, JSU.N(b.size - size + 1));    // now we know where the target of the jump is
             consume(COLON);
             size = b.size;
             startExpr(b, minPrecedence);                          // write the if-false expression
-            b.set(size - 1, Script.N(b.size - size + 1));    // this is the end; jump to here
+            b.set(size - 1, JSU.N(b.size - size + 1));    // this is the end; jump to here
             break;
         }
         case COMMA: {
@@ -724,18 +724,18 @@ class Parser extends Lexer implements ByteCodes {
             startExpr(b, -1);
             consume(RP);
             
-            b.add(parserLine, JF, Script.ZERO);                    // if false, jump to the else-block
+            b.add(parserLine, JF, JSU.ZERO);                    // if false, jump to the else-block
             int size = b.size;
             parseStatement(b, null);
             
             if (peekToken() == ELSE) {
                 consume(ELSE);
-                b.add(parserLine, JMP, Script.ZERO);               // if we took the true-block, jump over the else-block
-                b.set(size - 1, Script.N(b.size - size + 1));
+                b.add(parserLine, JMP, JSU.ZERO);               // if we took the true-block, jump over the else-block
+                b.set(size - 1, JSU.N(b.size - size + 1));
                 size = b.size;
                 parseStatement(b, null);
             }
-            b.set(size - 1, Script.N(b.size - size + 1));        // regardless of which branch we took, b[size] needs to point here
+            b.set(size - 1, JSU.N(b.size - size + 1));        // regardless of which branch we took, b[size] needs to point here
             break;
         }
         case WHILE: {
@@ -745,12 +745,12 @@ class Parser extends Lexer implements ByteCodes {
             int size = b.size;
             b.add(parserLine, POP);                                   // discard the first-iteration indicator
             startExpr(b, -1);
-            b.add(parserLine, JT, Script.N(2));                    // if the while() clause is true, jump over the BREAK
+            b.add(parserLine, JT, JSU.N(2));                    // if the while() clause is true, jump over the BREAK
             b.add(parserLine, BREAK);
             consume(RP);
             parseStatement(b, null);
             b.add(parserLine, CONTINUE);                              // if we fall out of the end, definately continue
-            b.set(size - 1, Script.N(b.size - size + 1));        // end of the loop
+            b.set(size - 1, JSU.N(b.size - size + 1));        // end of the loop
             break;
         }
         case SWITCH: {
@@ -768,10 +768,10 @@ class Parser extends Lexer implements ByteCodes {
                     startExpr(b, -1);
                     consume(COLON);
                     b.add(parserLine, EQ);                         // check if we should do this case-block
-                    b.add(parserLine, JF, Script.ZERO);         // if not, jump to the next one
+                    b.add(parserLine, JF, JSU.ZERO);         // if not, jump to the next one
                     int size = b.size;
                     while(peekToken() != CASE && peekToken() != DEFAULT && peekToken() != RC) parseStatement(b, null);
-                    b.set(size - 1, Script.N(1 + b.size - size));
+                    b.set(size - 1, JSU.N(1 + b.size - size));
                 } else if (peekToken() == DEFAULT) {
                     consume(DEFAULT);
                     consume(COLON);
@@ -783,7 +783,7 @@ class Parser extends Lexer implements ByteCodes {
                 } else {
                     throw pe("expected CASE, DEFAULT, or RC; got " + codeToString[peekToken()]);
                 }
-            b.set(size0 - 1, Script.N(b.size - size0 + 1));      // end of the loop
+            b.set(size0 - 1, JSU.N(b.size - size0 + 1));      // end of the loop
             break;
         }
             
@@ -795,12 +795,12 @@ class Parser extends Lexer implements ByteCodes {
             consume(WHILE);
             consume(LP);
             startExpr(b, -1);
-            b.add(parserLine, JT, Script.N(2));                  // check the while() clause; jump over the BREAK if true
+            b.add(parserLine, JT, JSU.N(2));                  // check the while() clause; jump over the BREAK if true
             b.add(parserLine, BREAK);
             b.add(parserLine, CONTINUE);
             consume(RP);
             consume(SEMI);
-            b.set(size - 1, Script.N(b.size - size + 1));      // end of the loop; write this location to the LOOP instruction
+            b.set(size - 1, JSU.N(b.size - size + 1));      // end of the loop; write this location to the LOOP instruction
             break;
         }
             
@@ -879,7 +879,7 @@ class Parser extends Lexer implements ByteCodes {
                     b.add(parserLine, JMP);
                     catchEnds.add(new Integer(b.size-1));
                     
-                    for(int i=0; i<3; i++) if (writebacks[i] != -1) b.set(writebacks[i], Script.N(b.size-writebacks[i]));
+                    for(int i=0; i<3; i++) if (writebacks[i] != -1) b.set(writebacks[i], JSU.N(b.size-writebacks[i]));
                     b.add(parserLine, POP); // pop the element thats on the stack from the compare
                 }
                 
@@ -888,7 +888,7 @@ class Parser extends Lexer implements ByteCodes {
                 
                 for(int i=0;i<catchEnds.size();i++) {
                     int n = ((Integer)catchEnds.get(i)).intValue();
-                    b.set(n, Script.N(b.size-n));
+                    b.set(n, JSU.N(b.size-n));
                 }
                 
                 // pop the try and catch markers
@@ -897,7 +897,7 @@ class Parser extends Lexer implements ByteCodes {
             }
                         
             // jump here if no exception was thrown
-            b.set(successJMPInsn, Script.N(b.size - successJMPInsn)); 
+            b.set(successJMPInsn, JSU.N(b.size - successJMPInsn)); 
                         
             int finallyJMPDistance = -1;
             if (peekToken() == FINALLY) {
@@ -938,14 +938,14 @@ class Parser extends Lexer implements ByteCodes {
                 
                 b.add(parserLine,SWAP); // get the keys enumeration object on top
                 b.add(parserLine,DUP);
-                b.add(parserLine,GET,Script.S("hasMoreElements"));
+                b.add(parserLine,GET,JSU.S("hasMoreElements"));
                 int size2 = b.size;
                 b.add(parserLine,JT);
                 b.add(parserLine,SWAP);
                 b.add(parserLine,BREAK);
-                b.set(size2, Script.N(b.size - size2));
+                b.set(size2, JSU.N(b.size - size2));
                 b.add(parserLine,DUP);
-                b.add(parserLine,GET,Script.S("nextElement"));
+                b.add(parserLine,GET,JSU.S("nextElement"));
 
                 scopePush(b);
                 
@@ -970,7 +970,7 @@ class Parser extends Lexer implements ByteCodes {
                 scopePop(b);
                 b.add(parserLine, CONTINUE);
                 // jump here on break
-                b.set(size, Script.N(b.size - size));
+                b.set(size, JSU.N(b.size - size));
                 
                 b.add(parserLine, POP);
             } else {
@@ -983,27 +983,27 @@ class Parser extends Lexer implements ByteCodes {
                 if (peekToken() != SEMI)
                     startExpr(e2, -1);
                 else
-                    e2.add(parserLine, JSFunction.LITERAL, Script.T);         // handle the for(foo;;foo) case
+                    e2.add(parserLine, JSFunction.LITERAL, JSU.T);         // handle the for(foo;;foo) case
                 consume(SEMI);
                 if (label != null) b.add(parserLine, LABEL, label);
                 b.add(parserLine, LOOP);
                 int size2 = b.size;
                     
-                b.add(parserLine, JT, Script.ZERO);                   // if we're on the first iteration, jump over the incrementor
+                b.add(parserLine, JT, JSU.ZERO);                   // if we're on the first iteration, jump over the incrementor
                 int size = b.size;
                 if (peekToken() != RP) {                                 // do the increment thing
                     startExpr(b, -1);
                     b.add(parserLine, POP);
                 }
-                b.set(size - 1, Script.N(b.size - size + 1));
+                b.set(size - 1, JSU.N(b.size - size + 1));
                 consume(RP);
                     
                 b.paste(e2);                                             // ok, *now* test if we're done yet
-                b.add(parserLine, JT, Script.N(2));                   // break out if we don't meet the test
+                b.add(parserLine, JT, JSU.N(2));                   // break out if we don't meet the test
                 b.add(parserLine, BREAK);
                 parseStatement(b, null);
                 b.add(parserLine, CONTINUE);                             // if we fall out the bottom, CONTINUE
-                b.set(size2 - 1, Script.N(b.size - size2 + 1));     // end of the loop
+                b.set(size2 - 1, JSU.N(b.size - size2 + 1));     // end of the loop
                     
                 scopePop(b);                            // get our scope back
             }
index d1a2d61..519eac7 100644 (file)
@@ -49,16 +49,16 @@ public class SOAP extends XMLRPC {
             if (key.endsWith("ype")) {
                 if (value.endsWith("boolean")) {
                     objects.pop();
-                    objects.push(Script.B(true));
+                    objects.push(JSU.B(true));
                 } else if (value.endsWith("int")) {
                     objects.pop();
-                    objects.push(Script.N(0));
+                    objects.push(JSU.N(0));
                 } else if (value.endsWith("double")) {
                     objects.pop();
-                    objects.push(Script.N(0.0));
+                    objects.push(JSU.N(0.0));
                 } else if (value.endsWith("string")) {
                     objects.pop();
-                    objects.push(Script.S(""));
+                    objects.push(JSU.S(""));
                 } else if (value.endsWith("base64")) {
                     objects.pop();
                     objects.push(new byte[] { });
@@ -152,7 +152,7 @@ public class SOAP extends XMLRPC {
         } else if (parent != null && parent instanceof JS) {
             objects.pop();
             try {
-                ((JS)parent).put(Script.S(name), me);
+                ((JS)parent).put(JSU.S(name), me);
             } catch (JSExn e) {
                 throw new Error("this should never happen");
             }
index 9598db4..8c06220 100644 (file)
@@ -13,34 +13,34 @@ public class Test extends JS.Obj {
     
     public static void main(String[] args) throws Exception {
         if(args.length == 0) { System.err.println("Usage Test filename"); System.exit(1); }
-        JS f = Script.fromReader(args[0],1,new FileReader(args[0]));
+        JS f = JSU.fromReader(args[0],1,new FileReader(args[0]));
         System.out.println(((JSFunction)f).dump());
         JS s = new JS.Obj();
-        s.put(Script.S("sys"),new Test());
-        f = Script.cloneWithNewGlobalScope(f,s);
+        s.put(JSU.S("sys"),new Test());
+        f = JSU.cloneWithNewGlobalScope(f,s);
         //JS ret = f.call(null,null,null,null,0);
         Interpreter i = new Interpreter((JSFunction)f, true, new JS[0]);
         JS ret = (JS)i.run(null);
         try { while(true) {
             if("throw".equals(action)) ret = (JS)i.run(new JSExn("this was thrown to a paused context"));
-            else if("bgget".equals(action)) ret = (JS)i.run(Script.S("I'm returning this from a get request"));
+            else if("bgget".equals(action)) ret = (JS)i.run(JSU.S("I'm returning this from a get request"));
             else {
                 System.out.println("got a background put " + action);
                 ret = (JS)i.run(null);
             }
         } } catch (Pausable.AlreadyRunningException e) {}
-        System.out.println("Script returned: " + Script.toString(ret));
+        System.out.println("Script returned: " + JSU.toString(ret));
     }
     
     public JS get(JS key) throws JSExn {
-        if(!Script.isString(key)) return null;
-        if("print".equals(Script.toString(key))) return METHOD;
-        if("clone".equals(Script.toString(key))) return METHOD;
-        if("firethis".equals(Script.toString(key))) return METHOD;
-        if("bgget".equals(Script.toString(key))) {
+        if(!JSU.isString(key)) return null;
+        if("print".equals(JSU.toString(key))) return METHOD;
+        if("clone".equals(JSU.toString(key))) return METHOD;
+        if("firethis".equals(JSU.toString(key))) return METHOD;
+        if("bgget".equals(JSU.toString(key))) {
             action = "bgget";
             try {
-                Script.pause();
+                JSU.pause();
             } catch(Pausable.NotPausableException e) {
                 throw new Error("should never happen");
             }
@@ -50,37 +50,37 @@ public class Test extends JS.Obj {
     }
         
     public void put(JS key, JS val) throws JSExn {
-        if("bgput".equals(Script.toString(key))) {
-            action = Script.toString(val);
+        if("bgput".equals(JSU.toString(key))) {
+            action = JSU.toString(val);
             try {
-                Script.pause();
+                JSU.pause();
             } catch(Pausable.NotPausableException e) {
                 throw new Error("should never happen");
             }
             return;
         }   
-        if("exit".equals(Script.toString(key))) {
-            System.exit(Script.toInt(val));
+        if("exit".equals(JSU.toString(key))) {
+            System.exit(JSU.toInt(val));
             return;
         }
         super.put(key,val);
     }
     
     public JS call(JS method, JS[] args) throws JSExn {
-        if(!Script.isString(method)) return null;
-        if("print".equals(Script.toString(method))) {
-            System.out.println(Script.str(args[0]));
+        if(!JSU.isString(method)) return null;
+        if("print".equals(JSU.toString(method))) {
+            System.out.println(JSU.str(args[0]));
             return null;
         }
-        if("clone".equals(Script.toString(method)))
+        if("clone".equals(JSU.toString(method)))
             return args.length < 1 || args[0] == null ? null : new JS.Clone(args[0]);
-        if("firethis".equals(Script.toString(method))) {
-            String action = Script.toString(args[0]);
+        if("firethis".equals(JSU.toString(method))) {
+            String action = JSU.toString(args[0]);
             JS target = args[1];
             JS key = args[2];
             if(action.equals("get")) return args[1].getAndTriggerTraps(key);
-            else if(action.equals("put")) args[1].putAndTriggerTraps(key,Script.S("some value"));
-            else if(action.equals("trigger")) return target.justTriggerTraps(key,Script.S("some trigger value"));
+            else if(action.equals("put")) args[1].putAndTriggerTraps(key,JSU.S("some value"));
+            else if(action.equals("trigger")) return target.justTriggerTraps(key,JSU.S("some trigger value"));
             return null;
         }
         return null;
index 44324e0..cdf4789 100644 (file)
@@ -40,7 +40,7 @@ public class XMLRPC extends JS.Immutable {
     public XMLRPC(String url, String method, XMLRPC httpSource) {
         this.http = httpSource.http; this.url = url; this.method = method; }
     public JS get(JS name) throws JSExn {
-        return new XMLRPC(url, (method.equals("") ? "" : method + ".") + Script.toString(name), this); }
+        return new XMLRPC(url, (method.equals("") ? "" : method + ".") + JSU.toString(name), this); }
 
 
     /** this holds character content as we read it in -- since there is only one per instance, we don't support mixed content */
@@ -150,7 +150,7 @@ public class XMLRPC extends JS.Immutable {
                 for(i=objects.size() - 1; objects.get(i) != null; i--);
                 JSArray arr = new JSArray();
                 try {
-                    for(int j = i + 1; j<objects.size(); j++) arr.put(Script.N(j - i - 1), (JS)objects.get(j));
+                    for(int j = i + 1; j<objects.size(); j++) arr.put(JSU.N(j - i - 1), (JS)objects.get(j));
                 } catch (JSExn e) {
                     throw new Error("this should never happen");
                 }
@@ -279,7 +279,7 @@ public class XMLRPC extends JS.Immutable {
 
         } else if (o instanceof JSArray) {
             if (tracker.get(o) != null) throw new JSExn("attempted to send multi-ref data structure via XML-RPC");
-            tracker.put(o, Script.B(true));
+            tracker.put(o, JSU.B(true));
             sb.append("                <value><array><data>\n");
             JSArray a = (JSArray)o;
             for(int i=0; i < a.size(); i++) appendObject(a.get(i), sb);
@@ -287,7 +287,7 @@ public class XMLRPC extends JS.Immutable {
 
         } else if (o instanceof JS) {
             if (tracker.get(o) != null) throw new JSExn("attempted to send multi-ref data structure via XML-RPC");
-            tracker.put(o, Script.B(true));
+            tracker.put(o, JSU.B(true));
             JS j = (JS)o;
             sb.append("                <value><struct>\n");
             Enumeration e = j.keys();