From df77b692d6869431a57174c1a8b97b0e7c8cc712 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 14 Feb 2023 16:36:48 +0100 Subject: [PATCH] Support "typedef" --- lib/std/collections/enumset.c3 | 14 +- lib/std/collections/priorityqueue.c3 | 2 +- lib/std/core/allocators/dynamic_arena.c3 | 10 +- lib/std/core/allocators/heap_allocator.c3 | 2 +- lib/std/core/allocators/temp_allocator.c3 | 18 +- lib/std/core/builtin.c3 | 2 +- lib/std/core/cinterop.c3 | 60 ++-- lib/std/core/mem_allocator.c3 | 2 +- lib/std/core/runtime.c3 | 2 +- lib/std/core/str.c3 | 8 +- lib/std/core/string.c3 | 10 +- lib/std/hash/fnv32a.c3 | 2 +- lib/std/io/dir.c3 | 2 +- lib/std/io/io_printf.c3 | 13 +- lib/std/libc/libc.c3 | 22 +- lib/std/math/math.c3 | 20 +- lib/std/math/math_vector.c3 | 12 +- lib/std/net/os/posix.c3 | 2 +- lib/std/net/os/win32.c3 | 2 +- lib/std/os/macos/cf_allocator.c3 | 6 +- lib/std/os/macos/cf_array.c3 | 6 +- lib/std/os/macos/core_foundation.c3 | 4 +- lib/std/os/macos/objc.c3 | 8 +- lib/std/os/win32/types.c3 | 334 +++++++++--------- lib/std/threads/os/thread_none.c3 | 8 +- lib/std/threads/os/thread_posix.c3 | 36 +- lib/std/threads/os/thread_win32.c3 | 6 +- lib/std/threads/thread.c3 | 14 +- src/compiler/enums.h | 1 + src/compiler/parse_global.c | 26 +- src/compiler/parse_stmt.c | 1 + src/compiler/tokens.c | 2 + src/version.h | 2 +- test/test_suite/abi/aarch64_hfa_args.c3t | 4 +- test/test_suite/abi/darwin64_avx.c3t | 8 +- test/test_suite/abi/darwin64_avx512.c3t | 4 +- test/test_suite/abi/darwin64_sse.c3t | 4 +- test/test_suite/abi/darwinx64_2.c3t | 8 +- test/test_suite/abi/riscv64-lp64-abi.c3t | 2 +- .../invalid_bitstruct_member_types.c3 | 4 +- test/test_suite/clang/2002-01_02.c3t | 2 +- test/test_suite/clang/2002-07.c3t | 2 +- .../compile_time_access_subscript.c3t | 2 +- .../compile_time/ct_switch_type_errors.c3 | 4 +- .../compile_time/ternary_folding.c3t | 2 +- test/test_suite/define/common.c3 | 2 +- test/test_suite/define/define_name_errors.c3 | 12 +- test/test_suite/define/forbidden_defines.c3 | 6 +- test/test_suite/distinct/distinct_invalid.c3 | 6 +- test/test_suite/distinct/distinct_slicing.c3 | 2 +- test/test_suite/distinct/distinct_struct.c3 | 2 +- .../distinct/distinct_struct_array.c3 | 6 +- test/test_suite/distinct/distinct_union.c3 | 6 +- test/test_suite/distinct/test_errors.c3 | 2 +- test/test_suite/distinct/test_ops_on_int.c3 | 2 +- .../test_suite/distinct/test_ops_on_struct.c3 | 2 +- .../errors/general_error_regression.c3t | 2 +- test/test_suite/expressions/addr_of_fails.c3 | 4 +- test/test_suite/expressions/assignability.c3 | 2 +- .../expressions/bool_conversions.c3t | 2 +- .../expressions/casts/cast_enum_to_various.c3 | 2 +- .../expressions/casts/cast_func_to_various.c3 | 6 +- .../expressions/casts/cast_unknown.c3 | 2 +- .../expressions/casts/explicit_cast.c3 | 6 +- .../casts/struct_cast_and_distinct.c3 | 2 +- .../from_docs/examples_functionpointer.c3t | 2 +- test/test_suite/from_docs/examples_struct.c3 | 2 +- .../functions/func_ptr_conversion_alias.c3t | 8 +- .../func_ptr_conversions_and_names.c3t | 6 +- test/test_suite/functions/naked_function.c3t | 2 +- test/test_suite/functions/test_regression.c3t | 16 +- .../functions/test_regression_mingw.c3t | 16 +- test/test_suite/functions/too_many_params.c3 | 2 +- test/test_suite/generic/enum_set_test.c3t | 2 +- test/test_suite/generic/generic_cyclic.c3 | 2 +- test/test_suite/generic/generic_recursion.c3t | 2 +- test/test_suite/lambda/lambda_in_macro.c3t | 4 +- test/test_suite/lambda/nested_lambda_def.c3t | 2 +- test/test_suite/lambda/simple_lambda.c3t | 2 +- test/test_suite/macros/type_params.c3t | 2 +- test/test_suite/methods/access.c3 | 2 +- .../methods/enum_distinct_err_methods.c3t | 2 +- .../methods/extension_method_generic.c3 | 2 +- test/test_suite/overloading/set_overload.c3t | 2 +- test/test_suite/statements/default_args.c3 | 4 +- .../statements/foreach_custom_errors.c3 | 2 +- .../statements/foreach_r_custom_errors.c3 | 2 +- test/test_suite/stdlib/map.c3t | 4 +- test/test_suite/stdlib/priorityqueue.c3t | 2 +- test/test_suite/struct/member_expr.c3 | 4 +- test/test_suite/struct/zero_member.c3 | 2 +- test/test_suite/symbols/shadow_struct.c3 | 4 +- test/test_suite/symbols/various.c3 | 2 +- test/test_suite/types/enum_inference.c3 | 2 +- test/test_suite/types/enum_ok.c3 | 2 +- test/test_suite/types/recursive_typedef.c3 | 12 +- test/test_suite/types/redefinition.c3 | 4 +- test/test_suite/types/typedefs.c3 | 2 +- test/unit/stdlib/collections/linkedlist.c3 | 2 +- 99 files changed, 468 insertions(+), 441 deletions(-) diff --git a/lib/std/collections/enumset.c3 b/lib/std/collections/enumset.c3 index f7eb08080..f042db38e 100644 --- a/lib/std/collections/enumset.c3 +++ b/lib/std/collections/enumset.c3 @@ -5,24 +5,24 @@ $assert(Enum.elements < 64, "Maximum number of elements for an enum used as enum $switch ($$C_INT_SIZE): $case 64: - define EnumSetType @private = ulong; + typedef EnumSetType @private = ulong; $case 32: $if (Enum.elements < 32): - define EnumSetType @private = uint; +typedef EnumSetType @private = uint; $else: - define EnumSetType @private = ulong; +typedef EnumSetType @private = ulong; $endif; $default: $if (Enum.elements < 16): - define EnumSetType @private = ushort; +typedef EnumSetType @private = ushort; $elif (Enum.elements < 31): - define EnumSetType @private = uint; +typedef EnumSetType @private = uint; $else: - define EnumSetType @private = ulong; +typedef EnumSetType @private = ulong; $endif; $endswitch; -define EnumSet = distinct EnumSetType; +typedef EnumSet = distinct EnumSetType; fn void EnumSet.add(EnumSet* this, Enum v) { diff --git a/lib/std/collections/priorityqueue.c3 b/lib/std/collections/priorityqueue.c3 index 92fac6a58..e6c2b9828 100644 --- a/lib/std/collections/priorityqueue.c3 +++ b/lib/std/collections/priorityqueue.c3 @@ -23,7 +23,7 @@ module std::collections::priorityqueue; import std::collections::list; -define Heap = List; +typedef Heap = List; struct PriorityQueue { diff --git a/lib/std/core/allocators/dynamic_arena.c3 b/lib/std/core/allocators/dynamic_arena.c3 index 41d73a167..9cd8d8de0 100644 --- a/lib/std/core/allocators/dynamic_arena.c3 +++ b/lib/std/core/allocators/dynamic_arena.c3 @@ -1,6 +1,6 @@ module std::core::mem::allocator; -struct DynamicArenaPage @private +struct DynamicArenaPage @local { void* memory; void* prev_arena; @@ -9,7 +9,7 @@ struct DynamicArenaPage @private void* last_ptr; } -struct DynamicArenaChunk @private +struct DynamicArenaChunk @local { usz size; } @@ -32,7 +32,7 @@ fn void DynamicArenaAllocator.free(DynamicArenaAllocator* this, void* ptr) @priv * @require old_pointer && size > 0 * @require this.page `tried to realloc pointer on invalid allocator` */ -fn void*! DynamicArenaAllocator._realloc(DynamicArenaAllocator* this, void* old_pointer, usz size, usz alignment, usz offset) @private +fn void*! DynamicArenaAllocator._realloc(DynamicArenaAllocator* this, void* old_pointer, usz size, usz alignment, usz offset) @local { DynamicArenaPage* current_page = this.page; alignment = alignment_for_allocation(alignment); @@ -82,7 +82,7 @@ fn void DynamicArenaAllocator.reset(DynamicArenaAllocator* this) @private * @require math::is_power_of_2(alignment) * @require size > 0 */ -fn void*! DynamicArenaAllocator._alloc_new(DynamicArenaAllocator* this, usz size, usz alignment, usz offset) @private +fn void*! DynamicArenaAllocator._alloc_new(DynamicArenaAllocator* this, usz size, usz alignment, usz offset) @local { // First, make sure that we can align it, extending the page size if needed. usz page_size = max(this.page_size, mem::aligned_offset(size + DynamicArenaChunk.sizeof + offset, alignment) - offset); @@ -113,7 +113,7 @@ fn void*! DynamicArenaAllocator._alloc_new(DynamicArenaAllocator* this, usz size * @require size > 0 * @require this */ -fn void*! DynamicArenaAllocator._alloc(DynamicArenaAllocator* this, usz size, usz alignment, usz offset) @private +fn void*! DynamicArenaAllocator._alloc(DynamicArenaAllocator* this, usz size, usz alignment, usz offset) @local { alignment = alignment_for_allocation(alignment); DynamicArenaPage* page = this.page; diff --git a/lib/std/core/allocators/heap_allocator.c3 b/lib/std/core/allocators/heap_allocator.c3 index 9e45caa47..343b78132 100644 --- a/lib/std/core/allocators/heap_allocator.c3 +++ b/lib/std/core/allocators/heap_allocator.c3 @@ -1,6 +1,6 @@ module std::core::mem::allocator; -define MemoryAllocFn = fn char[]!(usz); +typedef MemoryAllocFn = fn char[]!(usz); struct SimpleHeapAllocator { diff --git a/lib/std/core/allocators/temp_allocator.c3 b/lib/std/core/allocators/temp_allocator.c3 index 044046890..702c95661 100644 --- a/lib/std/core/allocators/temp_allocator.c3 +++ b/lib/std/core/allocators/temp_allocator.c3 @@ -1,7 +1,7 @@ module std::core::mem::allocator; import std::io; -struct TempAllocatorChunk @private +struct TempAllocatorChunk @local { usz size; char[*] data; @@ -31,8 +31,8 @@ struct TempAllocatorPage char[*] data; } -macro usz TempAllocatorPage.pagesize(TempAllocatorPage* page) { return page.size & ~PAGE_IS_ALIGNED; } -macro bool TempAllocatorPage.is_aligned(TempAllocatorPage* page) { return page.size & PAGE_IS_ALIGNED == PAGE_IS_ALIGNED; } +macro usz TempAllocatorPage.pagesize(TempAllocatorPage* page) => page.size & ~PAGE_IS_ALIGNED; +macro bool TempAllocatorPage.is_aligned(TempAllocatorPage* page) => page.size & PAGE_IS_ALIGNED == PAGE_IS_ALIGNED; /** * @require size >= 16 @@ -86,7 +86,7 @@ fn void*! temp_allocator_function(Allocator* data, usz size, usz alignment, usz unreachable(); } -fn void! TempAllocator._free(TempAllocator* this, void* old_pointer) @private +fn void! TempAllocator._free(TempAllocator* this, void* old_pointer) @local { // TODO fix free assert((uptr)old_pointer >= (uptr)&this.data, "Pointer originates from a different allocator."); @@ -96,7 +96,7 @@ fn void! TempAllocator._free(TempAllocator* this, void* old_pointer) @private this.used -= old_size; } } -fn void! TempAllocator._reset(TempAllocator* this, usz mark) @private +fn void! TempAllocator._reset(TempAllocator* this, usz mark) @local { TempAllocatorPage *last_page = this.last_page; while (last_page && last_page.mark > mark) @@ -109,14 +109,14 @@ fn void! TempAllocator._reset(TempAllocator* this, usz mark) @private this.used = mark; } -fn void! TempAllocator._free_page(TempAllocator* this, TempAllocatorPage* page) @inline @private +fn void! TempAllocator._free_page(TempAllocator* this, TempAllocatorPage* page) @inline @local { void* mem = page.start; if (page.is_aligned()) return this.backing_allocator.free_aligned(mem); return this.backing_allocator.free(mem); } -fn void*! TempAllocator._realloc_page(TempAllocator* this, TempAllocatorPage* page, usz size, usz alignment, usz offset) @inline @private +fn void*! TempAllocator._realloc_page(TempAllocator* this, TempAllocatorPage* page, usz size, usz alignment, usz offset) @inline @local { // Then the actual start pointer: void* real_pointer = page.start; @@ -144,7 +144,7 @@ fn void*! TempAllocator._realloc_page(TempAllocator* this, TempAllocatorPage* pa return data; } -fn void*! TempAllocator._realloc(TempAllocator* this, void* pointer, usz size, usz alignment, usz offset) @inline @private +fn void*! TempAllocator._realloc(TempAllocator* this, void* pointer, usz size, usz alignment, usz offset) @inline @local { TempAllocatorChunk *chunk = pointer - TempAllocatorChunk.sizeof; if (chunk.size == (usz)-1) @@ -170,7 +170,7 @@ fn void*! TempAllocator._realloc(TempAllocator* this, void* pointer, usz size, u * @require alignment <= MAX_MEMORY_ALIGNMENT `alignment too big` * @require this != null **/ -fn void*! TempAllocator._alloc(TempAllocator* this, usz size, usz alignment, usz offset, bool clear) @private +fn void*! TempAllocator._alloc(TempAllocator* this, usz size, usz alignment, usz offset, bool clear) @local { void* start_mem = &this.data; void* starting_ptr = start_mem + this.used; diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index b12a8fa3f..8016bad12 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -88,7 +88,7 @@ fn void default_panic(String message, String file, String function, uint line) $$trap(); } -define PanicFn = fn void(String message, String file, String function, uint line); +typedef PanicFn = fn void(String message, String file, String function, uint line); PanicFn panic = &default_panic; diff --git a/lib/std/core/cinterop.c3 b/lib/std/core/cinterop.c3 index 1fc6c2cc3..9445d7b43 100644 --- a/lib/std/core/cinterop.c3 +++ b/lib/std/core/cinterop.c3 @@ -18,70 +18,70 @@ $assert (C_LONG_SIZE <= C_LONG_LONG_SIZE); $switch ($$C_INT_SIZE): $case 64: - define CInt = long; - define CUInt = ulong; + typedef CInt = long; + typedef CUInt = ulong; $case 32: - define CInt = int; - define CUInt = uint; + typedef CInt = int; + typedef CUInt = uint; $case 16: - define CInt = short; - define CUInt = ushort; + typedef CInt = short; + typedef CUInt = ushort; $default: $assert(false, "Invalid C int size"); $endswitch; $switch ($$C_LONG_SIZE): $case 64: - define CLong = long; - define CULong = ulong; + typedef CLong = long; + typedef CULong = ulong; $case 32: - define CLong = int; - define CULong = uint; + typedef CLong = int; + typedef CULong = uint; $case 16: - define CLong = short; - define CULong = ushort; + typedef CLong = short; + typedef CULong = ushort; $default: $assert(false, "Invalid C long size"); $endswitch; $switch ($$C_SHORT_SIZE): $case 32: - define CShort = int; - define CUShort = uint; + typedef CShort = int; + typedef CUShort = uint; $case 16: - define CShort = short; - define CUShort = ushort; + typedef CShort = short; + typedef CUShort = ushort; $case 8: - define CShort = ichar; - define CUShort = char; + typedef CShort = ichar; + typedef CUShort = char; $default: $assert(false, "Invalid C short size"); $endswitch; $switch ($$C_LONG_LONG_SIZE): $case 128: - define CLongLong = int128; - define CULongLong = uint128; + typedef CLongLong = int128; + typedef CULongLong = uint128; $case 64: - define CLongLong = long; - define CULongLong = ulong; + typedef CLongLong = long; + typedef CULongLong = ulong; $case 32: - define CLongLong = int; - define CULongLong = uint; + typedef CLongLong = int; + typedef CULongLong = uint; $case 16: - define CLongLong = short; - define CULongLong = ushort; + typedef CLongLong = short; + typedef CULongLong = ushort; $default: $assert(false, "Invalid C long long size"); $endswitch; -define CSChar = ichar; -define CUChar = char; +typedef CSChar = ichar; +typedef CUChar = char; $if ($$C_CHAR_IS_SIGNED): - define CChar = ichar; + typedef CChar = ichar; $else: - define CChar = char; + typedef CChar = char; $endif; diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index de60e7954..c7e10361f 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -8,7 +8,7 @@ const DEFAULT_SIZE_PREFIX_ALIGNMENT = usz.alignof; const Allocator* NULL_ALLOCATOR = &_NULL_ALLOCATOR; const Allocator* LIBC_ALLOCATOR = &_SYSTEM_ALLOCATOR; -define AllocatorFunction = fn void*!(Allocator* allocator, usz new_size, usz alignment, usz offset, void* old_pointer, AllocationKind kind); +typedef AllocatorFunction = fn void*!(Allocator* allocator, usz new_size, usz alignment, usz offset, void* old_pointer, AllocationKind kind); struct Allocator { diff --git a/lib/std/core/runtime.c3 b/lib/std/core/runtime.c3 index cb6181289..7e5ff9174 100644 --- a/lib/std/core/runtime.c3 +++ b/lib/std/core/runtime.c3 @@ -28,7 +28,7 @@ struct VarArrayHeader void *allocator; } -define TestFn = fn void!(); +typedef TestFn = fn void!(); struct TestRunner { diff --git a/lib/std/core/str.c3 b/lib/std/core/str.c3 index 0e2673d35..18b59b6ef 100644 --- a/lib/std/core/str.c3 +++ b/lib/std/core/str.c3 @@ -1,9 +1,9 @@ module std::core::str; -define ZString = distinct char*; -define String = char[]; -define Char32 = uint; -define Char16 = ushort; +typedef ZString = distinct char*; +typedef String = char[]; +typedef Char32 = uint; +typedef Char16 = ushort; const uint SURROGATE_OFFSET @private = 0x10000; const uint SURROGATE_GENERIC_MASK @private = 0xF800; diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 977359251..07920ac56 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -1,11 +1,11 @@ module std::core::string; import libc; -define VarString = distinct void*; -define DynStr = VarString; -define DynString = VarString; -define DString = VarString; -define VString = VarString; +typedef VarString = distinct void*; +typedef DynStr = VarString; +typedef DynString = VarString; +typedef DString = VarString; +typedef VString = VarString; const usz MIN_CAPACITY = 16; diff --git a/lib/std/hash/fnv32a.c3 b/lib/std/hash/fnv32a.c3 index 8b5c4ae2b..8f1e12c7a 100644 --- a/lib/std/hash/fnv32a.c3 +++ b/lib/std/hash/fnv32a.c3 @@ -3,7 +3,7 @@ // a copy of which can be found in the LICENSE_STDLIB file. module std::hash::fnv32a; -define Fnv32a = distinct uint; +typedef Fnv32a = distinct uint; const FNV32A_START @private = 0x811c9dc5; const FNV32A_MUL @private = 0x01000193; diff --git a/lib/std/io/dir.c3 b/lib/std/io/dir.c3 index 8c85c7618..4d33d4afa 100644 --- a/lib/std/io/dir.c3 +++ b/lib/std/io/dir.c3 @@ -1,7 +1,7 @@ module std::io::dir; import std::io::os; // In progress. -define Path = distinct String; +typedef Path = distinct String; const PREFERRED_SEPARATOR = USE_WIN32_FILESYSTEM ? '\\' : '/'; const USE_WIN32_FILESYSTEM @private = env::OS_TYPE != OsType.WIN32; diff --git a/lib/std/io/io_printf.c3 b/lib/std/io/io_printf.c3 index 673c7608d..37545e19d 100644 --- a/lib/std/io/io_printf.c3 +++ b/lib/std/io/io_printf.c3 @@ -23,10 +23,10 @@ fault FormattingFault INVALID_FORMAT_TYPE, } -define OutputFn = fn void!(char c, void* buffer); -define ToStringFunction = fn String(void* value, Allocator *allocator); -define ToFormatFunction = fn void!(void* value, Formatter* formatter); -define FloatType = double; +typedef OutputFn = fn void!(char c, void* buffer); +typedef ToStringFunction = fn String(void* value, Allocator *allocator); +typedef ToFormatFunction = fn void!(void* value, Formatter* formatter); +typedef FloatType = double; fn usz! printf(String format, args...) @maydiscard { @@ -495,7 +495,8 @@ fn usz! Formatter.vprintf(Formatter* this, String format, variant[] variants) return this.idx; } -define StringFunctionMap = HashMap @private; -define FormatterFunctionMap = HashMap @private; +typedef StringFunctionMap = HashMap @private; +typedef FormatterFunctionMap = HashMap @private; + FormatterFunctionMap toformat_functions @private; StringFunctionMap tostring_functions @private; diff --git a/lib/std/libc/libc.c3 b/lib/std/libc/libc.c3 index 17a165444..7248a8d61 100644 --- a/lib/std/libc/libc.c3 +++ b/lib/std/libc/libc.c3 @@ -31,9 +31,9 @@ fn void errno_set(Errno e) os::errno_set((int)e); } -define TerminateFunction = fn void(); -define CompareFunction = fn int(void*, void*); -define JmpBuf = uptr[$$JMP_BUF_SIZE]; +typedef TerminateFunction = fn void(); +typedef CompareFunction = fn int(void*, void*); +typedef JmpBuf = uptr[$$JMP_BUF_SIZE]; $if (env::COMPILER_LIBC_AVAILABLE): @@ -147,8 +147,8 @@ $endif; // stdio -define Fpos = long; -define CFile = void*; +typedef Fpos = long; +typedef CFile = void*; $if (env::COMPILER_LIBC_AVAILABLE && env::OS_TYPE == OsType.LINUX): extern CFile __stdin @extern("stdin"); @@ -200,8 +200,8 @@ const int EOF = -1; const int FOPEN_MAX = 20; const int FILENAME_MAX = 1024; -define Errno = distinct CInt; -define SeekIndex = CLong; +typedef Errno = distinct CInt; +typedef SeekIndex = CLong; $if (env::COMPILER_LIBC_AVAILABLE): @@ -318,7 +318,7 @@ $endif; // time.h -define TimeOffset = CLong; +typedef TimeOffset = CLong; struct Tm { @@ -351,8 +351,8 @@ extern fn int nanosleep(TimeSpec* req, TimeSpec* remaining); const CLOCKS_PER_SEC = 1000000; // Time also needs to be per platform -define Time = long; -define Clock = ulong; +typedef Time = long; +typedef Clock = ulong; extern fn ZString asctime(Tm *timeptr); extern fn Clock clock(); @@ -365,7 +365,7 @@ extern fn usz strftime(char* str, usz maxsize, char* format, Tm *timeptr); extern fn Time time(Time *timer); // signal -define SignalFunction = fn void(int); +typedef SignalFunction = fn void(int); extern fn SignalFunction signal(int sig, SignalFunction function); // Incomplete diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index c34ce25fb..49f8afe13 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -85,22 +85,22 @@ fault MatrixError MATRIX_INVERSE_DOESNT_EXIST, } -define Complexf = Complex; -define Complex = Complex; +typedef Complexf = Complex; +typedef Complex = Complex; define complexf_identity = complex::identity; define complex_identity = complex::identity; -define Quaternionf = Quaternion; -define Quaternion = Quaternion; +typedef Quaternionf = Quaternion; +typedef Quaternion = Quaternion; define quaternionf_identity = quaternion::identity; define quaternion_identity = quaternion::identity; -define Matrix2f = Matrix2x2; -define Matrix2 = Matrix2x2; -define Matrix3f = Matrix3x3; -define Matrix3 = Matrix3x3; -define Matrix4f = Matrix4x4; -define Matrix4 = Matrix4x4; +typedef Matrix2f = Matrix2x2; +typedef Matrix2 = Matrix2x2; +typedef Matrix3f = Matrix3x3; +typedef Matrix3 = Matrix3x3; +typedef Matrix4f = Matrix4x4; +typedef Matrix4 = Matrix4x4; define matrix4_ortho = matrix::ortho; define matrix4_perspective = matrix::perspective; define matrix4f_ortho = matrix::ortho; diff --git a/lib/std/math/math_vector.c3 b/lib/std/math/math_vector.c3 index 544f85472..95a187865 100644 --- a/lib/std/math/math_vector.c3 +++ b/lib/std/math/math_vector.c3 @@ -1,13 +1,13 @@ module std::math::vector; import std::math; -define Vec2f = float[<2>]; -define Vec3f = float[<3>]; -define Vec4f = float[<4>]; +typedef Vec2f = float[<2>]; +typedef Vec3f = float[<3>]; +typedef Vec4f = float[<4>]; -define Vec2 = double[<2>]; -define Vec3 = double[<3>]; -define Vec4 = double[<4>]; +typedef Vec2 = double[<2>]; +typedef Vec3 = double[<3>]; +typedef Vec4 = double[<4>]; macro Vec2f.length_sq(Vec2f v) => v.dot(v); macro Vec3f.length_sq(Vec3f v) => v.dot(v); diff --git a/lib/std/net/os/posix.c3 b/lib/std/net/os/posix.c3 index 2d3341541..10a766522 100644 --- a/lib/std/net/os/posix.c3 +++ b/lib/std/net/os/posix.c3 @@ -6,7 +6,7 @@ $if (env::OS_TYPE != OsType.WIN32 && $defined(AddrInfo)): const int F_GETFL = 3; const int F_SETFL = 4; -define NativeSocket = distinct int; +typedef NativeSocket = distinct int; extern fn NativeSocket socket(int af, int type, int protocol) @extern("socket"); extern fn int getaddrinfo(ZString nodename, ZString servname, AddrInfo* hints, AddrInfo** res); diff --git a/lib/std/net/os/win32.c3 b/lib/std/net/os/win32.c3 index 3965c2171..1f30521dd 100644 --- a/lib/std/net/os/win32.c3 +++ b/lib/std/net/os/win32.c3 @@ -22,7 +22,7 @@ struct AddrInfo AddrInfo* ai_next; } -define NativeSocket = distinct uptr; +typedef NativeSocket = distinct uptr; extern fn int wsa_startup(int, void*) @extern("WSAStartup"); extern fn int ioctlsocket(NativeSocket, long cmd, ulong *argp); diff --git a/lib/std/os/macos/cf_allocator.c3 b/lib/std/os/macos/cf_allocator.c3 index 2c7e11e2b..3c362c11a 100644 --- a/lib/std/os/macos/cf_allocator.c3 +++ b/lib/std/os/macos/cf_allocator.c3 @@ -2,9 +2,9 @@ module std::os::macos::cf; $if (env::OS_TYPE == OsType.MACOSX): -define CFAllocatorRef = distinct void*; -define CFAllocatorContextRef = distinct void*; -define CFOptionFlags = usz; +typedef CFAllocatorRef = distinct void*; +typedef CFAllocatorContextRef = distinct void*; +typedef CFOptionFlags = usz; macro CFAllocatorRef default_allocator() => _macos_CFAllocatorGetDefault(); macro void CFAllocatorRef.dealloc(CFAllocatorRef allocator, void* ptr) => _macos_CFAllocatorDeallocate(allocator, ptr); diff --git a/lib/std/os/macos/cf_array.c3 b/lib/std/os/macos/cf_array.c3 index fe39b456a..ba9010272 100644 --- a/lib/std/os/macos/cf_array.c3 +++ b/lib/std/os/macos/cf_array.c3 @@ -2,9 +2,9 @@ module std::os::macos::cf; $if (env::OS_TYPE == OsType.MACOSX): -define CFArrayRef = distinct void*; -define CFArrayCallBacksRef = distinct void*; -define CFMutableArrayRef = distinct void*; +typedef CFArrayRef = distinct void*; +typedef CFArrayCallBacksRef = distinct void*; +typedef CFMutableArrayRef = distinct void*; extern fn CFArrayRef _macos_CFArrayCreate(CFAllocatorRef allocator, void** values, CFIndex num_values, CFArrayCallBacksRef callBacks) @extern("CFArrayCreate"); extern fn CFArrayRef _macos_CFArrayCopy(CFAllocatorRef allocator, CFArrayRef array) @extern("CFArrayCopy"); extern fn CFIndex _macos_CFArrayGetCount(CFArrayRef array) @extern("CFArrayGetCount"); diff --git a/lib/std/os/macos/core_foundation.c3 b/lib/std/os/macos/core_foundation.c3 index f44dd114c..791c2d01b 100644 --- a/lib/std/os/macos/core_foundation.c3 +++ b/lib/std/os/macos/core_foundation.c3 @@ -2,8 +2,8 @@ module std::os::macos::cf; $if (env::OS_TYPE == OsType.MACOSX): -define CFTypeRef = distinct void*; -define CFIndex = isz; +typedef CFTypeRef = distinct void*; +typedef CFIndex = isz; struct CFRange { CFIndex location; diff --git a/lib/std/os/macos/objc.c3 b/lib/std/os/macos/objc.c3 index d80d3d1ad..2b53922e5 100644 --- a/lib/std/os/macos/objc.c3 +++ b/lib/std/os/macos/objc.c3 @@ -2,10 +2,10 @@ module std::os::macos::objc; $if (env::OS_TYPE == OsType.MACOSX): -define Class = distinct void*; -define Method = distinct void*; -define Ivar = distinct void*; -define Selector = distinct void*; +typedef Class = distinct void*; +typedef Method = distinct void*; +typedef Ivar = distinct void*; +typedef Selector = distinct void*; fault ObjcFailure { diff --git a/lib/std/os/win32/types.c3 b/lib/std/os/win32/types.c3 index 978c9de35..cf52ceee3 100644 --- a/lib/std/os/win32/types.c3 +++ b/lib/std/os/win32/types.c3 @@ -1,172 +1,172 @@ module std::os::win32; -define Bool = int; -define Boolean = Byte; -define Byte = char; -define CChar = cinterop::CChar; -define Char = cinterop::CChar; -define Colorref = DWord; -define DWord = uint; -define DWordlong = ulong; -define DWordPtr = ULongPtr; -define DWord32 = uint; -define DWord64 = ulong; -define Float = float; -define HAccel = Handle; -define HalfPtr = int; -define Handle = PVoid; -define HBitmap = Handle; -define HBrush = Handle; -define HColorspace = Handle; -define HConv = Handle; -define HConvlist = Handle; -define HCursor = HIcon; -define HDc = Handle; -define HDDEdata = Handle; -define HDesk = Handle; -define HDrop = Handle; -define HDwp = Handle; -define HFile = int; -define HFont = Handle; -define HGdiobj = Handle; -define HGlobal = Handle; -define HHook = Handle; -define HIcon = Handle; -define HInstance = Handle; -define HKey = Handle; -define HKl = Handle; -define HLocal = Handle; -define HMenu = Handle; -define HMetafile = Handle; -define HModule = Handle; -define HMonitor = Handle; -define HPalette = Handle; -define HPen = Handle; -define HResult = Long; -define HRgn = Handle; -define HRsrc = Handle; -define HSz = Handle; -define HWinsta = Handle; -define HWnd = Handle; -define Int = int; -define IntPtr = iptr; -define Int8 = ichar; -define Int16 = short; -define Int32 = int; -define Int64 = long; -define Langid = Word; -define Lcid = DWord; -define Lctype = DWord; -define Lgrpid = DWord; -define Long = int; -define Longlong = long; -define LongPtr = iptr; -define Long32 = int; -define Long64 = long; -define LParam = LongPtr; -define LPBool = Bool*; -define LPByte = Byte*; -define LPColorref = DWord*; -define LPCStr = CChar*; -define LPCTstr = LPCWstr; -define LPCVoid = void*; -define LPCWstr = WChar*; -define LPDWord = DWord*; -define LPHandle = Handle*; -define LPInt = int*; -define LPLong = int*; -define LPStr = CChar*; -define LPTstr = LPWstr; -define LPVoid = void*; -define LPWord = Word*; -define LPWstr = WChar*; -define LResult = LongPtr; -define PBool = Bool*; -define PBoolean = Boolean*; -define PByte = Byte*; -define PChar = Char*; -define PCstr = Char*; -define PCTstr = LPCWstr; -define PCUnicodeString = UnicodeString*; -define PCWstr = Char16*; -define PDWord = DWord*; -define PDWordlong = DWordlong*; -define PDWordPtr = DWordPtr*; -define PDWord32 = DWord32*; -define PDWord64 = DWord64*; -define PFloat = Float*; -define PHalfPtr = HalfPtr*; -define PHandle = Handle*; -define PHKey = HKey*; -define PInt = int*; -define PIntPtr = IntPtr*; -define PInt8 = Int8*; -define PInt16 = Int16*; -define PInt32 = Int32*; -define PInt64 = Int64*; -define PLcid = PDWord; -define PLong = Long*; -define PLonglong = Longlong*; -define PLongPtr = LongPtr*; -define PLong32 = Long32*; -define PLong64 = Long64*; -define Pointer32 = uint; -define Pointer64 = uptr; -define PointerSigned = iptr; -define PointerUnsigned = uptr; -define PShort = Short*; -define PSizeT = usz*; -define PSSizeT = isz*; -define PStr = Char*; -define PTByte = TByte*; -define PTChar = TChar*; -define PTStr = LPWstr; -define PUChar = UChar*; -define PUHalfPtr = UHalfPtr*; -define PUInt = UInt*; -define PUIntPtr = UIntPtr*; -define PUInt8 = UInt8*; -define PUInt16 = UInt16*; -define PUInt32 = UInt32*; -define PUInt64 = UInt64*; -define PULong = ULong*; -define PULonglong = ULonglong*; -define PULongPtr = ULongPtr*; -define PULong32 = ULong32*; -define PULong64 = ULong64*; -define PUnicodeString = UnicodeString*; -define PUShort = UShort*; -define PVoid = void*; -define PWChar = WChar*; -define PWord = Word*; -define PWStr = WChar*; -define QWord = ulong; -define ScHandle = Handle; -define ScLong = LPVoid; -define ServiceStatusHandle = Handle; -define Short = short; -define SizeT = usz; -define SSizeT = isz; -define TByte = WChar; -define TChar = WChar; -define UChar = char; -define UHalfPtr = uint; -define UInt = uint; -define UIntPtr = uptr; -define UInt8 = char; -define UInt16 = ushort; -define UInt32 = uint; -define UInt64 = ulong; -define ULong = uint; -define ULonglong = ulong; -define ULongPtr = ulong; -define ULong32 = uint; -define ULong64 = ulong; -define UShort = ushort; -define Usn = Longlong; -define WChar = Char16; -define Word = ushort; -define WParam = UIntPtr; +typedef Bool = int; +typedef Boolean = Byte; +typedef Byte = char; +typedef CChar = cinterop::CChar; +typedef Char = cinterop::CChar; +typedef Colorref = DWord; +typedef DWord = uint; +typedef DWordlong = ulong; +typedef DWordPtr = ULongPtr; +typedef DWord32 = uint; +typedef DWord64 = ulong; +typedef Float = float; +typedef HAccel = Handle; +typedef HalfPtr = int; +typedef Handle = PVoid; +typedef HBitmap = Handle; +typedef HBrush = Handle; +typedef HColorspace = Handle; +typedef HConv = Handle; +typedef HConvlist = Handle; +typedef HCursor = HIcon; +typedef HDc = Handle; +typedef HDDEdata = Handle; +typedef HDesk = Handle; +typedef HDrop = Handle; +typedef HDwp = Handle; +typedef HFile = int; +typedef HFont = Handle; +typedef HGdiobj = Handle; +typedef HGlobal = Handle; +typedef HHook = Handle; +typedef HIcon = Handle; +typedef HInstance = Handle; +typedef HKey = Handle; +typedef HKl = Handle; +typedef HLocal = Handle; +typedef HMenu = Handle; +typedef HMetafile = Handle; +typedef HModule = Handle; +typedef HMonitor = Handle; +typedef HPalette = Handle; +typedef HPen = Handle; +typedef HResult = Long; +typedef HRgn = Handle; +typedef HRsrc = Handle; +typedef HSz = Handle; +typedef HWinsta = Handle; +typedef HWnd = Handle; +typedef Int = int; +typedef IntPtr = iptr; +typedef Int8 = ichar; +typedef Int16 = short; +typedef Int32 = int; +typedef Int64 = long; +typedef Langid = Word; +typedef Lcid = DWord; +typedef Lctype = DWord; +typedef Lgrpid = DWord; +typedef Long = int; +typedef Longlong = long; +typedef LongPtr = iptr; +typedef Long32 = int; +typedef Long64 = long; +typedef LParam = LongPtr; +typedef LPBool = Bool*; +typedef LPByte = Byte*; +typedef LPColorref = DWord*; +typedef LPCStr = CChar*; +typedef LPCTstr = LPCWstr; +typedef LPCVoid = void*; +typedef LPCWstr = WChar*; +typedef LPDWord = DWord*; +typedef LPHandle = Handle*; +typedef LPInt = int*; +typedef LPLong = int*; +typedef LPStr = CChar*; +typedef LPTstr = LPWstr; +typedef LPVoid = void*; +typedef LPWord = Word*; +typedef LPWstr = WChar*; +typedef LResult = LongPtr; +typedef PBool = Bool*; +typedef PBoolean = Boolean*; +typedef PByte = Byte*; +typedef PChar = Char*; +typedef PCstr = Char*; +typedef PCTstr = LPCWstr; +typedef PCUnicodeString = UnicodeString*; +typedef PCWstr = Char16*; +typedef PDWord = DWord*; +typedef PDWordlong = DWordlong*; +typedef PDWordPtr = DWordPtr*; +typedef PDWord32 = DWord32*; +typedef PDWord64 = DWord64*; +typedef PFloat = Float*; +typedef PHalfPtr = HalfPtr*; +typedef PHandle = Handle*; +typedef PHKey = HKey*; +typedef PInt = int*; +typedef PIntPtr = IntPtr*; +typedef PInt8 = Int8*; +typedef PInt16 = Int16*; +typedef PInt32 = Int32*; +typedef PInt64 = Int64*; +typedef PLcid = PDWord; +typedef PLong = Long*; +typedef PLonglong = Longlong*; +typedef PLongPtr = LongPtr*; +typedef PLong32 = Long32*; +typedef PLong64 = Long64*; +typedef Pointer32 = uint; +typedef Pointer64 = uptr; +typedef PointerSigned = iptr; +typedef PointerUnsigned = uptr; +typedef PShort = Short*; +typedef PSizeT = usz*; +typedef PSSizeT = isz*; +typedef PStr = Char*; +typedef PTByte = TByte*; +typedef PTChar = TChar*; +typedef PTStr = LPWstr; +typedef PUChar = UChar*; +typedef PUHalfPtr = UHalfPtr*; +typedef PUInt = UInt*; +typedef PUIntPtr = UIntPtr*; +typedef PUInt8 = UInt8*; +typedef PUInt16 = UInt16*; +typedef PUInt32 = UInt32*; +typedef PUInt64 = UInt64*; +typedef PULong = ULong*; +typedef PULonglong = ULonglong*; +typedef PULongPtr = ULongPtr*; +typedef PULong32 = ULong32*; +typedef PULong64 = ULong64*; +typedef PUnicodeString = UnicodeString*; +typedef PUShort = UShort*; +typedef PVoid = void*; +typedef PWChar = WChar*; +typedef PWord = Word*; +typedef PWStr = WChar*; +typedef QWord = ulong; +typedef ScHandle = Handle; +typedef ScLong = LPVoid; +typedef ServiceStatusHandle = Handle; +typedef Short = short; +typedef SizeT = usz; +typedef SSizeT = isz; +typedef TByte = WChar; +typedef TChar = WChar; +typedef UChar = char; +typedef UHalfPtr = uint; +typedef UInt = uint; +typedef UIntPtr = uptr; +typedef UInt8 = char; +typedef UInt16 = ushort; +typedef UInt32 = uint; +typedef UInt64 = ulong; +typedef ULong = uint; +typedef ULonglong = ulong; +typedef ULongPtr = ulong; +typedef ULong32 = uint; +typedef ULong64 = ulong; +typedef UShort = ushort; +typedef Usn = Longlong; +typedef WChar = Char16; +typedef Word = ushort; +typedef WParam = UIntPtr; struct UnicodeString { diff --git a/lib/std/threads/os/thread_none.c3 b/lib/std/threads/os/thread_none.c3 index f216d0f0f..e44f48dca 100644 --- a/lib/std/threads/os/thread_none.c3 +++ b/lib/std/threads/os/thread_none.c3 @@ -1,6 +1,6 @@ module std::thread; -define NativeMutex = distinct int; -define NativeConditionVariable = distinct int; -define NativeOnceFlag = distinct int; -define NativeThread = distinct int; \ No newline at end of file +typedef NativeMutex = distinct int; +typedef NativeConditionVariable = distinct int; +typedef NativeOnceFlag = distinct int; +typedef NativeThread = distinct int; \ No newline at end of file diff --git a/lib/std/threads/os/thread_posix.c3 b/lib/std/threads/os/thread_posix.c3 index ac0f0f541..1fa5fa25c 100644 --- a/lib/std/threads/os/thread_posix.c3 +++ b/lib/std/threads/os/thread_posix.c3 @@ -7,30 +7,30 @@ const PTHREAD_MUTEX_NORMAL = 0; const PTHREAD_MUTEX_ERRORCHECK = 1; const PTHREAD_MUTEX_RECURSIVE = 2; -define NativeMutex = PthreadMutex; -define NativeConditionVariable = PthreadCond; -define NativeThread = Pthread; -define NativeOnceFlag = PthreadOnce; +typedef NativeMutex = PthreadMutex; +typedef NativeConditionVariable = PthreadCond; +typedef NativeThread = Pthread; +typedef NativeOnceFlag = PthreadOnce; -define Pthread = distinct void*; +typedef Pthread = distinct void*; $if (env::OS_TYPE == OsType.LINUX): -define PthreadMutex = distinct ulong[5]; -define PthreadAttribute = distinct ulong[7]; -define PthreadMutexAttribute = distinct uint; -define PthreadCondAttribute = distinct uint; -define PthreadCond = distinct ulong[6]; -define PthreadOnce = distinct uint; +typedef PthreadMutex = distinct ulong[5]; +typedef PthreadAttribute = distinct ulong[7]; +typedef PthreadMutexAttribute = distinct uint; +typedef PthreadCondAttribute = distinct uint; +typedef PthreadCond = distinct ulong[6]; +typedef PthreadOnce = distinct uint; $else: -define PthreadMutex = distinct ulong[8]; -define PthreadMutexAttribute = distinct ulong[2]; -define PthreadAttribute = distinct ulong[8]; -define PthreadCond = distinct ulong[6]; -define PthreadCondAttribute = distinct ulong[8]; -define PthreadOnce = distinct ulong[2]; +typedef PthreadMutex = distinct ulong[8]; +typedef PthreadMutexAttribute = distinct ulong[2]; +typedef PthreadAttribute = distinct ulong[8]; +typedef PthreadCond = distinct ulong[6]; +typedef PthreadCondAttribute = distinct ulong[8]; +typedef PthreadOnce = distinct ulong[2]; $endif; -define PosixThreadFn = fn void*(void*); +typedef PosixThreadFn = fn void*(void*); extern fn int pthread_attr_destroy(PthreadAttribute*); extern fn int pthread_attr_getdetachstate(PthreadAttribute*, int*); diff --git a/lib/std/threads/os/thread_win32.c3 b/lib/std/threads/os/thread_win32.c3 index 33b07c146..ce34cfd4f 100644 --- a/lib/std/threads/os/thread_win32.c3 +++ b/lib/std/threads/os/thread_win32.c3 @@ -2,9 +2,9 @@ module std::thread::os; $if (thread::THREAD_MODEL == ThreadModel.WIN32): -define NativeThread = Win32_HANDLE; -define Win32_CRITICAL_SECTION = distinct ulong[5]; -define Win32_HANDLE = distinct ulong; +typedef NativeThread = Win32_HANDLE; +typedef Win32_CRITICAL_SECTION = distinct ulong[5]; +typedef Win32_HANDLE = distinct ulong; struct NativeMutex { diff --git a/lib/std/threads/thread.c3 b/lib/std/threads/thread.c3 index 55db5780c..54bc4c94f 100644 --- a/lib/std/threads/thread.c3 +++ b/lib/std/threads/thread.c3 @@ -11,19 +11,19 @@ const ThreadModel THREAD_MODEL = env::COMPILER_LIBC_AVAILABLE ? (env::OS_TYPE == OsType.WIN32 ? ThreadModel.WIN32 : ThreadModel.POSIX) : ThreadModel.NONE; -define MutexType = distinct int; +typedef MutexType = distinct int; const MutexType MUTEX_PLAIN = 0; const MutexType MUTEX_TIMED = 1; const MutexType MUTEX_RECURSIVE = 2; -define Mutex = distinct NativeMutex; -define ConditionVariable = distinct NativeConditionVariable; -define Thread = distinct NativeThread; -define OnceFlag = distinct NativeOnceFlag; -define OnceFn = fn void(); +typedef Mutex = distinct NativeMutex; +typedef ConditionVariable = distinct NativeConditionVariable; +typedef Thread = distinct NativeThread; +typedef OnceFlag = distinct NativeOnceFlag; +typedef OnceFn = fn void(); -define ThreadFn = fn int(void* arg); +typedef ThreadFn = fn int(void* arg); fault ThreadFault { diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 8222ab55e..5aa3f1aec 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -555,6 +555,7 @@ typedef enum TOKEN_SWITCH, TOKEN_TRUE, TOKEN_TRY, + TOKEN_TYPEDEF, TOKEN_UNION, TOKEN_VAR, TOKEN_WHILE, diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 581c45987..7deaf2937 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -40,6 +40,7 @@ void recover_top_level(ParseContext *c) case TOKEN_ENUM: case TOKEN_GENERIC: case TOKEN_DEFINE: + case TOKEN_TYPEDEF: case TOKEN_FAULT: return; case TOKEN_IDENT: // Incr arrays only @@ -1771,11 +1772,26 @@ static inline void decl_add_type(Decl *decl, TypeKind kind) */ static inline Decl *parse_define_type(ParseContext *c) { - advance_and_verify(c, TOKEN_DEFINE); + advance(c); Decl *decl = decl_new(DECL_POISONED, symstr(c), c->span); DEBUG_LOG("Parse define %s", decl->name); - advance_and_verify(c, TOKEN_TYPE_IDENT); + if (!try_consume(c, TOKEN_TYPE_IDENT)) + { + if (token_is_any_type(c->tok)) + { + SEMA_ERROR_HERE("'%s' is the name of a built-in type and can't be used as an alias.", + token_type_to_string(c->tok)); + return poisoned_decl; + } + if (token_is_some_ident(c->tok)) + { + SEMA_ERROR_HERE("The type name must start with an uppercase letter followed by at least 1 lowercase letter."); + return poisoned_decl; + } + SEMA_ERROR_HERE("A type name was expected here."); + return poisoned_decl; + } if (!parse_attributes(c, &decl->attributes, decl)) return false; CONSUME_OR_RET(TOKEN_EQ, poisoned_decl); bool distinct = false; @@ -2818,6 +2834,12 @@ AFTER_VISIBILITY: } SEMA_ERROR_HERE("There are more than one doc comment in a row, that is not allowed."); return poisoned_decl; + case TOKEN_TYPEDEF: + { + ASSIGN_DECL_OR_RET(decl, parse_define_type(c), poisoned_decl); + if (is_private) decl->visibility = VISIBLE_PRIVATE; + break; + } case TOKEN_DEFINE: { ASSIGN_DECL_OR_RET(decl, parse_define(c), poisoned_decl); diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index f551a03d2..ffbbe319c 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -1381,6 +1381,7 @@ Ast *parse_stmt(ParseContext *c) case TOKEN_FAULT: case TOKEN_UNION: case TOKEN_DEFINE: + case TOKEN_TYPEDEF: case TOKEN_DOCS_START: case TOKEN_DOCS_END: case TOKEN_DOC_COMMENT: diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index 4f05bc6bc..d5d9dc2eb 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -261,6 +261,8 @@ const char *token_type_to_string(TokenType type) return "true"; case TOKEN_TRY: return "try"; + case TOKEN_TYPEDEF: + return "typedef"; case TOKEN_TYPEID: return "typeid"; case TOKEN_UNION: diff --git a/src/version.h b/src/version.h index 5ad01c934..dbc7d59e2 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.63" \ No newline at end of file +#define COMPILER_VERSION "0.4.64" \ No newline at end of file diff --git a/test/test_suite/abi/aarch64_hfa_args.c3t b/test/test_suite/abi/aarch64_hfa_args.c3t index bead21eb7..c79fe0917 100644 --- a/test/test_suite/abi/aarch64_hfa_args.c3t +++ b/test/test_suite/abi/aarch64_hfa_args.c3t @@ -1,7 +1,7 @@ // #target: macos-aarch64 module test; -define Int8x16 = ichar[<16>]; -define Float32x3 = float[<3>]; +typedef Int8x16 = ichar[<16>]; +typedef Float32x3 = float[<3>]; struct HFAv3 { diff --git a/test/test_suite/abi/darwin64_avx.c3t b/test/test_suite/abi/darwin64_avx.c3t index 465b64271..39bd70659 100644 --- a/test/test_suite/abi/darwin64_avx.c3t +++ b/test/test_suite/abi/darwin64_avx.c3t @@ -2,7 +2,7 @@ // #opt: --x86vec=avx module test; -define Mm256 = float[<8>]; +typedef Mm256 = float[<8>]; struct St256 { Mm256 m; } @@ -19,7 +19,7 @@ fn void f39() { f38(x38); f37(x37); } // CHECK: declare void @func40(%struct.t128* byval(%struct.t128) align 16) -define Mm128 = float[<4>]; +typedef Mm128 = float[<4>]; struct Two128 { Mm128 m; Mm128 n; @@ -44,7 +44,7 @@ fn void func43(Sa s) { } -define Vec46 = float[<2>]; +typedef Vec46 = float[<2>]; extern fn void f46(Vec46,Vec46,Vec46,Vec46,Vec46,Vec46,Vec46,Vec46,Vec46,Vec46); fn void test46() { Vec46 x = {1,2}; f46(x,x,x,x,x,x,x,x,x,x); } @@ -69,7 +69,7 @@ fn void test54() { test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Complex { 0, 1.0 }); } -define Mm512 = float[<16>]; +typedef Mm512 = float[<16>]; struct St512 { Mm512 m; } diff --git a/test/test_suite/abi/darwin64_avx512.c3t b/test/test_suite/abi/darwin64_avx512.c3t index b45b3cd50..878abeb00 100644 --- a/test/test_suite/abi/darwin64_avx512.c3t +++ b/test/test_suite/abi/darwin64_avx512.c3t @@ -2,8 +2,8 @@ // #opt: --x86vec=avx512 module test; -define Mm256 = float[<8>]; -define Mm512 = float[<16>]; +typedef Mm256 = float[<8>]; +typedef Mm512 = float[<16>]; struct St512 { Mm512 m; } diff --git a/test/test_suite/abi/darwin64_sse.c3t b/test/test_suite/abi/darwin64_sse.c3t index 98dfe1932..175f8f6fb 100644 --- a/test/test_suite/abi/darwin64_sse.c3t +++ b/test/test_suite/abi/darwin64_sse.c3t @@ -2,7 +2,7 @@ // #opt: --x86vec=sse module test; -define Mm256 = float[<8>]; +typedef Mm256 = float[<8>]; struct St256 { Mm256 m; } @@ -19,7 +19,7 @@ fn void f39() { f38(x38); f37(x37); } // CHECK: declare void @func40(%struct.t128* byval(%struct.t128) align 16) -define Mm128 = float[<4>]; +typedef Mm128 = float[<4>]; struct Two128 { Mm128 m; Mm128 n; diff --git a/test/test_suite/abi/darwinx64_2.c3t b/test/test_suite/abi/darwinx64_2.c3t index 59a6cdd43..2020851a9 100644 --- a/test/test_suite/abi/darwinx64_2.c3t +++ b/test/test_suite/abi/darwinx64_2.c3t @@ -86,7 +86,7 @@ fn V4f32wrapper f27(V4f32wrapper x) { // PR22563 - We should unwrap simple structs and arrays to pass // and return them in the appropriate vector registers if possible. -define V8f32 = float[<8>]; +typedef V8f32 = float[<8>]; struct V8f32wrapper { V8f32 v; } @@ -133,15 +133,15 @@ fn float f31(F31foo x) { return x.c; } -define V1i64 = ulong[<1>]; +typedef V1i64 = ulong[<1>]; fn V1i64 f34(V1i64 arg) { return arg; } -define V1i64_2 = uint[<2>]; +typedef V1i64_2 = uint[<2>]; fn V1i64_2 f35(V1i64_2 arg) { return arg+arg; } -define V2i32 = float[<2>]; +typedef V2i32 = float[<2>]; fn V2i32 f36(V2i32 arg) { return arg; } diff --git a/test/test_suite/abi/riscv64-lp64-abi.c3t b/test/test_suite/abi/riscv64-lp64-abi.c3t index 25f1bb1e7..b2df61d82 100644 --- a/test/test_suite/abi/riscv64-lp64-abi.c3t +++ b/test/test_suite/abi/riscv64-lp64-abi.c3t @@ -5,7 +5,7 @@ struct Large { long a, b, c, d; } -define V32i8 = char[<32>]; +typedef V32i8 = char[<32>]; fn int f_scalar_stack_1(int a, int128 b, float c, float128 d, V32i8 e, char f, char g, char h) { diff --git a/test/test_suite/bitstruct/invalid_bitstruct_member_types.c3 b/test/test_suite/bitstruct/invalid_bitstruct_member_types.c3 index 21a1aaa19..e45249df5 100644 --- a/test/test_suite/bitstruct/invalid_bitstruct_member_types.c3 +++ b/test/test_suite/bitstruct/invalid_bitstruct_member_types.c3 @@ -5,8 +5,8 @@ bitstruct Test : int float a : 1..3; // #error: 'float' is not supported in a bitstruct, only enums, integer and boolean values may be used. } -define Baz = distinct float; -define Foo = distinct bool; +typedef Baz = distinct float; +typedef Foo = distinct bool; enum Boo { BAR diff --git a/test/test_suite/clang/2002-01_02.c3t b/test/test_suite/clang/2002-01_02.c3t index 4929eefff..94597a61d 100644 --- a/test/test_suite/clang/2002-01_02.c3t +++ b/test/test_suite/clang/2002-01_02.c3t @@ -52,7 +52,7 @@ struct Edge_rec int more_data; } -define QuadEdge = Edge_rec*; +typedef QuadEdge = Edge_rec*; struct EdgePair { QuadEdge left, right; diff --git a/test/test_suite/clang/2002-07.c3t b/test/test_suite/clang/2002-07.c3t index b94b25cf8..3ae3b30d3 100644 --- a/test/test_suite/clang/2002-07.c3t +++ b/test/test_suite/clang/2002-07.c3t @@ -143,7 +143,7 @@ struct Quad { Quad globalQuad = { 4, {1, 2}, null, 3, 156 }; -define FuncPtr = fn int(int); +typedef FuncPtr = fn int(int); fn uint ptrFunc(FuncPtr func, int x) { return func(x); diff --git a/test/test_suite/compile_time/compile_time_access_subscript.c3t b/test/test_suite/compile_time/compile_time_access_subscript.c3t index a88a0eb44..d03136d7f 100644 --- a/test/test_suite/compile_time/compile_time_access_subscript.c3t +++ b/test/test_suite/compile_time/compile_time_access_subscript.c3t @@ -22,7 +22,7 @@ macro check_type($Type) enum Blurb { FOO } -define Bdd = distinct Abc; +typedef Bdd = distinct Abc; fn void main() { var $i = int[4] { 1, 2, 3, 4 }; diff --git a/test/test_suite/compile_time/ct_switch_type_errors.c3 b/test/test_suite/compile_time/ct_switch_type_errors.c3 index 2e1dd90e1..f8c719918 100644 --- a/test/test_suite/compile_time/ct_switch_type_errors.c3 +++ b/test/test_suite/compile_time/ct_switch_type_errors.c3 @@ -22,8 +22,8 @@ fn void test1() $endswitch; } -define Foo = int; -define Bar = double; +typedef Foo = int; +typedef Bar = double; fn void test2() { $switch (int.typeid): diff --git a/test/test_suite/compile_time/ternary_folding.c3t b/test/test_suite/compile_time/ternary_folding.c3t index 796e96748..be61e6765 100644 --- a/test/test_suite/compile_time/ternary_folding.c3t +++ b/test/test_suite/compile_time/ternary_folding.c3t @@ -11,7 +11,7 @@ fn void test() fn int test2() { return 3; } -// #expect: ternary_folding.ll +/* #expect: ternary_folding.ll @ternary_folding_foo = local_unnamed_addr global i32 1, align 4 @ternary_folding_bar = local_unnamed_addr global double 2.000000e+00, align 8 diff --git a/test/test_suite/define/common.c3 b/test/test_suite/define/common.c3 index 53a163483..0e068e883 100644 --- a/test/test_suite/define/common.c3 +++ b/test/test_suite/define/common.c3 @@ -3,7 +3,7 @@ module foo; // define = define standard_foo = __stdin; define someFunctionIntBool = someFunction; -define FooInt = Foo; +typedef FooInt = Foo; define A_CONST_INT = A_CONST; define standard_foo = ofke; // #error: Expected '=' diff --git a/test/test_suite/define/define_name_errors.c3 b/test/test_suite/define/define_name_errors.c3 index 76f884abf..55a0f98f7 100644 --- a/test/test_suite/define/define_name_errors.c3 +++ b/test/test_suite/define/define_name_errors.c3 @@ -1,9 +1,9 @@ -define int = int; // #error: 'int' is the name of a built-in type and can't be used as an alias. -define main = int; // #error: 'main' is reserved and cannot be used as an alias. +typedef int = int; // #error: 'int' is the name of a built-in type and can't be used as an alias. +define main = foo; // #error: 'main' is reserved and cannot be used as an alias. -define hello = int; // #error: A type alias must start with an uppercase letter and contain at least one lower case letter -define hello = Foo; // #error: A type alias must start with an uppercase letter and contain at least one lower case letter +typedef hello = int; // #error: uppercase letter +typedef hello = Foo; // #error: uppercase letter -define HELLO = int; // #error: A type alias must start with an uppercase letter and contain at least one lower case letter -define HELLO = Foo; // #error: A type alias must start with an uppercase letter and contain at least one lower case letter \ No newline at end of file +typedef HELLO = int; // #error: uppercase letter +typedef HELLO = Foo; // #error: uppercase letter \ No newline at end of file diff --git a/test/test_suite/define/forbidden_defines.c3 b/test/test_suite/define/forbidden_defines.c3 index 86a7ca17d..206dfd45d 100644 --- a/test/test_suite/define/forbidden_defines.c3 +++ b/test/test_suite/define/forbidden_defines.c3 @@ -1,3 +1,3 @@ -define Abc = int[*]; // #error: Inferred array types can only -define Bcd = anyerr; // #error: 'anyerr' may not be aliased. -define Efd = variant; // #error: 'variant' may not be aliased. +typedef Abc = int[*]; // #error: Inferred array types can only +typedef Bcd = anyerr; // #error: 'anyerr' may not be aliased. +typedef Efd = variant; // #error: 'variant' may not be aliased. diff --git a/test/test_suite/distinct/distinct_invalid.c3 b/test/test_suite/distinct/distinct_invalid.c3 index 433d00332..89cb300ba 100644 --- a/test/test_suite/distinct/distinct_invalid.c3 +++ b/test/test_suite/distinct/distinct_invalid.c3 @@ -1,8 +1,8 @@ fault Error {} -define Foo1 = distinct Error; // #error: You cannot create a distinct type +typedef Foo1 = distinct Error; // #error: You cannot create a distinct type -define Foo3 = distinct void; // #error: create a distinct type from 'void' +typedef Foo3 = distinct void; // #error: create a distinct type from 'void' -define Foo4 = distinct typeid; // #error: create a distinct type from 'typeid' +typedef Foo4 = distinct typeid; // #error: create a distinct type from 'typeid' diff --git a/test/test_suite/distinct/distinct_slicing.c3 b/test/test_suite/distinct/distinct_slicing.c3 index e7a389f44..a69fa382e 100644 --- a/test/test_suite/distinct/distinct_slicing.c3 +++ b/test/test_suite/distinct/distinct_slicing.c3 @@ -1,4 +1,4 @@ -define Foo = distinct double[]; +typedef Foo = distinct double[]; fn void main() { diff --git a/test/test_suite/distinct/distinct_struct.c3 b/test/test_suite/distinct/distinct_struct.c3 index f7e7b39e0..e05b40f94 100644 --- a/test/test_suite/distinct/distinct_struct.c3 +++ b/test/test_suite/distinct/distinct_struct.c3 @@ -5,7 +5,7 @@ struct Struct double y; } -define Foo = distinct Struct; +typedef Foo = distinct Struct; struct Struct2 { diff --git a/test/test_suite/distinct/distinct_struct_array.c3 b/test/test_suite/distinct/distinct_struct_array.c3 index f6e4eb4e1..912face8f 100644 --- a/test/test_suite/distinct/distinct_struct_array.c3 +++ b/test/test_suite/distinct/distinct_struct_array.c3 @@ -1,6 +1,6 @@ module test; -define Foo = distinct int; +typedef Foo = distinct int; struct Struct { @@ -8,8 +8,8 @@ struct Struct int y; } -define Struct2 = distinct Struct; -define StructArr = distinct Struct2[3]; +typedef Struct2 = distinct Struct; +typedef StructArr = distinct Struct2[3]; fn void test(int x) { diff --git a/test/test_suite/distinct/distinct_union.c3 b/test/test_suite/distinct/distinct_union.c3 index 49af50a55..d3908cf93 100644 --- a/test/test_suite/distinct/distinct_union.c3 +++ b/test/test_suite/distinct/distinct_union.c3 @@ -6,7 +6,7 @@ union Union double y; } -define Foo = distinct Union; +typedef Foo = distinct Union; union Union2 { @@ -19,9 +19,9 @@ union Union2 } Foo f = { .x = 1 }; -define Union3 = distinct Union2; +typedef Union3 = distinct Union2; -define UnionArr = distinct Union3[3]; +typedef UnionArr = distinct Union3[3]; fn void test(int x) { diff --git a/test/test_suite/distinct/test_errors.c3 b/test/test_suite/distinct/test_errors.c3 index e90141453..abced5862 100644 --- a/test/test_suite/distinct/test_errors.c3 +++ b/test/test_suite/distinct/test_errors.c3 @@ -1,6 +1,6 @@ module test; -define Int2 = distinct int; +typedef Int2 = distinct int; fn void test() { diff --git a/test/test_suite/distinct/test_ops_on_int.c3 b/test/test_suite/distinct/test_ops_on_int.c3 index 76f50b233..e4f176290 100644 --- a/test/test_suite/distinct/test_ops_on_int.c3 +++ b/test/test_suite/distinct/test_ops_on_int.c3 @@ -1,6 +1,6 @@ module test; -define Foo = distinct int; +typedef Foo = distinct int; fn int test1() { diff --git a/test/test_suite/distinct/test_ops_on_struct.c3 b/test/test_suite/distinct/test_ops_on_struct.c3 index 8afcb4962..81f5c1751 100644 --- a/test/test_suite/distinct/test_ops_on_struct.c3 +++ b/test/test_suite/distinct/test_ops_on_struct.c3 @@ -6,7 +6,7 @@ struct Struct double y; } -define Foo = distinct Struct; +typedef Foo = distinct Struct; struct Struct2 { diff --git a/test/test_suite/errors/general_error_regression.c3t b/test/test_suite/errors/general_error_regression.c3t index 28cd8ee10..e72a6b694 100644 --- a/test/test_suite/errors/general_error_regression.c3t +++ b/test/test_suite/errors/general_error_regression.c3t @@ -19,7 +19,7 @@ fault Foob Y2 } -define Bar = distinct int; +typedef Bar = distinct int; enum MyEnum { diff --git a/test/test_suite/expressions/addr_of_fails.c3 b/test/test_suite/expressions/addr_of_fails.c3 index ec43851b4..b5df5a2cf 100644 --- a/test/test_suite/expressions/addr_of_fails.c3 +++ b/test/test_suite/expressions/addr_of_fails.c3 @@ -60,8 +60,8 @@ fn void test6() int[]* e = &arr[1..2]; // #error: To take the address of a temporary value, use '&&' instead of '&' } -define Baz = Foo; -define Bar = distinct int; +typedef Baz = Foo; +typedef Bar = distinct int; fault Err { FOO } union Un { int x; } enum MyEnum { BAR } diff --git a/test/test_suite/expressions/assignability.c3 b/test/test_suite/expressions/assignability.c3 index aeed1330d..0d6d2910d 100644 --- a/test/test_suite/expressions/assignability.c3 +++ b/test/test_suite/expressions/assignability.c3 @@ -1,4 +1,4 @@ -define Number = int; +typedef Number = int; fn void test1() { diff --git a/test/test_suite/expressions/bool_conversions.c3t b/test/test_suite/expressions/bool_conversions.c3t index 10e40721c..47949ece6 100644 --- a/test/test_suite/expressions/bool_conversions.c3t +++ b/test/test_suite/expressions/bool_conversions.c3t @@ -4,7 +4,7 @@ fn bool f0_0(void* a0) @private { return (bool)a0; } fn int f0() { return (int)f0_0((void*)0x2); } -define Test = fn void(); +typedef Test = fn void(); fn bool f1() { return (bool){| Test x @noinit; return x = (Test)0; |}; } diff --git a/test/test_suite/expressions/casts/cast_enum_to_various.c3 b/test/test_suite/expressions/casts/cast_enum_to_various.c3 index 343719a6f..e589f4f62 100644 --- a/test/test_suite/expressions/casts/cast_enum_to_various.c3 +++ b/test/test_suite/expressions/casts/cast_enum_to_various.c3 @@ -13,7 +13,7 @@ enum EnumB : char C, D } -define Func = fn void(Enum); +typedef Func = fn void(Enum); fn void test1(Enum e) { diff --git a/test/test_suite/expressions/casts/cast_func_to_various.c3 b/test/test_suite/expressions/casts/cast_func_to_various.c3 index 31fcb3154..d9a29a694 100644 --- a/test/test_suite/expressions/casts/cast_func_to_various.c3 +++ b/test/test_suite/expressions/casts/cast_func_to_various.c3 @@ -8,9 +8,9 @@ enum Enum : uptr A, B } -define Func = fn void(int); -define FuncOther = fn bool(char*); -define FuncSame = fn void(int); +typedef Func = fn void(int); +typedef FuncOther = fn bool(char*); +typedef FuncSame = fn void(int); fn void test1(Func arg) diff --git a/test/test_suite/expressions/casts/cast_unknown.c3 b/test/test_suite/expressions/casts/cast_unknown.c3 index 31d34c792..a181fa558 100644 --- a/test/test_suite/expressions/casts/cast_unknown.c3 +++ b/test/test_suite/expressions/casts/cast_unknown.c3 @@ -1,4 +1,4 @@ -define Number = int; +typedef Number = int; fn void test1() { diff --git a/test/test_suite/expressions/casts/explicit_cast.c3 b/test/test_suite/expressions/casts/explicit_cast.c3 index b374f02fe..93c2a17e3 100644 --- a/test/test_suite/expressions/casts/explicit_cast.c3 +++ b/test/test_suite/expressions/casts/explicit_cast.c3 @@ -1,6 +1,6 @@ -define Number8 = char; -define Number32 = int; -define DNumber32 = distinct int; +typedef Number8 = char; +typedef Number32 = int; +typedef DNumber32 = distinct int; fn void test1() { int a = (ichar)(10); diff --git a/test/test_suite/expressions/casts/struct_cast_and_distinct.c3 b/test/test_suite/expressions/casts/struct_cast_and_distinct.c3 index 816212d51..45441af99 100644 --- a/test/test_suite/expressions/casts/struct_cast_and_distinct.c3 +++ b/test/test_suite/expressions/casts/struct_cast_and_distinct.c3 @@ -1,6 +1,6 @@ module test; -define Foo = distinct int; +typedef Foo = distinct int; fn void test1() { diff --git a/test/test_suite/from_docs/examples_functionpointer.c3t b/test/test_suite/from_docs/examples_functionpointer.c3t index cbdc50894..4f757ce61 100644 --- a/test/test_suite/from_docs/examples_functionpointer.c3t +++ b/test/test_suite/from_docs/examples_functionpointer.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module demo; -define Callback = fn int(char* text, int value); +typedef Callback = fn int(char* text, int value); fn int my_callback(char* text, int value) { diff --git a/test/test_suite/from_docs/examples_struct.c3 b/test/test_suite/from_docs/examples_struct.c3 index dccc7d404..2cb28de7d 100644 --- a/test/test_suite/from_docs/examples_struct.c3 +++ b/test/test_suite/from_docs/examples_struct.c3 @@ -1,4 +1,4 @@ -define Callback = fn int(char c); +typedef Callback = fn int(char c); struct Person { int i; } struct Company { int j; } enum Status : int diff --git a/test/test_suite/functions/func_ptr_conversion_alias.c3t b/test/test_suite/functions/func_ptr_conversion_alias.c3t index 876cc3450..273bd9885 100644 --- a/test/test_suite/functions/func_ptr_conversion_alias.c3t +++ b/test/test_suite/functions/func_ptr_conversion_alias.c3t @@ -1,9 +1,9 @@ module test; -define Callback = fn void(); -define Callback2 = fn void(); +typedef Callback = fn void(); +typedef Callback2 = fn void(); -define GetCallback = fn Callback2**[][123]*(); +typedef GetCallback = fn Callback2**[][123]*(); fn Callback**[][123]* tester() { @@ -13,7 +13,7 @@ fn Callback**[][123]* tester() GetCallback x = &tester; -define GetCallbackOpt = fn Callback2!(); +typedef GetCallbackOpt = fn Callback2!(); fn Callback2! tester2() => null; diff --git a/test/test_suite/functions/func_ptr_conversions_and_names.c3t b/test/test_suite/functions/func_ptr_conversions_and_names.c3t index 63558b76a..9fc68b529 100644 --- a/test/test_suite/functions/func_ptr_conversions_and_names.c3t +++ b/test/test_suite/functions/func_ptr_conversions_and_names.c3t @@ -1,9 +1,9 @@ // #target: macos-x64 module test; import std::io; -define Func = fn int(int y); -define FuncOther = fn bool(char*); -define FuncSame = fn int(int z = 444); +typedef Func = fn int(int y); +typedef FuncOther = fn bool(char*); +typedef FuncSame = fn int(int z = 444); fn int test(int a) { return a; } fn int test2(int b = 3) { return b; } diff --git a/test/test_suite/functions/naked_function.c3t b/test/test_suite/functions/naked_function.c3t index 86580849e..55830a596 100644 --- a/test/test_suite/functions/naked_function.c3t +++ b/test/test_suite/functions/naked_function.c3t @@ -5,7 +5,7 @@ fn void test(int i) @naked } -// #expect: naked_function.ll +/* #expect: naked_function.ll define void @naked_function_test(i32 %0) #0 { entry: diff --git a/test/test_suite/functions/test_regression.c3t b/test/test_suite/functions/test_regression.c3t index 616ea8462..d18f0133a 100644 --- a/test/test_suite/functions/test_regression.c3t +++ b/test/test_suite/functions/test_regression.c3t @@ -67,8 +67,8 @@ fn int Foo2.mutate(Foo2 *foo) define oopsInt = test2::argh; define oopsDouble = test2::argh; -define Argh = fn int(double, Bobo); -define Argh2 = fn int(double, Bobo); +typedef Argh = fn int(double, Bobo); +typedef Argh2 = fn int(double, Bobo); @@ -80,7 +80,7 @@ fn int sum_us(int... x) return sum; } -define Frob = long; +typedef Frob = long; fn int sumd(int[] x) { @@ -97,13 +97,13 @@ struct Foo define getValueInt = test2::getValue; define getValueDouble = test2::getValue; -define IntBlob = test2::Blob; -define DoubleBlob = Blob; +typedef IntBlob = test2::Blob; +typedef DoubleBlob = Blob; define getMultInt = test2::getMult; define getMultDouble = test2::getMult; -define IntArray = List; -define IntList = LinkedList; +typedef IntArray = List; +typedef IntList = LinkedList; enum MyEnum : int { @@ -218,7 +218,7 @@ macro Hello wut() return Hello.FOO; } -define Bye = Hello; +typedef Bye = Hello; define wat = wut; define byebye = hello; diff --git a/test/test_suite/functions/test_regression_mingw.c3t b/test/test_suite/functions/test_regression_mingw.c3t index e93e16fb0..8c67bcc7b 100644 --- a/test/test_suite/functions/test_regression_mingw.c3t +++ b/test/test_suite/functions/test_regression_mingw.c3t @@ -69,8 +69,8 @@ fn int Foo2.mutate(Foo2 *foo) define oopsInt = test2::argh; define oopsDouble = test2::argh; -define Argh = fn int(double, Bobo); -define Argh2 = fn int(double, Bobo); +typedef Argh = fn int(double, Bobo); +typedef Argh2 = fn int(double, Bobo); @@ -82,7 +82,7 @@ fn int sum_us(int... x) return sum; } -define Frob = long; +typedef Frob = long; fn int sumd(int[] x) { @@ -99,13 +99,13 @@ struct Foo define getValueInt = test2::getValue; define getValueDouble = test2::getValue; -define IntBlob = test2::Blob; -define DoubleBlob = Blob; +typedef IntBlob = test2::Blob; +typedef DoubleBlob = Blob; define getMultInt = test2::getMult; define getMultDouble = test2::getMult; -define IntArray = List; -define IntList = LinkedList; +typedef IntArray = List; +typedef IntList = LinkedList; enum MyEnum : int { @@ -220,7 +220,7 @@ macro Hello wut() return Hello.FOO; } -define Bye = Hello; +typedef Bye = Hello; define wat = wut; define byebye = hello; diff --git a/test/test_suite/functions/too_many_params.c3 b/test/test_suite/functions/too_many_params.c3 index 1c63bfe6a..1c42ee6f0 100644 --- a/test/test_suite/functions/too_many_params.c3 +++ b/test/test_suite/functions/too_many_params.c3 @@ -1,5 +1,5 @@ import std::io; -define Tester = fn int(int x, int y, int z); +typedef Tester = fn int(int x, int y, int z); fn int test1( int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // 20 diff --git a/test/test_suite/generic/enum_set_test.c3t b/test/test_suite/generic/enum_set_test.c3t index ca891f648..2751b2d3e 100644 --- a/test/test_suite/generic/enum_set_test.c3t +++ b/test/test_suite/generic/enum_set_test.c3t @@ -3,7 +3,7 @@ module test; import std::io; import std::collections::enumset; -define AbcEnumSet = EnumSet; +typedef AbcEnumSet = EnumSet; enum Abc { diff --git a/test/test_suite/generic/generic_cyclic.c3 b/test/test_suite/generic/generic_cyclic.c3 index 8fda15c1a..8a6f686a3 100644 --- a/test/test_suite/generic/generic_cyclic.c3 +++ b/test/test_suite/generic/generic_cyclic.c3 @@ -2,7 +2,7 @@ module test; import bar; -define BazTest = Baz; +typedef BazTest = Baz; struct Test // #error: Recursive definition of 'Test' { diff --git a/test/test_suite/generic/generic_recursion.c3t b/test/test_suite/generic/generic_recursion.c3t index 2cffcd1a4..1ddb50dda 100644 --- a/test/test_suite/generic/generic_recursion.c3t +++ b/test/test_suite/generic/generic_recursion.c3t @@ -3,7 +3,7 @@ module test; import std::io; import std::collections::list; -define TreeNodeList = List; +typedef TreeNodeList = List; struct TreeNode { diff --git a/test/test_suite/lambda/lambda_in_macro.c3t b/test/test_suite/lambda/lambda_in_macro.c3t index 222759749..4c5b4b681 100644 --- a/test/test_suite/lambda/lambda_in_macro.c3t +++ b/test/test_suite/lambda/lambda_in_macro.c3t @@ -2,8 +2,8 @@ module test; import std::io; -define Callback1 = fn double(double x); -define Callback2 = fn int(int y); +typedef Callback1 = fn double(double x); +typedef Callback2 = fn int(int y); macro test2(y) { diff --git a/test/test_suite/lambda/nested_lambda_def.c3t b/test/test_suite/lambda/nested_lambda_def.c3t index 3a3d239cb..28a2236f9 100644 --- a/test/test_suite/lambda/nested_lambda_def.c3t +++ b/test/test_suite/lambda/nested_lambda_def.c3t @@ -32,7 +32,7 @@ macro Callback get_callback2() module bar; import foo; -define Callback = fn int(); +typedef Callback = fn int(); macro Callback get_callback() { diff --git a/test/test_suite/lambda/simple_lambda.c3t b/test/test_suite/lambda/simple_lambda.c3t index 69eb751a2..431701803 100644 --- a/test/test_suite/lambda/simple_lambda.c3t +++ b/test/test_suite/lambda/simple_lambda.c3t @@ -3,7 +3,7 @@ import std::io; import std::math::vector; import std::math; -define Callback = fn int(); +typedef Callback = fn int(); fn int xy(Callback a) => a(); diff --git a/test/test_suite/macros/type_params.c3t b/test/test_suite/macros/type_params.c3t index 1430897b6..e57c6abbd 100644 --- a/test/test_suite/macros/type_params.c3t +++ b/test/test_suite/macros/type_params.c3t @@ -5,7 +5,7 @@ macro foo($Foo) return a; } -define Bar = short; +typedef Bar = short; fn void test() { int x = foo(int); diff --git a/test/test_suite/methods/access.c3 b/test/test_suite/methods/access.c3 index ab3391c11..aed49d55e 100644 --- a/test/test_suite/methods/access.c3 +++ b/test/test_suite/methods/access.c3 @@ -10,7 +10,7 @@ struct An3 An2 y; } -define AnCall = fn void(); +typedef AnCall = fn void(); struct An2 { diff --git a/test/test_suite/methods/enum_distinct_err_methods.c3t b/test/test_suite/methods/enum_distinct_err_methods.c3t index 93e24cafd..d4a97fc8f 100644 --- a/test/test_suite/methods/enum_distinct_err_methods.c3t +++ b/test/test_suite/methods/enum_distinct_err_methods.c3t @@ -8,7 +8,7 @@ fault Foo X } -define Bar = distinct int; +typedef Bar = distinct int; enum MyEnum { diff --git a/test/test_suite/methods/extension_method_generic.c3 b/test/test_suite/methods/extension_method_generic.c3 index fe02609ff..364a2794f 100644 --- a/test/test_suite/methods/extension_method_generic.c3 +++ b/test/test_suite/methods/extension_method_generic.c3 @@ -1,7 +1,7 @@ module compiler_c3; import std::collections::list; -define IntArray = List; +typedef IntArray = List; extern fn void printf(char*, ...); diff --git a/test/test_suite/overloading/set_overload.c3t b/test/test_suite/overloading/set_overload.c3t index 6bc5e0068..69f60e247 100644 --- a/test/test_suite/overloading/set_overload.c3t +++ b/test/test_suite/overloading/set_overload.c3t @@ -3,7 +3,7 @@ module test; import std::collections::map; -define IntMap = HashMap; +typedef IntMap = HashMap; fn void main() { diff --git a/test/test_suite/statements/default_args.c3 b/test/test_suite/statements/default_args.c3 index 2c9aaa347..7ab73dda6 100644 --- a/test/test_suite/statements/default_args.c3 +++ b/test/test_suite/statements/default_args.c3 @@ -1,4 +1,4 @@ -define Foo = fn void(int a = 10); +typedef Foo = fn void(int a = 10); fn int abc() { return 1; } -define Foo2 = fn void(int a = abc()); +typedef Foo2 = fn void(int a = abc()); diff --git a/test/test_suite/statements/foreach_custom_errors.c3 b/test/test_suite/statements/foreach_custom_errors.c3 index 127d0df9f..60a4f30d0 100644 --- a/test/test_suite/statements/foreach_custom_errors.c3 +++ b/test/test_suite/statements/foreach_custom_errors.c3 @@ -4,7 +4,7 @@ fn void test1() foreach (a : x) { }; // #error: It's not possible to enumerate an expression of type 'int' } -define Test1 = distinct int; +typedef Test1 = distinct int; fn void test2() { diff --git a/test/test_suite/statements/foreach_r_custom_errors.c3 b/test/test_suite/statements/foreach_r_custom_errors.c3 index 81d59d474..cdd389f88 100644 --- a/test/test_suite/statements/foreach_r_custom_errors.c3 +++ b/test/test_suite/statements/foreach_r_custom_errors.c3 @@ -4,7 +4,7 @@ fn void test1() foreach_r (a : x) { }; // #error: It's not possible to enumerate an expression of type 'int' } -define Test1 = distinct int; +typedef Test1 = distinct int; fn void test2() { diff --git a/test/test_suite/stdlib/map.c3t b/test/test_suite/stdlib/map.c3t index a7536aaf7..f234260bc 100644 --- a/test/test_suite/stdlib/map.c3t +++ b/test/test_suite/stdlib/map.c3t @@ -6,8 +6,8 @@ import std::collections::map; struct Foo { int x; void* bar; } -define IntFooMap = HashMap; -define IntDoubleMap = HashMap; +typedef IntFooMap = HashMap; +typedef IntDoubleMap = HashMap; fn char[] Foo.to_string(Foo* foo, Allocator* allocator = mem::current_allocator()) { diff --git a/test/test_suite/stdlib/priorityqueue.c3t b/test/test_suite/stdlib/priorityqueue.c3t index 346eb36fd..e7590800b 100644 --- a/test/test_suite/stdlib/priorityqueue.c3t +++ b/test/test_suite/stdlib/priorityqueue.c3t @@ -4,7 +4,7 @@ import std::io; import std::math; import std::collections::priorityqueue; -define FooPriorityQueue = PriorityQueue; +typedef FooPriorityQueue = PriorityQueue; fn void main() { diff --git a/test/test_suite/struct/member_expr.c3 b/test/test_suite/struct/member_expr.c3 index 77782deda..1afc51e7a 100644 --- a/test/test_suite/struct/member_expr.c3 +++ b/test/test_suite/struct/member_expr.c3 @@ -1,7 +1,7 @@ -define Func = fn int(int); +typedef Func = fn int(int); -define Func2 = fn int(Foo*, int); +typedef Func2 = fn int(Foo*, int); struct Foo { diff --git a/test/test_suite/struct/zero_member.c3 b/test/test_suite/struct/zero_member.c3 index 98496e0d2..316f704cd 100644 --- a/test/test_suite/struct/zero_member.c3 +++ b/test/test_suite/struct/zero_member.c3 @@ -1,4 +1,4 @@ -define Foo = int[0]; // #error: An array may not have zero +typedef Foo = int[0]; // #error: An array may not have zero struct Bar { diff --git a/test/test_suite/symbols/shadow_struct.c3 b/test/test_suite/symbols/shadow_struct.c3 index 72b36f698..34aa1626b 100644 --- a/test/test_suite/symbols/shadow_struct.c3 +++ b/test/test_suite/symbols/shadow_struct.c3 @@ -4,7 +4,7 @@ struct Foo int y; } -define Foo = float; // #error: shadow a previous declaration +typedef Foo = float; // #error: shadow a previous declaration enum Bar { @@ -12,4 +12,4 @@ enum Bar TEST2 } -define Bar = float; // #error: shadow a previous declaration \ No newline at end of file +typedef Bar = float; // #error: shadow a previous declaration \ No newline at end of file diff --git a/test/test_suite/symbols/various.c3 b/test/test_suite/symbols/various.c3 index db36e6479..fc4937313 100644 --- a/test/test_suite/symbols/various.c3 +++ b/test/test_suite/symbols/various.c3 @@ -49,7 +49,7 @@ fn void test7() int v = array[1]; } -define Number = int; +typedef Number = int; fn void test8() { diff --git a/test/test_suite/types/enum_inference.c3 b/test/test_suite/types/enum_inference.c3 index 6899a879e..78c104e3e 100644 --- a/test/test_suite/types/enum_inference.c3 +++ b/test/test_suite/types/enum_inference.c3 @@ -13,7 +13,7 @@ enum Inf2 : char C, } -define BooInf = Inf; +typedef BooInf = Inf; fn void enumInferenceTest() diff --git a/test/test_suite/types/enum_ok.c3 b/test/test_suite/types/enum_ok.c3 index 1374947c8..c1c8ab000 100644 --- a/test/test_suite/types/enum_ok.c3 +++ b/test/test_suite/types/enum_ok.c3 @@ -4,7 +4,7 @@ enum EnumTest : long VALUE2 } -define Frob = long; +typedef Frob = long; enum EnumTestAlias : Frob { diff --git a/test/test_suite/types/recursive_typedef.c3 b/test/test_suite/types/recursive_typedef.c3 index 7d264a9d7..4473211f7 100644 --- a/test/test_suite/types/recursive_typedef.c3 +++ b/test/test_suite/types/recursive_typedef.c3 @@ -1,9 +1,9 @@ -define Number2 = Number1; // #error: Recursive definition of 'Number2' -define Number1 = Number2; +typedef Number2 = Number1; // #error: Recursive definition of 'Number2' +typedef Number1 = Number2; -define Number = Number; // #error: Recursive definition of 'Number' +typedef Number = Number; // #error: Recursive definition of 'Number' -define Loop2 = Loop; // #error: Recursive definition of 'Loop2' -define Loop3 = Loop2; -define Loop = Loop3; +typedef Loop2 = Loop; // #error: Recursive definition of 'Loop2' +typedef Loop3 = Loop2; +typedef Loop = Loop3; diff --git a/test/test_suite/types/redefinition.c3 b/test/test_suite/types/redefinition.c3 index a2e16bd89..78c8cd476 100644 --- a/test/test_suite/types/redefinition.c3 +++ b/test/test_suite/types/redefinition.c3 @@ -1,2 +1,2 @@ -define Number = int; -define Number = uint; // #error: 'Number' would shadow a previous declaration. \ No newline at end of file +typedef Number = int; +typedef Number = uint; // #error: 'Number' would shadow a previous declaration. \ No newline at end of file diff --git a/test/test_suite/types/typedefs.c3 b/test/test_suite/types/typedefs.c3 index 893061592..67ec8efd8 100644 --- a/test/test_suite/types/typedefs.c3 +++ b/test/test_suite/types/typedefs.c3 @@ -1,4 +1,4 @@ -define Arr = int[4]; +typedef Arr = int[4]; Arr a = { 3, 4, 5, 6 }; diff --git a/test/unit/stdlib/collections/linkedlist.c3 b/test/unit/stdlib/collections/linkedlist.c3 index 2962407a8..0595cb6bb 100644 --- a/test/unit/stdlib/collections/linkedlist.c3 +++ b/test/unit/stdlib/collections/linkedlist.c3 @@ -1,7 +1,7 @@ module linkedlist_test; import std::collections::linkedlist; -define IntList = LinkedList; +typedef IntList = LinkedList; fn void! test_push() @test {