mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
New faults and syntax (#2034)
- Remove `[?]` syntax. - Change `int!` to `int?` syntax. - New `fault` declarations. - Enum associated values can reference the calling enum.
This commit is contained in:
committed by
GitHub
parent
fefce25081
commit
25bccf4883
@@ -17,9 +17,9 @@ fn ByteReader* ByteReader.init(&self, char[] bytes)
|
||||
return self;
|
||||
}
|
||||
|
||||
fn usz! ByteReader.read(&self, char[] bytes) @dynamic
|
||||
fn usz? ByteReader.read(&self, char[] bytes) @dynamic
|
||||
{
|
||||
if (self.index >= self.bytes.len) return IoError.EOF?;
|
||||
if (self.index >= self.bytes.len) return io::EOF?;
|
||||
usz len = min(self.bytes.len - self.index, bytes.len);
|
||||
if (len == 0) return 0;
|
||||
mem::copy(bytes.ptr, &self.bytes[self.index], len);
|
||||
@@ -27,19 +27,19 @@ fn usz! ByteReader.read(&self, char[] bytes) @dynamic
|
||||
return len;
|
||||
}
|
||||
|
||||
fn char! ByteReader.read_byte(&self) @dynamic
|
||||
fn char? ByteReader.read_byte(&self) @dynamic
|
||||
{
|
||||
if (self.index >= self.bytes.len) return IoError.EOF?;
|
||||
if (self.index >= self.bytes.len) return io::EOF?;
|
||||
return self.bytes[self.index++];
|
||||
}
|
||||
|
||||
fn void! ByteReader.pushback_byte(&self) @dynamic
|
||||
fn void? ByteReader.pushback_byte(&self) @dynamic
|
||||
{
|
||||
if (!self.index) return IoError.INVALID_PUSHBACK?;
|
||||
if (!self.index) return INVALID_PUSHBACK?;
|
||||
self.index--;
|
||||
}
|
||||
|
||||
fn usz! ByteReader.seek(&self, isz offset, Seek seek) @dynamic
|
||||
fn usz? ByteReader.seek(&self, isz offset, Seek seek) @dynamic
|
||||
{
|
||||
isz new_index;
|
||||
switch (seek)
|
||||
@@ -48,12 +48,12 @@ fn usz! ByteReader.seek(&self, isz offset, Seek seek) @dynamic
|
||||
case CURSOR: new_index = self.index + offset;
|
||||
case END: new_index = self.bytes.len + offset;
|
||||
}
|
||||
if (new_index < 0) return IoError.INVALID_POSITION?;
|
||||
if (new_index < 0) return INVALID_POSITION?;
|
||||
self.index = new_index;
|
||||
return new_index;
|
||||
}
|
||||
|
||||
fn usz! ByteReader.write_to(&self, OutStream writer) @dynamic
|
||||
fn usz? ByteReader.write_to(&self, OutStream writer) @dynamic
|
||||
{
|
||||
if (self.index >= self.bytes.len) return 0;
|
||||
usz written = writer.write(self.bytes[self.index..])!;
|
||||
@@ -62,7 +62,7 @@ fn usz! ByteReader.write_to(&self, OutStream writer) @dynamic
|
||||
return written;
|
||||
}
|
||||
|
||||
fn usz! ByteReader.available(&self) @inline @dynamic
|
||||
fn usz? ByteReader.available(&self) @inline @dynamic
|
||||
{
|
||||
return max(0, self.bytes.len - self.index);
|
||||
}
|
||||
Reference in New Issue
Block a user