Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement nqp::flushfh on JVM.
  • Loading branch information
jnthn committed Oct 3, 2013
1 parent 1eb7d09 commit a4e9ac9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -1897,7 +1897,8 @@ QAST::OperationsJAST.map_classlib_core_op('tellfh', $TYPE_OPS, 'tellfh', [$RT_OB
QAST::OperationsJAST.map_classlib_core_op('readfh', $TYPE_OPS, 'readfh', [$RT_OBJ, $RT_OBJ, $RT_INT], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('writefh', $TYPE_OPS, 'writefh', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('printfh', $TYPE_OPS, 'printfh', [$RT_OBJ, $RT_STR], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('sayfh', $TYPE_OPS, 'sayfh', [$RT_OBJ, $RT_STR], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('sayfh', $TYPE_OPS, 'sayfh', [$RT_OBJ, $RT_STR], $RT_STR, :tc);QAST::OperationsJAST.map_classlib_core_op('sayfh', $TYPE_OPS, 'sayfh', [$RT_OBJ, $RT_STR], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('flushfh', $TYPE_OPS, 'flushfh', [$RT_OBJ], $RT_OBJ, :tc);QAST::OperationsJAST.map_classlib_core_op('sayfh', $TYPE_OPS, 'sayfh', [$RT_OBJ, $RT_STR], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('readlinefh', $TYPE_OPS, 'readlinefh', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('readlineintfh', $TYPE_OPS, 'readlineintfh', [$RT_OBJ, $RT_STR], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('readallfh', $TYPE_OPS, 'readallfh', [$RT_OBJ], $RT_STR, :tc);
Expand Down
8 changes: 8 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/io/FileHandle.java
Expand Up @@ -68,4 +68,12 @@ public long tell(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc, e);
}
}

public void flush(ThreadContext tc) {
try {
fc.force(false);
} catch (IOException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
}
}
1 change: 1 addition & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/io/IIOSyncWritable.java
Expand Up @@ -6,4 +6,5 @@ public interface IIOSyncWritable {
public void print(ThreadContext tc, String s);
public void say(ThreadContext tc, String s);
public void write(ThreadContext tc, byte[] bytes);
public void flush(ThreadContext tc);
}
4 changes: 4 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/io/ProcessHandle.java
Expand Up @@ -45,6 +45,10 @@ public ProcessHandle(ThreadContext tc, String cmd, String dir, Map<String, Strin
}
}

public void flush(ThreadContext tc) {
// Not provided.
}

static class ProcessChannel implements ByteChannel {
protected WritableByteChannel stdin;
protected ReadableByteChannel stdout;
Expand Down
4 changes: 4 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/io/SocketHandle.java
Expand Up @@ -32,4 +32,8 @@ public void connect(ThreadContext tc, String host, int port) {
throw ExceptionHandling.dieInternal(tc, e);
}
}

public void flush(ThreadContext tc) {
// Not provided.
}
}
4 changes: 4 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/io/StandardWriteHandle.java
Expand Up @@ -58,4 +58,8 @@ public void say(ThreadContext tc, String s) {
print(tc, s);
print(tc, System.lineSeparator());
}

public void flush(ThreadContext tc) {
ps.flush();
}
}
15 changes: 15 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -566,6 +566,21 @@ public static String sayfh(SixModelObject obj, String data, ThreadContext tc) {
return data;
}

public static SixModelObject flushfh(SixModelObject obj, ThreadContext tc) {
if (obj instanceof IOHandleInstance) {
IOHandleInstance h = (IOHandleInstance)obj;
if (h.handle instanceof IIOSyncWritable)
((IIOSyncWritable)h.handle).flush(tc);
else
throw ExceptionHandling.dieInternal(tc,
"This handle does not support flush");
}
else {
die_s("flushfh requires an object with the IOHandle REPR", tc);
}
return obj;
}

public static String readlinefh(SixModelObject obj, ThreadContext tc) {
if (obj instanceof IOHandleInstance) {
IOHandleInstance h = (IOHandleInstance)obj;
Expand Down

0 comments on commit a4e9ac9

Please sign in to comment.