Interface based streams. Fix for initializing with a force unwrap inside. Allow $define to take a list. Allow $define to return error on argument type mismatch in call. Fixed broken bit operations on boolean vectors.

This commit is contained in:
Christoffer Lerno
2023-10-30 14:07:37 +01:00
committed by Christoffer Lerno
parent e4c1328ef2
commit 1aa038c92f
42 changed files with 789 additions and 890 deletions

View File

@@ -3,11 +3,11 @@ import std::io;
struct CsvReader
{
Stream* stream;
InStream* stream;
String separator;
}
fn void CsvReader.init(&self, Stream* stream, String separator = ",")
fn void CsvReader.init(&self, InStream* stream, String separator = ",")
{
self.stream = stream;
self.separator = separator;
@@ -15,9 +15,9 @@ fn void CsvReader.init(&self, Stream* stream, String separator = ",")
fn String[]! CsvReader.read_row(self, Allocator* using = mem::heap())
{
@pool()
@pool(using)
{
return self.stream.treadline().split(self.separator, .using = using);
return io::treadline(self.stream).split(self.separator, .using = using);
};
}
@@ -30,13 +30,13 @@ fn void! CsvReader.skip_row(self) @maydiscard
{
@pool()
{
self.stream.readline(mem::temp())!;
(void)io::treadline(self.stream);
};
}
macro CsvReader.@each_row(self, int rows = int.max; @body(String[] row))
{
Stream* stream = self.stream;
InputStream* stream = self.stream;
String sep = self.separator;
while (rows--)
{

View File

@@ -15,7 +15,7 @@ fault JsonParsingError
INVALID_NUMBER,
}
fn Object*! parse(Stream* s, Allocator* using = mem::heap())
fn Object*! parse(InStream* s, Allocator* using = mem::heap())
{
JsonContext context = { .last_string = dstring::new_with_capacity(64, using), .stream = s, .allocator = using };
defer context.last_string.free();
@@ -44,7 +44,7 @@ enum JsonTokenType @local
struct JsonContext @local
{
uint line;
Stream* stream;
InStream* stream;
Allocator* allocator;
JsonTokenType token;
DString last_string;