Add io_reader.is_closed

This commit is contained in:
Nigel Tao committed 2020-02-19 12:22:00 +11:00
1 parent 27036043ae
commit a8406927ef
4 files changed
+23 -13

No files matched your search

+9 -6
View File
@@ -93,6 +93,9 @@ size_t indent;
// ---- // ----
const char* read_src() { const char* read_src() {
if (src.meta.closed) {
return "main: read error: unexpected EOF";
}
src.compact(); src.compact();
if (src.meta.wi >= src.data.len) { if (src.meta.wi >= src.data.len) {
return "main: src buffer is full"; return "main: src buffer is full";
@@ -100,12 +103,12 @@ const char* read_src() {
size_t n = fread(src.data.ptr + src.meta.wi, sizeof(uint8_t), size_t n = fread(src.data.ptr + src.meta.wi, sizeof(uint8_t),
src.data.len - src.meta.wi, stdin); src.data.len - src.meta.wi, stdin);
src.meta.wi += n; src.meta.wi += n;
if (n == 0) { if (n > 0) {
if (feof(stdin)) { // No-op.
return "main: read error: unexpected EOF"; } else if (feof(stdin)) {
} else { src.meta.closed = true;
return "main: read error"; } else {
} return "main: read error";
} }
return nullptr; return nullptr;
} }
+4
View File
@@ -160,6 +160,10 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
b.printf(", ((uint64_t)(%s%s - %s%s)))", iopPrefix, name, io0Prefix, name) b.printf(", ((uint64_t)(%s%s - %s%s)))", iopPrefix, name, io0Prefix, name)
return nil return nil
case t.IDIsClosed:
b.printf("(%s && %s->meta.closed)", name, name)
return nil
case t.IDMark: case t.IDMark:
b.printf("((uint64_t)(%s%s - %s%s))", iopPrefix, name, io0Prefix, name) b.printf("((uint64_t)(%s%s - %s%s))", iopPrefix, name, io0Prefix, name)
return nil return nil
+1
View File
@@ -249,6 +249,7 @@ var Funcs = []string{
"io_reader.available() u64", "io_reader.available() u64",
"io_reader.count_since(mark: u64) u64", "io_reader.count_since(mark: u64) u64",
"io_reader.is_closed() bool",
"io_reader.mark() u64", "io_reader.mark() u64",
"io_reader.position() u64", "io_reader.position() u64",
"io_reader.since(mark: u64) slice u8", "io_reader.since(mark: u64) slice u8",
+9 -7
View File
@@ -491,13 +491,14 @@ const (
IDCanUndoByte = ID(0x160) IDCanUndoByte = ID(0x160)
IDCountSince = ID(0x161) IDCountSince = ID(0x161)
IDHistoryAvailable = ID(0x162) IDHistoryAvailable = ID(0x162)
IDMark = ID(0x163) IDIsClosed = ID(0x163)
IDPosition = ID(0x164) IDMark = ID(0x164)
IDSince = ID(0x165) IDPosition = ID(0x165)
IDSkip = ID(0x166) IDSince = ID(0x166)
IDSkip32 = ID(0x167) IDSkip = ID(0x167)
IDSkip32Fast = ID(0x168) IDSkip32 = ID(0x168)
IDTake = ID(0x169) IDSkip32Fast = ID(0x169)
IDTake = ID(0x16A)
IDCopyFromSlice = ID(0x170) IDCopyFromSlice = ID(0x170)
IDCopyN32FromHistory = ID(0x171) IDCopyN32FromHistory = ID(0x171)
@@ -841,6 +842,7 @@ var builtInsByID = [nBuiltInIDs]string{
IDCanUndoByte: "can_undo_byte", IDCanUndoByte: "can_undo_byte",
IDCountSince: "count_since", IDCountSince: "count_since",
IDHistoryAvailable: "history_available", IDHistoryAvailable: "history_available",
IDIsClosed: "is_closed",
IDMark: "mark", IDMark: "mark",
IDPosition: "position", IDPosition: "position",
IDSince: "since", IDSince: "since",