From 33b05bcfeb6d0f132f2eb0e36ef92b1c0df400eb Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 27 Feb 2025 11:10:41 +0100 Subject: [PATCH] More deprecations in lib6, and updates to lib7 --- lib/std/collections/anylist.c3 | 15 +++- lib/std/collections/bitset.c3 | 23 ++++- lib/std/collections/hashmap.c3 | 90 +++++++++++++++---- lib/std/collections/linkedlist.c3 | 9 +- lib/std/collections/list.c3 | 46 ++++++++-- lib/std/collections/map.c3 | 2 +- lib/std/collections/object.c3 | 4 +- lib/std/core/allocators/tracking_allocator.c3 | 2 +- lib/std/core/builtin.c3 | 2 +- lib/std/core/dstring.c3 | 49 ++++++++-- lib/std/core/string.c3 | 2 +- lib/std/core/test.c3 | 2 +- lib/std/io/os/ls.c3 | 4 +- lib/std/io/stream.c3 | 18 +++- lib/std/io/stream/bytebuffer.c3 | 24 ++++- lib/std/io/stream/bytewriter.c3 | 28 +++++- lib/std/io/stream/multireader.c3 | 30 ++++++- lib/std/io/stream/multiwriter.c3 | 30 ++++++- lib/std/math/bigint.c3 | 2 +- lib/std/math/random/math.seeder.c3 | 2 +- lib/std/net/url.c3 | 4 +- lib/std/os/linux/linux.c3 | 2 +- lib/std/os/macos/darwin.c3 | 2 +- lib/std/os/win32/process.c3 | 2 +- lib/std/threads/buffered_channel.c3 | 6 +- lib/std/threads/unbuffered_channel.c3 | 2 +- lib7/std/collections/anylist.c3 | 34 +------ lib7/std/core/dstring.c3 | 10 +-- lib7/std/core/runtime_benchmark.c3 | 2 +- lib7/std/core/runtime_test.c3 | 2 +- lib7/std/core/string.c3 | 14 +-- lib7/std/io/formatter.c3 | 3 +- lib7/std/io/io.c3 | 2 +- lib7/std/io/os/ls.c3 | 2 +- lib7/std/io/os/temp_directory.c3 | 2 +- lib7/std/io/path.c3 | 20 ++--- lib7/std/io/stream.c3 | 2 +- lib7/std/io/stream/bytebuffer.c3 | 6 +- lib7/std/io/stream/bytewriter.c3 | 6 +- lib7/std/io/stream/multireader.c3 | 6 +- lib7/std/io/stream/multiwriter.c3 | 6 +- lib7/std/net/inetaddr.c3 | 2 +- lib7/std/net/url.c3 | 12 +-- lib7/std/net/url_encoding.c3 | 4 +- lib7/std/os/env.c3 | 8 +- lib7/std/os/subprocess.c3 | 4 +- lib7/std/threads/event/event_thread.c3 | 2 +- lib7/std/time/time.c3 | 2 +- resources/examples/binarydigits.c3 | 2 +- test/src/test_suite_runner.c3 | 2 +- .../functions/missing_return_lambda.c3 | 2 +- .../statements/dead_statements.c3t | 2 +- test/unit/stdlib/collections/copy_map.c3 | 2 +- test/unit/stdlib/core/dstring.c3 | 2 +- test/unit/stdlib/io/varint.c3 | 4 +- test/unit/stdlib/net/url.c3 | 2 +- test/unit/stdlib/sort/sorted.c3 | 2 +- test/unit/stdlib/threads/channel.c3 | 4 +- test/unit7/stdlib/core/dstring.c3 | 4 +- test/unit7/stdlib/io/bits.c3 | 36 ++++---- test/unit7/stdlib/io/bufferstream.c3 | 8 +- test/unit7/stdlib/io/bytebuffer.c3 | 2 +- test/unit7/stdlib/io/bytestream.c3 | 4 +- test/unit7/stdlib/io/multireader.c3 | 4 +- test/unit7/stdlib/io/multiwriter.c3 | 2 +- test/unit7/stdlib/io/stream.c3 | 12 +-- test/unit7/stdlib/io/teereader.c3 | 2 +- test/unit7/stdlib/io/varint.c3 | 4 +- test/unit7/stdlib/net/url.c3 | 10 +-- 69 files changed, 439 insertions(+), 226 deletions(-) diff --git a/lib/std/collections/anylist.c3 b/lib/std/collections/anylist.c3 index 18ba0554c..e63fa7085 100644 --- a/lib/std/collections/anylist.c3 +++ b/lib/std/collections/anylist.c3 @@ -21,7 +21,7 @@ struct AnyList (Printable) @param initial_capacity "The initial capacity to reserve" *> -fn AnyList* AnyList.new_init(&self, usz initial_capacity = 16, Allocator allocator = null) +fn AnyList* AnyList.new_init(&self, usz initial_capacity = 16, Allocator allocator = null) @deprecated("Use init(mem)") { return self.init(allocator ?: allocator::heap(), initial_capacity) @inline; } @@ -52,7 +52,18 @@ fn AnyList* AnyList.init(&self, Allocator allocator, usz initial_capacity = 16) @param initial_capacity "The initial capacity to reserve" *> -fn AnyList* AnyList.temp_init(&self, usz initial_capacity = 16) +fn AnyList* AnyList.temp_init(&self, usz initial_capacity = 16) @deprecated("Use tinit") +{ + return self.init(allocator::temp(), initial_capacity) @inline; +} + + +<* + Initialize the list using the temp allocator. + + @param initial_capacity "The initial capacity to reserve" +*> +fn AnyList* AnyList.tinit(&self, usz initial_capacity = 16) { return self.init(allocator::temp(), initial_capacity) @inline; } diff --git a/lib/std/collections/bitset.c3 b/lib/std/collections/bitset.c3 index 6e0619cb0..3301146ea 100644 --- a/lib/std/collections/bitset.c3 +++ b/lib/std/collections/bitset.c3 @@ -86,15 +86,30 @@ struct GrowableBitSet @param initial_capacity @param [&inout] allocator "The allocator to use, defaults to the heap allocator" *> -fn GrowableBitSet* GrowableBitSet.new_init(&self, usz initial_capacity = 1, Allocator allocator = allocator::heap()) +fn GrowableBitSet* GrowableBitSet.new_init(&self, usz initial_capacity = 1, Allocator allocator = allocator::heap()) @deprecated("Use init(mem)") { - self.data.new_init(initial_capacity, allocator); + self.data.init(allocator, initial_capacity); return self; } -fn GrowableBitSet* GrowableBitSet.temp_init(&self, usz initial_capacity = 1) +<* + @param initial_capacity + @param [&inout] allocator "The allocator to use, defaults to the heap allocator" +*> +fn GrowableBitSet* GrowableBitSet.init(&self, Allocator allocator, usz initial_capacity = 1) { - return self.new_init(initial_capacity, allocator::temp()) @inline; + self.data.init(allocator, initial_capacity); + return self; +} + +fn GrowableBitSet* GrowableBitSet.temp_init(&self, usz initial_capacity = 1) @deprecated("Use tinit()") +{ + return self.init(allocator::temp(), initial_capacity) @inline; +} + +fn GrowableBitSet* GrowableBitSet.tinit(&self, usz initial_capacity = 1) +{ + return self.init(allocator::temp(), initial_capacity) @inline; } fn void GrowableBitSet.free(&self) diff --git a/lib/std/collections/hashmap.c3 b/lib/std/collections/hashmap.c3 index 36588b796..26971aa5d 100644 --- a/lib/std/collections/hashmap.c3 +++ b/lib/std/collections/hashmap.c3 @@ -24,7 +24,7 @@ struct HashMap (Printable) @require !self.allocator "Map was already initialized" @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" *> -fn HashMap* HashMap.new_init(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = null) +fn HashMap* HashMap.new_init(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = null) @deprecated("Use init(mem)") { return self.init(allocator ?: allocator::heap(), capacity, load_factor); } @@ -52,7 +52,18 @@ fn HashMap* HashMap.init(&self, Allocator allocator, uint capacity = DEFAULT_INI @require !self.allocator "Map was already initialized" @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" *> -fn HashMap* HashMap.temp_init(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR) +fn HashMap* HashMap.temp_init(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR) @deprecated("Use tinit()") +{ + return self.init(allocator::temp(), capacity, load_factor) @inline; +} + +<* + @require capacity > 0 "The capacity must be 1 or higher" + @require load_factor > 0.0 "The load factor must be higher than 0" + @require !self.allocator "Map was already initialized" + @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" +*> +fn HashMap* HashMap.tinit(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR) { return self.init(allocator::temp(), capacity, load_factor) @inline; } @@ -65,9 +76,9 @@ fn HashMap* HashMap.temp_init(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, f @require !self.allocator "Map was already initialized" @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" *> -macro HashMap* HashMap.new_init_with_key_values(&self, ..., uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) +macro HashMap* HashMap.new_init_with_key_values(&self, ..., uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) @deprecated("Use init_with_key_values(mem)") { - self.new_init(capacity, load_factor, allocator); + self.init(capacity, load_factor, allocator); $for (var $i = 0; $i < $vacount; $i += 2) self.set($vaarg[$i], $vaarg[$i+1]); $endfor @@ -84,10 +95,10 @@ macro HashMap* HashMap.new_init_with_key_values(&self, ..., uint capacity = DEFA @require !self.allocator "Map was already initialized" @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" *> -fn HashMap* HashMap.new_init_from_keys_and_values(&self, Key[] keys, Value[] values, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) +fn HashMap* HashMap.new_init_from_keys_and_values(&self, Key[] keys, Value[] values, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) @deprecated("Use init_from_keys_and_values(mem)") { assert(keys.len == values.len); - self.new_init(capacity, load_factor, allocator); + self.init(allocator, capacity, load_factor); for (usz i = 0; i < keys.len; i++) { self.set(keys[i], values[i]); @@ -102,9 +113,25 @@ fn HashMap* HashMap.new_init_from_keys_and_values(&self, Key[] keys, Value[] val @require !self.allocator "Map was already initialized" @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" *> -macro HashMap* HashMap.temp_init_with_key_values(&self, ..., uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR) +macro HashMap* HashMap.temp_init_with_key_values(&self, ..., uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR) @deprecated("Use tinit_with_key_values") { - self.temp_init(capacity, load_factor); + self.tinit(capacity, load_factor); + $for (var $i = 0; $i < $vacount; $i += 2) + self.set($vaarg[$i], $vaarg[$i+1]); + $endfor + return self; +} + +<* + @require $vacount % 2 == 0 "There must be an even number of arguments provided for keys and values" + @require capacity > 0 "The capacity must be 1 or higher" + @require load_factor > 0.0 "The load factor must be higher than 0" + @require !self.allocator "Map was already initialized" + @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" +*> +macro HashMap* HashMap.tinit_with_key_values(&self, ..., uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR) +{ + self.tinit(capacity, load_factor); $for (var $i = 0; $i < $vacount; $i += 2) self.set($vaarg[$i], $vaarg[$i+1]); $endfor @@ -121,10 +148,31 @@ macro HashMap* HashMap.temp_init_with_key_values(&self, ..., uint capacity = DEF @require !self.allocator "Map was already initialized" @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" *> -fn HashMap* HashMap.temp_init_from_keys_and_values(&self, Key[] keys, Value[] values, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) +fn HashMap* HashMap.temp_init_from_keys_and_values(&self, Key[] keys, Value[] values, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) @deprecated("Use tinit_from_keys_and_values") { assert(keys.len == values.len); - self.temp_init(capacity, load_factor); + self.tinit(capacity, load_factor); + for (usz i = 0; i < keys.len; i++) + { + self.set(keys[i], values[i]); + } + return self; +} + +<* + @param [in] keys "The keys for the HashMap entries" + @param [in] values "The values for the HashMap entries" + @param [&inout] allocator "The allocator to use" + @require keys.len == values.len "Both keys and values arrays must be the same length" + @require capacity > 0 "The capacity must be 1 or higher" + @require load_factor > 0.0 "The load factor must be higher than 0" + @require !self.allocator "Map was already initialized" + @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" +*> +fn HashMap* HashMap.tinit_from_keys_and_values(&self, Key[] keys, Value[] values, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) +{ + assert(keys.len == values.len); + self.tinit(capacity, load_factor); for (usz i = 0; i < keys.len; i++) { self.set(keys[i], values[i]); @@ -146,18 +194,18 @@ fn bool HashMap.is_initialized(&map) <* @param [&in] other_map "The map to copy from." *> -fn HashMap* HashMap.new_init_from_map(&self, HashMap* other_map) +fn HashMap* HashMap.new_init_from_map(&self, HashMap* other_map) @deprecated("Use init_from_map(mem, map)") { - return self.init_from_map(other_map, allocator::heap()) @inline; + return self.init_from_map(allocator::heap(), other_map) @inline; } <* @param [&inout] allocator "The allocator to use" @param [&in] other_map "The map to copy from." *> -fn HashMap* HashMap.init_from_map(&self, HashMap* other_map, Allocator allocator) +fn HashMap* HashMap.init_from_map(&self, Allocator allocator, HashMap* other_map) { - self.new_init(other_map.table.len, other_map.load_factor, allocator); + self.init(allocator, other_map.table.len, other_map.load_factor); self.put_all_for_create(other_map); return self; } @@ -165,9 +213,17 @@ fn HashMap* HashMap.init_from_map(&self, HashMap* other_map, Allocator allocator <* @param [&in] other_map "The map to copy from." *> -fn HashMap* HashMap.temp_init_from_map(&map, HashMap* other_map) +fn HashMap* HashMap.temp_init_from_map(&map, HashMap* other_map) @deprecated("Use tinit_from_map") { - return map.init_from_map(other_map, allocator::temp()) @inline; + return map.init_from_map(allocator::temp(), other_map) @inline; +} + +<* + @param [&in] other_map "The map to copy from." +*> +fn HashMap* HashMap.tinit_from_map(&map, HashMap* other_map) +{ + return map.init_from_map(allocator::temp(), other_map) @inline; } fn bool HashMap.is_empty(&map) @inline @@ -240,7 +296,7 @@ fn bool HashMap.set(&map, Key key, Value value) @operator([]=) // If the map isn't initialized, use the defaults to initialize it. if (!map.allocator) { - map.new_init(); + map.init(allocator::heap()); } uint hash = rehash(key.hash()); uint index = index_for(hash, map.table.len); diff --git a/lib/std/collections/linkedlist.c3 b/lib/std/collections/linkedlist.c3 index 192111e02..3f50a949d 100644 --- a/lib/std/collections/linkedlist.c3 +++ b/lib/std/collections/linkedlist.c3 @@ -33,13 +33,18 @@ fn LinkedList* LinkedList.init(&self, Allocator allocator) <* @return "the initialized list" *> -fn LinkedList* LinkedList.new_init(&self) +fn LinkedList* LinkedList.new_init(&self) @deprecated("Use init(mem)") { return self.init(allocator::heap()) @inline; } -fn LinkedList* LinkedList.temp_init(&self) +fn LinkedList* LinkedList.temp_init(&self) @deprecated("Use tinit()") +{ + return self.init(allocator::temp()) @inline; +} + +fn LinkedList* LinkedList.tinit(&self) { return self.init(allocator::temp()) @inline; } diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index 8f6a45e00..010344bd7 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -37,7 +37,7 @@ fn List* List.init(&self, Allocator allocator, usz initial_capacity = 16) @param initial_capacity "The initial capacity to reserve" @param [&inout] allocator "The allocator to use, defaults to the heap allocator" *> -fn List* List.new_init(&self, usz initial_capacity = 16, Allocator allocator = allocator::heap()) +fn List* List.new_init(&self, usz initial_capacity = 16, Allocator allocator = allocator::heap()) @deprecated("Use init(mem)") { self.allocator = allocator; self.size = 0; @@ -52,7 +52,17 @@ fn List* List.new_init(&self, usz initial_capacity = 16, Allocator allocator = a @param initial_capacity "The initial capacity to reserve" *> -fn List* List.temp_init(&self, usz initial_capacity = 16) +fn List* List.temp_init(&self, usz initial_capacity = 16) @deprecated("Use tinit()") +{ + return self.init(allocator::temp(), initial_capacity) @inline; +} + +<* + Initialize the list using the temp allocator. + + @param initial_capacity "The initial capacity to reserve" +*> +fn List* List.tinit(&self, usz initial_capacity = 16) { return self.init(allocator::temp(), initial_capacity) @inline; } @@ -63,9 +73,20 @@ fn List* List.temp_init(&self, usz initial_capacity = 16) @param [in] values `The values to initialize the list with.` @require self.size == 0 "The List must be empty" *> -fn List* List.new_init_with_array(&self, Type[] values, Allocator allocator = allocator::heap()) +fn List* List.new_init_with_array(&self, Type[] values, Allocator allocator = allocator::heap()) @deprecated("Use init_with_array(mem)") { - self.new_init(values.len, allocator) @inline; + return self.init_with_array(allocator, values); +} + +<* + Initialize a new list with an array. + + @param [in] values `The values to initialize the list with.` + @require self.size == 0 "The List must be empty" +*> +fn List* List.init_with_array(&self, Allocator allocator, Type[] values) +{ + self.init(allocator, values.len) @inline; self.add_array(values) @inline; return self; } @@ -76,9 +97,22 @@ fn List* List.new_init_with_array(&self, Type[] values, Allocator allocator = al @param [in] values `The values to initialize the list with.` @require self.size == 0 "The List must be empty" *> -fn List* List.temp_init_with_array(&self, Type[] values) +fn List* List.temp_init_with_array(&self, Type[] values) @deprecated("Use tinit_with_array()") { - self.temp_init(values.len) @inline; + self.tinit(values.len) @inline; + self.add_array(values) @inline; + return self; +} + +<* + Initialize a temporary list with an array. + + @param [in] values `The values to initialize the list with.` + @require self.size == 0 "The List must be empty" +*> +fn List* List.tinit_with_array(&self, Type[] values) +{ + self.tinit(values.len) @inline; self.add_array(values) @inline; return self; } diff --git a/lib/std/collections/map.c3 b/lib/std/collections/map.c3 index bb5c1077c..0e4e999ff 100644 --- a/lib/std/collections/map.c3 +++ b/lib/std/collections/map.c3 @@ -26,7 +26,7 @@ struct MapImpl @require load_factor > 0.0 "The load factor must be higher than 0" @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum" *> -fn Map new(uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) +fn Map new(uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator allocator = allocator::heap()) @deprecated("Map is deprecated") { MapImpl* map = allocator::alloc(allocator, MapImpl); _init(map, capacity, load_factor, allocator); diff --git a/lib/std/collections/object.c3 b/lib/std/collections/object.c3 index f14dc87d0..34c9ae446 100644 --- a/lib/std/collections/object.c3 +++ b/lib/std/collections/object.c3 @@ -156,7 +156,7 @@ fn void Object.init_map_if_needed(&self) @private if (self.is_empty()) { self.type = ObjectInternalMap.typeid; - self.map.new_init(allocator: self.allocator); + self.map.init(self.allocator); } } @@ -168,7 +168,7 @@ fn void Object.init_array_if_needed(&self) @private if (self.is_empty()) { self.type = ObjectInternalList.typeid; - self.array.new_init(allocator: self.allocator); + self.array.init(self.allocator); } } diff --git a/lib/std/core/allocators/tracking_allocator.c3 b/lib/std/core/allocators/tracking_allocator.c3 index b2d5de3bd..84cffa334 100644 --- a/lib/std/core/allocators/tracking_allocator.c3 +++ b/lib/std/core/allocators/tracking_allocator.c3 @@ -34,7 +34,7 @@ struct TrackingAllocator (Allocator) fn void TrackingAllocator.init(&self, Allocator allocator) { *self = { .inner_allocator = allocator }; - self.map.new_init(allocator: allocator); + self.map.init(allocator); } <* diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index c99121688..e0e39e80d 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -146,7 +146,7 @@ fn void panicf(String fmt, String file, String function, uint line, args...) @stack_mem(512; Allocator allocator) { DString s; - s.new_init(allocator: allocator); + s.init(allocator); s.appendf(fmt, ...args); in_panic = false; panic(s.str_view(), file, function, line); diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index a9b584c07..74d456370 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -9,7 +9,7 @@ const usz MIN_CAPACITY @private = 16; <* @require !self.data() "String already initialized" *> -fn DString DString.new_init(&self, usz capacity = MIN_CAPACITY, Allocator allocator = allocator::heap()) +fn DString DString.new_init(&self, usz capacity = MIN_CAPACITY, Allocator allocator = allocator::heap()) @deprecated("Use init(mem)") { if (capacity < MIN_CAPACITY) capacity = MIN_CAPACITY; StringData* data = allocator::alloc_with_padding(allocator, StringData, capacity)!!; @@ -22,15 +22,37 @@ fn DString DString.new_init(&self, usz capacity = MIN_CAPACITY, Allocator alloca <* @require !self.data() "String already initialized" *> -fn DString DString.temp_init(&self, usz capacity = MIN_CAPACITY) +fn DString DString.init(&self, Allocator allocator, usz capacity = MIN_CAPACITY) { - self.new_init(capacity, allocator::temp()) @inline; + if (capacity < MIN_CAPACITY) capacity = MIN_CAPACITY; + StringData* data = allocator::alloc_with_padding(allocator, StringData, capacity)!!; + data.allocator = allocator; + data.len = 0; + data.capacity = capacity; + return *self = (DString)data; +} + +<* + @require !self.data() "String already initialized" +*> +fn DString DString.temp_init(&self, usz capacity = MIN_CAPACITY) @deprecated("Use tinit()") +{ + self.init(allocator::temp(), capacity) @inline; + return *self; +} + +<* + @require !self.data() "String already initialized" +*> +fn DString DString.tinit(&self, usz capacity = MIN_CAPACITY) +{ + self.init(allocator::temp(), capacity) @inline; return *self; } fn DString new_with_capacity(usz capacity, Allocator allocator = allocator::heap()) { - return (DString){}.new_init(capacity, allocator); + return (DString){}.init(allocator, capacity); } fn DString temp_with_capacity(usz capacity) => new_with_capacity(capacity, allocator::temp()) @inline; @@ -99,16 +121,25 @@ fn void DString.replace(&self, String needle, String replacement) }; } -fn DString DString.new_concat(self, DString b, Allocator allocator = allocator::heap()) +fn DString DString.new_concat(self, DString b, Allocator allocator = allocator::heap()) @deprecated("Use concat(mem)") { DString string; - string.new_init(self.len() + b.len(), allocator); + string.init(allocator, self.len() + b.len()); string.append(self); string.append(b); return string; } -fn DString DString.temp_concat(self, DString b) => self.new_concat(b, allocator::temp()); +fn DString DString.concat(self, Allocator allocator, DString b) +{ + DString string; + string.init(allocator, self.len() + b.len()); + string.append(self); + string.append(b); + return string; +} + +fn DString DString.temp_concat(self, DString b) => self.concat(allocator::temp(), b); fn ZString DString.zstr_view(&self) { @@ -543,7 +574,7 @@ macro void DString.insert_at(&self, usz index, value) fn usz! DString.appendf(&self, String format, args...) @maydiscard { - if (!self.data()) self.new_init(format.len + 20); + if (!self.data()) self.init(mem, format.len + 20); @pool(self.data().allocator) { Formatter formatter; @@ -554,7 +585,7 @@ fn usz! DString.appendf(&self, String format, args...) @maydiscard fn usz! DString.appendfn(&self, String format, args...) @maydiscard { - if (!self.data()) self.new_init(format.len + 20); + if (!self.data()) self.init(mem, format.len + 20); @pool(self.data().allocator) { Formatter formatter; diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 3bccacec6..0a849ecc9 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -870,7 +870,7 @@ macro String new_struct_to_str(x, Allocator allocator = allocator::heap()) DString s; @stack_mem(512; Allocator mem) { - s.new_init(allocator: mem); + s.init(mem); io::fprint(&s, x)!!; return s.copy_str(allocator); }; diff --git a/lib/std/core/test.c3 b/lib/std/core/test.c3 index 0383e374a..0f183fa24 100644 --- a/lib/std/core/test.c3 +++ b/lib/std/core/test.c3 @@ -72,7 +72,7 @@ macro @check(#condition, String format = "", args...) @stack_mem(512; Allocator allocator) { DString s; - s.new_init(allocator: allocator); + s.init(allocator); s.appendf("check `%s` failed. ", $stringify(#condition)); s.appendf(format, ...args); print_panicf(s.str_view()); diff --git a/lib/std/io/os/ls.c3 b/lib/std/io/os/ls.c3 index 3dcef7089..7a51865e8 100644 --- a/lib/std/io/os/ls.c3 +++ b/lib/std/io/os/ls.c3 @@ -4,7 +4,7 @@ import std::io, std::os; fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Allocator allocator) { PathList list; - list.new_init(allocator: allocator); + list.init(allocator); DIRPtr directory = posix::opendir(dir.str_view() ? dir.as_zstr() : (ZString)"."); defer if (directory) posix::closedir(directory); if (!directory) return (path::is_dir(dir) ? IoError.CANNOT_READ_DIR : IoError.FILE_NOT_DIR)?; @@ -27,7 +27,7 @@ import std::time, std::os, std::io; fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Allocator allocator) { PathList list; - list.new_init(allocator: allocator); + list.init(allocator); @pool(allocator) { diff --git a/lib/std/io/stream.c3 b/lib/std/io/stream.c3 index a545bf084..19da0a2e4 100644 --- a/lib/std/io/stream.c3 +++ b/lib/std/io/stream.c3 @@ -80,7 +80,23 @@ macro usz! read_all(stream, char[] buffer) <* @require @is_instream(stream) *> -macro char[]! read_new_fully(stream, Allocator allocator = allocator::heap()) +macro char[]! read_new_fully(stream, Allocator allocator = allocator::heap()) @deprecated("Use read_fully(mem)") +{ + usz len = available(stream)!; + char* data = allocator::malloc_try(allocator, len)!; + defer catch allocator::free(allocator, data); + usz read = 0; + while (read < len) + { + read += stream.read(data[read:len - read])!; + } + return data[:len]; +} + +<* + @require @is_instream(stream) +*> +macro char[]! read_fully(Allocator allocator, stream) { usz len = available(stream)!; char* data = allocator::malloc_try(allocator, len)!; diff --git a/lib/std/io/stream/bytebuffer.c3 b/lib/std/io/stream/bytebuffer.c3 index 46e1512e2..919184f8d 100644 --- a/lib/std/io/stream/bytebuffer.c3 +++ b/lib/std/io/stream/bytebuffer.c3 @@ -16,7 +16,7 @@ struct ByteBuffer (InStream, OutStream) max_read defines how many bytes might be kept before its internal buffer is shrinked. @require self.bytes.len == 0 "Buffer already initialized." *> -fn ByteBuffer* ByteBuffer.new_init(&self, usz max_read, usz initial_capacity = 16, Allocator allocator = allocator::heap()) +fn ByteBuffer* ByteBuffer.init(&self, Allocator allocator, usz max_read, usz initial_capacity = 16) { *self = { .allocator = allocator, .max_read = max_read }; initial_capacity = max(initial_capacity, 16); @@ -24,9 +24,27 @@ fn ByteBuffer* ByteBuffer.new_init(&self, usz max_read, usz initial_capacity = 1 return self; } -fn ByteBuffer* ByteBuffer.temp_init(&self, usz max_read, usz initial_capacity = 16) +<* + ByteBuffer provides a streamable read/write buffer. + max_read defines how many bytes might be kept before its internal buffer is shrinked. + @require self.bytes.len == 0 "Buffer already initialized." +*> +fn ByteBuffer* ByteBuffer.new_init(&self, usz max_read, usz initial_capacity = 16, Allocator allocator = allocator::heap()) @deprecated("Use init(mem)") { - return self.new_init(max_read, initial_capacity, allocator::temp()); + *self = { .allocator = allocator, .max_read = max_read }; + initial_capacity = max(initial_capacity, 16); + self.grow(initial_capacity); + return self; +} + +fn ByteBuffer* ByteBuffer.tinit(&self, usz max_read, usz initial_capacity = 16) +{ + return self.init(allocator::temp(), max_read, initial_capacity); +} + +fn ByteBuffer* ByteBuffer.temp_init(&self, usz max_read, usz initial_capacity = 16) @deprecated("Use tinit()") +{ + return self.init(allocator::temp(), max_read, initial_capacity); } <* diff --git a/lib/std/io/stream/bytewriter.c3 b/lib/std/io/stream/bytewriter.c3 index 538b491a0..c5386a3e1 100644 --- a/lib/std/io/stream/bytewriter.c3 +++ b/lib/std/io/stream/bytewriter.c3 @@ -14,7 +14,19 @@ struct ByteWriter (OutStream) @require self.bytes.len == 0 "Init may not run on already initialized data" @ensure (bool)allocator, self.index == 0 *> -fn ByteWriter* ByteWriter.new_init(&self, Allocator allocator = allocator::heap()) +fn ByteWriter* ByteWriter.new_init(&self, Allocator allocator = allocator::heap()) @deprecated("Use init(mem)") +{ + *self = { .bytes = {}, .allocator = allocator }; + return self; +} + +<* + @param [&inout] self + @param [&inout] allocator + @require self.bytes.len == 0 "Init may not run on already initialized data" + @ensure (bool)allocator, self.index == 0 +*> +fn ByteWriter* ByteWriter.init(&self, Allocator allocator) { *self = { .bytes = {}, .allocator = allocator }; return self; @@ -25,9 +37,19 @@ fn ByteWriter* ByteWriter.new_init(&self, Allocator allocator = allocator::heap( @require self.bytes.len == 0 "Init may not run on already initialized data" @ensure self.index == 0 *> -fn ByteWriter* ByteWriter.temp_init(&self) +fn ByteWriter* ByteWriter.tinit(&self) { - return self.new_init(allocator::temp()) @inline; + return self.init(allocator::temp()) @inline; +} + +<* + @param [&inout] self + @require self.bytes.len == 0 "Init may not run on already initialized data" + @ensure self.index == 0 +*> +fn ByteWriter* ByteWriter.temp_init(&self) @deprecated("Use tinit") +{ + return self.init(allocator::temp()) @inline; } fn ByteWriter* ByteWriter.init_with_buffer(&self, char[] data) diff --git a/lib/std/io/stream/multireader.c3 b/lib/std/io/stream/multireader.c3 index 065940b4a..f26813a54 100644 --- a/lib/std/io/stream/multireader.c3 +++ b/lib/std/io/stream/multireader.c3 @@ -18,7 +18,21 @@ struct MultiReader (InStream) @require self.readers.len == 0 "Init may not run on already initialized data" @ensure self.index == 0 *> -fn MultiReader* MultiReader.new_init(&self, InStream... readers, Allocator allocator = allocator::heap()) +fn MultiReader* MultiReader.new_init(&self, InStream... readers, Allocator allocator = allocator::heap()) @deprecated("Use init(mem)") +{ + InStream []copy = allocator::new_array(allocator, InStream, readers.len); + copy[..] = readers[..]; + *self = { .readers = copy, .allocator = allocator }; + return self; +} + +<* + @param [&inout] self + @param [&inout] allocator + @require self.readers.len == 0 "Init may not run on already initialized data" + @ensure self.index == 0 +*> +fn MultiReader* MultiReader.init(&self, Allocator allocator, InStream... readers) { InStream []copy = allocator::new_array(allocator, InStream, readers.len); copy[..] = readers[..]; @@ -31,9 +45,19 @@ fn MultiReader* MultiReader.new_init(&self, InStream... readers, Allocator alloc @require self.readers.len == 0 "Init may not run on already initialized data" @ensure self.index == 0 *> -fn MultiReader* MultiReader.temp_init(&self, InStream... readers) +fn MultiReader* MultiReader.temp_init(&self, InStream... readers) @deprecated("Use tinit()") { - return self.new_init(...readers, allocator: allocator::temp()); + return self.init(allocator::temp(), ...readers); +} + +<* + @param [&inout] self + @require self.readers.len == 0 "Init may not run on already initialized data" + @ensure self.index == 0 +*> +fn MultiReader* MultiReader.tinit(&self, InStream... readers) +{ + return self.init(allocator::temp(), ...readers); } fn void MultiReader.free(&self) diff --git a/lib/std/io/stream/multiwriter.c3 b/lib/std/io/stream/multiwriter.c3 index 787d5c762..5536bee08 100644 --- a/lib/std/io/stream/multiwriter.c3 +++ b/lib/std/io/stream/multiwriter.c3 @@ -15,7 +15,21 @@ struct MultiWriter (OutStream) @require writers.len > 0 @require self.writers.len == 0 "Init may not run on already initialized data" *> -fn MultiWriter* MultiWriter.new_init(&self, OutStream... writers, Allocator allocator = allocator::heap()) +fn MultiWriter* MultiWriter.init(&self, Allocator allocator, OutStream... writers) +{ + OutStream[] copy = allocator::new_array(allocator, OutStream, writers.len); + copy[..] = writers[..]; + *self = { .writers = copy, .allocator = allocator }; + return self; +} + +<* + @param [&inout] self + @param [&inout] allocator + @require writers.len > 0 + @require self.writers.len == 0 "Init may not run on already initialized data" +*> +fn MultiWriter* MultiWriter.new_init(&self, OutStream... writers, Allocator allocator = allocator::heap()) @deprecated("Use init(mem)") { OutStream[] copy = allocator::new_array(allocator, OutStream, writers.len); copy[..] = writers[..]; @@ -28,9 +42,19 @@ fn MultiWriter* MultiWriter.new_init(&self, OutStream... writers, Allocator allo @require writers.len > 0 @require self.writers.len == 0 "Init may not run on already initialized data" *> -fn MultiWriter* MultiWriter.temp_init(&self, OutStream... writers) +fn MultiWriter* MultiWriter.temp_init(&self, OutStream... writers) @deprecated("Use tinit") { - return self.new_init(...writers, allocator: allocator::temp()); + return self.init(allocator::temp(), ...writers); +} + +<* + @param [&inout] self + @require writers.len > 0 + @require self.writers.len == 0 "Init may not run on already initialized data" +*> +fn MultiWriter* MultiWriter.tinit(&self, OutStream... writers) +{ + return self.init(allocator::temp(), ...writers); } fn void MultiWriter.free(&self) diff --git a/lib/std/math/bigint.c3 b/lib/std/math/bigint.c3 index 36568c286..ba3267a86 100644 --- a/lib/std/math/bigint.c3 +++ b/lib/std/math/bigint.c3 @@ -531,7 +531,7 @@ fn String BigInt.to_string_with_radix(&self, int radix, Allocator allocator) { BigInt a = *self; DString str; - str.new_init(4096, allocator: mem); + str.init(mem, 4096); bool negative = self.is_negative(); if (negative) { diff --git a/lib/std/math/random/math.seeder.c3 b/lib/std/math/random/math.seeder.c3 index 3c4449ddb..84de920bf 100644 --- a/lib/std/math/random/math.seeder.c3 +++ b/lib/std/math/random/math.seeder.c3 @@ -86,7 +86,7 @@ fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC) hash(&entropy), random_int, hash(clock::now()), - hash(&DString.new_init), + hash(&DString.init), hash(allocator::heap()) }; return bitcast(entropy_data, char[8 * 4]); diff --git a/lib/std/net/url.c3 b/lib/std/net/url.c3 index 27ede360b..b41f1ab87 100644 --- a/lib/std/net/url.c3 +++ b/lib/std/net/url.c3 @@ -275,7 +275,7 @@ fn UrlQueryValues parse_query(String query, Allocator allocator) { UrlQueryValues vals; vals.map.init(allocator); - vals.key_order.new_init(allocator: allocator); + vals.key_order.init(allocator); Splitter raw_vals = query.tokenize("&"); while (try String rv = raw_vals.next()) @@ -309,7 +309,7 @@ fn UrlQueryValues* UrlQueryValues.add(&self, String key, String value) else { UrlQueryValueList new_list; - new_list.new_init_with_array({ value_copy }, self.allocator); + new_list.init_with_array(self.allocator, { value_copy }); (*self)[key] = new_list; self.key_order.push(key.copy(self.allocator)); } diff --git a/lib/std/os/linux/linux.c3 b/lib/std/os/linux/linux.c3 index 305db433e..83fd1a81b 100644 --- a/lib/std/os/linux/linux.c3 +++ b/lib/std/os/linux/linux.c3 @@ -218,7 +218,7 @@ fn void! backtrace_add_element(BacktraceList *list, void* addr, Allocator alloca fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator allocator) { BacktraceList list; - list.new_init(backtrace.len, allocator); + list.init(allocator, backtrace.len); defer catch { foreach (trace : list) diff --git a/lib/std/os/macos/darwin.c3 b/lib/std/os/macos/darwin.c3 index 6c8fe9203..8d5cc3716 100644 --- a/lib/std/os/macos/darwin.c3 +++ b/lib/std/os/macos/darwin.c3 @@ -136,7 +136,7 @@ fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator allocator) { void *load_addr = (void *)load_address()!; BacktraceList list; - list.new_init(backtrace.len, allocator); + list.init(allocator, backtrace.len); defer catch { foreach (trace : list) diff --git a/lib/std/os/win32/process.c3 b/lib/std/os/win32/process.c3 index 7986388b2..39606e2f3 100644 --- a/lib/std/os/win32/process.c3 +++ b/lib/std/os/win32/process.c3 @@ -157,7 +157,7 @@ Win32_DWORD64 displacement; fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator allocator) { BacktraceList list; - list.new_init(backtrace.len, allocator); + list.init(allocator, backtrace.len); Win32_HANDLE process = getCurrentProcess(); symInitialize(process, null, 1); defer symCleanup(process); diff --git a/lib/std/threads/buffered_channel.c3 b/lib/std/threads/buffered_channel.c3 index b9b23c9f5..97407b16e 100644 --- a/lib/std/threads/buffered_channel.c3 +++ b/lib/std/threads/buffered_channel.c3 @@ -21,12 +21,12 @@ struct BufferedChannelImpl @private Type[?] buf; } -fn void! BufferedChannel.new_init(&self, usz size = 1) +fn void! BufferedChannel.new_init(&self, usz size = 1) @deprecated("Use init(mem)") { - return self.init(size, allocator::heap()); + return self.init(mem, size); } -fn void! BufferedChannel.init(&self, usz size = 1, Allocator allocator) +fn void! BufferedChannel.init(&self, Allocator allocator, usz size = 1) { BufferedChannelImpl* channel = allocator::new_with_padding(allocator, BufferedChannelImpl, Type.sizeof * size)!; defer catch allocator::free(allocator, channel); diff --git a/lib/std/threads/unbuffered_channel.c3 b/lib/std/threads/unbuffered_channel.c3 index c27321a2b..c2fd0674e 100644 --- a/lib/std/threads/unbuffered_channel.c3 +++ b/lib/std/threads/unbuffered_channel.c3 @@ -18,7 +18,7 @@ struct UnbufferedChannelImpl @private ConditionVariable read_cond; } -fn void! UnbufferedChannel.new_init(&self) => self.init(allocator::heap()); +fn void! UnbufferedChannel.new_init(&self) @deprecated("Use init") => self.init(allocator::heap()); fn void! UnbufferedChannel.init(&self, Allocator allocator) { diff --git a/lib7/std/collections/anylist.c3 b/lib7/std/collections/anylist.c3 index 6f2b1c8fc..fc369ce81 100644 --- a/lib7/std/collections/anylist.c3 +++ b/lib7/std/collections/anylist.c3 @@ -107,29 +107,13 @@ macro AnyList.pop(&self, $Type) Pop the last value and allocate the copy using the given allocator. @return! IteratorResult.NO_MORE_ELEMENT *> -fn any! AnyList.copy_pop(&self, Allocator allocator = allocator::heap()) +fn any! AnyList.copy_pop(&self, Allocator allocator) { if (!self.size) return IteratorResult.NO_MORE_ELEMENT?; defer self.free_element(self.entries[self.size]); return allocator::clone_any(allocator, self.entries[--self.size]); } -<* - Pop the last value and allocate the copy using the given allocator. - @return! IteratorResult.NO_MORE_ELEMENT - @deprecated `use copy_pop` -*> -fn any! AnyList.new_pop(&self, Allocator allocator = allocator::heap()) -{ - return self.copy_pop(allocator); -} - -<* - Pop the last value and allocate the copy using the temp allocator - @return! IteratorResult.NO_MORE_ELEMENT - @deprecated `use tcopy_pop` -*> -fn any! AnyList.temp_pop(&self) => self.copy_pop(tmem()); <* Pop the last value and allocate the copy using the temp allocator @@ -176,17 +160,9 @@ fn any! AnyList.pop_first_retained(&self) return self.entries[0]; } -<* - Same as new_pop() but pops the first value instead. - @deprecated `use copy_pop_first` -*> -fn any! AnyList.new_pop_first(&self, Allocator allocator = allocator::heap()) -{ - return self.copy_pop_first(allocator) @inline; -} <* - Same as new_pop() but pops the first value instead. + Same as copy_pop() but pops the first value instead. *> fn any! AnyList.copy_pop_first(&self, Allocator allocator = allocator::heap()) { @@ -201,12 +177,6 @@ fn any! AnyList.copy_pop_first(&self, Allocator allocator = allocator::heap()) *> fn any! AnyList.tcopy_pop_first(&self) => self.copy_pop_first(tmem()); -<* - Same as temp_pop() but pops the first value instead. - @deprecated `use tcopy_pop_first` -*> -fn any! AnyList.temp_pop_first(&self) => self.new_pop_first(tmem()); - <* @require index < self.size *> diff --git a/lib7/std/core/dstring.c3 b/lib7/std/core/dstring.c3 index bf4d57cf0..0bb453343 100644 --- a/lib7/std/core/dstring.c3 +++ b/lib7/std/core/dstring.c3 @@ -32,7 +32,7 @@ fn DString new_with_capacity(Allocator allocator, usz capacity) return (DString){}.init(allocator, capacity); } -fn DString tnew_with_capacity(usz capacity) => new_with_capacity(tmem(), capacity) @inline; +fn DString temp_with_capacity(usz capacity) => new_with_capacity(tmem(), capacity) @inline; fn DString new(Allocator allocator, String c = "") { @@ -46,7 +46,7 @@ fn DString new(Allocator allocator, String c = "") return (DString)data; } -fn DString tnew(String s = "") => new(tmem(), s) @inline; +fn DString temp(String s = "") => new(tmem(), s) @inline; fn void DString.replace_char(self, char ch, char replacement) @@ -297,7 +297,7 @@ fn void DString.append_chars(&self, String str) if (!other_len) return; if (!*self) { - *self = tnew(str); + *self = temp(str); return; } self.reserve(other_len); @@ -339,7 +339,7 @@ fn void DString.append_char(&self, char c) { if (!*self) { - *self = tnew_with_capacity(MIN_CAPACITY); + *self = temp_with_capacity(MIN_CAPACITY); } self.reserve(1); StringData* data = self.data(); @@ -607,7 +607,7 @@ fn void DString.reserve(&self, usz addition) StringData* data = self.data(); if (!data) { - *self = dstring::tnew_with_capacity(addition); + *self = dstring::temp_with_capacity(addition); return; } usz len = data.len + addition; diff --git a/lib7/std/core/runtime_benchmark.c3 b/lib7/std/core/runtime_benchmark.c3 index f07256773..f60a25b7b 100644 --- a/lib7/std/core/runtime_benchmark.c3 +++ b/lib7/std/core/runtime_benchmark.c3 @@ -123,7 +123,7 @@ fn bool run_benchmarks(BenchmarkUnit[] benchmarks) @if(!$$OLD_TEST) usz len = max_name + 9; - DString name = dstring::tnew_with_capacity(64); + DString name = dstring::temp_with_capacity(64); name.append_repeat('-', len / 2); name.append(" BENCHMARKS "); name.append_repeat('-', len - len / 2); diff --git a/lib7/std/core/runtime_test.c3 b/lib7/std/core/runtime_test.c3 index 00d275e8f..77bff489a 100644 --- a/lib7/std/core/runtime_test.c3 +++ b/lib7/std/core/runtime_test.c3 @@ -238,7 +238,7 @@ fn bool run_tests(String[] args, TestUnit[] tests) @private int tests_passed = 0; int tests_skipped = 0; int test_count = tests.len; - DString name = dstring::tnew_with_capacity(64); + DString name = dstring::temp_with_capacity(64); usz len = max_name + 9; name.append_repeat('-', len / 2); name.append(" TESTS "); diff --git a/lib7/std/core/string.c3 b/lib7/std/core/string.c3 index 2dccdcd9e..2980b56fc 100644 --- a/lib7/std/core/string.c3 +++ b/lib7/std/core/string.c3 @@ -41,7 +41,7 @@ fault NumberConversion *> fn ZString tformat_zstr(String fmt, args...) { - DString str = dstring::tnew_with_capacity(fmt.len + args.len * 8); + DString str = dstring::temp_with_capacity(fmt.len + args.len * 8); str.appendf(fmt, ...args); return str.zstr_view(); } @@ -54,7 +54,7 @@ fn ZString tformat_zstr(String fmt, args...) *> fn String format(Allocator allocator, String fmt, args...) => @pool(allocator) { - DString str = dstring::tnew_with_capacity(fmt.len + args.len * 8); + DString str = dstring::temp_with_capacity(fmt.len + args.len * 8); str.appendf(fmt, ...args); return str.copy_str(allocator); } @@ -66,7 +66,7 @@ fn String format(Allocator allocator, String fmt, args...) => @pool(allocator) *> fn String tformat(String fmt, args...) { - DString str = dstring::tnew_with_capacity(fmt.len + args.len * 8); + DString str = dstring::temp_with_capacity(fmt.len + args.len * 8); str.appendf(fmt, ...args); return str.str_view(); } @@ -99,7 +99,7 @@ fn String join(Allocator allocator, String[] s, String joiner) } @pool(allocator) { - DString res = dstring::tnew_with_capacity(total_size); + DString res = dstring::temp_with_capacity(total_size); res.append(s[0]); foreach (String* &str : s[1..]) { @@ -671,8 +671,8 @@ fn String! new_from_wstring(Allocator allocator, WString wstring) return new_from_utf16(allocator, utf16); } -fn String! tnew_from_wstring(WString wstring) => new_from_wstring(tmem(), wstring) @inline; -fn String! tnew_from_utf16(Char16[] utf16) => new_from_utf16(tmem(), utf16) @inline; +fn String! temp_from_wstring(WString wstring) => new_from_wstring(tmem(), wstring) @inline; +fn String! temp_from_utf16(Char16[] utf16) => new_from_utf16(tmem(), utf16) @inline; fn usz String.utf8_codepoints(s) { @@ -831,4 +831,4 @@ macro String new_from_struct(Allocator allocator, x) }; } -macro String tnew_from_struct(x) => new_from_struct(tmem(), x); +macro String temp_from_struct(x) => new_from_struct(tmem(), x); diff --git a/lib7/std/io/formatter.c3 b/lib7/std/io/formatter.c3 index c685a23c9..9ce3f29ae 100644 --- a/lib7/std/io/formatter.c3 +++ b/lib7/std/io/formatter.c3 @@ -27,8 +27,7 @@ macro bool is_struct_with_default_print($Type) { return $Type.kindof == STRUCT &&& !$defined($Type.to_format) - &&& !$defined($Type.to_new_string) - &&& !$defined($Type.to_string); + &&& !$defined($Type.to_constant_string); } <* diff --git a/lib7/std/io/io.c3 b/lib7/std/io/io.c3 index fa31ff35f..40cde0846 100644 --- a/lib7/std/io/io.c3 +++ b/lib7/std/io/io.c3 @@ -68,7 +68,7 @@ macro String! readline(Allocator allocator, stream = io::stdin()) if (val == '\n') return ""; @pool(allocator) { - DString str = dstring::tnew_with_capacity(256); + DString str = dstring::temp_with_capacity(256); if (val != '\r') str.append(val); while (1) { diff --git a/lib7/std/io/os/ls.c3 b/lib7/std/io/os/ls.c3 index a3008bd0b..4bc446801 100644 --- a/lib7/std/io/os/ls.c3 +++ b/lib7/std/io/os/ls.c3 @@ -41,7 +41,7 @@ fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Al if (no_dirs && (find_data.dwFileAttributes & win32::FILE_ATTRIBUTE_DIRECTORY)) continue; @pool(allocator) { - String filename = string::tnew_from_wstring((WString)&find_data.cFileName)!; + String filename = string::temp_from_wstring((WString)&find_data.cFileName)!; if (filename == ".." || filename == ".") continue; list.push(path::new(allocator, filename)!); }; diff --git a/lib7/std/io/os/temp_directory.c3 b/lib7/std/io/os/temp_directory.c3 index 0f53880e8..75c50449d 100644 --- a/lib7/std/io/os/temp_directory.c3 +++ b/lib7/std/io/os/temp_directory.c3 @@ -17,7 +17,7 @@ fn Path! native_temp_directory(Allocator allocator) @if(env::WIN32) => @pool(all if (!len) return IoError.GENERAL_ERROR?; Char16[] buff = mem::temp_alloc_array(Char16, len + (usz)1); if (!win32::getTempPathW(len, buff)) return IoError.GENERAL_ERROR?; - return path::new(allocator, string::tnew_from_utf16(buff[:len])); + return path::new(allocator, string::temp_from_utf16(buff[:len])); } module std::io::os @if(env::NO_LIBC); diff --git a/lib7/std/io/path.c3 b/lib7/std/io/path.c3 index 6e6547df0..2420b5161 100644 --- a/lib7/std/io/path.c3 +++ b/lib7/std/io/path.c3 @@ -52,7 +52,7 @@ macro void! chdir(path) $if @typeis(path, String): @pool() { - return os::native_chdir(tnew(path)); + return os::native_chdir(temp(path)); }; $else return os::native_chdir(path) @inline; @@ -100,7 +100,7 @@ enum MkdirPermissions macro bool! mkdir(Path path, bool recursive = false, MkdirPermissions permissions = NORMAL) { $if @typeis(path, String): - @pool() { return _mkdir(tnew(path), recursive, permissions); }; + @pool() { return _mkdir(temp(path), recursive, permissions); }; $else return _mkdir(path, recursive, permissions); $endif @@ -118,7 +118,7 @@ macro bool! mkdir(Path path, bool recursive = false, MkdirPermissions permission macro bool! rmdir(path) { $if @typeis(path, String): - @pool() { return _rmdir(tnew(path)); }; + @pool() { return _rmdir(temp(path)); }; $else return _mkdir(path); $endif @@ -152,14 +152,14 @@ fn Path! new(Allocator allocator, String path, PathEnv path_env = DEFAULT_ENV) @return! PathResult.INVALID_PATH `if the path was invalid` *> -fn Path! tnew(String path, PathEnv path_env = DEFAULT_ENV) +fn Path! temp(String path, PathEnv path_env = DEFAULT_ENV) { return new(tmem(), path, path_env); } fn Path! from_win32_wstring(Allocator allocator, WString path) => @pool(allocator) { - return path::new(allocator, string::tnew_from_wstring(path)!); + return path::new(allocator, string::temp_from_wstring(path)!); } fn Path! for_windows(Allocator allocator, String path) @@ -189,7 +189,7 @@ fn Path! Path.append(self, Allocator allocator, String filename) @pool(allocator) { - DString dstr = dstring::tnew_with_capacity(self.path_string.len + 1 + filename.len); + DString dstr = dstring::temp_with_capacity(self.path_string.len + 1 + filename.len); dstr.append(self.path_string); dstr.append(PREFERRED_SEPARATOR); dstr.append(filename); @@ -223,7 +223,7 @@ fn usz! start_of_base_name(String str, PathEnv path_env) @local fn bool! String.is_absolute_path(self) => @pool() { - return tnew(self).is_absolute(); + return temp(self).is_absolute(); } fn bool! Path.is_absolute(self) @@ -238,7 +238,7 @@ fn bool! Path.is_absolute(self) fn Path! String.to_absolute_path(self, Allocator allocator) => @pool(allocator) { - return tnew(self).absolute(allocator); + return temp(self).absolute(allocator); } <* @@ -274,7 +274,7 @@ fn Path! Path.absolute(self, Allocator allocator) fn String! String.file_basename(self, Allocator allocator) => @pool(allocator) { - return tnew(self).basename().copy(allocator); + return temp(self).basename().copy(allocator); } fn String! String.file_tbasename(self) => self.file_basename(tmem()); @@ -291,7 +291,7 @@ fn String! String.path_tdirname(self) => self.path_dirname(tmem()); fn String! String.path_dirname(self, Allocator allocator) => @pool(allocator) { - return tnew(self).dirname().copy(allocator); + return temp(self).dirname().copy(allocator); } fn String Path.dirname(self) diff --git a/lib7/std/io/stream.c3 b/lib7/std/io/stream.c3 index a545bf084..0f083229d 100644 --- a/lib7/std/io/stream.c3 +++ b/lib7/std/io/stream.c3 @@ -80,7 +80,7 @@ macro usz! read_all(stream, char[] buffer) <* @require @is_instream(stream) *> -macro char[]! read_new_fully(stream, Allocator allocator = allocator::heap()) +macro char[]! read_fully(Allocator allocator, stream) { usz len = available(stream)!; char* data = allocator::malloc_try(allocator, len)!; diff --git a/lib7/std/io/stream/bytebuffer.c3 b/lib7/std/io/stream/bytebuffer.c3 index 46e1512e2..c1964fa30 100644 --- a/lib7/std/io/stream/bytebuffer.c3 +++ b/lib7/std/io/stream/bytebuffer.c3 @@ -16,7 +16,7 @@ struct ByteBuffer (InStream, OutStream) max_read defines how many bytes might be kept before its internal buffer is shrinked. @require self.bytes.len == 0 "Buffer already initialized." *> -fn ByteBuffer* ByteBuffer.new_init(&self, usz max_read, usz initial_capacity = 16, Allocator allocator = allocator::heap()) +fn ByteBuffer* ByteBuffer.init(&self, Allocator allocator, usz max_read, usz initial_capacity = 16) { *self = { .allocator = allocator, .max_read = max_read }; initial_capacity = max(initial_capacity, 16); @@ -24,9 +24,9 @@ fn ByteBuffer* ByteBuffer.new_init(&self, usz max_read, usz initial_capacity = 1 return self; } -fn ByteBuffer* ByteBuffer.temp_init(&self, usz max_read, usz initial_capacity = 16) +fn ByteBuffer* ByteBuffer.tinit(&self, usz max_read, usz initial_capacity = 16) { - return self.new_init(max_read, initial_capacity, allocator::temp()); + return self.init(tmem(), max_read, initial_capacity); } <* diff --git a/lib7/std/io/stream/bytewriter.c3 b/lib7/std/io/stream/bytewriter.c3 index 538b491a0..377aaab7e 100644 --- a/lib7/std/io/stream/bytewriter.c3 +++ b/lib7/std/io/stream/bytewriter.c3 @@ -14,7 +14,7 @@ struct ByteWriter (OutStream) @require self.bytes.len == 0 "Init may not run on already initialized data" @ensure (bool)allocator, self.index == 0 *> -fn ByteWriter* ByteWriter.new_init(&self, Allocator allocator = allocator::heap()) +fn ByteWriter* ByteWriter.init(&self, Allocator allocator) { *self = { .bytes = {}, .allocator = allocator }; return self; @@ -25,9 +25,9 @@ fn ByteWriter* ByteWriter.new_init(&self, Allocator allocator = allocator::heap( @require self.bytes.len == 0 "Init may not run on already initialized data" @ensure self.index == 0 *> -fn ByteWriter* ByteWriter.temp_init(&self) +fn ByteWriter* ByteWriter.tinit(&self) { - return self.new_init(allocator::temp()) @inline; + return self.init(tmem()) @inline; } fn ByteWriter* ByteWriter.init_with_buffer(&self, char[] data) diff --git a/lib7/std/io/stream/multireader.c3 b/lib7/std/io/stream/multireader.c3 index 065940b4a..6cfdd1eb5 100644 --- a/lib7/std/io/stream/multireader.c3 +++ b/lib7/std/io/stream/multireader.c3 @@ -18,7 +18,7 @@ struct MultiReader (InStream) @require self.readers.len == 0 "Init may not run on already initialized data" @ensure self.index == 0 *> -fn MultiReader* MultiReader.new_init(&self, InStream... readers, Allocator allocator = allocator::heap()) +fn MultiReader* MultiReader.init(&self, Allocator allocator, InStream... readers) { InStream []copy = allocator::new_array(allocator, InStream, readers.len); copy[..] = readers[..]; @@ -31,9 +31,9 @@ fn MultiReader* MultiReader.new_init(&self, InStream... readers, Allocator alloc @require self.readers.len == 0 "Init may not run on already initialized data" @ensure self.index == 0 *> -fn MultiReader* MultiReader.temp_init(&self, InStream... readers) +fn MultiReader* MultiReader.tinit(&self, InStream... readers) { - return self.new_init(...readers, allocator: allocator::temp()); + return self.init(tmem(), ...readers); } fn void MultiReader.free(&self) diff --git a/lib7/std/io/stream/multiwriter.c3 b/lib7/std/io/stream/multiwriter.c3 index 787d5c762..ec1dbc4c1 100644 --- a/lib7/std/io/stream/multiwriter.c3 +++ b/lib7/std/io/stream/multiwriter.c3 @@ -15,7 +15,7 @@ struct MultiWriter (OutStream) @require writers.len > 0 @require self.writers.len == 0 "Init may not run on already initialized data" *> -fn MultiWriter* MultiWriter.new_init(&self, OutStream... writers, Allocator allocator = allocator::heap()) +fn MultiWriter* MultiWriter.init(&self, Allocator allocator, OutStream... writers) { OutStream[] copy = allocator::new_array(allocator, OutStream, writers.len); copy[..] = writers[..]; @@ -28,9 +28,9 @@ fn MultiWriter* MultiWriter.new_init(&self, OutStream... writers, Allocator allo @require writers.len > 0 @require self.writers.len == 0 "Init may not run on already initialized data" *> -fn MultiWriter* MultiWriter.temp_init(&self, OutStream... writers) +fn MultiWriter* MultiWriter.tinit(&self, OutStream... writers) { - return self.new_init(...writers, allocator: allocator::temp()); + return self.init(tmem(), ...writers); } fn void MultiWriter.free(&self) diff --git a/lib7/std/net/inetaddr.c3 b/lib7/std/net/inetaddr.c3 index 2ffec94b5..1f82bb2ad 100644 --- a/lib7/std/net/inetaddr.c3 +++ b/lib7/std/net/inetaddr.c3 @@ -255,7 +255,7 @@ fn bool InetAddress.is_multicast_link_local(InetAddress* addr) fn AddrInfo*! addrinfo(String host, uint port, AIFamily ai_family, AISockType ai_socktype) @if(os::SUPPORTS_INET) => @pool() { ZString zhost = host.zstr_tcopy(); - DString str = dstring::tnew_with_capacity(32); + DString str = dstring::temp_with_capacity(32); str.appendf("%d", port); AddrInfo hints = { .ai_family = ai_family, .ai_socktype = ai_socktype }; AddrInfo* ai; diff --git a/lib7/std/net/url.c3 b/lib7/std/net/url.c3 index ad500071c..e88da8e24 100644 --- a/lib7/std/net/url.c3 +++ b/lib7/std/net/url.c3 @@ -254,15 +254,7 @@ struct UrlQueryValues @param [in] query @return "a UrlQueryValues HashMap" *> -fn UrlQueryValues temp_parse_query(String query) => parse_query(query, allocator::temp()); - -<* - Parse the query parameters of the Url into a UrlQueryValues map. - - @param [in] query - @return "a UrlQueryValues HashMap" -*> -fn UrlQueryValues new_parse_query(String query) => parse_query(query, allocator::heap()); +fn UrlQueryValues parse_query_to_temp(String query) => parse_query(tmem(), query); <* Parse the query parameters of the Url into a UrlQueryValues map. @@ -271,7 +263,7 @@ fn UrlQueryValues new_parse_query(String query) => parse_query(query, allocator: @param [inout] allocator @return "a UrlQueryValues HashMap" *> -fn UrlQueryValues parse_query(String query, Allocator allocator) +fn UrlQueryValues parse_query(Allocator allocator, String query) { UrlQueryValues vals; vals.map.init(allocator); diff --git a/lib7/std/net/url_encoding.c3 b/lib7/std/net/url_encoding.c3 index e1baee050..2bef12573 100644 --- a/lib7/std/net/url_encoding.c3 +++ b/lib7/std/net/url_encoding.c3 @@ -70,7 +70,7 @@ fn usz encode_len(String s, UrlEncodingMode mode) @inline fn String encode(Allocator allocator, String s, UrlEncodingMode mode) => @pool(allocator) { usz n = encode_len(s, mode); - DString builder = dstring::tnew_with_capacity(n); + DString builder = dstring::temp_with_capacity(n); foreach(i, c: s) { @@ -137,7 +137,7 @@ fn usz! decode_len(String s, UrlEncodingMode mode) @inline fn String! decode(Allocator allocator, String s, UrlEncodingMode mode) => @pool(allocator) { usz n = decode_len(s, mode)!; - DString builder = dstring::tnew_with_capacity(n); + DString builder = dstring::temp_with_capacity(n); for (usz i = 0; i < s.len; i++) { diff --git a/lib7/std/os/env.c3 b/lib7/std/os/env.c3 index bbf62bafe..1d60b0f9a 100644 --- a/lib7/std/os/env.c3 +++ b/lib7/std/os/env.c3 @@ -77,15 +77,11 @@ fn String! get_home_dir(Allocator using = allocator::heap()) return get_var(using, home); } -fn Path! get_config_dir(Allocator allocator = allocator::heap()) @deprecated("use new_get_config_dir()") -{ - return new_get_config_dir(allocator) @inline; -} <* Returns the current user's config directory. *> -fn Path! new_get_config_dir(Allocator allocator) => @pool(allocator) +fn Path! get_config_dir(Allocator allocator) => @pool(allocator) { $if env::WIN32: return path::new(allocator, tget_var("AppData")); @@ -97,7 +93,7 @@ fn Path! new_get_config_dir(Allocator allocator) => @pool(allocator) String s = tget_var("XDG_CONFIG_HOME") ?? tget_var("HOME")!; const DIR = ".config"; $endif - return path::tnew(s).append(allocator, DIR); + return path::temp(s).append(allocator, DIR); $endif } diff --git a/lib7/std/os/subprocess.c3 b/lib7/std/os/subprocess.c3 index 719f76781..2d374970e 100644 --- a/lib7/std/os/subprocess.c3 +++ b/lib7/std/os/subprocess.c3 @@ -74,7 +74,7 @@ fn void! create_named_pipe_helper(void** rd, void **wr) @local @if(env::WIN32) fn WString convert_command_line_win32(String[] command_line) @inline @if(env::WIN32) @local { - DString str = dstring::tnew_with_capacity(512); + DString str = dstring::temp_with_capacity(512); foreach LINE: (i, s : command_line) { if (i != 0) str.append(' '); @@ -138,7 +138,7 @@ fn SubProcess! create(String[] command_line, SubProcessOptions options = {}, Str WString used_environment = null; if (!options.inherit_environment) { - DString env = dstring::tnew_with_capacity(64); + DString env = dstring::temp_with_capacity(64); if (!environment.len) { env.append("\0"); diff --git a/lib7/std/threads/event/event_thread.c3 b/lib7/std/threads/event/event_thread.c3 index 0a55165a3..b62c47093 100644 --- a/lib7/std/threads/event/event_thread.c3 +++ b/lib7/std/threads/event/event_thread.c3 @@ -173,7 +173,7 @@ fn void remove_all_pool_threads(EventThreadPool* pool) @local <* @require size > 0 "Must have at least one thread" *> -fn EventThreadPool* EventThreadPool.new_init(&self, int size, String name, Allocator allocator, void* monitor_context) +fn EventThreadPool* EventThreadPool.init(&self, int size, String name, Allocator allocator, void* monitor_context) { *self = { .is_alive = true, .name = name.copy(allocator), .monitor_context = monitor_context, .allocator = allocator }; self.pool.init(allocator); diff --git a/lib7/std/time/time.c3 b/lib7/std/time/time.c3 index 05e329990..a15218212 100644 --- a/lib7/std/time/time.c3 +++ b/lib7/std/time/time.c3 @@ -120,7 +120,7 @@ fn usz! NanoDuration.to_format(&self, Formatter* formatter) @dynamic bool neg = nd < 0; if (neg) nd = -nd; - DString str = dstring::tnew_with_capacity(64); + DString str = dstring::temp_with_capacity(64); if (nd < 1_000_000_000) { // Less than 1s: print milliseconds, microseconds and nanoseconds. diff --git a/resources/examples/binarydigits.c3 b/resources/examples/binarydigits.c3 index 914f4df80..aa1621eec 100644 --- a/resources/examples/binarydigits.c3 +++ b/resources/examples/binarydigits.c3 @@ -15,7 +15,7 @@ fn DString bin(int x) { int bits = x == 0 ? 1 : 1 + (int)math::log2(x); DString str; - str.new_init(); + str.init(mem); str.append_repeat('0', bits); for (int i = 0; i < bits; i++) { diff --git a/test/src/test_suite_runner.c3 b/test/src/test_suite_runner.c3 index aabf31de5..5d43d7e30 100644 --- a/test/src/test_suite_runner.c3 +++ b/test/src/test_suite_runner.c3 @@ -476,7 +476,7 @@ fn void test_file(Path file_path) io::printfn(`FAILED - %s did not contain: "%s"`, file.name, next); io::printfn("\n\n\n---------------------------------------------------> %s\n\n", file.name); (void)file_ll.seek(0); - (void)io::printn((String)io::read_new_fully(&file_ll, allocator: allocator::temp())); + (void)io::printn((String)io::read_fully(tmem(), &file_ll)); io::printfn("<---------------------------------------------------- %s\n", file_path); return; } diff --git a/test/test_suite7/functions/missing_return_lambda.c3 b/test/test_suite7/functions/missing_return_lambda.c3 index 1189df58b..b7ff6af10 100644 --- a/test/test_suite7/functions/missing_return_lambda.c3 +++ b/test/test_suite7/functions/missing_return_lambda.c3 @@ -2,7 +2,7 @@ import std::io::path; fn void! process_dir(String dir_name) { - path::Path p = path::tnew(dir_name)!; + path::Path p = path::temp(dir_name)!; path::PathWalker fnwalk = fn bool!(Path p, bool is_dir, void*) { // #error: issing return statement at the end io::printfn("path is %s", p); }; diff --git a/test/test_suite7/statements/dead_statements.c3t b/test/test_suite7/statements/dead_statements.c3t index 5abbaa7d7..228f2a6af 100644 --- a/test/test_suite7/statements/dead_statements.c3t +++ b/test/test_suite7/statements/dead_statements.c3t @@ -7,7 +7,7 @@ import std::collections::list; fn void! load_corpus2(String code, String path) @local { for(;;) io::printfn("hi"); - path::Path p = path::tnew(path)!; // #warning: This code will never execute + path::Path p = path::temp(path)!; // #warning: This code will never execute if (!path::exists(p)) { diff --git a/test/unit/stdlib/collections/copy_map.c3 b/test/unit/stdlib/collections/copy_map.c3 index abb70709b..56613e544 100644 --- a/test/unit/stdlib/collections/copy_map.c3 +++ b/test/unit/stdlib/collections/copy_map.c3 @@ -12,7 +12,7 @@ fn void copy_map() @test mem::@scoped(&alloc) { IntMap x; - x.new_init(); + x.init(mem); DString y; y.append("hello"); x.set(y.str_view(), 123); diff --git a/test/unit/stdlib/core/dstring.c3 b/test/unit/stdlib/core/dstring.c3 index 9c42c60c5..9663793fa 100644 --- a/test/unit/stdlib/core/dstring.c3 +++ b/test/unit/stdlib/core/dstring.c3 @@ -107,7 +107,7 @@ fn void test_append() DString str2 = dstring::new("yyy"); defer str2.free(); - DString str3 = str.new_concat(str2); + DString str3 = str.concat(mem, str2); defer str3.free(); s = str3.str_view(); assert(s == "xxxyyy", "got '%s'; want 'xxxyyy'", s); diff --git a/test/unit/stdlib/io/varint.c3 b/test/unit/stdlib/io/varint.c3 index 391f04b12..4a2a202d2 100644 --- a/test/unit/stdlib/io/varint.c3 +++ b/test/unit/stdlib/io/varint.c3 @@ -4,7 +4,7 @@ import std::io; fn void write_read() { ByteBuffer buf; - buf.temp_init(16); + buf.tinit(16); usz n; uint x; uint y; @@ -45,7 +45,7 @@ fn void samples() foreach (tc : tcases) { ByteWriter bw; - bw.temp_init(); + bw.tinit(); usz n = io::write_varint(&bw, tc.in)!!; assert(n == tc.bytes.len, "got %d; want %d", n, tc.bytes.len); char[] bytes = bw.bytes[:bw.index]; diff --git a/test/unit/stdlib/net/url.c3 b/test/unit/stdlib/net/url.c3 index f13576240..3ae44a21f 100644 --- a/test/unit/stdlib/net/url.c3 +++ b/test/unit/stdlib/net/url.c3 @@ -396,7 +396,7 @@ fn void test_query_values_withempty() fn void test_url_idempotence() { UrlQueryValues query_builder; - query_builder.new_init(); + query_builder.init(mem); defer query_builder.free(); query_builder.add("profileSQL", "true"); diff --git a/test/unit/stdlib/sort/sorted.c3 b/test/unit/stdlib/sort/sorted.c3 index b82019bfc..7fb55a524 100644 --- a/test/unit/stdlib/sort/sorted.c3 +++ b/test/unit/stdlib/sort/sorted.c3 @@ -67,7 +67,7 @@ fn void sorted() // with list List() list; - list.temp_init(); + list.tinit(); list.add_array(tc.input); got = is_sorted(list); diff --git a/test/unit/stdlib/threads/channel.c3 b/test/unit/stdlib/threads/channel.c3 index 0b708763a..1ba742cdb 100644 --- a/test/unit/stdlib/threads/channel.c3 +++ b/test/unit/stdlib/threads/channel.c3 @@ -10,7 +10,7 @@ fn void init_destroy_buffered() @test for (usz i = 0; i < 20; i++) { BufferedChannel() c; - c.new_init(1)!!; + c.init(mem, 1)!!; defer c.destroy()!!; } } @@ -28,7 +28,7 @@ fn void init_destroy_unbuffered() @test fn void push_to_buffered_channel_no_lock() @test { BufferedChannel() c; - c.new_init(1)!!; + c.init(mem, 1)!!; defer c.destroy()!!; c.push(1)!!; diff --git a/test/unit7/stdlib/core/dstring.c3 b/test/unit7/stdlib/core/dstring.c3 index f30ee5543..e45dc465a 100644 --- a/test/unit7/stdlib/core/dstring.c3 +++ b/test/unit7/stdlib/core/dstring.c3 @@ -173,7 +173,7 @@ fn void test_join() fn void test_insert_at() { - DString str = dstring::tnew(" world"); + DString str = dstring::temp(" world"); String s; str.insert_at(0, ""); @@ -208,7 +208,7 @@ fn void test_insert_at() fn void test_insert_at_overlaps() { - DString str = dstring::tnew("abc"); + DString str = dstring::temp("abc"); String s; String v; diff --git a/test/unit7/stdlib/io/bits.c3 b/test/unit7/stdlib/io/bits.c3 index bd2afd9bc..7a7402979 100644 --- a/test/unit7/stdlib/io/bits.c3 +++ b/test/unit7/stdlib/io/bits.c3 @@ -3,7 +3,7 @@ import std::io; fn void test_write_0b1() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -16,7 +16,7 @@ fn void test_write_0b1() { fn void test_write_0b1111() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -29,7 +29,7 @@ fn void test_write_0b1111() { fn void test_write_0b1111_1111() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -42,7 +42,7 @@ fn void test_write_0b1111_1111() { fn void test_write_0b1000() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -55,7 +55,7 @@ fn void test_write_0b1000() { fn void test_write_0b01000() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -68,7 +68,7 @@ fn void test_write_0b01000() { fn void test_write_0b0001() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -82,7 +82,7 @@ fn void test_write_0b0001() { fn void test_write_0b0000_0001() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -95,7 +95,7 @@ fn void test_write_0b0000_0001() { fn void test_write_10_bits() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -109,7 +109,7 @@ fn void test_write_10_bits() { fn void test_write_16_bits() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -122,7 +122,7 @@ fn void test_write_16_bits() { fn void test_write_24_bits() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -135,7 +135,7 @@ fn void test_write_24_bits() { fn void test_write_30_bits() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -148,7 +148,7 @@ fn void test_write_30_bits() { fn void test_write_32_bits() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -161,7 +161,7 @@ fn void test_write_32_bits() { fn void test_write_2_bits_multiple() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -176,7 +176,7 @@ fn void test_write_2_bits_multiple() { fn void test_write_10_bits_multiple() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -192,7 +192,7 @@ fn void test_write_10_bits_multiple() { fn void test_write_24_bits_multiple() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -206,7 +206,7 @@ fn void test_write_24_bits_multiple() { fn void test_write_30_bits_multiple() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -220,7 +220,7 @@ fn void test_write_30_bits_multiple() { fn void test_write_32_bits_multiple() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); @@ -234,7 +234,7 @@ fn void test_write_32_bits_multiple() { fn void test_write_mixed_multiple() { ByteWriter w; - w.temp_init(); + w.tinit(); BitWriter bw; bw.init(&w); diff --git a/test/unit7/stdlib/io/bufferstream.c3 b/test/unit7/stdlib/io/bufferstream.c3 index 76a3b0d89..a308d03e3 100644 --- a/test/unit7/stdlib/io/bufferstream.c3 +++ b/test/unit7/stdlib/io/bufferstream.c3 @@ -27,7 +27,7 @@ fn void readbuffer() reader_buf.init(&src, buf[..]); ByteWriter bw; - bw.temp_init(); + bw.tinit(); usz n = io::copy_to(&reader_buf, &bw)!!; @@ -39,7 +39,7 @@ fn void readbuffer() fn void writebuffer_large() { ByteWriter out; - out.temp_init(); + out.tinit(); char[16] buf; WriteBuffer write_buf; write_buf.init(&out, buf[..]); @@ -56,7 +56,7 @@ fn void writebuffer() ByteReader br; br.init(DATA); ByteWriter out; - out.temp_init(); + out.tinit(); char[3] buf; WriteBuffer write_buf; write_buf.init(&out, buf[..]); @@ -71,7 +71,7 @@ fn void writebuffer() fn void writebuffer_write_byte() { ByteWriter out; - out.temp_init(); + out.tinit(); char[2] buf; WriteBuffer write_buf; write_buf.init(&out, buf[..]); diff --git a/test/unit7/stdlib/io/bytebuffer.c3 b/test/unit7/stdlib/io/bytebuffer.c3 index eafbe9ec9..a83669c5b 100644 --- a/test/unit7/stdlib/io/bytebuffer.c3 +++ b/test/unit7/stdlib/io/bytebuffer.c3 @@ -4,7 +4,7 @@ import std::io; fn void write_read() { ByteBuffer buffer; - buffer.new_init(0); + buffer.init(mem, 0); defer buffer.free(); buffer.write("hello")!!; diff --git a/test/unit7/stdlib/io/bytestream.c3 b/test/unit7/stdlib/io/bytestream.c3 index 3c9384090..d88f9db4d 100644 --- a/test/unit7/stdlib/io/bytestream.c3 +++ b/test/unit7/stdlib/io/bytestream.c3 @@ -12,7 +12,7 @@ fn void bytestream() usz len = s.read(&buffer)!!; assert((String)buffer[:len] == "abc"); ByteWriter w; - w.new_init(); + w.init(mem); defer (void)w.destroy(); OutStream ws = &w; ws.write("helloworld")!!; @@ -44,7 +44,7 @@ fn void bytewriter_read_from() InStream s = &r; ByteWriter bw; - bw.temp_init(); + bw.tinit(); bw.read_from(s)!!; assert(bw.str_view() == data); diff --git a/test/unit7/stdlib/io/multireader.c3 b/test/unit7/stdlib/io/multireader.c3 index 747f9b219..552fd9549 100644 --- a/test/unit7/stdlib/io/multireader.c3 +++ b/test/unit7/stdlib/io/multireader.c3 @@ -3,7 +3,7 @@ module std::io @test; fn void test_multireader() { MultiReader mr; - mr.temp_init( + mr.tinit( &&wrap_bytes("foo"), &&wrap_bytes(" "), &&wrap_bytes("bar"), @@ -12,7 +12,7 @@ fn void test_multireader() defer mr.free(); ByteWriter w; - io::copy_to(&mr, w.temp_init())!!; + io::copy_to(&mr, w.tinit())!!; String want = "foo bar!"; assert(w.str_view() == want, diff --git a/test/unit7/stdlib/io/multiwriter.c3 b/test/unit7/stdlib/io/multiwriter.c3 index 8261bab34..2bf5d0295 100644 --- a/test/unit7/stdlib/io/multiwriter.c3 +++ b/test/unit7/stdlib/io/multiwriter.c3 @@ -4,7 +4,7 @@ fn void test_multiwriter() { ByteWriter w1, w2; MultiWriter mw; - mw.temp_init(w1.temp_init(), w2.temp_init()); + mw.tinit(w1.tinit(), w2.tinit()); defer mw.free(); String want = "foobar"; diff --git a/test/unit7/stdlib/io/stream.c3 b/test/unit7/stdlib/io/stream.c3 index 14e960d66..74fe81d65 100644 --- a/test/unit7/stdlib/io/stream.c3 +++ b/test/unit7/stdlib/io/stream.c3 @@ -27,7 +27,7 @@ fn void read_uint128_test() fn void write_ushort_test() { ByteWriter bw; - bw.temp_init(); + bw.tinit(); io::write_be_short(&bw, 0x348a)!!; assert(bw.str_view() == &&x'348a'); } @@ -35,7 +35,7 @@ fn void write_ushort_test() fn void write_uint_test() { ByteWriter bw; - bw.temp_init(); + bw.tinit(); io::write_be_int(&bw, 0x3421348a)!!; assert(bw.str_view() == &&x'3421348a'); } @@ -43,7 +43,7 @@ fn void write_uint_test() fn void write_ulong_test() { ByteWriter bw; - bw.temp_init(); + bw.tinit(); io::write_be_long(&bw, 0xaabbccdd3421348a)!!; assert(bw.str_view() == &&x'aabbccdd3421348a'); } @@ -51,7 +51,7 @@ fn void write_ulong_test() fn void write_uint128_test() { ByteWriter bw; - bw.temp_init(); + bw.tinit(); io::write_be_int128(&bw, 0xaabbccdd3421348aaabbccdd3421348a)!!; assert(bw.str_view() == &&x'aabbccdd3421348aaabbccdd3421348a'); } @@ -59,7 +59,7 @@ fn void write_uint128_test() fn void write_tiny_bytearray_test() { ByteWriter bw; - bw.temp_init(); + bw.tinit(); io::write_tiny_bytearray(&bw, &&x"aabbcc00112233")!!; assert(bw.str_view() == &&x'07aabbcc00112233'); } @@ -67,7 +67,7 @@ fn void write_tiny_bytearray_test() fn void write_short_bytearray_test() { ByteWriter bw; - bw.temp_init(); + bw.tinit(); io::write_short_bytearray(&bw, &&x"aabbcc00112233")!!; assert(bw.str_view() == &&x'0007aabbcc00112233'); } diff --git a/test/unit7/stdlib/io/teereader.c3 b/test/unit7/stdlib/io/teereader.c3 index c76181f5f..5e07b4447 100644 --- a/test/unit7/stdlib/io/teereader.c3 +++ b/test/unit7/stdlib/io/teereader.c3 @@ -5,7 +5,7 @@ fn void test_teereader() String want = "foobar"; ByteWriter w; - TeeReader r = tee_reader((ByteReader){}.init(want), w.temp_init()); + TeeReader r = tee_reader((ByteReader){}.init(want), w.tinit()); char[16] buf; usz n = r.read(buf[..])!!; diff --git a/test/unit7/stdlib/io/varint.c3 b/test/unit7/stdlib/io/varint.c3 index 391f04b12..4a2a202d2 100644 --- a/test/unit7/stdlib/io/varint.c3 +++ b/test/unit7/stdlib/io/varint.c3 @@ -4,7 +4,7 @@ import std::io; fn void write_read() { ByteBuffer buf; - buf.temp_init(16); + buf.tinit(16); usz n; uint x; uint y; @@ -45,7 +45,7 @@ fn void samples() foreach (tc : tcases) { ByteWriter bw; - bw.temp_init(); + bw.tinit(); usz n = io::write_varint(&bw, tc.in)!!; assert(n == tc.bytes.len, "got %d; want %d", n, tc.bytes.len); char[] bytes = bw.bytes[:bw.index]; diff --git a/test/unit7/stdlib/net/url.c3 b/test/unit7/stdlib/net/url.c3 index ffcd97368..d35d43e5f 100644 --- a/test/unit7/stdlib/net/url.c3 +++ b/test/unit7/stdlib/net/url.c3 @@ -337,7 +337,7 @@ fn void test_query_values1() Url url = url::parse(mem, "foo://example.com:8042/over/there?name=ferret=ok#nose")!!; defer url.free(); - UrlQueryValues vals = url::temp_parse_query(url.query); + UrlQueryValues vals = url::parse_query_to_temp(url.query); defer vals.free(); assert(vals.len() == 1); @@ -352,7 +352,7 @@ fn void test_query_values2() Url url = url::parse(mem, "foo://example.com:8042/over/there?name=ferret&age=99&age=11#nose")!!; defer url.free(); - UrlQueryValues vals = url::new_parse_query(url.query); + UrlQueryValues vals = url::parse_query(mem, url.query); defer vals.free(); assert(vals.len() == 2); @@ -371,7 +371,7 @@ fn void test_escaped_query_values() Url url = url::parse(mem, "foo://example.com:8042/over/there?k%3Bey=%3Ckey%3A+0x90%3E&age=99&age=11#nose")!!; defer url.free(); - UrlQueryValues vals = url::new_parse_query(url.query); + UrlQueryValues vals = url::parse_query(mem, url.query); defer vals.free(); assert(vals.len() == 2); @@ -385,7 +385,7 @@ fn void test_query_values_withempty() Url url = url::parse(mem, "foo://example.com:8042/over/there?name=ferret&&&age=99&age=11")!!; defer url.free(); - UrlQueryValues vals = url::new_parse_query(url.query); + UrlQueryValues vals = url::parse_query(mem, url.query); defer vals.free(); assert(vals.len() == 2); } @@ -426,7 +426,7 @@ fn void test_url_idempotence() Url parsed = url::parse(mem, url_string)!!; defer parsed.free(); - UrlQueryValues vals = url::new_parse_query(parsed.query); + UrlQueryValues vals = url::parse_query(mem, parsed.query); defer vals.free(); assert(vals.len() == 2);