From b6f5938eda9109c8777cf451503580e47ed08dd9 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 24 Feb 2025 01:44:57 +0100 Subject: [PATCH] Change to {} generics in lib7. Update qoi and other encodings and multiple other small changes. --- lib7/std/atomic.c3 | 2 +- lib7/std/collections/bitset.c3 | 2 +- lib7/std/collections/object.c3 | 6 +-- lib7/std/collections/ringbuffer.c3 | 2 +- lib7/std/compression/qoi.c3 | 35 +++----------- lib7/std/core/allocators/heap_allocator.c3 | 2 +- .../std/core/allocators/tracking_allocator.c3 | 2 +- lib7/std/core/array.c3 | 24 ++-------- lib7/std/core/runtime_benchmark.c3 | 4 +- lib7/std/core/runtime_test.c3 | 4 +- lib7/std/encoding/base32.c3 | 10 ++-- lib7/std/encoding/base64.c3 | 10 ++-- lib7/std/experimental/FrameScheduler.c3 | 8 ++-- lib7/std/hash/hmac.c3 | 2 +- lib7/std/hash/md5.c3 | 6 +-- lib7/std/hash/sha1.c3 | 6 +-- lib7/std/hash/sha256.c3 | 6 +-- lib7/std/io/path.c3 | 2 +- lib7/std/math/math.c3 | 48 +++++++++---------- lib7/std/math/math_complex.c3 | 2 +- lib7/std/math/math_matrix.c3 | 2 +- lib7/std/math/math_quaternion.c3 | 2 +- lib7/std/math/math_vector.c3 | 4 +- lib7/std/net/inetaddr.c3 | 19 +++----- lib7/std/net/net.c3 | 7 +-- lib7/std/os/backtrace.c3 | 2 +- lib7/std/sort/countingsort.c3 | 8 ++-- lib7/std/sort/insertionsort.c3 | 6 +-- lib7/std/sort/quicksort.c3 | 8 ++-- lib7/std/threads/buffered_channel.c3 | 9 +--- lib7/std/threads/pool.c3 | 2 +- lib7/std/threads/unbuffered_channel.c3 | 4 +- test/unit7/stdlib/compression/qoi.c3 | 6 +-- test/unit7/stdlib/core/array.c3 | 12 ++--- test/unit7/stdlib/encoding/base32.c3 | 4 +- test/unit7/stdlib/net/inetaddr.c3 | 18 +++---- test/unit7/stdlib/threads/channel.c3 | 32 ++++++------- 37 files changed, 135 insertions(+), 193 deletions(-) diff --git a/lib7/std/atomic.c3 b/lib7/std/atomic.c3 index 754a34620..c26cf793e 100644 --- a/lib7/std/atomic.c3 +++ b/lib7/std/atomic.c3 @@ -1,7 +1,7 @@ // Copyright (c) 2023 Eduardo José Gómez Hernández. All rights reserved. // Use of this source code is governed by the MIT license // a copy of which can be found in the LICENSE_STDLIB file. -module std::atomic::types(); +module std::atomic::types{Type}; struct Atomic { diff --git a/lib7/std/collections/bitset.c3 b/lib7/std/collections/bitset.c3 index 52ed4091a..128f41622 100644 --- a/lib7/std/collections/bitset.c3 +++ b/lib7/std/collections/bitset.c3 @@ -70,7 +70,7 @@ fn void BitSet.set_bool(&self, usz i, bool value) @operator([]=) @inline <* @require Type.kindof == UNSIGNED_INT *> -module std::collections::growablebitset(); +module std::collections::growablebitset{Type}; import std::collections::list; const BITS = Type.sizeof * 8; diff --git a/lib7/std/collections/object.c3 b/lib7/std/collections/object.c3 index a0697865a..b2ce81704 100644 --- a/lib7/std/collections/object.c3 +++ b/lib7/std/collections/object.c3 @@ -462,7 +462,7 @@ fn Object* Object.get_or_create_obj(&self, String key) return container; } -def ObjectInternalMap = HashMap() @private; -def ObjectInternalList = List() @private; -def ObjectInternalMapEntry = Entry() @private; +def ObjectInternalMap = HashMap{String, Object*} @private; +def ObjectInternalList = List{Object*} @private; +def ObjectInternalMapEntry = Entry{String, Object*} @private; diff --git a/lib7/std/collections/ringbuffer.c3 b/lib7/std/collections/ringbuffer.c3 index a164b2226..d3213d770 100644 --- a/lib7/std/collections/ringbuffer.c3 +++ b/lib7/std/collections/ringbuffer.c3 @@ -1,7 +1,7 @@ <* @require Type.kindof == ARRAY : "Required an array type" *> -module std::collections::ringbuffer(); +module std::collections::ringbuffer{Type}; import std::io; def Element = $typeof((Type){}[0]); diff --git a/lib7/std/compression/qoi.c3 b/lib7/std/compression/qoi.c3 index 1b4a1fb09..b896b7e6d 100644 --- a/lib7/std/compression/qoi.c3 +++ b/lib7/std/compression/qoi.c3 @@ -74,18 +74,10 @@ import std::io; fn usz! write(String filename, char[] input, QOIDesc* desc) => @pool() { // encode data - char[] output = new_encode(input, desc, allocator: allocator::temp())!; + char[] output = encode(tmem(), input, desc)!; - // open file - File! f = file::open(filename, "wb"); - if (catch f) return QOIError.FILE_OPEN_FAILED?; - - // write data to file and close it - usz! written = f.write(output); - if (catch written) return QOIError.FILE_WRITE_FAILED?; - if (catch f.close()) return QOIError.FILE_WRITE_FAILED?; - - return written; + file::save(filename, output)!; + return output.len; } @@ -110,29 +102,20 @@ fn usz! write(String filename, char[] input, QOIDesc* desc) => @pool() @param [&out] desc `The descriptor to fill with the image's info` @param channels `The channels to be used` *> -fn char[]! new_read(String filename, QOIDesc* desc, QOIChannels channels = AUTO, Allocator allocator = allocator::heap()) => @pool(allocator) +fn char[]! read(Allocator allocator, String filename, QOIDesc* desc, QOIChannels channels = AUTO) => @pool(allocator) { // read file char[] data = file::load_temp(filename) ?? QOIError.FILE_OPEN_FAILED?!; // pass data to decode function - return new_decode(data, desc, channels, allocator); + return decode(allocator, data, desc, channels); } -fn char[]! read(String filename, QOIDesc* desc, QOIChannels channels = AUTO, Allocator allocator = allocator::heap()) @deprecated("Use new_read") -{ - return new_read(filename, desc, channels, allocator); -} // Back to basic non-stdio mode module std::compression::qoi; import std::bits; -fn char[]! encode(char[] input, QOIDesc* desc, Allocator allocator = allocator::heap()) @deprecated("use encode_new") -{ - return new_encode(input, desc, allocator); -} - <* Encode raw RGB or RGBA pixels into a QOI image in memory. @@ -146,7 +129,7 @@ fn char[]! encode(char[] input, QOIDesc* desc, Allocator allocator = allocator:: @param [in] input `The raw RGB or RGBA pixels to encode` @param [&in] desc `The descriptor of the image` *> -fn char[]! new_encode(char[] input, QOIDesc* desc, Allocator allocator = allocator::heap()) @nodiscard +fn char[]! encode(Allocator allocator, char[] input, QOIDesc* desc) @nodiscard { // check info in desc if (desc.width == 0 || desc.height == 0) return QOIError.INVALID_PARAMETERS?; @@ -278,10 +261,6 @@ fn char[]! new_encode(char[] input, QOIDesc* desc, Allocator allocator = allocat } -fn char[]! decode(char[] data, QOIDesc* desc, QOIChannels channels = AUTO, Allocator allocator = allocator::heap()) -{ - return new_decode(data, desc, channels, allocator); -} <* Decode a QOI image from memory. @@ -304,7 +283,7 @@ fn char[]! decode(char[] data, QOIDesc* desc, QOIChannels channels = AUTO, Alloc @param [&out] desc `The descriptor to fill with the image's info` @param channels `The channels to be used` *> -fn char[]! new_decode(char[] data, QOIDesc* desc, QOIChannels channels = AUTO, Allocator allocator = allocator::heap()) @nodiscard +fn char[]! decode(Allocator allocator, char[] data, QOIDesc* desc, QOIChannels channels = AUTO) @nodiscard { // check input data if (data.len < Header.sizeof + END_OF_STREAM.len) return QOIError.INVALID_DATA?; diff --git a/lib7/std/core/allocators/heap_allocator.c3 b/lib7/std/core/allocators/heap_allocator.c3 index ccd18c250..3ea8e126a 100644 --- a/lib7/std/core/allocators/heap_allocator.c3 +++ b/lib7/std/core/allocators/heap_allocator.c3 @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2024 Christoffer Lerno. All rights reserved. +// Copyright (c) 2021-2025 Christoffer Lerno. All rights reserved. // Use of this source code is governed by the MIT license // a copy of which can be found in the LICENSE_STDLIB file. diff --git a/lib7/std/core/allocators/tracking_allocator.c3 b/lib7/std/core/allocators/tracking_allocator.c3 index ad4eb81fe..9f1366496 100644 --- a/lib7/std/core/allocators/tracking_allocator.c3 +++ b/lib7/std/core/allocators/tracking_allocator.c3 @@ -13,7 +13,7 @@ struct Allocation void*[MAX_BACKTRACE] backtrace; } -def AllocMap = HashMap(); +def AllocMap = HashMap { uptr, Allocation }; // A simple tracking allocator. // It tracks allocations using a hash map but diff --git a/lib7/std/core/array.c3 b/lib7/std/core/array.c3 index abb808e34..6dd9cdc67 100644 --- a/lib7/std/core/array.c3 +++ b/lib7/std/core/array.c3 @@ -26,7 +26,7 @@ macro slice2d(array_ptr, x = 0, xlen = 0, y = 0, ylen = 0) if (xlen < 1) xlen = $typeof((*array_ptr)[0]).len + xlen; if (ylen < 1) ylen = $typeof((*array_ptr)).len + ylen; var $ElementType = $typeof((*array_ptr)[0][0]); - return Slice2d(<$ElementType>) { ($ElementType*)array_ptr, $typeof((*array_ptr)[0]).len, y, ylen, x, xlen }; + return Slice2d{$ElementType} { ($ElementType*)array_ptr, $typeof((*array_ptr)[0]).len, y, ylen, x, xlen }; } @@ -56,7 +56,7 @@ macro rindex_of(array, element) @require @typeis(arr1[0], $typeof(arr2[0])) "Arrays must have the same type" @ensure result.len == arr1.len + arr2.len *> -macro concat(arr1, arr2, Allocator allocator) @nodiscard +macro concat(Allocator allocator, arr1, arr2) @nodiscard { var $Type = $typeof(arr1[0]); $Type[] result = allocator::alloc_array(allocator, $Type, arr1.len + arr2.len); @@ -70,22 +70,6 @@ macro concat(arr1, arr2, Allocator allocator) @nodiscard } return result; } -<* - Concatenate two arrays or slices, returning a slice containing the concatenation of them. - - @param [in] arr1 - @param [in] arr2 - @param [&inout] allocator "The allocator to use, default is the heap allocator" - @require @typekind(arr1) == SLICE || @typekind(arr1) == ARRAY - @require @typekind(arr2) == SLICE || @typekind(arr2) == ARRAY - @require @typeis(arr1[0], $typeof(arr2[0])) "Arrays must have the same type" - @ensure return.len == arr1.len + arr2.len -*> -macro concat_new(arr1, arr2, Allocator allocator = allocator::heap()) @nodiscard -{ - return concat(arr1, arr2, allocator); -} - <* Concatenate two arrays or slices, returning a slice containing the concatenation of them, allocated using the temp allocator. @@ -97,9 +81,9 @@ macro concat_new(arr1, arr2, Allocator allocator = allocator::heap()) @nodiscard @require @typeis(arr1[0], $typeof(arr2[0])) "Arrays must have the same type" @ensure return.len == arr1.len + arr2.len *> -macro tconcat(arr1, arr2) @nodiscard => concat(arr1, arr2, allocator::temp()); +macro tconcat(arr1, arr2) @nodiscard => concat(allocator::temp(), arr1, arr2); -module std::core::array::slice(); +module std::core::array::slice{Type}; struct Slice2d { diff --git a/lib7/std/core/runtime_benchmark.c3 b/lib7/std/core/runtime_benchmark.c3 index 777597a9d..f07256773 100644 --- a/lib7/std/core/runtime_benchmark.c3 +++ b/lib7/std/core/runtime_benchmark.c3 @@ -10,7 +10,7 @@ struct BenchmarkUnit BenchmarkFn func; } -fn BenchmarkUnit[] benchmark_collection_create(Allocator allocator = allocator::heap()) +fn BenchmarkUnit[] benchmark_collection_create(Allocator allocator) { BenchmarkFn[] fns = $$BENCHMARK_FNS; String[] names = $$BENCHMARK_NAMES; @@ -170,5 +170,5 @@ fn bool run_benchmarks(BenchmarkUnit[] benchmarks) @if(!$$OLD_TEST) fn bool default_benchmark_runner(String[] args) => @pool() { - return run_benchmarks(benchmark_collection_create(allocator::temp())); + return run_benchmarks(benchmark_collection_create(tmem())); } diff --git a/lib7/std/core/runtime_test.c3 b/lib7/std/core/runtime_test.c3 index 5fad98705..ce5a678ae 100644 --- a/lib7/std/core/runtime_test.c3 +++ b/lib7/std/core/runtime_test.c3 @@ -45,7 +45,7 @@ struct TestUnit TestFn func; } -fn TestUnit[] test_collection_create(Allocator allocator = allocator::heap()) +fn TestUnit[] test_collection_create(Allocator allocator) { TestFn[] fns = $$TEST_FNS; String[] names = $$TEST_NAMES; @@ -317,6 +317,6 @@ fn bool run_tests(String[] args, TestUnit[] tests) @private fn bool default_test_runner(String[] args) => @pool() { assert(test_context == null, "test suite is already running"); - return run_tests(args, test_collection_create(allocator::temp())); + return run_tests(args, test_collection_create(tmem())); } diff --git a/lib7/std/encoding/base32.c3 b/lib7/std/encoding/base32.c3 index 856db8b96..1900f2bcb 100644 --- a/lib7/std/encoding/base32.c3 +++ b/lib7/std/encoding/base32.c3 @@ -20,7 +20,7 @@ const char DEFAULT_PAD = '='; @require padding < 0xFF "Invalid padding character" @return "The encoded string." *> -fn String! encode(char[] src, Allocator allocator, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) +fn String! encode(Allocator allocator, char[] src, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) { char[] dst = allocator::alloc_array(allocator, char, encode_len(src.len, padding)); return encode_buffer(src, dst, padding, alphabet); @@ -34,16 +34,14 @@ fn String! encode(char[] src, Allocator allocator, char padding = DEFAULT_PAD, B @require padding < 0xFF "Invalid padding character" @return "The decoded data." *> -fn char[]! decode(char[] src, Allocator allocator, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) +fn char[]! decode(Allocator allocator, char[] src, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) { char[] dst = allocator::alloc_array(allocator, char, decode_len(src.len, padding)); return decode_buffer(src, dst, padding, alphabet); } -fn String! encode_new(char[] code, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) @inline => encode(code, allocator::heap(), padding, alphabet); -fn String! encode_temp(char[] code, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) @inline => encode(code, allocator::temp(), padding, alphabet); -fn char[]! decode_new(char[] code, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) @inline => decode(code, allocator::heap(), padding, alphabet); -fn char[]! decode_temp(char[] code, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) @inline => decode(code, allocator::temp(), padding, alphabet); +fn String! tencode(char[] code, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) @inline => encode(tmem(), code, padding, alphabet); +fn char[]! tdecode(char[] code, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) @inline => decode(tmem(), code, padding, alphabet); <* Calculate the length in bytes of the decoded data. diff --git a/lib7/std/encoding/base64.c3 b/lib7/std/encoding/base64.c3 index 96828ab1e..9659439c9 100644 --- a/lib7/std/encoding/base64.c3 +++ b/lib7/std/encoding/base64.c3 @@ -43,22 +43,20 @@ const Base64Alphabet URL = { const STD_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; -fn String encode(char[] src, Allocator allocator, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) +fn String encode(Allocator allocator, char[] src, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) { char[] dst = allocator::alloc_array(allocator, char, encode_len(src.len, padding)); return encode_buffer(src, dst, padding, alphabet); } -fn char[]! decode(char[] src, Allocator allocator, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) +fn char[]! decode(Allocator allocator, char[] src, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) { char[] dst = allocator::alloc_array(allocator, char, decode_len(src.len, padding))!; return decode_buffer(src, dst, padding, alphabet); } -fn String encode_new(char[] code, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) @inline => encode(code, allocator::heap(), padding, alphabet); -fn String encode_temp(char[] code, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) @inline => encode(code, allocator::temp(), padding, alphabet); -fn char[]! decode_new(char[] code, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) @inline => decode(code, allocator::heap(), padding, alphabet); -fn char[]! decode_temp(char[] code, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) @inline => decode(code, allocator::temp(), padding, alphabet); +fn String tencode(char[] code, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) @inline => encode(tmem(), code, padding, alphabet); +fn char[]! tdecode(char[] code, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) @inline => decode(tmem(), code, padding, alphabet); <* diff --git a/lib7/std/experimental/FrameScheduler.c3 b/lib7/std/experimental/FrameScheduler.c3 index e44fe18a1..c8bb7b1bf 100644 --- a/lib7/std/experimental/FrameScheduler.c3 +++ b/lib7/std/experimental/FrameScheduler.c3 @@ -1,4 +1,4 @@ -module std::experimental::scheduler(); +module std::experimental::scheduler{Event}; import std::collections, std::thread, std::time; struct DelayedSchedulerEvent @local @@ -19,9 +19,9 @@ fn int DelayedSchedulerEvent.compare_to(self, DelayedSchedulerEvent other) @loca struct FrameScheduler { - PriorityQueue() delayed_events; - List() events; - List() pending_events; + PriorityQueue{DelayedSchedulerEvent} delayed_events; + List{Event} events; + List{Event} pending_events; bool pending; Mutex mtx; } diff --git a/lib7/std/hash/hmac.c3 b/lib7/std/hash/hmac.c3 index a9be8dbe8..2a511410d 100644 --- a/lib7/std/hash/hmac.c3 +++ b/lib7/std/hash/hmac.c3 @@ -1,4 +1,4 @@ -module std::hash::hmac(); +module std::hash::hmac{HashAlg, HASH_BYTES, BLOCK_BYTES}; import std::crypto; struct Hmac diff --git a/lib7/std/hash/md5.c3 b/lib7/std/hash/md5.c3 index 4267fab89..df6321798 100644 --- a/lib7/std/hash/md5.c3 +++ b/lib7/std/hash/md5.c3 @@ -13,9 +13,9 @@ struct Md5 uint[16] block; } -def HmacMd5 = Hmac(); -def hmac = hmac::hash(); -def pbkdf2 = hmac::pbkdf2(); +def HmacMd5 = Hmac{Md5, HASH_BYTES, BLOCK_BYTES}; +def hmac = hmac::hash{Md5, HASH_BYTES, BLOCK_BYTES}; +def pbkdf2 = hmac::pbkdf2{Md5, HASH_BYTES, BLOCK_BYTES}; fn char[HASH_BYTES] hash(char[] data) { diff --git a/lib7/std/hash/sha1.c3 b/lib7/std/hash/sha1.c3 index 4ddb27b60..4dad804f1 100644 --- a/lib7/std/hash/sha1.c3 +++ b/lib7/std/hash/sha1.c3 @@ -18,9 +18,9 @@ struct Sha1 char[BLOCK_BYTES] buffer; } -def HmacSha1 = Hmac(); -def hmac = hmac::hash(); -def pbkdf2 = hmac::pbkdf2(); +def HmacSha1 = Hmac{Sha1, HASH_BYTES, BLOCK_BYTES}; +def hmac = hmac::hash{Sha1, HASH_BYTES, BLOCK_BYTES}; +def pbkdf2 = hmac::pbkdf2{Sha1, HASH_BYTES, BLOCK_BYTES}; fn char[HASH_BYTES] hash(char[] data) { diff --git a/lib7/std/hash/sha256.c3 b/lib7/std/hash/sha256.c3 index b18200c96..a5e86ff3b 100644 --- a/lib7/std/hash/sha256.c3 +++ b/lib7/std/hash/sha256.c3 @@ -34,9 +34,9 @@ struct Sha256 char[BLOCK_SIZE] buffer; } -def HmacSha256 = Hmac(); -def hmac = hmac::hash(); -def pbkdf2 = hmac::pbkdf2(); +def HmacSha256 = Hmac{Sha256, HASH_SIZE, BLOCK_SIZE}; +def hmac = hmac::hash{Sha256, HASH_SIZE, BLOCK_SIZE}; +def pbkdf2 = hmac::pbkdf2{Sha256, HASH_SIZE, BLOCK_SIZE}; fn char[HASH_SIZE] hash(char[] data) { diff --git a/lib7/std/io/path.c3 b/lib7/std/io/path.c3 index 4c40f80e5..5c0055a27 100644 --- a/lib7/std/io/path.c3 +++ b/lib7/std/io/path.c3 @@ -7,7 +7,7 @@ const char PREFERRED_SEPARATOR_WIN32 = '\\'; const char PREFERRED_SEPARATOR_POSIX = '/'; const char PREFERRED_SEPARATOR = env::WIN32 ? PREFERRED_SEPARATOR_WIN32 : PREFERRED_SEPARATOR_POSIX; -def PathList = List(); +def PathList = List { Path }; fault PathResult { diff --git a/lib7/std/math/math.c3 b/lib7/std/math/math.c3 index 93a70a607..a07a04854 100644 --- a/lib7/std/math/math.c3 +++ b/lib7/std/math/math.c3 @@ -90,33 +90,33 @@ fault MatrixError MATRIX_INVERSE_DOESNT_EXIST, } -def Complexf = Complex(); -def Complex = Complex(); -def COMPLEX_IDENTITY = complex::IDENTITY() @builtin; -def COMPLEXF_IDENTITY = complex::IDENTITY() @builtin; +def Complexf = Complex{float}; +def Complex = Complex{double}; +def COMPLEX_IDENTITY = complex::IDENTITY{double} @builtin; +def COMPLEXF_IDENTITY = complex::IDENTITY{float} @builtin; -def Quaternionf = Quaternion(); -def Quaternion = Quaternion(); -def QUATERNION_IDENTITY = quaternion::IDENTITY() @builtin; -def QUATERNIONF_IDENTITY = quaternion::IDENTITY() @builtin; +def Quaternionf = Quaternion{float}; +def Quaternion = Quaternion{double}; +def QUATERNION_IDENTITY = quaternion::IDENTITY{double} @builtin; +def QUATERNIONF_IDENTITY = quaternion::IDENTITY{float} @builtin; -def Matrix2f = Matrix2x2(); -def Matrix2 = Matrix2x2(); -def Matrix3f = Matrix3x3(); -def Matrix3 = Matrix3x3(); -def Matrix4f = Matrix4x4(); -def Matrix4 = Matrix4x4(); -def matrix4_ortho = matrix::ortho() @builtin; -def matrix4_perspective = matrix::perspective() @builtin; -def matrix4f_ortho = matrix::ortho() @builtin; -def matrix4f_perspective = matrix::perspective() @builtin; +def Matrix2f = Matrix2x2{float}; +def Matrix2 = Matrix2x2{double}; +def Matrix3f = Matrix3x3{float}; +def Matrix3 = Matrix3x3{double}; +def Matrix4f = Matrix4x4{float}; +def Matrix4 = Matrix4x4{double}; +def matrix4_ortho = matrix::ortho{double} @builtin; +def matrix4_perspective = matrix::perspective{double} @builtin; +def matrix4f_ortho = matrix::ortho{float} @builtin; +def matrix4f_perspective = matrix::perspective{float} @builtin; -def MATRIX2_IDENTITY = matrix::IDENTITY2() @builtin; -def MATRIX2F_IDENTITY = matrix::IDENTITY2() @builtin; -def MATRIX3_IDENTITY = matrix::IDENTITY3() @builtin; -def MATRIX3F_IDENTITY = matrix::IDENTITY3() @builtin; -def MATRIX4_IDENTITY = matrix::IDENTITY4() @builtin; -def MATRIX4F_IDENTITY = matrix::IDENTITY4() @builtin; +def MATRIX2_IDENTITY = matrix::IDENTITY2{double} @builtin; +def MATRIX2F_IDENTITY = matrix::IDENTITY2{float} @builtin; +def MATRIX3_IDENTITY = matrix::IDENTITY3{double} @builtin; +def MATRIX3F_IDENTITY = matrix::IDENTITY3{float} @builtin; +def MATRIX4_IDENTITY = matrix::IDENTITY4{double} @builtin; +def MATRIX4F_IDENTITY = matrix::IDENTITY4{float} @builtin; <* diff --git a/lib7/std/math/math_complex.c3 b/lib7/std/math/math_complex.c3 index 7843fec2e..df3a39543 100644 --- a/lib7/std/math/math_complex.c3 +++ b/lib7/std/math/math_complex.c3 @@ -1,4 +1,4 @@ -module std::math::complex(); +module std::math::complex{Real}; union Complex { diff --git a/lib7/std/math/math_matrix.c3 b/lib7/std/math/math_matrix.c3 index c9486ea0b..afd060aff 100644 --- a/lib7/std/math/math_matrix.c3 +++ b/lib7/std/math/math_matrix.c3 @@ -1,4 +1,4 @@ -module std::math::matrix(); +module std::math::matrix{Real}; import std::math::vector; struct Matrix2x2 diff --git a/lib7/std/math/math_quaternion.c3 b/lib7/std/math/math_quaternion.c3 index 226c76231..18a7940ef 100644 --- a/lib7/std/math/math_quaternion.c3 +++ b/lib7/std/math/math_quaternion.c3 @@ -1,4 +1,4 @@ -module std::math::quaternion(); +module std::math::quaternion{Real}; import std::math::vector; union Quaternion { diff --git a/lib7/std/math/math_vector.c3 b/lib7/std/math/math_vector.c3 index 48c2bd80a..1d686a8cc 100644 --- a/lib7/std/math/math_vector.c3 +++ b/lib7/std/math/math_vector.c3 @@ -66,8 +66,8 @@ fn Vec3 Vec3.refract(self, Vec3 n, double r) => refract3(self, n, r); fn void ortho_normalize(Vec3f* v1, Vec3f* v2) => ortho_normalize3(v1, v2); fn void ortho_normalized(Vec3* v1, Vec3* v2) => ortho_normalize3(v1, v2); -fn Matrix4f matrix4f_look_at(Vec3f eye, Vec3f target, Vec3f up) @deprecated => matrix::look_at()(eye, target, up); -fn Matrix4 matrix4_look_at(Vec3 eye, Vec3 target, Vec3 up) @deprecated => matrix::look_at()(eye, target, up); +fn Matrix4f matrix4f_look_at(Vec3f eye, Vec3f target, Vec3f up) @deprecated => matrix::look_at{float}(eye, target, up); +fn Matrix4 matrix4_look_at(Vec3 eye, Vec3 target, Vec3 up) @deprecated => matrix::look_at{double}(eye, target, up); fn Vec3f Vec3f.rotate_quat(self, Quaternionf q) => rotate_by_quat3(self, q); fn Vec3 Vec3.rotate_quat(self, Quaternion q) => rotate_by_quat3(self, q); diff --git a/lib7/std/net/inetaddr.c3 b/lib7/std/net/inetaddr.c3 index 26c8f4650..2ffec94b5 100644 --- a/lib7/std/net/inetaddr.c3 +++ b/lib7/std/net/inetaddr.c3 @@ -56,19 +56,14 @@ fn usz! InetAddress.to_format(InetAddress* addr, Formatter* formatter) @dynamic return formatter.printf("%d.%d.%d.%d", addr.ipv4.a, addr.ipv4.b, addr.ipv4.c, addr.ipv4.d)!; } -fn String InetAddress.to_new_string(InetAddress* addr, Allocator allocator = allocator::heap()) @dynamic +fn String InetAddress.to_string(&self, Allocator allocator) { - if (addr.is_ipv6) - { - char[8 * 5 + 1] buffer; - String res = (String)io::bprintf(&buffer, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", - addr.ipv6.a, addr.ipv6.b, addr.ipv6.c, addr.ipv6.d, - addr.ipv6.e, addr.ipv6.f, addr.ipv6.g, addr.ipv6.h)!!; - return res.copy(allocator); - } - char[3 * 4 + 3 + 1] buffer; - String res = (String)io::bprintf(&buffer, "%d.%d.%d.%d", addr.ipv4.a, addr.ipv4.b, addr.ipv4.c, addr.ipv4.d)!!; - return res.copy(allocator); + return string::format(allocator, "%s", *self); +} + +fn String InetAddress.to_tstring(&self) +{ + return string::format(tmem(), "%s", *self); } fn InetAddress! ipv6_from_str(String s) diff --git a/lib7/std/net/net.c3 b/lib7/std/net/net.c3 index b1dc258fb..7a5f600d5 100644 --- a/lib7/std/net/net.c3 +++ b/lib7/std/net/net.c3 @@ -58,14 +58,9 @@ fn uint! ipv4toint(String s) return out; } -fn String! int_to_new_ipv4(uint val, Allocator allocator = allocator::heap()) +fn String! int_to_ipv4(uint val, Allocator allocator) { char[3 * 4 + 3 + 1] buffer; String res = (String)io::bprintf(&buffer, "%d.%d.%d.%d", val >> 24, (val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)!; return res.copy(allocator); } - -fn String! int_to_temp_ipv4(uint val) -{ - return int_to_new_ipv4(val, allocator::temp()); -} diff --git a/lib7/std/os/backtrace.c3 b/lib7/std/os/backtrace.c3 index c2e7dd9b9..39ddce575 100644 --- a/lib7/std/os/backtrace.c3 +++ b/lib7/std/os/backtrace.c3 @@ -91,7 +91,7 @@ fn void*[] capture_current(void*[] buffer) $endswitch } -def BacktraceList = List(); +def BacktraceList = List{Backtrace}; def symbolize_backtrace = linux::symbolize_backtrace @if(env::LINUX); def symbolize_backtrace = win32::symbolize_backtrace @if(env::WIN32); diff --git a/lib7/std/sort/countingsort.c3 b/lib7/std/sort/countingsort.c3 index 38598059e..09ab21a32 100644 --- a/lib7/std/sort/countingsort.c3 +++ b/lib7/std/sort/countingsort.c3 @@ -11,20 +11,20 @@ Sort list using the counting sort algorithm. macro countingsort(list, key_fn = EMPTY_MACRO_SLOT) @builtin { usz len = sort::len_from_list(list); - cs::csort(<$typeof(list), $typeof(key_fn)>)(list, 0, len, key_fn, ~((uint)0)); + cs::csort{$typeof(list), $typeof(key_fn)}(list, 0, len, key_fn, ~((uint)0)); } macro insertionsort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin { - is::isort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, (usz)start, (usz)end, cmp, context); + is::isort{$typeof(list), $typeof(cmp), $typeof(context)}(list, (usz)start, (usz)end, cmp, context); } macro quicksort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin { - qs::qsort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, (isz)start, (isz)(end-1), cmp, context); + qs::qsort{$typeof(list), $typeof(cmp), $typeof(context)}(list, (isz)start, (isz)(end-1), cmp, context); } -module std::sort::cs(); +module std::sort::cs{Type, KeyFn}; def Counts = usz[256] @private; def Ranges = usz[257] @private; diff --git a/lib7/std/sort/insertionsort.c3 b/lib7/std/sort/insertionsort.c3 index 6e1ed6953..f3106067c 100644 --- a/lib7/std/sort/insertionsort.c3 +++ b/lib7/std/sort/insertionsort.c3 @@ -10,14 +10,14 @@ macro insertionsort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @b { $if @typekind(list) == POINTER &&& (@typekind(*list) == ARRAY || @typekind(*list) == VECTOR): $typeof((*list)[0])[] list2 = list; - is::isort(<$typeof(list2), $typeof(cmp), $typeof(context)>)(list2, 0, list.len, cmp, context); + is::isort{$typeof(list2), $typeof(cmp), $typeof(context)}(list2, 0, list.len, cmp, context); $else usz len = sort::len_from_list(list); - is::isort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len, cmp, context); + is::isort{$typeof(list), $typeof(cmp), $typeof(context)}(list, 0, (isz)len, cmp, context); $endif } -module std::sort::is(); +module std::sort::is{Type, CmpFn, Context}; def ElementType = $typeof(((Type){})[0]); diff --git a/lib7/std/sort/quicksort.c3 b/lib7/std/sort/quicksort.c3 index 1dcb22d85..ca7e77eb2 100644 --- a/lib7/std/sort/quicksort.c3 +++ b/lib7/std/sort/quicksort.c3 @@ -11,10 +11,10 @@ macro quicksort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @built { $if @typekind(list) == POINTER &&& (@typekind(*list) == ARRAY || @typekind(*list) == VECTOR): $typeof((*list)[0])[] list2 = list; - qs::qsort(<$typeof(list2), $typeof(cmp), $typeof(context)>)(list2, 0, (isz)list.len - 1, cmp, context); + qs::qsort{$typeof(list2), $typeof(cmp), $typeof(context)}(list2, 0, (isz)list.len - 1, cmp, context); $else usz len = sort::len_from_list(list); - qs::qsort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len - 1, cmp, context); + qs::qsort{$typeof(list), $typeof(cmp), $typeof(context)}(list, 0, (isz)len - 1, cmp, context); $endif } @@ -30,10 +30,10 @@ list will be partially sorted. macro quickselect(list, isz k, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin { usz len = sort::len_from_list(list); - return qs::qselect(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len - 1, k, cmp, context); + return qs::qselect{$typeof(list), $typeof(cmp), $typeof(context)}(list, 0, (isz)len - 1, k, cmp, context); } -module std::sort::qs(); +module std::sort::qs{Type, CmpFn, Context}; def ElementType = $typeof(((Type){})[0]); diff --git a/lib7/std/threads/buffered_channel.c3 b/lib7/std/threads/buffered_channel.c3 index b9b23c9f5..2d53c1f4d 100644 --- a/lib7/std/threads/buffered_channel.c3 +++ b/lib7/std/threads/buffered_channel.c3 @@ -1,4 +1,4 @@ -module std::thread::channel(); +module std::thread::channel{Type}; distinct BufferedChannel = void*; @@ -21,12 +21,7 @@ struct BufferedChannelImpl @private Type[?] buf; } -fn void! BufferedChannel.new_init(&self, usz size = 1) -{ - return self.init(size, allocator::heap()); -} - -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/lib7/std/threads/pool.c3 b/lib7/std/threads/pool.c3 index df80a7d30..55afb6c07 100644 --- a/lib7/std/threads/pool.c3 +++ b/lib7/std/threads/pool.c3 @@ -1,4 +1,4 @@ -module std::thread::pool(); +module std::thread::pool{SIZE}; import std::thread; struct ThreadPool diff --git a/lib7/std/threads/unbuffered_channel.c3 b/lib7/std/threads/unbuffered_channel.c3 index c27321a2b..a17bf748d 100644 --- a/lib7/std/threads/unbuffered_channel.c3 +++ b/lib7/std/threads/unbuffered_channel.c3 @@ -1,4 +1,4 @@ -module std::thread::channel(); +module std::thread::channel{Type}; distinct UnbufferedChannel = void*; @@ -18,8 +18,6 @@ struct UnbufferedChannelImpl @private ConditionVariable read_cond; } -fn void! UnbufferedChannel.new_init(&self) => self.init(allocator::heap()); - fn void! UnbufferedChannel.init(&self, Allocator allocator) { UnbufferedChannelImpl* channel = allocator::alloc(allocator, UnbufferedChannelImpl); diff --git a/test/unit7/stdlib/compression/qoi.c3 b/test/unit7/stdlib/compression/qoi.c3 index a3f8a8a9a..0b6aca4e3 100644 --- a/test/unit7/stdlib/compression/qoi.c3 +++ b/test/unit7/stdlib/compression/qoi.c3 @@ -15,20 +15,20 @@ fn void test_qoi_all() QOIDesc test_desc; // decode the test data - char[] decoded = qoi::new_decode(TEST_QOI_DATA[..], &test_desc)!!; + char[] decoded = qoi::decode(mem, TEST_QOI_DATA[..], &test_desc)!!; defer free(decoded); assert(test_desc.width == 340 && test_desc.height == 169, "Expected resolution of 340x169"); // encode the decoded data - char[] encoded = qoi::new_encode(decoded, &test_desc)!!; + char[] encoded = qoi::encode(mem, decoded, &test_desc)!!; assert(encoded == TEST_QOI_DATA[..], "Encoder output should match the test data"); defer free(encoded); // encode and write the decoded data to a file usz written = qoi::write("unittest.qoi", decoded, &test_desc)!!; // read and decode the written data - char[] read = qoi::new_read("unittest.qoi", &test_desc)!!; + char[] read = qoi::read(mem, "unittest.qoi", &test_desc)!!; assert(read == decoded, "Read data should match the decoded data"); // cleanup diff --git a/test/unit7/stdlib/core/array.c3 b/test/unit7/stdlib/core/array.c3 index b5c3502cc..2342209e0 100644 --- a/test/unit7/stdlib/core/array.c3 +++ b/test/unit7/stdlib/core/array.c3 @@ -21,12 +21,12 @@ fn void find_subarray() fn void concat() { int[3] a = { 1, 2, 3 }; - free(array::concat_new(a, a)); - free(array::concat_new(a[..], a[..])); - free(array::concat_new(a[:0], a[:0])); - free(array::concat_new((int[2]) { 1, 2 }, a[:0])); - free(array::concat_new(a[:0], (int[2]) { 1, 2 })); - int[] c = array::concat_new(a[1..2], a); + free(array::concat(mem, a, a)); + free(array::concat(mem, a[..], a[..])); + free(array::concat(mem, a[:0], a[:0])); + free(array::concat(mem, (int[2]) { 1, 2 }, a[:0])); + free(array::concat(mem, a[:0], (int[2]) { 1, 2 })); + int[] c = array::concat(mem, a[1..2], a); defer free(c); assert (c == (int[]){ 2, 3, 1, 2, 3 }); } diff --git a/test/unit7/stdlib/encoding/base32.c3 b/test/unit7/stdlib/encoding/base32.c3 index fe6b3b960..f850231a7 100644 --- a/test/unit7/stdlib/encoding/base32.c3 +++ b/test/unit7/stdlib/encoding/base32.c3 @@ -98,10 +98,10 @@ fn void base32_api() { foreach (t : std_tests) { - String got = base32::encode_temp(t.dec)!!; + String got = base32::tencode(t.dec)!!; assert(got == t.enc, "got: %s, want: %s", got, t.enc); - char[] got_chars = base32::decode_temp(t.enc)!!; + char[] got_chars = base32::tdecode(t.enc)!!; assert(got_chars == t.dec, "got: %s, want: %s", got_chars, t.dec); } }; diff --git a/test/unit7/stdlib/net/inetaddr.c3 b/test/unit7/stdlib/net/inetaddr.c3 index 6c8572302..af938af6c 100644 --- a/test/unit7/stdlib/net/inetaddr.c3 +++ b/test/unit7/stdlib/net/inetaddr.c3 @@ -12,21 +12,21 @@ fn void test_ipv4() fn void test_ipv4_to_string() { InetAddress a = net::ipv4_from_str("127.0.0.1")!!; - assert(a.to_new_string(allocator::temp()) == "127.0.0.1"); + assert(a.to_tstring() == "127.0.0.1"); } fn void test_ipv6_to_string() { InetAddress a = net::ipv6_from_str("2001:db8::2:1")!!; - free(a.to_new_string()); + free(a.to_string(mem)); - assert(a.to_new_string(allocator::temp()) == "2001:0db8:0000:0000:0000:0000:0002:0001"); - assert(net::ipv6_from_str("2001:db8::1").to_new_string(allocator::temp())!! == "2001:0db8:0000:0000:0000:0000:0000:0001"); - assert(net::ipv6_from_str("::1").to_new_string(allocator::temp())!! == "0000:0000:0000:0000:0000:0000:0000:0001"); - assert(net::ipv6_from_str("2001::1").to_new_string(allocator::temp())!! == "2001:0000:0000:0000:0000:0000:0000:0001"); - assert(net::ipv6_from_str("2001:db8:1234::").to_new_string(allocator::temp())!! == "2001:0db8:1234:0000:0000:0000:0000:0000"); - assert(net::ipv6_from_str("2001::").to_new_string(allocator::temp())!! == "2001:0000:0000:0000:0000:0000:0000:0000"); - assert(net::ipv6_from_str("::").to_new_string(allocator::temp())!! == "0000:0000:0000:0000:0000:0000:0000:0000"); + assert(a.to_tstring() == "2001:0db8:0000:0000:0000:0000:0002:0001"); + assert(net::ipv6_from_str("2001:db8::1").to_tstring()!! == "2001:0db8:0000:0000:0000:0000:0000:0001"); + assert(net::ipv6_from_str("::1").to_tstring()!! == "0000:0000:0000:0000:0000:0000:0000:0001"); + assert(net::ipv6_from_str("2001::1").to_tstring()!! == "2001:0000:0000:0000:0000:0000:0000:0001"); + assert(net::ipv6_from_str("2001:db8:1234::").to_tstring()!! == "2001:0db8:1234:0000:0000:0000:0000:0000"); + assert(net::ipv6_from_str("2001::").to_tstring()!! == "2001:0000:0000:0000:0000:0000:0000:0000"); + assert(net::ipv6_from_str("::").to_tstring()!! == "0000:0000:0000:0000:0000:0000:0000:0000"); } fn void test_ipv4_parse() diff --git a/test/unit7/stdlib/threads/channel.c3 b/test/unit7/stdlib/threads/channel.c3 index 90b55d05a..bf7f8876c 100644 --- a/test/unit7/stdlib/threads/channel.c3 +++ b/test/unit7/stdlib/threads/channel.c3 @@ -10,7 +10,7 @@ fn void init_destroy_buffered() @test for (usz i = 0; i < 20; i++) { BufferedChannel{int} c; - c.new_init(1)!!; + c.init(mem, 1)!!; defer c.destroy()!!; } } @@ -20,7 +20,7 @@ fn void init_destroy_unbuffered() @test for (usz i = 0; i < 20; i++) { UnbufferedChannel{int} c; - c.new_init()!!; + c.init(mem)!!; defer c.destroy()!!; } } @@ -28,7 +28,7 @@ fn void init_destroy_unbuffered() @test fn void push_to_buffered_channel_no_lock() @test { BufferedChannel{int} c; - c.new_init(1)!!; + c.init(mem, 1)!!; defer c.destroy()!!; c.push(1)!!; @@ -37,7 +37,7 @@ fn void push_to_buffered_channel_no_lock() @test fn void push_pop_buffered_no_locks() @test { BufferedChannel{int} c; - c.new_init(1)!!; + c.init(mem, 1)!!; defer c.destroy()!!; c.push(123)!!; @@ -48,7 +48,7 @@ fn void push_pop_buffered_no_locks() @test fn void push_pop_unbuffered_with_locks() @test { UnbufferedChannel{int} c; - c.new_init()!!; + c.init(mem)!!; defer c.destroy()!!; Thread thread; @@ -71,7 +71,7 @@ fn void push_pop_unbuffered_with_locks() @test fn void sending_to_closed_unbuffered_chan_is_forbidden() @test { UnbufferedChannel{int} c; - c.new_init()!!; + c.init(mem, )!!; defer c.destroy()!!; c.close()!!; @@ -87,7 +87,7 @@ fn void sending_to_closed_unbuffered_chan_is_forbidden() @test fn void sending_to_closed_buffered_chan_is_forbidden() @test { BufferedChannel{int} c; - c.new_init(1)!!; + c.init(mem, 1)!!; defer c.destroy()!!; c.close()!!; @@ -103,7 +103,7 @@ fn void sending_to_closed_buffered_chan_is_forbidden() @test fn void reading_from_empty_closed_unbuffered_chan_is_forbidden() @test { UnbufferedChannel{int} c; - c.new_init()!!; + c.init(mem, )!!; defer c.destroy()!!; c.close()!!; @@ -119,7 +119,7 @@ fn void reading_from_empty_closed_unbuffered_chan_is_forbidden() @test fn void reading_from_empty_closed_buffered_chan_is_forbidden() @test { BufferedChannel{int} c; - c.new_init(1)!!; + c.init(mem, 1)!!; defer c.destroy()!!; c.close()!!; @@ -135,7 +135,7 @@ fn void reading_from_empty_closed_buffered_chan_is_forbidden() @test fn void reading_from_non_empty_closed_buffered_chan_is_ok() @test { BufferedChannel{int} c; - c.new_init(3)!!; + c.init(mem, 3)!!; defer c.destroy()!!; c.push(1)!!; @@ -164,7 +164,7 @@ fn void reading_from_non_empty_closed_buffered_chan_is_ok() @test fn void reading_from_empty_buffered_chan_aborted_by_close() @test { BufferedChannel{int} c; - c.new_init(3)!!; + c.init(mem, 3)!!; defer c.destroy()!!; Thread thread; @@ -190,7 +190,7 @@ fn void reading_from_empty_buffered_chan_aborted_by_close() @test fn void reading_from_unbuffered_chan_aborted_by_close() @test { UnbufferedChannel{int} c; - c.new_init()!!; + c.init(mem, )!!; defer c.destroy()!!; Thread thread; @@ -216,7 +216,7 @@ fn void reading_from_unbuffered_chan_aborted_by_close() @test fn void sending_to_full_buffered_chan_aborted_by_close() @test { BufferedChannel{int} c; - c.new_init(1)!!; + c.init(mem, 1)!!; defer c.destroy()!!; c.push(1)!!; @@ -244,7 +244,7 @@ fn void sending_to_full_buffered_chan_aborted_by_close() @test fn void sending_to_unbuffered_chan_aborted_by_close() @test { UnbufferedChannel{int} c; - c.new_init()!!; + c.init(mem, )!!; defer c.destroy()!!; Thread thread; @@ -270,7 +270,7 @@ fn void sending_to_unbuffered_chan_aborted_by_close() @test fn void multiple_actions_unbuffered() @test { UnbufferedChannel{int} c; - c.new_init()!!; + c.init(mem, )!!; defer c.destroy()!!; Thread thread; @@ -304,7 +304,7 @@ fn void multiple_actions_unbuffered() @test fn void multiple_actions_buffered() @test { BufferedChannel{int} c; - c.new_init(10)!!; + c.init(mem, 10)!!; defer c.destroy()!!; Thread thread;