preliminary core conversion
authorbrian <brian@brianweb.net>
Tue, 6 Jul 2004 00:04:25 +0000 (00:04 +0000)
committerbrian <brian@brianweb.net>
Tue, 6 Jul 2004 00:04:25 +0000 (00:04 +0000)
darcs-hash:20040706000425-24bed-2f16fdf8a0fa2cee22210a7a38817d9ac7e91d07.gz

14 files changed:
src/org/ibex/core/Box.java
src/org/ibex/core/Ibex.java
src/org/ibex/core/Main.java
src/org/ibex/core/Template.java
src/org/ibex/graphics/Color.java
src/org/ibex/graphics/HTML.java
src/org/ibex/graphics/Surface.java
src/org/ibex/net/HTTP.java
src/org/ibex/net/SOAP.java
src/org/ibex/net/XMLRPC.java
src/org/ibex/plat/Platform.java
src/org/ibex/util/Grammar.java
src/org/ibex/util/Log.java
src/org/ibex/util/Preprocessor.java

index bb8a27b..29cd9bc 100644 (file)
@@ -57,7 +57,7 @@ public final class Box extends JSScope implements Task {
     // FIXME memory leak
     static Hash boxToCursor = new Hash(500, 3);
 
-    static final Font DEFAULT_FONT = Font.getFont((Stream)Main.builtin.get("fonts/vera/Vera.ttf"), 10);
+    static final Font DEFAULT_FONT = Font.getFont((Stream)Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10);
 
 
     // Flags //////////////////////////////////////////////////////////////////////
@@ -230,9 +230,11 @@ public final class Box extends JSScope implements Task {
         set(REPLACE); // FIXME: be smarter / more incremental
     }
     
+    private final static JS SIZECHANGE = JS.S("SizeChange");
+    
     void resize(int x, int y, int width, int height) {
         if (x == this.x && y == this.y && width == this.width && height == this.height) return;
-        boolean sizechange = (this.width != width || this.height != height) && hasTrap("SizeChange");
+        boolean sizechange = (this.width != width || this.height != height) && hasTrap(SIZECHANGE);
         int thisx = parent == null ? 0 : this.x;
         int thisy = parent == null ? 0 : this.y;
         Box who = (parent == null ? this : parent);
@@ -248,7 +250,7 @@ public final class Box extends JSScope implements Task {
             this.width = width; this.height = height; this.x = x; this.y = y;
             dirty();
         }
-        if (sizechange) putAndTriggerTrapsAndCatchExceptions("SizeChange", T);
+        if (sizechange) putAndTriggerTrapsAndCatchExceptions(SIZECHANGE, T);
     }
 
     private float targetColumnSize = (float)0.0;
@@ -434,10 +436,10 @@ public final class Box extends JSScope implements Task {
     // Methods to implement org.ibex.js.JS //////////////////////////////////////
 
   
-    public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+    public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
         switch (nargs) {
             case 1: {
-                //#switch(method)
+                //#switch(JS.toString(method))
                 case "indexof":
                     Box b = (Box)a0;
                     if (b.parent != this)
@@ -449,8 +451,8 @@ public final class Box extends JSScope implements Task {
                 case "distanceto":
                     Box b = (Box)a0;
                     JS ret = new JS.O();
-                    ret.put("x", N(b.localToGlobalX(0) - localToGlobalX(0)));
-                    ret.put("y", N(b.localToGlobalY(0) - localToGlobalY(0)));
+                    ret.put(JS.S("x"), N(b.localToGlobalX(0) - localToGlobalX(0)));
+                    ret.put(JS.S("y"), N(b.localToGlobalY(0) - localToGlobalY(0)));
                     return ret;
 
                 //#end
@@ -459,29 +461,30 @@ public final class Box extends JSScope implements Task {
         return super.callMethod(method, a0, a1, a2, rest, nargs);
     }
 
-    public Object get(Object name) throws JSExn {
-        if (name instanceof Number)
-            return redirect == null ? null : redirect == this ? getChild(toInt(name)) : redirect.get(name);
+    public JS get(JS name) throws JSExn {
+        if (JS.isInt(name))
+            return redirect == null ? null : redirect == this ? getChild(JS.toInt(name)) : redirect.get(name);
 
-        //#switch(name)
-        case "surface": return parent == null ? null : parent.getAndTriggerTraps("surface");
+        //#switch(JS.toString(name))
+        case "surface": return parent == null ? null : parent.getAndTriggerTraps(name);
         case "indexof": return METHOD;
         case "distanceto": return METHOD;
-        case "text": return text;
-        case "path": 
-            if (path != null) return path.toString();
+        case "text": return JS.S(text);
+        case "path": {
+            if (path != null) return JS.S(path.toString());
             if (text == null) return null;
             if (font == null) return null;
             String ret = "";
             for(int i=0; i<text.length(); i++) ret += font.glyphs[text.charAt(i)].path;
-            return ret;
-        case "fill": return Color.colorToString(fillcolor);
-        case "strokecolor": return Color.colorToString(strokecolor);
-        case "textcolor": return Color.colorToString(strokecolor);
+            return JS.S(ret);
+        }
+        case "fill": return JS.S(Color.colorToString(fillcolor));
+        case "strokecolor": return JS.S(Color.colorToString(strokecolor));
+        case "textcolor": return JS.S(Color.colorToString(strokecolor));
         case "font": return font == null ? null : font.stream;
         case "fontsize": return font == null ? N(10) : N(font.pointsize);
         case "strokewidth": return N(strokewidth);
-        case "align": return alignToString();
+        case "align": return JS.S(alignToString());
         case "thisbox": return this;
         case "shrink": return B(test(HSHRINK) || test(VSHRINK));
         case "hshrink": return B(test(HSHRINK));
@@ -500,18 +503,18 @@ public final class Box extends JSScope implements Task {
         case "minheight": return N(minheight);
         case "maxheight": return N(maxheight);
         case "clip": return B(test(CLIP));
-        case "visible": return B(test(VISIBLE) && (parent == null || (parent.get("visible") == T)));
+        case "visible": return B(test(VISIBLE) && (parent == null || (parent.get(JS.S("visible")) == T)));
         case "packed": return B(test(PACKED));
         case "globalx": return N(localToGlobalX(0));
         case "globaly": return N(localToGlobalY(0));
-        case "cursor": return test(CURSOR) ? boxToCursor.get(this) : null;
+        case "cursor": return test(CURSOR) ? JS.S((String)boxToCursor.get(this)) : null;
         case "mouse":
             if (getSurface() == null) return null;
             if (getSurface()._mousex == Integer.MAX_VALUE)
                 throw new JSExn("you cannot read from the box.mouse property in background thread context");
             return new Mouse();
-        case "numchildren": return redirect == null ? N(0) : redirect == this ? N(treeSize()) : redirect.get("numchildren");
-        case "redirect": return redirect == null ? null : redirect == this ? T : redirect.get("redirect");
+        case "numchildren": return redirect == null ? N(0) : redirect == this ? N(treeSize()) : redirect.get(JS.S("numchildren"));
+        case "redirect": return redirect == null ? null : redirect == this ? T : redirect.get(JS.S("redirect"));
         case "Minimized": if (parent == null && getSurface() != null) return B(getSurface().minimized);
         default: return super.get(name);
         //#end
@@ -519,8 +522,8 @@ public final class Box extends JSScope implements Task {
     }
 
     private class Mouse extends JS implements JS.Cloneable {
-        public Object get(Object key) {
-            //#switch(key)
+        public JS get(JS key) throws JSExn {
+            //#switch(JS.toString(key))
             case "x": return N(globalToLocalX(getSurface()._mousex));
             case "y": return N(globalToLocalY(getSurface()._mousey));
 
@@ -546,13 +549,13 @@ public final class Box extends JSScope implements Task {
     }
     //#end
 
-    public void put(Object name, Object value) throws JSExn {
-        if (name instanceof Number) { put(toInt(name), value); return; }
-        //#switch(name)
+    public void put(JS name, JS value) throws JSExn {
+        if (JS.isInt(name)) { put(JS.toInt(name), value); return; }
+        //#switch(JS.toString(name))
         case "thisbox":     if (value == null) removeSelf();
-        case "text":        if (value == null) value = ""; CHECKSET_STRING(text); RECONSTRAIN(); dirty();
-        case "strokecolor": value = N(Color.stringToColor((String)value)); CHECKSET_INT(strokecolor); dirty();
-        case "textcolor":   value = N(Color.stringToColor((String)value)); CHECKSET_INT(strokecolor); dirty();
+        case "text":        { String s = value == null ?  "" : JS.toString(value); CHECKSET_STRING(text); RECONSTRAIN(); dirty(); }
+        case "strokecolor": value = N(Color.stringToColor(JS.toString(value))); CHECKSET_INT(strokecolor); dirty();
+        case "textcolor":   value = N(Color.stringToColor(JS.toString(value))); CHECKSET_INT(strokecolor); dirty();
         case "strokewidth": CHECKSET_SHORT(strokewidth); dirty();
         case "shrink":      CHECKSET_FLAG(HSHRINK | VSHRINK); RECONSTRAIN();
         case "hshrink":     CHECKSET_FLAG(HSHRINK); RECONSTRAIN();
@@ -568,8 +571,8 @@ public final class Box extends JSScope implements Task {
         case "rowspan":     if (toInt(value) > 0) { CHECKSET_SHORT(rowspan); if (parent != null) parent.REPACK(); }
         case "visible":     CHECKSET_FLAG(VISIBLE); RECONSTRAIN(); dirty();
         case "packed":      CHECKSET_FLAG(PACKED); if (parent != null) { parent.REPACK(); } else { REPACK(); }
-        case "align":       clear(ALIGNS); setAlign(value == null ? "center" : value); REPLACE();
-        case "cursor":      setCursor(value);
+        case "align":       clear(ALIGNS); setAlign(value == null ? "center" : JS.toString(value)); REPLACE();
+        case "cursor":      setCursor(JS.toString(value));
         case "fill":        setFill(value);
         case "clip":        CHECKSET_FLAG(CLIP); if (parent == null) dirty(); else parent.dirty();
         case "rows": CHECKSET_SHORT(rows); if (rows==0){set(FIXED, COLS);if(cols==0)cols=1;} else set(FIXED, ROWS); REPACK();
@@ -577,8 +580,8 @@ public final class Box extends JSScope implements Task {
 
         // FIXME: remove
         case "mouse":
-            int mousex = toInt(((JS)value).get("x"));
-            int mousey = toInt(((JS)value).get("y"));
+            int mousex = toInt(((JS)value).get(JS.S("x")));
+            int mousey = toInt(((JS)value).get(JS.S("y")));
             getSurface()._mousex = localToGlobalX(mousex);
             getSurface()._mousey = localToGlobalY(mousey);
 
@@ -592,7 +595,7 @@ public final class Box extends JSScope implements Task {
         case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); dirty();
         case "font":
             if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property");
-            if (font == value) return;  // FIXME: unclone()
+            //FIXME: if (font == value) return;  // FIXME: unclone()
             font = value == null ? null : Font.getFont((Stream)value, font == null ? 10 : font.pointsize);
             RECONSTRAIN();
             dirty();
@@ -629,9 +632,9 @@ public final class Box extends JSScope implements Task {
         case "KeyReleased":   if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value);
         case "Move":          if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value);
         case "HScroll":       if (!test(STOP_UPWARD_PROPAGATION) && parent != null)
-            parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize())));
+            parent.putAndTriggerTraps(name, N(JS.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize())));
         case "VScroll":       if (!test(STOP_UPWARD_PROPAGATION) && parent != null)
-            parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize())));
+            parent.putAndTriggerTraps(name, N(JS.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize())));
 
         case "_Move":         propagateDownward(name, value, false);
         case "_Press1":       propagateDownward(name, value, false);
@@ -675,7 +678,7 @@ public final class Box extends JSScope implements Task {
         }
     }
 
-    private void setAlign(Object value) {
+    private void setAlign(String value) {
         clear(ALIGNS);
         //#switch(value)
         case "topleft": set(ALIGN_TOP | ALIGN_LEFT);
@@ -690,7 +693,7 @@ public final class Box extends JSScope implements Task {
         //#end
     }
     
-    private void setCursor(Object value) {
+    private void setCursor(String value) throws JSExn {
         if (value == null) { clear(CURSOR); boxToCursor.remove(this); return; }
         if (value.equals(boxToCursor.get(this))) return;
         set(CURSOR);
@@ -702,24 +705,22 @@ public final class Box extends JSScope implements Task {
         if (surface.cursor != tempcursor) surface.syncCursor();
     }
 
-    private void setFill(Object value) throws JSExn {
+    private void setFill(JS value) throws JSExn {
         if (value == null) {
             if (texture == null && fillcolor == 0) return;
             texture = null;
             fillcolor = 0;
-        } else if (value instanceof String) {
-            int newfillcolor = Color.stringToColor((String)value);
+        } else if (JS.isString(value)) {
+            int newfillcolor = Color.stringToColor(JS.toString(value));
             if (newfillcolor == fillcolor) return;
             fillcolor = newfillcolor;
             texture = null;
-        } else if (value instanceof JS) {
+        } else {
             Picture newtex = Picture.load((JS)value, this);
             if (texture == newtex) return;
             texture = newtex;
             fillcolor = 0;
             if (texture != null && texture.isLoaded) perform();
-        } else {
-            throw new JSExn("fill must be null, a String, or a stream, not a " + value.getClass());
         }
         dirty();
     }
@@ -728,9 +729,9 @@ public final class Box extends JSScope implements Task {
      *  Handles events which propagate down the box tree.  If obscured
      *  is set, then we merely check for Enter/Leave.
      */
-    private void propagateDownward(Object name_, Object value, boolean obscured) {
+    private void propagateDownward(JS name_, JS value, boolean obscured) throws JSExn {
 
-        String name = (String)name_;
+        String name = JS.toString(name_);
         if (getSurface() == null) return;
         int x = globalToLocalX(getSurface()._mousex);
         int y = globalToLocalY(getSurface()._mousey);
@@ -738,28 +739,28 @@ public final class Box extends JSScope implements Task {
         boolean isinside = test(VISIBLE) && inside(x, y) && !obscured;
         if (!wasinside && isinside) {
             set(MOUSEINSIDE);
-            putAndTriggerTrapsAndCatchExceptions("Enter", T);
+            putAndTriggerTrapsAndCatchExceptions(JS.S("Enter"), T);
         }
         if (isinside && test(CURSOR)) getSurface().cursor = (String)boxToCursor.get(this);
         if (wasinside && !isinside) {
             clear(MOUSEINSIDE);
-            putAndTriggerTrapsAndCatchExceptions("Leave", T);
+            putAndTriggerTrapsAndCatchExceptions(JS.S("Leave"), T);
         }
 
         boolean found = false;
         if (wasinside || isinside)
             for(Box child = getChild(treeSize() - 1); child != null; child = child.prevSibling()) {
                 boolean save_stop = child.test(STOP_UPWARD_PROPAGATION);
-                Object value2 = value;
+                JS value2 = value;
                 if (name.equals("_HScroll") || name.equals("_VScroll"))
-                    value2 = N(((Number)value).floatValue() * ((float)child.fontSize()) / (float)fontSize());
+                    value2 = N(JS.toFloat(value) * ((float)child.fontSize()) / (float)fontSize());
                 if (obscured || !child.inside(x - child.x, y - child.y)) {
-                    child.propagateDownward(name, value2, true);
+                    child.propagateDownward(name_, value2, true);
                 } else try {
                     found = true;
                     child.clear(STOP_UPWARD_PROPAGATION);
-                    if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name, value2);
-                    else child.propagateDownward(name, value2, obscured);
+                    if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name_, value2);
+                    else child.propagateDownward(name_, value2, obscured);
                 } finally {
                     if (save_stop) child.set(STOP_UPWARD_PROPAGATION); else child.clear(STOP_UPWARD_PROPAGATION);
                 }
@@ -771,7 +772,7 @@ public final class Box extends JSScope implements Task {
         if (!obscured && !found)
             if ("_Move".equals(name) || name.startsWith("_Release") || wasinside)
                 if (name != null)
-                    putAndTriggerTrapsAndCatchExceptions(name.substring(1), value);
+                    putAndTriggerTrapsAndCatchExceptions(JS.S(name.substring(1)), value);
     }
 
     /** figures out what box in this subtree of the Box owns the pixel at x,y relitave to the Surface */
@@ -862,10 +863,10 @@ public final class Box extends JSScope implements Task {
         deleteNode(i);
         b.parent = null;
         REPACK();
-        putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+        putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);
     }
     
-    public void put(int i, Object value) throws JSExn {
+    public void put(int i, JS value) throws JSExn {
         if (i < 0) return;
             
         if (value != null && !(value instanceof Box)) {
@@ -874,22 +875,22 @@ public final class Box extends JSScope implements Task {
         }
 
         if (redirect == null) {
-            if (value == null) putAndTriggerTrapsAndCatchExceptions("ChildChange", getChild(i));
+            if (value == null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), getChild(i));
             else JS.warn("attempt to add/remove children to/from a node with a null redirect");
 
         } else if (redirect != this) {
-            if (value != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", value);
+            if (value != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), value);
             redirect.put(i, value);
             if (value == null) {
-                Box b = (Box)redirect.get(new Integer(i));
-                if (b != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+                Box b = (Box)redirect.get(JS.N(i));
+                if (b != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);
             }
 
         } else if (value == null) {
             if (i < 0 || i > treeSize()) return;
             Box b = getChild(i);
             removeChild(i);
-            putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+            putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);
 
         } else {
             Box b = (Box)value;
@@ -918,26 +919,19 @@ public final class Box extends JSScope implements Task {
             REPACK();
             
             b.dirty(); 
-            putAndTriggerTrapsAndCatchExceptions("ChildChange", b);
+            putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b);
         }
     }
     
-    public void putAndTriggerTrapsAndCatchExceptions(Object name, Object val) {
+    public void putAndTriggerTrapsAndCatchExceptions(JS name, JS val) {
         try {
             putAndTriggerTraps(name, val);
         } catch (JSExn e) {
-            JS.log("caught js exception while putting to trap \""+name+"\"");
+            JS.log("caught js exception while putting to trap \""+ JS.debugToString(name)+"\"");
             JS.log(e);
         } catch (Exception e) {
-            JS.log("caught exception while putting to trap \""+name+"\"");
+            JS.log("caught exception while putting to trap \""+ JS.debugToString(name)+"\"");
             JS.log(e);
         }
     }
-
 }
-
-
-
-
-
-
index b44ba5a..6492ed2 100644 (file)
@@ -29,9 +29,9 @@ public final class Ibex extends JS implements JS.Cloneable {
         while(str.indexOf('.') != -1) {
             String path = str.substring(0, str.indexOf('.'));
             str = str.substring(str.indexOf('.') + 1);
-            ret = (JS)ret.get(path);
+            ret = ret.get(JS.S(path));
         }
-        if (!"".equals(str)) ret = (JS)ret.get(str);
+        if (!"".equals(str)) ret = ret.get(JS.S(str));
         return ret;
     }
 
@@ -39,13 +39,13 @@ public final class Ibex extends JS implements JS.Cloneable {
     private class Sub extends JS {
         String key;
         Sub(String key) { this.key = key; }
-        public void put(Object key, Object val) throws JSExn { Ibex.this.put(this.key + "." + key, val); }
-        public Object get(Object key) throws JSExn { return Ibex.this.get(this.key + "." + key); }
-        public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+        public void put(JS key, JS val) throws JSExn { Ibex.this.put(this.key + "." + JS.toString(key), val); }
+        public JS get(JS key) throws JSExn { return Ibex.this.get(this.key + "." + JS.toString(key)); }
+        public JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
             return Ibex.this.callMethod(this.key, a0, a1, a2, rest, nargs);
         }
-        public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
-            return Ibex.this.callMethod(this.key + "." + method, a0, a1, a2, rest, nargs);
+        public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
+            return Ibex.this.callMethod(this.key + "." + JS.toString(method), a0, a1, a2, rest, nargs);
         }
     }
     private Cache subCache = new Cache(20);
@@ -55,7 +55,8 @@ public final class Ibex extends JS implements JS.Cloneable {
         return ret;
     }
 
-    public Object get(Object name) throws JSExn {
+    public JS get(JS key) throws JSExn { return JS.isString(key) ? get(JS.toString(key)) : null; }
+    JS get(String name) throws JSExn {
         if (name instanceof String && ((String)name).length() == 0) return rr;
         //#switch(name)
         case "math": return ibexMath;
@@ -70,9 +71,9 @@ public final class Ibex extends JS implements JS.Cloneable {
         case "ui.font.wait": return METHOD;
         case "ui.font.width": return METHOD;
         case "ui.font.height": return METHOD;
-        case "ui.font.sansserif": return Main.builtin.get("fonts/vera/Vera.ttf");
-        case "ui.font.monospace": return Main.builtin.get("fonts/vera/VeraMono.ttf");
-        case "ui.font.serif": return Main.builtin.get("fonts/vera/VeraSe.ttf");
+        case "ui.font.sansserif": return Main.builtin.get(JS.S("fonts/vera/Vera.ttf"));
+        case "ui.font.monospace": return Main.builtin.get(JS.S("fonts/vera/VeraMono.ttf"));
+        case "ui.font.serif": return Main.builtin.get(JS.S("fonts/vera/VeraSe.ttf"));
         case "ui.browser": return METHOD;
         case "ui.mouse": return getSub("ui.mouse");
         case "ui.mouse.button":
@@ -82,18 +83,18 @@ public final class Ibex extends JS implements JS.Cloneable {
             else return ZERO;
         case "ui.key": return getSub("ui.key");
         case "ui.key.name": return getSub("ui.key.name");
-        case "ui.key.name.alt": return Platform.altKeyName();
+        case "ui.key.name.alt": return JS.S(Platform.altKeyName());
         case "ui.key.alt": return Surface.alt ? T : F;
         case "ui.key.control": return Surface.control ? T : F;
         case "ui.key.shift": return Surface.shift ? T : F;
-        case "ui.clipboard": return Platform.getClipBoard();
+        case "ui.clipboard": return JS.S((String)Platform.getClipBoard());
         case "ui.maxdim": return N(Short.MAX_VALUE);
         case "ui.screen": return getSub("ui.screen");
         case "ui.screen.width": return N(Platform.getScreenWidth());
         case "ui.screen.height": return N(Platform.getScreenHeight());
         case "undocumented": return getSub("undocumented");
-        case "undocumented.initialOrigin": return Main.origin;
-        case "undocumented.initialTemplate": return Main.initialTemplate;
+        case "undocumented.initialOrigin": return JS.S(Main.origin);
+        case "undocumented.initialTemplate": return JS.S(Main.initialTemplate);
         case "thread": return getSub("thread");
         case "thread.yield": return METHOD;
         case "thread.sleep": return METHOD;
@@ -123,13 +124,14 @@ public final class Ibex extends JS implements JS.Cloneable {
         case "crypto.sha1": return METHOD;
         case "crypto.rc4": return METHOD;
         //#end
-        return super.get(name);
+        return null;
     }
 
-    public void put(Object name, final Object value) throws JSExn {
+    public void put(JS key, JS value) throws JSExn { if(JS.isString(key)) put(JS.toString(key),value); else super.put(key,value); }
+    void put(Object name, final JS value) throws JSExn {
         //#switch(name)
         case "thread": Scheduler.add((Task)value); return;
-        case "ui.clipboard": Platform.setClipBoard((String)value); return;
+        case "ui.clipboard": Platform.setClipBoard(JS.toString(value)); return;
         case "ui.frame": Platform.createSurface((Box)value, true, true); return;
         case "ui.window": Platform.createSurface((Box)value, false, true); return;
         case "undocumented.proxyAuthorization":
@@ -140,11 +142,15 @@ public final class Ibex extends JS implements JS.Cloneable {
         throw new JSExn("attempted to put unknown property: ibex."+name);
     }
 
-    public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
+    public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
+        if(JS.isString(name)) return callMethod(JS.toString(name),a,b,c,rest,nargs);
+        return super.callMethod(name,a,b,c,rest,nargs);
+    }
+    JS callMethod(String name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
         try {
             //#switch(name)
             case "date": return new JSDate(a, b, c, rest, nargs);
-            case "net.rpc.soap": return new SOAP((String)a, "", (String)b, (String)c);
+            case "net.rpc.soap": return new SOAP(JS.toString(a), "", JS.toString(b), JS.toString(c));
                 // FIXME support object dumping
             case "log.debug":    JS.debug(a== null ? "**null**" : a.toString()); return null;
             case "log.info":     JS.info(a== null ? "**null**" : a.toString()); return null;
@@ -164,14 +170,14 @@ public final class Ibex extends JS implements JS.Cloneable {
                         if(a == null) throw new JSExn("can't clone the null value");
                         return ((JS)a).jsclone();
                     case "bless": return bless((JS)a);
-                    case "ui.browser": Platform.newBrowserWindow((String)a); return null;
+                    case "ui.browser": Platform.newBrowserWindow(JS.toString(a)); return null;
                     case "stream.unzip": return new Stream.Zip((Stream)a);
                     case "stream.uncab": return new Stream.Cab((Stream)a);
                     case "stream.cache":
                         try { return new Stream.CachedStream((Stream)a, "resources", true); }
                         catch (Stream.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); }
                     case "stream.url": {
-                        String url = (String)a;
+                        String url = JS.toString(a);
                         if (url.startsWith("http://")) return new Stream.HTTP(url);
                         else if (url.startsWith("https://")) return new Stream.HTTP(url);
                         else if (url.startsWith("data:")) return new Stream.ByteArray(Base64.decode(url.substring(5)), null);
@@ -184,7 +190,7 @@ public final class Ibex extends JS implements JS.Cloneable {
                     }
                     case "thread.sleep": sleep(JS.toInt(a)); return null;
                     case "regexp": return new JSRegexp(a, null);
-                    case "net.rpc.xml": return new XMLRPC((String)a, "");
+                    case "net.rpc.xml": return new XMLRPC(JS.toString(a), "");
                     case "crypto.rsa": /* FEATURE */ return null;
                     case "crypto.md5": /* FEATURE */ return null;
                     case "crypto.sha1": /* FEATURE */ return null;
@@ -192,7 +198,7 @@ public final class Ibex extends JS implements JS.Cloneable {
                     case "stream.parse.html": throw new JSExn("not implemented yet"); //return null;
                     case "stream.parse.xml": new XMLHelper((JS)b).doParse((JS)a); return null;
                         // FIXME backgrounding
-                    case "stream.parse.utf8": try { return new String(InputStreamToByteArray.convert(Stream.getInputStream(a))); }
+                    case "stream.parse.utf8": try { return JS.S(new String(InputStreamToByteArray.convert(Stream.getInputStream(a)))); }
                                               catch (Exception e) { Log.warn(this, e); }
                     //#end
                     break;
@@ -203,9 +209,9 @@ public final class Ibex extends JS implements JS.Cloneable {
                     //#end
                 case 3:
                     //#switch(name)
-                    case "ui.font.height": return N(Font.getFont((Stream)a, JS.toInt(b)).textheight((String)c));
+                    case "ui.font.height": return N(Font.getFont((Stream)a, JS.toInt(b)).textheight(JS.toString(c)));
                     case "ui.font.wait": throw new Error("FIXME: ibex.ui.font.wait not implemented");
-                    case "ui.font.width": return N(Font.getFont((Stream)a, JS.toInt(b)).textwidth((String)c));
+                    case "ui.font.width": return N(Font.getFont((Stream)a, JS.toInt(b)).textwidth(JS.toString(c)));
                     //#end
                     break;
             }
@@ -242,9 +248,9 @@ public final class Ibex extends JS implements JS.Cloneable {
     
     public static final JSMath ibexMath = new JSMath() {
             // FEATURE: find a cleaner way to do this
-            private JS gs = new JSScope.Global();
-            public Object get(Object key) throws JSExn {
-                //#switch(key)
+            private JS gs = /*new JSScope.Global();*/ null; // FIXME: Global scope
+            public JS get(JS key) throws JSExn {
+                //#switch(JS.toString(key))
                 case "isNaN": return METHOD;
                 case "isFinite": return METHOD;
                 case "NaN": return METHOD;
@@ -252,8 +258,8 @@ public final class Ibex extends JS implements JS.Cloneable {
                 //#end
                 return super.get(key);
             }
-            public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
-                //#switch(name)
+            public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
+                //#switch(JS.toString(name))
                 case "isNaN": return gs.callMethod(name,a,b,c,rest,nargs);
                 case "isFinite": return gs.callMethod(name,a,b,c,rest,nargs);
                 case "NaN": return gs.callMethod(name,a,b,c,rest,nargs);
@@ -264,9 +270,9 @@ public final class Ibex extends JS implements JS.Cloneable {
     };
 
     public static final JS ibexString = new JS() {
-            private JS gs = new JSScope.Global();
-            public Object get(Object key) throws JSExn {
-                //#switch(key)
+            private JS gs = /*new JSScope.Global();*/ null; // FIXME: Global scope
+            public JS get(JS key) throws JSExn {
+                //#switch(JS.toString(key))
                 case "parseInt": return METHOD;
                 case "parseFloat": return METHOD;
                 case "decodeURI": return METHOD;
@@ -279,8 +285,8 @@ public final class Ibex extends JS implements JS.Cloneable {
                 //#end
                 return super.get(key);
             }
-            public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
-                //#switch(name)
+            public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
+                //#switch(JS.toString(name))
                 case "parseInt": return gs.callMethod(name,a,b,c,rest,nargs);
                 case "parseFloat": return gs.callMethod(name,a,b,c,rest,nargs);
                 case "decodeURI": return gs.callMethod(name,a,b,c,rest,nargs);
@@ -300,29 +306,29 @@ public final class Ibex extends JS implements JS.Cloneable {
         private JS characters, whitespace, endElement, startElement;
         public XMLHelper(JS b) throws JSExn {
             super(BUFFER_SIZE);
-            startElement = (JS)b.getAndTriggerTraps("startElement");
-            endElement   = (JS)b.getAndTriggerTraps("endElement");
-            characters   = (JS)b.getAndTriggerTraps("characters");
-            whitespace   = (JS)b.getAndTriggerTraps("whitespace");
+            startElement = b.getAndTriggerTraps(JS.S("startElement"));
+            endElement   = b.getAndTriggerTraps(JS.S("endElement"));
+            characters   = b.getAndTriggerTraps(JS.S("characters"));
+            whitespace   = b.getAndTriggerTraps(JS.S("whitespace"));
         }
 
         public void startElement(XML.Element c) throws XML.Exn { try {
                 JS attrs = new JS.O();
                 // FIXME attribute URIs? add an additional hash?
-                for(int i=0; i<c.getAttrLen(); i++) attrs.put(c.getAttrKey(i), c.getAttrVal(i));
-                startElement.call(c.getLocalName(), attrs, c.getUri(), null, 3);
+                for(int i=0; i<c.getAttrLen(); i++) attrs.put(JS.S(c.getAttrKey(i)), JS.S(c.getAttrVal(i)));
+                startElement.call(JS.S(c.getLocalName()), attrs, JS.S(c.getUri()), null, 3);
         } catch (JSExn jse) { throw new Wrapper(jse); } }
 
         public void endElement(XML.Element c) throws XML.Exn { try {
-                endElement.call(c.getLocalName(), c.getUri(), null, null, 2);
+                endElement.call(JS.S(c.getLocalName()), JS.S(c.getUri()), null, null, 2);
         } catch (JSExn jse) { throw new Wrapper(jse); } }
 
         public void characters(char[] ch, int start, int length) throws XML.Exn { try {
-                characters.call(new String(ch, start, length), null, null, null, 1);
+                characters.call(JS.S(new String(ch, start, length)), null, null, null, 1);
         } catch (JSExn jse) { throw new Wrapper(jse); } }
 
         public void whitespace(char[] ch, int start, int length) throws XML.Exn { try {
-                whitespace.call(new String(ch, start, length), null, null, null, 1);
+                whitespace.call(JS.S(new String(ch, start, length)), null, null, null, 1);
         } catch (JSExn jse) { throw new Wrapper(jse); } }
 
         public void doParse(JS s) throws JSExn {
@@ -346,21 +352,19 @@ public final class Ibex extends JS implements JS.Cloneable {
     public static class Blessing extends JS.Clone {
         private Ibex ibex;
         private Template t = null;
-        public Object parentkey = null;
+        public JS parentkey = null;
         public Blessing parent = null;
         private Hash cache = new Hash();
-        public Blessing(JS clonee, Ibex ibex, Blessing parent, Object parentkey) throws JSExn {
+        public Blessing(JS clonee, Ibex ibex, Blessing parent, JS parentkey) throws JSExn {
             super(clonee); this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; }
-        public Object get(Object key) throws JSExn {
-            if (key.equals("")) return ((Object)getStatic());
-            if (cache.get(key) != null) return cache.get(key);
-            Object ret = new Blessing((JS)clonee.get(key), ibex, this, key);
+        public JS get(JS key) throws JSExn {
+            if (JS.isString(key) && JS.toString(key).equals("")) return getStatic();
+            if (cache.get(key) != null) return (JS)cache.get(key);
+            JS ret = new Blessing(clonee.get(key), ibex, this, key);
             cache.put(key, ret);
             return ret;
         }
-        public static Blessing getBlessing(Object o) {
-            if (!(o instanceof JS)) return null;
-            JS js = (JS)o;
+        public static Blessing getBlessing(JS js) {
             while (js instanceof JS.Clone && !(js instanceof Blessing)) js = ((JS.Clone)js).getClonee();
             if (!(js instanceof Blessing)) return null;
             return (Blessing)js;
@@ -373,7 +377,7 @@ public final class Ibex extends JS implements JS.Cloneable {
             String[] exts = new String[] { ".png", ".jpeg", ".gif" };
             for (int i=0; i < exts.length; i++)
                 try {
-                    InputStream in = Stream.getInputStream(parent.get(parentkey + exts[i]));
+                    InputStream in = Stream.getInputStream(parent.get(JS.S(JS.toString(parentkey) + exts[i])));
                     if (in != null) return in;
                 } catch (IOException f) { /* DELIBERATE */ }
             return null;
@@ -381,7 +385,7 @@ public final class Ibex extends JS implements JS.Cloneable {
         public JSScope getStatic() {
             try {
                 if (t == null) {
-                    JS res = (JS) parent.get(parentkey + ".t");
+                    JS res = (JS) parent.get(JS.S(JS.toString(parentkey) + ".t"));
                     t = Template.buildTemplate(res.unclone().toString(), res, ibex);
                 }
                 return t.staticScope;
@@ -390,12 +394,13 @@ public final class Ibex extends JS implements JS.Cloneable {
                 return null;
             }
         }
-        public Object call(Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
+        public JS call(JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
             // GROSS hack
             if (nargs != 1 && nargs != 9999) throw new JSExn("FIXME can only call with one arg");
             getStatic();
             if (t == null) throw new JSExn("No such template " + parentkey);
-            if (nargs == 9999) return t;
+            if (nargs == 9999) /*return t;*/ throw new Error("FIXME"); // FIXME: 9999 stuff
+            if(!(a instanceof Box)) throw new JSExn("can only apply templates to boxes");
             t.apply((Box)a);
             return a;
         }
index b7be374..7d1f62a 100644 (file)
@@ -93,7 +93,7 @@ public class Main {
         final Ibex ibex = new Ibex(rr);
 
         org.ibex.graphics.Surface.scarImage =
-            Picture.load((Stream)Main.builtin.get("org/ibex/core/builtin/scar.png"),
+            Picture.load((Stream)Main.builtin.get(JS.S("org/ibex/core/builtin/scar.png")),
                          new Task() { public void perform() throws JSExn, UnknownHostException {
                              if (Log.on) Log.info(Main.class, "invoking initial template");
                              ibex.resolveString(startupTemplate, false).call(new Box(), null, null, null, 1);
index 1e742c4..ddbf5b0 100644 (file)
@@ -26,7 +26,7 @@ public class Template {
     String id = null;                   ///< the id of this box
     String redirect = null;             ///< the id of the redirect target; only meaningful on a root node
     private String[] keys;              ///< keys to be "put" to instances of this template; elements correspond to those of vals
-    private Object[] vals;              ///< values to be "put" to instances of this template; elements correspond to those of keys
+    private JS[] vals;                  ///< values to be "put" to instances of this template; elements correspond to those of keys
     private String[] urikeys;
     private String[] urivals;
     private Vec children = new Vec();   ///< during XML parsing, this holds the list of currently-parsed children; null otherwise
@@ -85,40 +85,40 @@ public class Template {
         PerInstantiationScope pis = new PerInstantiationScope(b, ibex, parentPis, staticObject);
         for(int i=0; i<urikeys.length; i++) {
             if (urikeys[i] == null) continue;
-            pis.declare(urikeys[i]);
-            pis.put(urikeys[i], ibex.resolveString(urivals[i], true));
+            // FEATURE: Cache urikeys and resolved resources
+            pis.declare(JS.S(urikeys[i]));
+            pis.put(JS.S(urikeys[i]), ibex.resolveString(urivals[i], true));
         }
 
         // FIXME needs to obey the new application-ordering rules
         for (int i=0; children != null && i<children.size(); i++) {
             Box kid = new Box();
             ((Template)children.elementAt(i)).apply(kid, pis);
-            b.putAndTriggerTraps(b.get("numchildren"), kid);
+            b.putAndTriggerTraps(b.get(JS.S("numchildren")), kid);
         }
 
         if (script != null) JS.cloneWithNewParentScope(script, pis).call(null, null, null, null, 0);
 
-        Object key, val;
         for(int i=0; keys != null && i < keys.length; i++) {
             if (keys[i] == null) continue;
-            key = keys[i];
-            val = vals[i];
+            String key = keys[i];
+            JS val = vals[i];
 
             if ("null".equals(val)) val = null;
 
-            if (val != null && val instanceof String && ((String)val).length() > 0) {
-                switch (((String)val).charAt(0)) {
+            if (JS.isString(val) && (JS.toString(val).length() > 0)) {
+                switch (JS.toString(val).charAt(0)) {
                     case '$':
                         val = pis.get(val);
-                        if (val == null) throw new JSExn("unknown box id '"+vals[i]+"' referenced in XML attribute");
+                        if (val == null) throw new JSExn("unknown box id '"+JS.toString(vals[i])+"' referenced in XML attribute");
                         break;
                     case '.':
-                        val = ibex.resolveString(((String)val).substring(1), false);
+                        val = ibex.resolveString(JS.toString(val).substring(1), false);
                     // FIXME: url case
                     // FIXME: should we be resolving all of these in the XML-parsing code?
                 }
             }
-            b.putAndTriggerTraps(key, val);
+            b.putAndTriggerTraps(JS.S(key), val);
         }
     }
 
@@ -126,7 +126,7 @@ public class Template {
 
     // XML Parsing /////////////////////////////////////////////////////////////////
 
-    public static Template buildTemplate(String sourceName, Object s, Ibex ibex) {
+    public static Template buildTemplate(String sourceName, JS s, Ibex ibex) {
         try {
             return new TemplateHelper(sourceName, s, ibex).t;
         } catch (Exception e) {
@@ -154,7 +154,7 @@ public class Template {
 
         String initial_uri = "";
 
-       public TemplateHelper(String sourceName, Object s, Ibex ibex) throws XML.Exn, IOException, JSExn {
+       public TemplateHelper(String sourceName, JS s, Ibex ibex) throws XML.Exn, IOException, JSExn {
             this.sourceName = sourceName;
             this.ibex = ibex;
             InputStream is = Stream.getInputStream(s);
@@ -207,7 +207,8 @@ public class Template {
                 // GROSS hack
                 try {
                     // GROSSER hack
-                    t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999);
+                    // t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999);
+                    throw new Error("FIXME - 9999 thing"); // FIXME:9999 thing
                 } catch (Exception e) {
                     Log.error(Template.class, e);
                 }
@@ -253,7 +254,7 @@ public class Template {
             } });
 
             t.keys = new String[keys.size()];
-            t.vals = new Object[vals.size()];
+            t.vals = new JS[vals.size()];
             keys.copyInto(t.keys);
             vals.copyInto(t.vals);
 
@@ -263,8 +264,8 @@ public class Template {
 
                 String valString = t.vals[i].toString();
                 
-                if (valString.equals("true")) t.vals[i] = Boolean.TRUE;
-                else if (valString.equals("false")) t.vals[i] = Boolean.FALSE;
+                if (valString.equals("true")) t.vals[i] = JS.T;
+                else if (valString.equals("false")) t.vals[i] = JS.F;
                 else if (valString.equals("null")) t.vals[i] = null;
                 else {
                     boolean hasNonNumeral = false;
@@ -277,8 +278,8 @@ public class Template {
                             hasNonNumeral = true;
                             break;
                         }
-                    if (valString.length() > 0 && !hasNonNumeral) t.vals[i] = new Double(valString);
-                    else t.vals[i] = valString.intern();
+                    if (valString.length() > 0 && !hasNonNumeral) t.vals[i] = JS.N(Double.parseDouble((valString)));
+                    else t.vals[i] = JS.S(valString.intern()); // FEATURE: JS.intern() ?
                 }
             }
         }
@@ -331,8 +332,9 @@ public class Template {
         JS myStatic = null;
         void putDollar(String key, Box target) throws JSExn {
             if (parentBoxPis != null) parentBoxPis.putDollar(key, target);
-            declare("$" + key);
-            put("$" + key, target);
+            JS jskey = JS.S("$" + key);
+            declare(jskey);
+            put(jskey, target);
         }
         public PerInstantiationScope(JSScope parentScope, Ibex ibex, PerInstantiationScope parentBoxPis, JS myStatic) {
             super(parentScope);
@@ -340,11 +342,14 @@ public class Template {
             this.ibex = ibex;
             this.myStatic = myStatic;
         }
-        public Object get(Object key) throws JSExn {
+        public JS get(JS key) throws JSExn {
             if (super.has(key)) return super.get(key);
-            if (key.equals("ibex")) return ibex;
-            if (key.equals("")) return ibex.get("");
-            if (key.equals("static")) return myStatic;
+            if(JS.isString(key)) {
+                String s = JS.toString(key);
+                if (s.equals("ibex")) return ibex;
+                if (s.equals("")) return ibex.get(key);
+                if (s.equals("static")) return myStatic;
+            }
             return super.get(key);
         }
     }
index 210aade..f12e433 100644 (file)
@@ -8,7 +8,7 @@ public class Color {
     public static int stringToColor(String s) {
         // FIXME support three-char strings by doubling digits
         if (s == null) return 0x00000000;
-        else if (standard.get(s) != null) return 0xFF000000 | org.ibex.js.JS.toInt(standard.get(s));
+        else if (standard.get(s) != null) return 0xFF000000 | ((Integer)standard.get(s)).intValue();
         else if (s.length() == 7 && s.charAt(0) == '#') try {
             // FEATURE  alpha
             return 0xFF000000 |
index 8896e6f..e34704e 100644 (file)
@@ -50,9 +50,24 @@ public class HTML {
     /** true iff we have encountered an LI more recently than the last OL/UL */
     private static boolean withinLI = false;
 
+    // FEATURE: This is ugly
+    private static class JS extends org.ibex.js.JS.O {
+        public void put(String key, Object value) throws JSExn {
+            if(value instanceof String) put(JS.S(key),JS.S((String)value));
+            else if(value instanceof Number) put(JS.S(key), JS.N((Number)value));
+            else if(value == null) put(JS.S(key),null);
+            else throw new Error("FIXME");
+        }
+        public Object _get(String key) throws JSExn {
+            org.ibex.js.JS js = get(JS.S(key));
+            if(JS.isInt(js)) return new Integer(JS.toInt(js));
+            return JS.toString(js);
+        }
+    }
+    
     public static synchronized JS parseReader(Reader r) throws IOException, JSExn {
         CharStream cs = new CharStream(r);
-        JS h = new JS.O();
+        JS h = new JS();
 
         withinLI = false;
         h.put("$name", "html");
@@ -137,7 +152,7 @@ public class HTML {
      */
     private static String parseBody(CharStream cs, JS h, String elementName) throws IOException, JSExn {
         String cdata = "";
-        int length = h.get("$numchildren") == null ? 0 : Integer.parseInt(h.get("$numchildren").toString());
+        int length = h._get("$numchildren") == null ? 0 : Integer.parseInt(h._get("$numchildren").toString());
         while(true) {
             String closetag = null;
 
@@ -163,7 +178,7 @@ public class HTML {
             try {
                 // scan subelement
                 if (cs.peek() != '/') {
-                    JS kid = new JS.O();
+                    JS kid = new JS();
                     closetag = parseElement(cs, kid);
                     h.put(String.valueOf(length), kid); 
                     h.put("$numchildren", new Integer(++length));
index 31ac36e..574cc35 100644 (file)
@@ -17,8 +17,8 @@ public abstract class Surface extends PixelBuffer implements Task {
 
     // Static Data ////////////////////////////////////////////////////////////////////////////////
 
-    private static Boolean T = Boolean.TRUE;
-    private static Boolean F = Boolean.FALSE;
+    private static final JS T = JS.T;
+    private static final JS F = JS.F;
 
     /** all instances of Surface which need to be refreshed by the Scheduler */
     public static Vec allSurfaces = new Vec();
@@ -96,7 +96,7 @@ public abstract class Surface extends PixelBuffer implements Task {
             Scheduler.add(new Task() { public void perform() throws JSExn {
                 Platform.clipboardReadEnabled = true;
                 try {
-                    root.putAndTriggerTraps("_Press3", T);
+                    root.putAndTriggerTraps(JS.S("_Press3"), T);
                 } finally {
                     Platform.clipboardReadEnabled = false;
                 }
@@ -130,6 +130,7 @@ public abstract class Surface extends PixelBuffer implements Task {
         }
     }
 
+    private final static JS MOVE = JS.S("_Move");
     /** we enqueue ourselves in the Scheduler when we have a Move message to deal with */
     private Task mover = new Task() {
             public void perform() {
@@ -139,7 +140,7 @@ public abstract class Surface extends PixelBuffer implements Task {
                 String oldcursor = cursor;  cursor = "default";
                 // FIXME: Root (ONLY) gets motion events outside itself (if trapped)
                 if (oldmousex != mousex || oldmousey != mousey)
-                    root.putAndTriggerTrapsAndCatchExceptions("_Move", T);
+                    root.putAndTriggerTrapsAndCatchExceptions(MOVE, T);
                 if (!cursor.equals(oldcursor)) syncCursor();
             } };
 
@@ -155,10 +156,10 @@ public abstract class Surface extends PixelBuffer implements Task {
         Scheduler.add(mover);
     }
 
-    protected final void HScroll(int pixels) { new Message("_HScroll", new Integer(pixels), root); }
-    protected final void VScroll(int pixels) { new Message("_VScroll", new Integer(pixels), root); }
-    protected final void HScroll(float lines) { new Message("_HScroll", new Float(lines), root); }
-    protected final void VScroll(float lines) { new Message("_VScroll", new Float(lines), root); }
+    protected final void HScroll(int pixels) { new Message("_HScroll", JS.N(pixels), root); }
+    protected final void VScroll(int pixels) { new Message("_VScroll", JS.N(pixels), root); }
+    protected final void HScroll(float lines) { new Message("_HScroll", JS.N(lines), root); }
+    protected final void VScroll(float lines) { new Message("_VScroll", JS.N(lines), root); }
 
     /** subclasses should invoke this method when the user resizes the window */
     protected final void SizeChange(final int width, final int height) {
@@ -175,14 +176,14 @@ public abstract class Surface extends PixelBuffer implements Task {
         Scheduler.add(new Task() { public void perform() throws JSExn {
             root.x = x;
             root.y = y;
-            root.putAndTriggerTrapsAndCatchExceptions("PosChange", T);
+            root.putAndTriggerTrapsAndCatchExceptions(JS.S("PosChange"), T);
         }});
     }
 
     private final String[] doubleClick = new String[] { null, "_DoubleClick1", "_DoubleClick2", "_DoubleClick3" };
     protected final void DoubleClick(int button) { new Message(doubleClick[button], T, root); }
-    protected final void KeyPressed(String key) { new Message("_KeyPressed", key, root); }
-    protected final void KeyReleased(String key) { new Message("_KeyReleased", key, root); }
+    protected final void KeyPressed(String key) { new Message("_KeyPressed", JS.S(key), root); }
+    protected final void KeyReleased(String key) { new Message("_KeyReleased", JS.S(key), root); }
     protected final void Close() { new Message("Close", T, root); }
     protected final void Minimized(boolean b) { minimized = b; new Message("Minimized", b ? T : F, root); }
     protected final void Maximized(boolean b) { maximized = b; new Message("Maximized", b ? T : F, root); }
@@ -304,37 +305,37 @@ public abstract class Surface extends PixelBuffer implements Task {
     public class Message implements Task {
         
         private Box boxContainingMouse;
-        private Object value;
+        private JS value;
         public String name;
         
-        Message(String name, Object value, Box boxContainingMouse) {
+        Message(String name, JS value, Box boxContainingMouse) {
             this.boxContainingMouse = boxContainingMouse;
             this.name = name;
             this.value = value;
             Scheduler.add(this);
         }
         
-        public void perform() {
+        public void perform() throws JSExn {
             if (name.equals("_KeyPressed")) {
-                String value = (String)this.value;
+                String value = JS.toString(this.value);
                 if (value.toLowerCase().endsWith("shift")) shift = true;     else if (shift) value = value.toUpperCase();
                 if (value.toLowerCase().equals("alt")) alt = true;           else if (alt) value = "A-" + value;
                 if (value.toLowerCase().endsWith("control")) control = true; else if (control) value = "C-" + value;
                 if (value.equals("C-v") || value.equals("A-v")) Platform.clipboardReadEnabled = true;
-                this.value = value;
+                this.value = JS.S(value);
             } else if (name.equals("_KeyReleased")) {
-                String value = (String)this.value;
+                String value = JS.toString(this.value);
                 if (value.toLowerCase().equals("alt")) alt = false;
                 else if (value.toLowerCase().equals("control")) control = false;
                 else if (value.toLowerCase().equals("shift")) shift = false;
-                this.value = value;
+                this.value = JS.S(value);
             } else if (name.equals("_HScroll") || name.equals("_VScroll")) {
                 // FIXME: technically points != pixels
-                if (value instanceof Integer)
-                    value = new Float(((Integer)value).intValue() * root.fontSize());
+                if (JS.isInt(value))
+                    value = JS.N(JS.toInt(value) * root.fontSize());
             }
             try {
-                boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(name, value);
+                boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(JS.S(name), value);
             } finally {
                 Platform.clipboardReadEnabled = false;
             }
index 5f8a4ed..3c2d970 100644 (file)
@@ -271,9 +271,9 @@ public class HTTP {
         if (Log.verbose) Log.info(this, "evaluating PAC script");
         String pac = null;
         try {
-            Object obj = pacFunc.call(url, host, null, null, 2);
-            if (Log.verbose) Log.info(this, "  PAC script returned \"" + obj + "\"");
-            pac = obj.toString();
+            JS obj = pacFunc.call(JS.S(url), JS.S(host), null, null, 2);
+            if (Log.verbose) Log.info(this, "  PAC script returned \"" + JS.debugToString(obj) + "\"");
+            pac = JS.toString(obj);
         } catch (Throwable e) {
             if (Log.on) Log.info(this, "PAC script threw exception " + e);
             return null;
@@ -718,7 +718,7 @@ public class HTTP {
             return ret;
         }
     
-        public static JSScope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
+        public static JSScope proxyAutoConfigRootScope = /*new ProxyAutoConfigRootScope();*/ null; // FIXME: New api
         public static JS getProxyAutoConfigFunction(String url) {
             try { 
                 BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET()));
@@ -747,7 +747,7 @@ public class HTTP {
 
                 JS scr = JS.fromReader("PAC script at " + url, 0, new StringReader(script));
                 JS.cloneWithNewParentScope(scr, proxyAutoConfigRootScope).call(null, null, null, null, 0);
-                return (JS)proxyAutoConfigRootScope.get("FindProxyForURL");
+                return (JS)proxyAutoConfigRootScope.get(JS.S("FindProxyForURL"));
             } catch (Exception e) {
                 if (Log.on) {
                     Log.info(Platform.class, "WPAD detection failed due to:");
@@ -790,8 +790,8 @@ public class HTTP {
                             // FIXME
                             //Template.buildTemplate("org/ibex/builtin/proxy_authorization.ibex", Stream.getInputStream((JS)Main.builtin.get("org/ibex/builtin/proxy_authorization.ibex")), new Ibex(null));
                             t.apply(b);
-                            b.put("realm", realm);
-                            b.put("proxyIP", proxyIP);
+                            b.put(JS.S("realm"), JS.S(realm));
+                            b.put(JS.S("proxyIP"), JS.S(proxyIP));
                         }
                     });
 
@@ -803,7 +803,8 @@ public class HTTP {
 
         // ProxyAutoConfigRootJSScope ////////////////////////////////////////////////////////////////////
 
-        public static class ProxyAutoConfigRootScope extends JSScope.Global {
+        // FIXME: JS Update for new API
+        /*public static class ProxyAutoConfigRootScope extends JSScope.Global {
 
             public ProxyAutoConfigRootScope() { super(); }
         
@@ -915,7 +916,7 @@ public class HTTP {
                 return false;
             }
             public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
-        }
+        }*/
 
 
         /**
index 55f18f5..3d998d5 100644 (file)
@@ -136,7 +136,7 @@ public class SOAP extends XMLRPC {
         }
         
         // remove ourselves
-        Object me = objects.elementAt(objects.size() - 1);
+        JS me = (JS) objects.elementAt(objects.size() - 1);
 
         // find our parent
         Object parent = objects.size() > 1 ? objects.elementAt(objects.size() - 2) : null;
@@ -152,7 +152,7 @@ public class SOAP extends XMLRPC {
         } else if (parent != null && parent instanceof JS) {
             objects.removeElementAt(objects.size() - 1);
             try {
-                ((JS)parent).put(name, me);
+                ((JS)parent).put(JS.S(name), me);
             } catch (JSExn e) {
                 throw new Error("this should never happen");
             }
@@ -162,7 +162,9 @@ public class SOAP extends XMLRPC {
     }
 
     /** Appends the SOAP representation of <code>o</code> to <code>sb</code> */
-    void appendObject(String name, Object o, StringBuffer sb) throws JSExn {
+    void appendObject(String name, JS o, StringBuffer sb) throws JSExn {
+        // FIXME: Update for new api
+        /*
         if (o instanceof Number) {
             if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) {
                 sb.append("                <" + name + " xsi:type=\"xsd:int\">");
@@ -239,7 +241,7 @@ public class SOAP extends XMLRPC {
             }
             sb.append("</" + name + ">\r\n");
 
-        }
+        }*/
     }
 
     protected String buildRequest(JSArray args) throws JSExn, IOException {
@@ -261,7 +263,7 @@ public class SOAP extends XMLRPC {
             Enumeration e = ((JS)args.elementAt(0)).keys();
             while(e.hasMoreElements()) {
                 Object key = e.nextElement();
-                appendObject((String)key, ((JS)args.elementAt(0)).get(key), content);
+                appendObject((String)key, args.elementAt(0).get((JS)key), content);
             }
         }
         content.append("    </" + method + "></SOAP-ENV:Body></SOAP-ENV:Envelope>\r\n");
index 290415f..66908d8 100644 (file)
@@ -92,17 +92,17 @@ public class XMLRPC extends JS {
         
         public void endElement(XML.Element c) {
             //#switch(c.getLocalName())
-            case "int": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
-            case "i4": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
-            case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? Boolean.TRUE : Boolean.FALSE, objects.size() - 1);
-            case "string": objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
-            case "double": objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+            case "int": objects.setElementAt(JS.N(Integer.parseInt(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
+            case "i4": objects.setElementAt(JS.N(Integer.parseInt(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
+            case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? JS.T : JS.F, objects.size() - 1);
+            case "string": objects.setElementAt(JS.S(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+            case "double": objects.setElementAt(JS.N(Double.parseDouble(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
             case "base64":
                 objects.setElementAt(new Stream.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())),
                                                           null), objects.size() - 1);
-            case "name": objects.addElement(new String(content.getBuf(), 0, content.size()));
+            case "name": objects.addElement(JS.S(new String(content.getBuf(), 0, content.size())));
             case "value": if ("".equals(objects.lastElement()))
-                objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
+                objects.setElementAt(JS.S(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
             case "dateTime.iso8601":
                 String s = new String(content.getBuf(), 0, content.size());
                 
@@ -129,11 +129,11 @@ public class XMLRPC extends JS {
                                     "the server sent a <dateTime.iso8601> tag which was malformed: " + s);
                 }
             case "member":
-                Object memberValue = objects.elementAt(objects.size() - 1);
+                JS memberValue = (JS) objects.elementAt(objects.size() - 1);
                 String memberName = (String)objects.elementAt(objects.size() - 2);
                 JS struct = (JS)objects.elementAt(objects.size() - 3);
                 try {
-                    struct.put(memberName, memberValue);
+                    struct.put(JS.S(memberName), memberValue);
                 } catch (JSExn e) {
                     throw new Error("this should never happen");
                 }
@@ -143,7 +143,7 @@ public class XMLRPC extends JS {
                 for(i=objects.size() - 1; objects.elementAt(i) != null; i--);
                 JSArray arr = new JSArray();
                 try {
-                    for(int j = i + 1; j<objects.size(); j++) arr.put(new Integer(j - i - 1), objects.elementAt(j));
+                    for(int j = i + 1; j<objects.size(); j++) arr.put(JS.N(j - i - 1), (JS)objects.elementAt(j));
                 } catch (JSExn e) {
                     throw new Error("this should never happen");
                 }
@@ -186,9 +186,10 @@ public class XMLRPC extends JS {
     }
 
     /** Appends the XML-RPC representation of <code>o</code> to <code>sb</code> */
-    void appendObject(Object o, StringBuffer sb) throws JSExn {
-
-        if (o == null) {
+    void appendObject(JS o, StringBuffer sb) throws JSExn {
+        // FIXME: Update for new api
+        throw new Error("FIXME");
+        /*if (o == null) {
             throw new JSExn("attempted to send a null value via XML-RPC");
 
         } else if (o instanceof Number) {
@@ -295,19 +296,19 @@ public class XMLRPC extends JS {
         } else {
             throw new JSExn("attempt to send object of type " + o.getClass().getName() + " via XML-RPC");
 
-        }
+        }*/
     }
 
 
     // Call Sequence //////////////////////////////////////////////////////////////////////////
 
-    public final Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+    public final JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
         JSArray args = new JSArray();
         for(int i=0; i<nargs; i++) args.addElement(i==0?a0:i==1?a1:i==2?a2:rest[i-3]);
         return call(args);
     }
 
-    public final Object call(final JSArray args) throws JSExn {
+    public final JS call(final JSArray args) throws JSExn {
         try {
             final JS.UnpauseCallback callback = JS.pause();
             new java.lang.Thread() { public void run() { call(callback, args); }  }.start();
@@ -328,21 +329,21 @@ public class XMLRPC extends JS {
             BufferedReader br = new BufferedReader(new InputStreamReader(is));
             try {
                 new Helper().parse(br);
-                final Object result = fault ? new JSExn(objects.elementAt(0)) : objects.size() == 0 ? null : objects.elementAt(0);
-                Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(result); }});
+                final JSExn exn = fault ? new JSExn(objects.elementAt(0).toString()) : null;
+                final JS result = fault ? null : objects.size() == 0 ? null : (JS) objects.elementAt(0);
+                Scheduler.add(new Task() { public void perform() throws JSExn { if(fault) callback.unpause(exn); else callback.unpause(result); }});
             } finally {
                 tracker.clear();
                 objects.setSize(0);
             }
         } catch (final JSExn e) {
-            final Exception e2 = e;
-            Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(e2); }});
+            Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(e); }});
         } catch (final IOException e) {
             final Exception e2 = e;
-            Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2)); }});
+            Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2.toString())); }});
         } catch (final XML.Exn e) {
             final Exception e2 = e;
-            Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2)); }});
+            Scheduler.add(new Task() { public void perform() throws JSExn { callback.unpause(new JSExn(e2.toString())); }});
         }
     }
 }
index 5ad71c2..b7d88d1 100644 (file)
@@ -119,7 +119,7 @@ public abstract class Platform {
             ret.Refresh();
         }
         try {
-            if (b.get("titlebar") != null) ret.setTitleBarText((String)b.get("titlebar"));
+            if (b.get(JS.S("titlebar")) != null) ret.setTitleBarText(JS.toString(b.get(JS.S("titlebar"))));
         } catch (JSExn e) {
             Log.warn(Platform.class, e);
         }
index 565de4d..683c118 100644 (file)
@@ -6,8 +6,10 @@ public abstract class Grammar extends JS {
 
     public JS action = null;
 
+    // FIXME: Updae for new api
+    
     // means we call()ed a Grammar that hasn't been bound to a scope yet
-    public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+    /*public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
         throw new Error("this should never happen");
     }
 
@@ -101,5 +103,5 @@ public abstract class Grammar extends JS {
         public int match(String s, int start, Hash v, JSScope scope) throws JSExn {
             return ((Grammar)scope.get(key)).matchAndWrite(s, start, v, scope, key);
         }
-    }
+    }*/
 }
index 70f1054..467a339 100644 (file)
@@ -208,7 +208,8 @@ public class Log {
         logstream.println(classname + colorize(levelcolor, bright, str));
     }
 
-    public static void recursiveLog(String indent, String name, Object o) throws JSExn {
+    // FIXME: Update for new api
+    /*public static void recursiveLog(String indent, String name, Object o) throws JSExn {
         if (!name.equals("")) name += " : ";
 
         if (o == null) {
@@ -235,6 +236,6 @@ public class Log {
             JS.log(indent + name + o);
 
         }
-    }
+    }*/
 
 }
index a226731..ae66770 100644 (file)
@@ -61,7 +61,7 @@ public class Preprocessor {
     private PrintWriter out;
 
     private Hashtable replace = new Hashtable();
-    private Hashtable repeatreplace = null;
+    private Hashtable[] repeatreplaces = null;
     private Vector sinceLastRepeat = null;
     private Vector err = new Vector();
 
@@ -144,12 +144,18 @@ PROCESS:
                     out.print("\n");  // preserve line numbers
                 }
                 StringTokenizer st = new StringTokenizer(trimmed, " ");
-                repeatreplace = (Hashtable)replace.clone();
+                repeatreplaces = null;
                 while (st.hasMoreTokens()) {
                     String tok = st.nextToken().trim();
                     String key = tok.substring(0, tok.indexOf('/'));
-                    String val = tok.substring(tok.indexOf('/') + 1);
-                    repeatreplace.put(key, val);
+                    String vals = tok.substring(tok.indexOf('/') + 1);
+                    StringTokenizer st2 = new StringTokenizer(vals,"/");
+                    if(repeatreplaces == null) {
+                        repeatreplaces = new Hashtable[st2.countTokens()];
+                        for(int i=0;i<repeatreplaces.length;i++) repeatreplaces[i] = (Hashtable) replace.clone();
+                    }
+                    for(int i=0;st2.hasMoreTokens() && i<repeatreplaces.length;i++)
+                        repeatreplaces[i].put(key, st2.nextToken());
                 }
                 sinceLastRepeat = new Vector();
                 out.print("\n"); // preserve line numbers
@@ -157,9 +163,11 @@ PROCESS:
             } else if (trimmed.startsWith("//#end")) {
                 if (sinceLastRepeat == null) { err.add(new Warning("#end orphaned")); continue PROCESS; }
                 Hashtable save = replace;
-                replace = repeatreplace;
                 out.print("\n");
-                for(int i=0; i<sinceLastRepeat.size() - 1; i++) out.print(processLine((String)sinceLastRepeat.elementAt(i), true));
+                for(int i=0;i<repeatreplaces.length;i++) {
+                    replace = repeatreplaces[i];
+                    for(int j=0; j<sinceLastRepeat.size() - 1; j++) out.print(processLine((String)sinceLastRepeat.elementAt(j), true));
+                }
                 sinceLastRepeat = null;
                 replace = save;
 
@@ -214,9 +222,9 @@ PROCESS:
                     buildTrie("", byLength[i]);
                     out.print("}; break; }  ");
                 }
-                out.print("} /* switch */ ");
+                out.print("} "); /* switch */
                 if (Default != null) out.print(" " + Default);
-                out.print(" } while(false); /* OUTER */\n");
+                out.print(" } while(false);\n"); /* OUTER */
                 enumSwitch++;
 
             } else {