2003/09/20 05:03:47
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:36:00 +0000 (07:36 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:36:00 +0000 (07:36 +0000)
darcs-hash:20040130073600-2ba56-ca584c6901bb1e923c0861d6e27eb943ed8a7d60.gz

Makefile
src/org/xwt/Platform.java
src/org/xwt/Res.java
src/org/xwt/mips/ELF.java
src/org/xwt/mips/Interpreter.java
src/org/xwt/plat/Darwin.cc
src/org/xwt/plat/GCJ.cc
src/org/xwt/plat/GCJ.java
src/org/xwt/translators/Font.java

index 0a8b83d..7d0cb52 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -132,8 +132,8 @@ $(target_bin): build/$(platform)/$(platform).ar upstream/jpeg-6b/build-$(target)
 # Special treatment:
 #
 
 # Special treatment:
 #
 
-builtin_src := $(find src/org/xwt/builtin)
-build/res/resources.jar: $(builtin_src:src/%=build/res/%) build/res/freetype.mips
+builtin_src := $(shell find src/org/xwt/builtin -name '*.*')
+build/res/builtin.jar: $(builtin_src:src/%=build/res/%) build/res/freetype.mips
        @echo -e "\n\033[1mzipping            res/* -> .jar: builtin.jar\033[0m"
        cd build/res; $(jar) cf builtin.jar $(^:build/res/%=%)
 
        @echo -e "\n\033[1mzipping            res/* -> .jar: builtin.jar\033[0m"
        cd build/res; $(jar) cf builtin.jar $(^:build/res/%=%)
 
@@ -151,11 +151,12 @@ build/$(platform)/builtin.o: build/res/builtin.jar
 # having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
 gcj: .vendor .install_gcc-3.3_$(target) $(target_bin)
 
 # having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
 gcj: .vendor .install_gcc-3.3_$(target) $(target_bin)
 
-build/JVM/xwt.jar: $(java_sources:build/java/%.java=build/class/%.class)
+build/JVM/xwt.jar: $(java_sources:build/java/%.java=build/class/%.class) build/res/builtin.jar
        @echo -e "\n\033[1marchiving         .class -> .jar:   build/JVM/xwt.jar\033[0m"
        mkdir -p build/JVM
        echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
        @echo -e "\n\033[1marchiving         .class -> .jar:   build/JVM/xwt.jar\033[0m"
        mkdir -p build/JVM
        echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
-       cd build/class; $(jar) cfm ../JVM/xwt.jar ../JVM/.manifest `find .`;
+       cd build/class/org/xwt; ln -sf ../../../res/builtin.jar
+       cd build/class; $(jar) cfm ../JVM/xwt.jar ../JVM/.manifest `find . \! -type d`;
 
 
 
 
 
 
@@ -172,7 +173,7 @@ build/mips/%.c.o: src/%.c
 build/res/freetype.mips: build/mips/org/xwt/translators/Freetype.c.o build/mips/org/xwt/mips/crt0.c.o build/mips/org/xwt/mips/syscalls.c.o
        make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
        @echo -e "\n\033[1mlinking               .o -> .mips:  $@\033[0m"
 build/res/freetype.mips: build/mips/org/xwt/translators/Freetype.c.o build/mips/org/xwt/mips/crt0.c.o build/mips/org/xwt/mips/syscalls.c.o
        make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
        @echo -e "\n\033[1mlinking               .o -> .mips:  $@\033[0m"
-       mkdir -p build/mips
+       mkdir -p build/mips build/res
        upstream/install/bin/mips-unknown-elf-gcc \
                -nostdlib \
                --static \
        upstream/install/bin/mips-unknown-elf-gcc \
                -nostdlib \
                --static \
index f081948..30b46e1 100644 (file)
@@ -211,24 +211,7 @@ public class Platform {
 
     /** returns an InputStream to the builtin xwar */
     protected InputStream _getBuiltinInputStream() {
 
     /** returns an InputStream to the builtin xwar */
     protected InputStream _getBuiltinInputStream() {
-        try {
-            return new FileInputStream("builtin.xwar");
-        } catch (Exception e) {
-            Log.log(this, e);
-            return null;
-        }
-        //return this.getClass().getClassLoader().getResourceAsStream("org/xwt/builtin.xwar");
-    }
-
-    /** returns an InputStream to the builtin xwar */
-    protected InputStream _getFreetypeInputStream() {
-        try {
-            return new FileInputStream("freetype.mips");
-        } catch (Exception e) {
-            Log.log(this, e);
-            return null;
-        }
-        //return this.getClass().getClassLoader().getResourceAsStream("org/xwt/freetype.mips");
+        return this.getClass().getClassLoader().getResourceAsStream("org/xwt/builtin.jar");
     }
 
     /** returns the value of the environment variable key, or null if no such key exists */
     }
 
     /** returns the value of the environment variable key, or null if no such key exists */
@@ -324,9 +307,6 @@ public class Platform {
     /** returns an InputStream to the builtin xwar */
     public static InputStream getBuiltinInputStream() { return platform._getBuiltinInputStream(); }
         
     /** returns an InputStream to the builtin xwar */
     public static InputStream getBuiltinInputStream() { return platform._getBuiltinInputStream(); }
         
-    /** returns an InputStream to the freetype mips binary */
-    public static InputStream getFreetypeInputStream() { return platform._getFreetypeInputStream(); }
-        
     /** creates and returns a picture */
     public static Picture createPicture(ImageDecoder i) { return platform._createPicture(i.getData(), i.getWidth(), i.getHeight()); }
 
     /** creates and returns a picture */
     public static Picture createPicture(ImageDecoder i) { return platform._createPicture(i.getData(), i.getWidth(), i.getHeight()); }
 
index 8f7906a..b956931 100644 (file)
@@ -14,7 +14,17 @@ public abstract class Res extends JS {
     public final InputStream getInputStream() throws IOException { return getInputStream(""); }
 
     public Res graft(Object newResource) { throw new JS.Exn("cannot graft onto this resource"); }
     public final InputStream getInputStream() throws IOException { return getInputStream(""); }
 
     public Res graft(Object newResource) { throw new JS.Exn("cannot graft onto this resource"); }
-    public Object get(Object key) { return new Ref(this, key); } 
+
+    private Hash refCache = null;
+    public Object get(Object key) {
+        Object ret = refCache == null ? null : refCache.get(key);
+        if (ret != null) return ret;
+        ret = new Ref(this, key);
+        if (refCache == null) refCache = new Hash();
+        refCache.put(key, ret);
+        return ret;
+    }
+
     public void put(Object key, Object val) { throw new JS.Exn("cannot put to a resource"); } 
     public Object[] keys() { throw new JS.Exn("cannot enumerate a resource"); } 
 
     public void put(Object key, Object val) { throw new JS.Exn("cannot put to a resource"); } 
     public Object[] keys() { throw new JS.Exn("cannot enumerate a resource"); } 
 
index 50f7ab3..8f2c771 100644 (file)
@@ -2,7 +2,18 @@ package org.xwt.mips;
 import java.io.*;
 
 class ELF {
 import java.io.*;
 
 class ELF {
-    private MyRandomAccessFile fd;
+
+    private DataInput fd;
+    private Object image;
+    private void seek(long l) throws IOException {
+        if (image instanceof RandomAccessFile) {
+            ((RandomAccessFile)image).seek(l);
+        } else if (image instanceof byte[]) {
+            ByteArrayInputStream bais = new ByteArrayInputStream((byte[])image);
+            bais.skip(l);
+            fd = new DataInputStream(bais);
+        }
+    }
     
     public ELFHeader header;
     public PHeader[] pheaders;
     
     public ELFHeader header;
     public PHeader[] pheaders;
@@ -10,6 +21,10 @@ class ELF {
     
     private boolean sectionReaderActive;
     
     
     private boolean sectionReaderActive;
     
+    private static void skipFully(DataInput fd, int n) throws IOException {
+        while(n>0) n -= fd.skipBytes(n);
+    }
+
     public class ELFHeader {
         byte klass;
         byte data;
     public class ELFHeader {
         byte klass;
         byte data;
@@ -37,10 +52,10 @@ class ELF {
             if(fd.readInt() != ELF_MAGIC) throw new ELFException("Bad Magic (is: " );
             klass = fd.readByte();
             data = fd.readByte();
             if(fd.readInt() != ELF_MAGIC) throw new ELFException("Bad Magic (is: " );
             klass = fd.readByte();
             data = fd.readByte();
-            fd.skipFully(1); // version
+            skipFully(fd, 1); // version
             osabi = fd.readByte();
             abiversion = fd.readByte();
             osabi = fd.readByte();
             abiversion = fd.readByte();
-            fd.skipFully(7);
+            skipFully(fd, 7);
             type = fd.readShort();
             machine = fd.readShort();
             version = fd.readInt();
             type = fd.readShort();
             machine = fd.readShort();
             version = fd.readInt();
@@ -127,21 +142,22 @@ class ELF {
         }
     }
     
         }
     }
     
-    public ELF(String file) throws IOException, ELFException {
-        fd = new MyRandomAccessFile(file,"r");
+    public ELF(Object img) throws IOException, ELFException {
+        image = img;
+        seek(0);
         header = new ELFHeader();
         pheaders = new PHeader[header.phnum];
         for(int i=0;i<header.phnum;i++) {
         header = new ELFHeader();
         pheaders = new PHeader[header.phnum];
         for(int i=0;i<header.phnum;i++) {
-            fd.seek(header.phoff+i*header.phentsize);
+            seek(header.phoff+i*header.phentsize);
             pheaders[i] = new PHeader();
         }
         sheaders = new SHeader[header.shnum];
         for(int i=0;i<header.shnum;i++) {
             pheaders[i] = new PHeader();
         }
         sheaders = new SHeader[header.shnum];
         for(int i=0;i<header.shnum;i++) {
-            fd.seek(header.shoff+i*header.shentsize);
+            seek(header.shoff+i*header.shentsize);
             sheaders[i] = new SHeader();
         }
         if(header.shstrndx < 0 || header.shstrndx >= header.shnum) throw new ELFException("Bad shstrndx");
             sheaders[i] = new SHeader();
         }
         if(header.shstrndx < 0 || header.shstrndx >= header.shnum) throw new ELFException("Bad shstrndx");
-        fd.seek(sheaders[header.shstrndx].offset);
+        seek(sheaders[header.shstrndx].offset);
         byte[] a = new byte[sheaders[header.shstrndx].size];
         fd.readFully(a);
         for(int i=0;i<header.shnum;i++) {
         byte[] a = new byte[sheaders[header.shstrndx].size];
         fd.readFully(a);
         for(int i=0;i<header.shnum;i++) {
@@ -161,13 +177,6 @@ class ELF {
     
     public class ELFException extends IOException { ELFException(String s) { super(s); } }
     
     
     public class ELFException extends IOException { ELFException(String s) { super(s); } }
     
-    private class MyRandomAccessFile extends RandomAccessFile  {
-        MyRandomAccessFile(String f,String m) throws IOException { super(f,m); }
-        public void skipFully(int n) throws IOException {
-            while(n>0) n-= skipBytes(n);
-        }
-    }
-
     private class SectionInputStream extends InputStream {
         private int pos;
         private int maxpos;
     private class SectionInputStream extends InputStream {
         private int pos;
         private int maxpos;
@@ -176,14 +185,24 @@ class ELF {
                 throw new IOException("Section reader already active");
             sectionReaderActive = true;
             pos = start;
                 throw new IOException("Section reader already active");
             sectionReaderActive = true;
             pos = start;
-            fd.seek(pos);
+            seek(pos);
             maxpos = end;
         }
         
         private int bytesLeft() { return maxpos - pos; }
             maxpos = end;
         }
         
         private int bytesLeft() { return maxpos - pos; }
-        public int read() throws IOException { if(bytesLeft()==0) return -1; int b = fd.read(); if(b >= 0) pos++; return b; }
+        public int read() throws IOException {
+            if(bytesLeft()==0) return -1;
+            try {
+                byte b = fd.readByte();
+                pos++;
+                return b;
+            } catch (EOFException e) {
+                return -1;
+            }
+        }
         public int read(byte[] b, int off, int len) throws IOException {
         public int read(byte[] b, int off, int len) throws IOException {
-            int n = fd.read(b,off,Math.min(len,bytesLeft())); if(n > 0) pos += n; return n;
+            fd.readFully(b, off, len);
+            return len;
         }
         public void close() { sectionReaderActive = false; }
     }
         }
         public void close() { sectionReaderActive = false; }
     }
index 81aa042..a957297 100644 (file)
@@ -26,7 +26,7 @@ public class Interpreter extends VM {
     private int nextPC;
     
     // The filename if the binary we're running
     private int nextPC;
     
     // The filename if the binary we're running
-    private String image;
+    private Object image;
     
     // Register Operations
     private final void setFC(boolean b) { fcsr = (fcsr&~0x800000) | (b ? 0x800000 : 0x000000); }
     
     // Register Operations
     private final void setFC(boolean b) { fcsr = (fcsr&~0x800000) | (b ? 0x800000 : 0x000000); }
@@ -614,8 +614,10 @@ public class Interpreter extends VM {
     }
     
     // Image loading function
     }
     
     // Image loading function
-    void loadImage(String file) throws IOException {
-        ELF elf = new ELF(file);
+    void loadImage(Object file) throws IOException {
+        ELF elf = null;
+        if (file instanceof String) elf = new ELF(new RandomAccessFile((String)file,"r"));
+        else if (file instanceof byte[]) elf = new ELF((byte[])file);
         if(elf.header.type != ELF.ELFHeader.ET_EXEC)
             throw new IOException("Binary is not an executable");
         if(elf.header.machine != ELF.ELFHeader.EM_MIPS)
         if(elf.header.type != ELF.ELFHeader.ET_EXEC)
             throw new IOException("Binary is not an executable");
         if(elf.header.machine != ELF.ELFHeader.EM_MIPS)
@@ -662,6 +664,7 @@ public class Interpreter extends VM {
     }
     public Interpreter() { }
     public Interpreter(String image) throws IOException { loadImage(image); }
     }
     public Interpreter() { }
     public Interpreter(String image) throws IOException { loadImage(image); }
+    public Interpreter(byte[] image) throws IOException { loadImage(image); }
     
     // Debug functions
     // NOTE: This probably requires a jdk > 1.1, however, it is only used for debugging
     
     // Debug functions
     // NOTE: This probably requires a jdk > 1.1, however, it is only used for debugging
@@ -670,7 +673,7 @@ public class Interpreter extends VM {
         String line;
         if(image==null) return null;
         try {
         String line;
         if(image==null) return null;
         try {
-            Process p = Runtime.getRuntime().exec(new String[]{addr2line,"-e",image,toHex(pc)});
+            Process p = Runtime.getRuntime().exec(new String[]{addr2line,"-e",image.toString(),toHex(pc)});
             line = new BufferedReader(new InputStreamReader(p.getInputStream())).readLine();
             if(line == null) return null;
             while(line.startsWith("../")) line = line.substring(3);
             line = new BufferedReader(new InputStreamReader(p.getInputStream())).readLine();
             if(line == null) return null;
             while(line.startsWith("../")) line = line.substring(3);
index 0e0b2a7..068b766 100644 (file)
@@ -28,6 +28,7 @@
 #include <org/xwt/util/Semaphore.h>
 
 #include <stdlib.h>
 #include <org/xwt/util/Semaphore.h>
 
 #include <stdlib.h>
+#include <objc/objc.h>
 
 #include "DarwinCarbonHeaders.h"
 
 
 #include "DarwinCarbonHeaders.h"
 
@@ -540,6 +541,15 @@ void Darwin$CarbonSurface::natInit(jboolean framed) {
     rect.top = 0; rect.left = 0; rect.bottom = 10; rect.right=10;
     r = CreateNewWindow(wc,attr,&rect,&window);
     checkStatus(r,"CreateNewWindow");
     rect.top = 0; rect.left = 0; rect.bottom = 10; rect.right=10;
     r = CreateNewWindow(wc,attr,&rect,&window);
     checkStatus(r,"CreateNewWindow");
+
+    id NSWindowClass = objc_getClass("NSWindow");
+    printf("nswindowclass is %x\n", NSWindowClass);
+    SEL selector = sel_registerName("initWithWindowRef");
+    printf("selector is %s\n", selector);
+    objc_method method = class_getClassMethod(NSWindowClass, selector);
+    printf("method is %x\n", method);
+    id windowInstance = objc_msgSend(NSWindowClass, selector, window);
+    printf("instance is %x\n", windowInstance);
     
     GCJ$Retainer::retain(this); // Need to account for the EventHandlers pointer to us
     EventHandlerUPP upp = NewEventHandlerUPP(our_windowEventHandler);
     
     GCJ$Retainer::retain(this); // Need to account for the EventHandlers pointer to us
     EventHandlerUPP upp = NewEventHandlerUPP(our_windowEventHandler);
index c9d336d..3050a2b 100644 (file)
@@ -25,27 +25,14 @@ extern "C" {
 
 // builtin.xwar /////////////////////////////////////////////////////////
 
 
 // builtin.xwar /////////////////////////////////////////////////////////
 
-extern unsigned char builtin_xwar[];
-extern int builtin_xwar_length;
+extern unsigned char builtin_bytes[];
+extern int builtin_length;
 
 java::io::InputStream* org::xwt::plat::GCJ::_getBuiltinInputStream() {
 
 java::io::InputStream* org::xwt::plat::GCJ::_getBuiltinInputStream() {
-    jbyteArray ret = JvNewByteArray(builtin_xwar_length);
-    memcpy(elements(ret), builtin_xwar, builtin_xwar_length);
+    jbyteArray ret = JvNewByteArray(builtin_length);
+    memcpy(elements(ret), builtin_bytes, builtin_length);
     return new java::io::ByteArrayInputStream(ret);
 }
     return new java::io::ByteArrayInputStream(ret);
 }
-           
-
-// freetype.mips /////////////////////////////////////////////////////////
-
-extern unsigned char freetype_mips[];
-extern int freetype_mips_length;
-
-java::io::InputStream* org::xwt::plat::GCJ::_getFreetypeInputStream() {
-    jbyteArray ret = JvNewByteArray(freetype_mips_length);
-    memcpy(elements(ret), freetype_mips, freetype_mips_length);
-    return new java::io::ByteArrayInputStream(ret);
-}
-           
 
 
 
 
 
 
index 9484439..788ced5 100644 (file)
@@ -22,7 +22,6 @@ public abstract class GCJ extends Platform {
     protected org.xwt.Weak _getWeak(Object o) { return new Java2Weak(o); }
 
     protected native InputStream _getBuiltinInputStream();
     protected org.xwt.Weak _getWeak(Object o) { return new Java2Weak(o); }
 
     protected native InputStream _getBuiltinInputStream();
-    protected native InputStream _getFreetypeInputStream();
 
     private static class Java2Weak extends java.lang.ref.WeakReference implements org.xwt.Weak {
         public Java2Weak(Object o) { super(o); }
 
     private static class Java2Weak extends java.lang.ref.WeakReference implements org.xwt.Weak {
         public Java2Weak(Object o) { super(o); }
index 190f927..8026108 100644 (file)
@@ -2,6 +2,7 @@ package org.xwt.translators;
 import org.xwt.*;
 import org.xwt.util.*;
 import java.io.*;
 import org.xwt.*;
 import org.xwt.util.*;
 import java.io.*;
+import java.util.zip.*;
 
 // FEATURE: use streams, not memoryfont's
 // FEATURE: kerning pairs
 
 // FEATURE: use streams, not memoryfont's
 // FEATURE: kerning pairs
@@ -13,9 +14,15 @@ public class Font {
 
     public static synchronized void renderGlyphs(Res res, int pointsize, int firstGlyph, int lastGlyph, Cache glyphCache) {
         try {
 
     public static synchronized void renderGlyphs(Res res, int pointsize, int firstGlyph, int lastGlyph, Cache glyphCache) {
         try {
+           
             if (vm == null) {
             if (vm == null) {
-                vm = new org.xwt.mips.Interpreter("freetype.mips");
-                vm.start(new String[]{ "freetype.mips"});
+
+                InputStream bis = Platform.getBuiltinInputStream();
+                ZipInputStream zis = new ZipInputStream(bis);
+                for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry());
+                byte[] image = Resources.isToByteArray(zis);
+                vm = new org.xwt.mips.Interpreter(image);
+                vm.start(new String[]{ "freetype.mips" });
                 vm.execute();
             }
 
                 vm.execute();
             }