more changes
authorbdemsky <bdemsky>
Sun, 4 Nov 2007 03:33:00 +0000 (03:33 +0000)
committerbdemsky <bdemsky>
Sun, 4 Nov 2007 03:33:00 +0000 (03:33 +0000)
17 files changed:
Robust/src/ClassLibrary/BufferedOutputStream.java
Robust/src/ClassLibrary/BufferedWriter.java
Robust/src/ClassLibrary/FileOutputStream.java
Robust/src/ClassLibrary/FileWriter.java [new file with mode: 0644]
Robust/src/ClassLibrary/OutputStream.java
Robust/src/ClassLibrary/OutputStreamWriter.java [new file with mode: 0644]
Robust/src/ClassLibrary/SocketInputStream.java
Robust/src/ClassLibrary/SocketJava.java
Robust/src/ClassLibrary/SocketOutputStream.java [new file with mode: 0644]
Robust/src/ClassLibrary/String.java
Robust/src/ClassLibrary/System.java
Robust/src/ClassLibrary/Writer.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/Main/Main.java
Robust/src/Runtime/file.c
Robust/src/Runtime/runtime.c
Robust/src/Runtime/runtime.h

index f6adbd097dc8d45af90889ead3979f630b44695e..8a36bde25bf550f628a5b72b7290a5a5adaf3563 100644 (file)
@@ -1,6 +1,19 @@
 public class BufferedOutputStream extends OutputStream {
     OutputStream o;
 
-    
+    public BufferedOutputStream(OutputStream o) {
+       this.o=o;
+    }
 
+    public void write(byte []b, int off, int len) {
+       o.write(b, off, len);
+    }
+
+    public void flush() {
+       o.flush();
+    }
+
+    public void close() {
+       o.close();
+    }
 }
index f9b0049afc55733255d2c9b0263fc03ac49d5492..c800ef3b6bbb8d25e6863b911bedcb7a18d9af66 100644 (file)
@@ -1,6 +1,10 @@
 public class BufferedWriter extends Writer {
     Writer out;
 
+    public BufferedWriter(Writer out) {
+       this.out=out;
+    }
+
     public void write(String s) {
        out.write(s);
     }
@@ -13,4 +17,8 @@ public class BufferedWriter extends Writer {
        out.flush();
     }
 
+    public void close() {
+       out.close();
+    }
+
 }
