mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Updated stdlib to experimental allocator first. Updates to DString, String and anything using new_* syntax.
This commit is contained in:
@@ -38,26 +38,20 @@ fn void CsvReader.init(&self, InStream stream, String separator = ",")
|
||||
self.stream = stream;
|
||||
self.separator = separator;
|
||||
}
|
||||
|
||||
fn CsvRow! CsvReader.read_new_row(self)
|
||||
{
|
||||
return self.read_row(allocator::heap()) @inline;
|
||||
}
|
||||
|
||||
<*
|
||||
@param [&inout] allocator
|
||||
*>
|
||||
fn CsvRow! CsvReader.read_row(self, Allocator allocator)
|
||||
{
|
||||
String row = io::readline(self.stream, allocator: allocator)!;
|
||||
String row = io::readline(allocator, self.stream)!;
|
||||
defer catch allocator::free(allocator, row);
|
||||
String[] list = row.split(self.separator, allocator: allocator);
|
||||
String[] list = row.split(allocator, self.separator);
|
||||
return { list, row, allocator };
|
||||
}
|
||||
|
||||
fn CsvRow! CsvReader.read_temp_row(self)
|
||||
fn CsvRow! CsvReader.tread_row(self)
|
||||
{
|
||||
return self.read_row(allocator::temp()) @inline;
|
||||
return self.read_row(tmem()) @inline;
|
||||
}
|
||||
|
||||
<*
|
||||
|
||||
@@ -13,22 +13,21 @@ fn char[]! decode_buffer(char[] code, char[] buffer)
|
||||
return buffer[:decode_bytes(code, buffer)!];
|
||||
}
|
||||
|
||||
fn String encode(char[] code, Allocator allocator)
|
||||
fn String encode(Allocator allocator, char[] code)
|
||||
{
|
||||
char[] data = allocator::alloc_array(allocator, char, encode_len(code.len));
|
||||
return (String)data[:encode_bytes(code, data)];
|
||||
}
|
||||
|
||||
fn char[]! decode(char[] code, Allocator allocator)
|
||||
fn char[]! decode(Allocator allocator, char[] code)
|
||||
{
|
||||
char[] data = allocator::alloc_array(allocator, char, decode_len(code.len));
|
||||
return data[:decode_bytes(code, data)!];
|
||||
}
|
||||
|
||||
fn String encode_new(char[] code) @inline => encode(code, allocator::heap());
|
||||
fn String encode_temp(char[] code) @inline => encode(code, allocator::temp());
|
||||
fn char[]! decode_new(char[] code) @inline => decode(code, allocator::heap());
|
||||
fn char[]! decode_temp(char[] code) @inline => decode(code, allocator::temp());
|
||||
fn String tencode(char[] code) @inline => encode(tmem(), code);
|
||||
fn char[]! tdecode(char[] code) @inline => decode(tmem(), code);
|
||||
|
||||
|
||||
<*
|
||||
Calculate the size of the encoded data.
|
||||
|
||||
@@ -15,21 +15,21 @@ fault JsonParsingError
|
||||
INVALID_NUMBER,
|
||||
}
|
||||
|
||||
fn Object*! parse_string(String s, Allocator allocator = allocator::heap())
|
||||
fn Object*! parse_string(Allocator allocator, String s)
|
||||
{
|
||||
return parse((ByteReader){}.init(s), allocator);
|
||||
return parse(allocator, (ByteReader){}.init(s));
|
||||
}
|
||||
|
||||
fn Object*! temp_parse_string(String s)
|
||||
fn Object*! tparse_string(String s)
|
||||
{
|
||||
return parse((ByteReader){}.init(s), allocator::temp());
|
||||
return parse(tmem(), (ByteReader){}.init(s));
|
||||
}
|
||||
|
||||
fn Object*! parse(InStream s, Allocator allocator = allocator::heap())
|
||||
fn Object*! parse(Allocator allocator, InStream s)
|
||||
{
|
||||
@stack_mem(512; Allocator mem)
|
||||
{
|
||||
JsonContext context = { .last_string = dstring::new_with_capacity(64, mem), .stream = s, .allocator = allocator };
|
||||
JsonContext context = { .last_string = dstring::new_with_capacity(mem, 64), .stream = s, .allocator = allocator };
|
||||
@pool(allocator)
|
||||
{
|
||||
return parse_any(&context);
|
||||
@@ -37,9 +37,9 @@ fn Object*! parse(InStream s, Allocator allocator = allocator::heap())
|
||||
};
|
||||
}
|
||||
|
||||
fn Object*! temp_parse(InStream s)
|
||||
fn Object*! tparse(InStream s)
|
||||
{
|
||||
return parse(s, allocator::temp());
|
||||
return parse(tmem(), s);
|
||||
}
|
||||
|
||||
// -- Implementation follows --
|
||||
@@ -106,7 +106,7 @@ fn JsonTokenType! lex_number(JsonContext *context, char c) @local
|
||||
{
|
||||
@stack_mem(256; Allocator mem)
|
||||
{
|
||||
DString t = dstring::new_with_capacity(32, allocator: mem);
|
||||
DString t = dstring::new_with_capacity(mem, 32);
|
||||
bool negate = c == '-';
|
||||
if (negate)
|
||||
{
|
||||
@@ -159,7 +159,7 @@ fn Object*! parse_map(JsonContext* context) @local
|
||||
|
||||
@stack_mem(256; Allocator mem)
|
||||
{
|
||||
DString temp_key = dstring::new_with_capacity(32, mem);
|
||||
DString temp_key = dstring::new_with_capacity(mem, 32);
|
||||
while (token != JsonTokenType.RBRACE)
|
||||
{
|
||||
if (token != JsonTokenType.STRING) return JsonParsingError.UNEXPECTED_CHARACTER?;
|
||||
|
||||
Reference in New Issue
Block a user