From: megacz Date: Fri, 30 Jan 2004 07:41:14 +0000 (+0000) Subject: 2003/11/13 05:04:23 X-Git-Tag: RC3~359 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=2b0231dd1c60cb677b7ed69fcad4b6a53af560a7;p=org.ibex.core.git 2003/11/13 05:04:23 darcs-hash:20040130074114-2ba56-a363dff767469d49fef57a08b9668bb8a2885a76.gz --- diff --git a/src/org/xwt/js/Regexp.java b/src/org/xwt/js/Regexp.java deleted file mode 100644 index 834a425..0000000 --- a/src/org/xwt/js/Regexp.java +++ /dev/null @@ -1,361 +0,0 @@ -package org.xwt.js; - -import gnu.regexp.*; - -public class Regexp extends JS.Obj { - private boolean global; - private RE re; - private int lastIndex; - - public Regexp(Object arg0, Object arg1) throws JS.Exn { - if(arg0 instanceof Regexp) { - Regexp r = (Regexp) arg0; - this.global = r.global; - this.re = r.re; - this.lastIndex = r.lastIndex; - } else { - String pattern = arg0.toString(); - String sFlags = null; - int flags = 0; - if(arg1 != null) sFlags = (String)arg1; - if(sFlags == null) sFlags = ""; - for(int i=0;i= s.length()) { - lastIndex = 0; - return null; - } - - REMatch match = re.getMatch(s,start); - if(global) - lastIndex = match == null ? s.length() : match.getEndIndex(); - if(match == null) - return null; - else - return matchToExecResult(match,re,s); - } - - private static Object matchToExecResult(REMatch match, RE re, String s) { - JS.Obj ret = new JS.Obj(); - ret.put("index",new Integer(match.getStartIndex())); - ret.put("input",s); - int n = re.getNumSubs(); - ret.put("length",new Integer(n+1)); - ret.put("0",match.toString()); - for(int i=1;i<=n;i++) - ret.put(Integer.toString(i),match.toString(i)); - return ret; - } - - - private Object exec(JS.Array args) throws JS.Exn { - if(args.length() < 1) throw new JS.Exn("Not enough args to exec"); - String s = args.elementAt(0).toString(); - return exec(s); - } - - private Object test(JS.Array args) throws JS.Exn { - if(args.length() < 1) throw new JS.Exn("Not enough args to match"); - String s = args.elementAt(0).toString(); - - if(global) { - int start = global ? lastIndex : 0; - if(start < 0 || start >= s.length()) { - lastIndex = 0; - return null; - } - - REMatch match = re.getMatch(s,start); - lastIndex = match != null ? s.length() : match.getEndIndex(); - return wrapBool(match != null); - } else { - return wrapBool(re.getMatch(s) != null); - } - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append('/'); - sb.append(_get("source")); - sb.append('/'); - if(global) sb.append('g'); - if(Boolean.TRUE.equals(_get("ignoreCase"))) sb.append('i'); - if(Boolean.TRUE.equals(_get("multiline"))) sb.append('m'); - return sb.toString(); - } - - public static Object stringMatch(Object o, JS.Array args) throws JS.Exn { - if(args.length() < 1) throw new JS.Exn("not enough args to match"); - Object arg0 = args.elementAt(0); - String s = o.toString(); - RE re; - Regexp regexp = null; - if(arg0 instanceof Regexp) { - regexp = (Regexp) arg0; - re = regexp.re; - } else { - re = newRE(arg0.toString(),0); - } - - if(regexp == null) { - REMatch match = re.getMatch(s); - return matchToExecResult(match,re,s); - } - if(!regexp.global) - return regexp.exec(s); - - JS.Array ret = new JS.Array(); - REMatch[] matches = re.getAllMatches(s); - for(int i=0;i 0) - regexp.lastIndex = matches[matches.length-1].getEndIndex(); - else - regexp.lastIndex = s.length(); - return ret; - } - - public static Object stringSearch(Object o, JS.Array args) throws JS.Exn { - if(args.length() < 1) throw new JS.Exn("not enough args to match"); - Object arg0 = args.elementAt(0); - String s = o.toString(); - RE re; - if(arg0 instanceof Regexp) - re = ((Regexp)arg0).re; - else - re = newRE(arg0.toString(),0); - REMatch match = re.getMatch(s); - if(match == null) return new Integer(-1); - return new Integer(match.getStartIndex()); - } - - public static Object stringReplace(Object o, JS.Array args) throws JS.Exn { - if(args.length() < 2) throw new JS.Exn("not enough args to replace"); - Object arg0 = args.elementAt(0); - Object arg1 = args.elementAt(1); - String s = o.toString(); - RE re; - JS.Callable replaceFunc = null; - String replaceString = null; - Regexp regexp = null; - if(arg0 instanceof Regexp) { - regexp = (Regexp) arg0; - re = regexp.re; - } else { - re = newRE(arg0.toString(),0); - } - if(arg1 instanceof JS.Callable) - replaceFunc = (JS.Callable) arg1; - else - replaceString = arg1.toString(); - REMatch[] matches; - if(regexp != null && regexp.global) { - matches = re.getAllMatches(s); - if(regexp != null) { - if(matches.length > 0) - regexp.lastIndex = matches[matches.length-1].getEndIndex(); - else - regexp.lastIndex = s.length(); - } - } else { - REMatch match = re.getMatch(s); - if(match != null) - matches = new REMatch[]{ match }; - else - matches = new REMatch[0]; - } - - StringBuffer sb = new StringBuffer(s.length()); - int pos = 0; - char[] sa = s.toCharArray(); - for(int i=0;i= '0' && c2 <= '9') { - n = (c - '0') * 10 + (c2 - '0'); - i++; - } else { - n = c - '0'; - } - if(n > 0) - sb.append(match.toString(n)); - break; - case '$': - sb.append('$'); break; - case '&': - sb.append(match.toString()); break; - case '`': - sb.append(source.substring(0,match.getStartIndex())); break; - case '\'': - sb.append(source.substring(match.getEndIndex())); break; - default: - sb.append('$'); - sb.append(c); - } - } - if(i < s.length()) sb.append(s.charAt(i)); - return sb.toString(); - } - - - public static Object stringSplit(Object o,JS.Array args) { - String s = o.toString(); - if(args.length() < 1 || args.elementAt(0) == null || s.length() == 0) { - JS.Array ret = new JS.Array(); - ret.addElement(s); - return ret; - } - Object arg0 = args.elementAt(0); - - int limit = args.length() < 2 ? Integer.MAX_VALUE : JS.toInt(args.elementAt(1)); - if(limit < 0) limit = Integer.MAX_VALUE; - if(limit == 0) return new JS.Array(); - - RE re = null; - Regexp regexp = null; - String sep = null; - JS.Array ret = new JS.Array(); - int p = 0; - - if(arg0 instanceof Regexp) { - regexp = (Regexp) arg0; - re = regexp.re; - } else { - sep = arg0.toString(); - } - - // special case this for speed. additionally, the code below doesn't properly handle - // zero length strings - if(sep != null && sep.length()==0) { - int len = s.length(); - for(int i=0;i> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF))); if (x1 == x3 && x2 == x4) { g.fillRect(x1, y1, x4 - x1, y2 - y1); diff --git a/src/org/xwt/plat/Darwin.java b/src/org/xwt/plat/Darwin.java index 44d0ec2..907b937 100644 --- a/src/org/xwt/plat/Darwin.java +++ b/src/org/xwt/plat/Darwin.java @@ -98,20 +98,20 @@ public class Darwin extends POSIX { private final class CarbonOpenGL extends OpenGL { public RawData rawPixelFormat; - public RawData rawSharedContext; + public RawData rawSharedJSContext; public int maxAglSurfaceTexSize; public int maxSurfaceWidth; public int maxSurfaceHeight; private native boolean initPixelFormat(); - private native void initSharedContext(); + private native void initSharedJSContext(); public CarbonOpenGL() throws NotSupportedException { if(!jaguar) throw new NotSupportedException("OpenGL requires Mac OS X 10.2 or greater"); if(!initPixelFormat()) throw new NotSupportedException("Couldn't get an acceptable pixel format"); - initSharedContext(); + initSharedJSContext(); } public void init() throws NotSupportedException { @@ -123,7 +123,7 @@ public class Darwin extends POSIX { } maxSurfaceWidth = maxSurfaceHeight = maxAglSurfaceTexSize; } - protected native void activateSharedContext(); + protected native void activateSharedJSContext(); } static abstract class CarbonSurface extends Surface.DoubleBufferedSurface { @@ -216,7 +216,7 @@ public class Darwin extends POSIX { CarbonMessage.add(new CarbonMessage() { public void perform() { GLCarbonPixelBuffer.this.natInit(); sem.release(); } }); sem.block(); } - public native void activateContext(); + public native void activateJSContext(); protected void finalize() { CarbonMessage.add(new CarbonMessage() { public void perform() { natCleanup(rawWindowRef,rawCTX); } }); gl.deleteTexture(textureName); diff --git a/src/org/xwt/plat/OpenGL.java b/src/org/xwt/plat/OpenGL.java index d4bbe1e..8ed60c2 100644 --- a/src/org/xwt/plat/OpenGL.java +++ b/src/org/xwt/plat/OpenGL.java @@ -28,7 +28,7 @@ abstract class OpenGL { } } - // This MUST be called after OpenGL is instansiated (and activateSharedContext is functioning) + // This MUST be called after OpenGL is instansiated (and activateSharedJSContext is functioning) public void init() throws NotSupportedException { natInit(); glVersion = parseVersion(version); @@ -46,7 +46,7 @@ abstract class OpenGL { Log.log(this,"Max rectangular texture size: " + maxRectTexSize); } - protected abstract void activateSharedContext(); + protected abstract void activateSharedJSContext(); public static class NotSupportedException extends Exception { public NotSupportedException(String s) { super(s); } @@ -66,7 +66,7 @@ abstract class OpenGL { } // This should activate the drawing context and prepare the double buffer for drawing - protected abstract void activateContext(); + protected abstract void activateJSContext(); protected static native void drawableInit(int w, int h); @@ -74,7 +74,7 @@ abstract class OpenGL { public native void setClip(int x, int y, int x2, int y2); public native void resetClip(); - public native void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color); + public native void fillJSTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color); public void drawString(String font, String text, int x, int y, int color) { //System.out.println("drawString(): " + text); @@ -88,7 +88,7 @@ abstract class OpenGL { } private void drawPicture_(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int color) { - activateContext(); + activateJSContext(); setColor(color); GLPicture p = (GLPicture) source; p.draw(dx,dy,cx1,cy1,cx2,cy2); diff --git a/src/org/xwt/plat/Win32.java b/src/org/xwt/plat/Win32.java index 1689ef6..100da9b 100644 --- a/src/org/xwt/plat/Win32.java +++ b/src/org/xwt/plat/Win32.java @@ -92,8 +92,8 @@ public class Win32 extends GCJ { HTTP.Proxy ret = new HTTP.Proxy(); if (container[2] != null) { - ret.proxyAutoConfigFunction = HTTP.Proxy.getProxyAutoConfigFunction(container[2]); - if (ret.proxyAutoConfigFunction != null) return ret; + ret.proxyAutoConfigJSFunction = HTTP.Proxy.getProxyAutoConfigJSFunction(container[2]); + if (ret.proxyAutoConfigJSFunction != null) return ret; } if (container[0] == null) return null; @@ -274,7 +274,7 @@ public class Win32 extends GCJ { public native void finalize(); // FIXME: try to use os acceleration - public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) { + public void fillJSTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) { if (x1 == x3 && x2 == x4) { fillRect(x1, y1, x4, y2, argb); } else for(int y=y1; y maxSize) remove(lru.k1, lru.k2); } } diff --git a/src/org/xwt/util/Hash.java b/src/org/xwt/util/Hash.java index 30d07ed..8256152 100644 --- a/src/org/xwt/util/Hash.java +++ b/src/org/xwt/util/Hash.java @@ -50,13 +50,9 @@ public class Hash { } /** returns all the primary keys in the table */ - public Object[] keys() { - int howmany = 0; - for(int i=0; i", message); - } else { - log(current.getSourceName() + ":" + current.getLine(), message); - } - } + public static void logJS(Object message) { log(JSContext.getSource() + ":" + JSContext.getLine(), message); } /** message can be a String or a Throwable */ public static synchronized void log(Object o, Object message) { @@ -75,4 +68,33 @@ public class Log { } } + public static void recurseiveLog(String indent, String name, Object o) { + if (!name.equals("")) name += " : "; + + if (o == null) { + Log.logJS(indent + name + ""); + + } else if (o instanceof JSArray) { + Log.logJS(indent + name + ""); + JSArray na = (JSArray)o; + for(int i=0; i"); + JS s = (JS)o; + Enumeration e = s.keys(); + while(e.hasMoreElements()) { + Object key = e.nextElement(); + if (key != null) + recurse(indent + " ", key.toString(), + (key instanceof Integer) ? + s.get(((Integer)key)) : s.get(key.toString())); + } + } else { + Log.logJS(indent + name + o); + + } + } + } diff --git a/src/org/xwt/util/Preprocessor.java b/src/org/xwt/util/Preprocessor.java index 2309257..47c3134 100644 --- a/src/org/xwt/util/Preprocessor.java +++ b/src/org/xwt/util/Preprocessor.java @@ -37,13 +37,34 @@ public class Preprocessor { String trimmed = s.trim(); if (trimmed.startsWith("//#define ")) { trimmed = trimmed.substring(10).trim(); - String key = trimmed.substring(0, trimmed.indexOf(' ')); - String val = trimmed.substring(trimmed.indexOf(' ')).trim(); - replace.put(key, val); + if (trimmed.indexOf('(') >= 0 && trimmed.indexOf('(') < trimmed.indexOf(' ')) { + JSFunctionMacro fm = new JSFunctionMacro(); + String key = trimmed.substring(0, trimmed.indexOf('(')); + String unbound = trimmed.substring(trimmed.indexOf('(') + 1, trimmed.indexOf(')')); + if (unbound.indexOf(',') == -1) { + fm.unbound1 = unbound; + } else { + fm.unbound1 = unbound.substring(0, unbound.indexOf(',')); + fm.unbound2 = unbound.substring(unbound.indexOf(',') + 1); + } + fm.expression = trimmed.substring(trimmed.indexOf(')')+1).trim(); + replace.put(key, fm); + } else { + String key = trimmed.substring(0, trimmed.indexOf(' ')); + String val = trimmed.substring(trimmed.indexOf(' ')).trim(); + replace.put(key, val); + } System.out.println(); // preserve line numbers } else if (trimmed.startsWith("//#repeat ")) { - StringTokenizer st = new StringTokenizer(trimmed.substring(9), " "); + trimmed = trimmed.substring(9); + while(trimmed.charAt(trimmed.length() - 1) == '\\') { + String s2 = br.readLine().trim(); + if (s2.startsWith("//")) s2 = s2.substring(2).trim(); + trimmed += s2; + System.out.println(); // preserve line numbers + } + StringTokenizer st = new StringTokenizer(trimmed, " "); repeatreplace = (Hashtable)replace.clone(); while (st.hasMoreTokens()) { String tok = st.nextToken().trim(); @@ -58,7 +79,7 @@ public class Preprocessor { Hashtable save = replace; replace = repeatreplace; System.out.println(); - for(int i=0; i