nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: Ballz improvements
[nit.git]
/
src
/
interpreter
/
primitive_types.nit
diff --git
a/src/interpreter/primitive_types.nit
b/src/interpreter/primitive_types.nit
index
127815b
..
4912404
100644
(file)
--- a/
src/interpreter/primitive_types.nit
+++ b/
src/interpreter/primitive_types.nit
@@
-14,46
+14,70
@@
# underlying implementation and that the services are semantically correct.
module primitive_types
# underlying implementation and that the services are semantically correct.
module primitive_types
-intrude import standard::file
+intrude import core::file
+intrude import core::text::flat
# Wrapper for `NativeFile`
class PrimitiveNativeFile
# Wrapper for `NativeFile`
class PrimitiveNativeFile
- var file: FStream
+ var file: Stream
init native_stdin do
init native_stdin do
- file = new IFStream.from_fd(0)
+ init(sys.stdin)
end
init native_stdout do
end
init native_stdout do
- file = new OFStream.from_fd(1)
+ init(sys.stdout)
end
init native_stderr do
end
init native_stderr do
- file = new OFStream.from_fd(2)
+ init(sys.stderr)
end
init io_open_read(path: String) do
end
init io_open_read(path: String) do
- file = new IFStream.open(path.to_s)
+ init(new FileReader.open(path.to_s))
end
init io_open_write(path: String) do
end
init io_open_write(path: String) do
- file = new OFStream.open(path.to_s)
+ init(new FileWriter.open(path.to_s))
end
end
- fun address_is_null: Bool do return file._file.address_is_null
+ fun address_is_null: Bool do
+ if file isa FileStream then return file.as(FileStream)._file.address_is_null
+ return false
+ end
- fun io_read(buf: NativeString, len: Int): Int do return file._file.io_read(buf, len)
+ fun io_read(buf: NativeString, len: Int): Int do
+ if file isa FileStream then return file.as(FileStream)._file.io_read(buf, len)
+ var str = file.as(Reader).read(len)
+ str.to_cstring.copy_to(buf, str.length, 0, 0)
+ return str.length
+ end
- fun io_write(buf: NativeString, len: Int): Int do return file._file.io_write(buf, len)
+ fun io_write(buf: NativeString, from, len: Int): Int do
+ if file isa FileStream then return file.as(FileStream)._file.io_write(buf, from, len)
+ file.as(Writer).write(buf.to_s_with_length(len).substring_from(from))
+ return len
+ end
- fun io_close: Int do return file._file.io_close
+ fun io_close: Int do
+ if file isa FileStream then return file.as(FileStream)._file.io_close
+ file.close
+ return 0
+ end
- fun fileno: Int do return file._file.fileno
+ fun fileno: Int do
+ if file isa FileStream then return file.as(FileStream)._file.fileno
+ return 0
+ end
- fun flush: Int do return file._file.flush
+ fun flush: Int do
+ if file isa FileStream then return file.as(FileStream)._file.flush
+ return 0
+ end
fun set_buffering_type(size, mode: Int): Int do
fun set_buffering_type(size, mode: Int): Int do
- return file._file.set_buffering_type(size, mode)
+ if file isa FileStream then return file.as(FileStream)._file.set_buffering_type(size, mode)
+ return 0
end
end
end
end