index d5b1f6bf9f03694ec56275a4f341c41448a8c312..cbb464996d7672ec9adb629eab75afa6a3878adf 100644 (file)
@@ -1,10 +1,17 @@
-public class FileOutputStream {
+public class FileOutputStream extends OutputStream {
     private int fd;
 
     public FileOutputStream(String pathname) {
        fd=nativeOpen(pathname.getBytes());
     }
 
+    public FileOutputStream(String pathname, boolean append) {
+       if(append)      
+               fd=nativeAppend(pathname.getBytes());
+       else
+               fd=nativeOpen(pathname.getBytes());
+    }
+
     public FileOutputStream(String pathname, int mode) {
        if(mode==0)     
                fd=nativeAppend(pathname.getBytes());
@@ -22,7 +29,7 @@ public class FileOutputStream {
 
     private static native int nativeOpen(byte[] filename);
     private static native int nativeAppend(byte[] filename);
-    private static native void nativeWrite(int fd, byte[] array);
+    private static native void nativeWrite(int fd, byte[] array, int off, int len);
     private static native void nativeClose(int fd);
     private static native void nativeFlush(int fd);
     
@@ -33,7 +40,7 @@ public class FileOutputStream {
     }
 
     public void write(byte[] b) {
-       nativeWrite(fd, b);
+       nativeWrite(fd, b, 0, b.length);
     }
 
     public void flush() {
diff --git a/Robust/src/ClassLibrary/FileWriter.java b/Robust/src/ClassLibrary/FileWriter.java
new file mode 100644 (file)
index 0000000..66f7377
--- /dev/null
@@ -0,0 +1,6 @@
+public class FileWriter extends OutputStreamWriter {
+    public FileWriter(String file, boolean append) {
+       super(new FileOutputStream(file, append));
+    }
+
+}
index d1318bb02f16d5d75a1ad3cd7460d00b4ae70169..22fadd1991b9955cf2ae6141d1043ce41fed67a1 100644 (file)
@@ -7,4 +7,13 @@ public class OutputStream {
 
     public void write(byte[] b) {
     }
+
+    public void write(byte[] b, int off, int len) {
+    }
+
+    public void flush() {
+    }
+    
+    public void close() {
+    }
 }
diff --git a/Robust/src/ClassLibrary/OutputStreamWriter.java b/Robust/src/ClassLibrary/OutputStreamWriter.java
new file mode 100644 (file)
index 0000000..b1afd6e
--- /dev/null
@@ -0,0 +1,10 @@
+public class OutputStreamWriter extends Writer {
+    OutputStream fos;
+    public OutputStreamWriter(OutputStream fos)  {
+       this.fos=fos;
+    }
+
+    
+
+
+}
index 0539785a09d515d278c789b55088eac774c7c984..b63bfcd8a378f2a85f4f0cda661f5023dc49ace9 100644 (file)
@@ -1,4 +1,4 @@
-public class SocketInputStream {
+public class SocketInputStream extends InputStream {
     Socket s;
     public SocketInputStream(Socket s) {
        this.s=s;
index 55624e1b54bc3998d29d0777c16db64eaf69f234..a24a7fe3780c6dd76a836809aafa71f1da6f1c8a 100644 (file)
@@ -1,8 +1,20 @@
 public class Socket {
     /* File Descriptor */
     int fd;
-    
+    SocketInputStream sin;
+    SocketOutputStream sout;
+
     public Socket() {
+       sin=new SocketInputStream(this);
+       sout=new SocketOutputStream(this);
+    }
+
+    public InputStream getInputStream() {
+       return sin;
+    }
+
+    public OutputStream getOutputStream() {
+       return sout;
     }
 
     public Socket(String host, int port) {
diff --git a/Robust/src/ClassLibrary/SocketOutputStream.java b/Robust/src/ClassLibrary/SocketOutputStream.java
new file mode 100644 (file)
index 0000000..6e4167d
--- /dev/null
@@ -0,0 +1,8 @@
+public class SocketOutputStream extends OutputStream {
+    Socket s;
+    public SocketOutputStream(Socket s) {
+       this.s=s;
+    }
+
+    
+}
index 4048cc024f7a5242423a6de18ba04c0934dafc7c..4ad4b7c97af2ebeaddc16b06dbe642413e05e268 100644 (file)
@@ -251,6 +251,38 @@ public class String {
        return new String(chararray);
     }
 
+    public static String valueOf(long x) {
+       int length=0;
+       long tmp;
+       if (x<0)
+           tmp=-x;
+       else
+           tmp=x;
+       do {
+           tmp=tmp/10;
+           length=length+1;
+       } while(tmp!=0);
+       
+       char chararray[];
+       if (x<0)
+           chararray=new char[length+1];
+       else
+           chararray=new char[length];
+       int voffset;
+       if (x<0) {
+           chararray[0]='-';
+           voffset=1;
+           x=-x;
+       } else
+           voffset=0;
+               
+       do {
+           chararray[--length+voffset]=(char)(x%10+'0');
+           x=x/10;
+       } while (length!=0);
+       return new String(chararray);
+    }
+
     public int hashCode() {
        if (cachedHashcode!=0)
            return cachedHashcode;
index 89b33ea44d07b2ac0cc6a6e583a703d1b846d4df..d1352339f91f8b8c2bf2ff5645a9a2462ceb945a 100644 (file)
@@ -9,4 +9,6 @@ public class System {
     public static void error() {
        System.printString("Error (Use Breakpoint on ___System______error method for more information!)\n");
     }
+
+    public static native void exit(int status);
 }
index c245a141c429a8b71ba9225df8f67f4248740d50..e0959e55eab143fd2172d924598228fc0aa6fe8a 100644 (file)
@@ -1,5 +1,4 @@
 public class Writer {
-
     public void write(String s) {
     }
 
@@ -9,4 +8,7 @@ public class Writer {
 
     public void flush() {
     }
+
+    public void close() {
+    }
 }
index 789db3ed79885dc081133602b9d627fd7095df7d..cf5650c2be7a45a0d8cce24db6512b14b0eb5fe8 100644 (file)
@@ -1869,9 +1869,12 @@ public class BuildCode {
     }
 
     private void generateFlatReturnNode(FlatMethod fm, LocalityBinding lb, FlatReturnNode frn, PrintWriter output) {
-       if (frn.getReturnTemp()!=null)
-           output.println("return "+generateTemp(fm, frn.getReturnTemp(), lb)+";");
-       else
+       if (frn.getReturnTemp()!=null) {
+           if (frn.getReturnTemp().getType().isPtr())
+               output.println("return (struct "+fm.getMethod().getReturnType().getSafeSymbol()+"*)"+generateTemp(fm, frn.getReturnTemp(), lb)+";");
+           else
+               output.println("return "+generateTemp(fm, frn.getReturnTemp(), lb)+";");
+       } else
            output.println("return;");
     }
 
index cb377a9308e6fdd63a7f7edc972ba35028e4a267..4265e6049ed7307957fdf84c27034d9c9361b1b5 100644 (file)
@@ -96,7 +96,8 @@ public class Main {
       readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java");
       readSourceFile(state, ClassLibraryPrefix+"File.java");
       readSourceFile(state, ClassLibraryPrefix+"InetAddress.java");
-
+      readSourceFile(state, ClassLibraryPrefix+"SocketInputStream.java");
+      readSourceFile(state, ClassLibraryPrefix+"SocketOutputStream.java");
 
 
       if (state.TASK) {
index 39cc326309a19862f5dd73d64691390b7336797e..63f21bd5dde37a242ddc4f2a30bec2654dc4e7e4 100644 (file)
@@ -7,10 +7,9 @@
 #include "mem.h"
 #include "runtime.h"
 
-void CALL12(___FileOutputStream______nativeWrite____I__AR_B, int fd, int fd, struct ArrayObject * ___array___) {
-  int length=VAR(___array___)->___length___;
+void CALL34(___FileOutputStream______nativeWrite____I__AR_B_I_I, int fd, int off, int len, int fd, struct ArrayObject * ___array___, int off, int len) {
   char * string= (((char *)& VAR(___array___)->___length___)+sizeof(int));
-  int status=write(fd, string, length);
+  int status=write(fd, &string[off], len);
 }
 
 void CALL11(___FileOutputStream______nativeClose____I, int fd, int fd) {
index 3917da59afd5cb5de5c7579edeeccf4773310293..7f72751159fd1e2f8f29f0cc2b5917f20ca72dbe 100644 (file)
@@ -74,6 +74,10 @@ void injectinstructionfailure() {
 #endif
 }
 
+void CALL11(___System______exit____I,int ___status___, int ___status___) {
+  exit(___status___);
+}
+
 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
     struct ArrayObject * chararray=VAR(___s___)->___value___;
     int i;
index af2c790196e635531975a09e91bef7d38cd4232b..fdef2c2ff2facdb131401b35451e78a8d0ee2497 100644 (file)
@@ -59,6 +59,7 @@ void createstartupobject();
 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
+#define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
 #else
 #define VAR(name) name
 #define CALL00(name) name()
@@ -68,6 +69,7 @@ void createstartupobject();
 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
+#define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
 #endif
 
 #ifdef TASK