diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index 0b7f7c9bb..6eac30d9d 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -4,7 +4,7 @@ module std::collections::list; import std::math; -typedef ElementPredicate = fn bool(Type *type); +def ElementPredicate = fn bool(Type *type); struct List { diff --git a/lib/std/collections/object.c3 b/lib/std/collections/object.c3 index 8a5990201..83b003059 100644 --- a/lib/std/collections/object.c3 +++ b/lib/std/collections/object.c3 @@ -472,7 +472,7 @@ fn Object* Object.get_or_create_obj(Object* o, String key) return container; } -typedef ObjectInternalMap @private = HashMap; -typedef ObjectInternalList @private = List; -typedef ObjectInternalMapEntry @private = Entry; +def ObjectInternalMap @private = HashMap; +def ObjectInternalList @private = List; +def ObjectInternalMapEntry @private = Entry; diff --git a/lib/std/collections/priorityqueue.c3 b/lib/std/collections/priorityqueue.c3 index beb98cc12..c27b3da9e 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; -typedef Heap = List; +def Heap = List; struct PriorityQueue { diff --git a/lib/std/core/allocators/arena_allocator.c3 b/lib/std/core/allocators/arena_allocator.c3 index d0c637421..bc2a25d1e 100644 --- a/lib/std/core/allocators/arena_allocator.c3 +++ b/lib/std/core/allocators/arena_allocator.c3 @@ -103,7 +103,7 @@ fn void*! ArenaAllocator._alloc(ArenaAllocator* this, usz size, usz alignment, u usz end = (usz)(aligned_pointer_to_offset - this.data.ptr) + size - offset; if (end > total_len) return AllocationFailure.OUT_OF_MEMORY?; this.used = end; - void *mem = aligned_pointer_to_offset - offset; + void* mem = aligned_pointer_to_offset - offset; ArenaAllocatorHeader* header = mem - ArenaAllocatorHeader.sizeof; header.size = size; return mem; diff --git a/lib/std/core/allocators/heap_allocator.c3 b/lib/std/core/allocators/heap_allocator.c3 index fcb443eaa..5fe6db54d 100644 --- a/lib/std/core/allocators/heap_allocator.c3 +++ b/lib/std/core/allocators/heap_allocator.c3 @@ -4,7 +4,7 @@ module std::core::mem::allocator; -typedef MemoryAllocFn = fn char[]!(usz); +def MemoryAllocFn = fn char[]!(usz); struct SimpleHeapAllocator { diff --git a/lib/std/core/allocators/tracking_allocator.c3 b/lib/std/core/allocators/tracking_allocator.c3 index 8efc5beab..2f9e35387 100644 --- a/lib/std/core/allocators/tracking_allocator.c3 +++ b/lib/std/core/allocators/tracking_allocator.c3 @@ -5,7 +5,7 @@ module std::core::mem::allocator; import std::collections::map; -typedef PtrMap = HashMap; +def PtrMap = HashMap; // A simple tracking allocator. // It tracks allocations using a hash map but diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 170887580..197be536a 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -104,7 +104,7 @@ fn void default_panic(String message, String file, String function, uint line) $$trap(); } -typedef PanicFn = fn void(String message, String file, String function, uint line); +def 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 56d9e5d32..07b1201f4 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: - typedef CInt = long; - typedef CUInt = ulong; + def CInt = long; + def CUInt = ulong; $case 32: - typedef CInt = int; - typedef CUInt = uint; + def CInt = int; + def CUInt = uint; $case 16: - typedef CInt = short; - typedef CUInt = ushort; + def CInt = short; + def CUInt = ushort; $default: $error "Invalid C int size"; $endswitch $switch ($$C_LONG_SIZE) $case 64: - typedef CLong = long; - typedef CULong = ulong; + def CLong = long; + def CULong = ulong; $case 32: - typedef CLong = int; - typedef CULong = uint; + def CLong = int; + def CULong = uint; $case 16: - typedef CLong = short; - typedef CULong = ushort; + def CLong = short; + def CULong = ushort; $default: $error "Invalid C long size"; $endswitch $switch ($$C_SHORT_SIZE) $case 32: - typedef CShort = int; - typedef CUShort = uint; + def CShort = int; + def CUShort = uint; $case 16: - typedef CShort = short; - typedef CUShort = ushort; + def CShort = short; + def CUShort = ushort; $case 8: - typedef CShort = ichar; - typedef CUShort = char; + def CShort = ichar; + def CUShort = char; $default: $error "Invalid C short size"; $endswitch $switch ($$C_LONG_LONG_SIZE) $case 128: - typedef CLongLong = int128; - typedef CULongLong = uint128; + def CLongLong = int128; + def CULongLong = uint128; $case 64: - typedef CLongLong = long; - typedef CULongLong = ulong; + def CLongLong = long; + def CULongLong = ulong; $case 32: - typedef CLongLong = int; - typedef CULongLong = uint; + def CLongLong = int; + def CULongLong = uint; $case 16: - typedef CLongLong = short; - typedef CULongLong = ushort; + def CLongLong = short; + def CULongLong = ushort; $default: $error "Invalid C long long size"; $endswitch -typedef CSChar = ichar; -typedef CUChar = char; +def CSChar = ichar; +def CUChar = char; $if $$C_CHAR_IS_SIGNED: - typedef CChar = ichar; + def CChar = ichar; $else - typedef CChar = char; + def CChar = char; $endif diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index cc54d3dd6..84b0e5f84 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -1,6 +1,6 @@ module std::core::dstring; -typedef DString = distinct void*; +def DString = distinct void*; const usz MIN_CAPACITY @private = 16; diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index d0f2b43e0..fd12e0d8f 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -6,7 +6,7 @@ const DEFAULT_SIZE_PREFIX_ALIGNMENT = usz.alignof; const Allocator* NULL_ALLOCATOR = &_NULL_ALLOCATOR; const Allocator* LIBC_ALLOCATOR = &_SYSTEM_ALLOCATOR; -typedef AllocatorFunction = fn void*!(Allocator* allocator, usz new_size, usz alignment, usz offset, void* old_pointer, AllocationKind kind); +def 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 824280315..f593d6ef4 100644 --- a/lib/std/core/runtime.c3 +++ b/lib/std/core/runtime.c3 @@ -15,7 +15,7 @@ struct SubArrayContainer usz len; } -typedef TestFn = fn void!(); +def TestFn = fn void!(); struct TestRunner { diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index e68433183..eb59920fa 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -1,9 +1,9 @@ module std::core::string; import std::ascii; -typedef ZString = distinct inline char*; -typedef Char32 = uint; -typedef Char16 = ushort; +def ZString = distinct inline char*; +def Char32 = uint; +def Char16 = ushort; fault UnicodeResult { @@ -361,6 +361,30 @@ fn Char32[]! String.to_utf32(String s, Allocator* using = mem::heap()) return data[:codepoints]; } +fn void String.convert_ascii_to_lower(String s) +{ + foreach (&c : s) if (*c >= 'A' && *c <= 'Z') *c += 'a' - 'A'; +} + +fn String String.ascii_to_lower(String s, Allocator* using = mem::heap()) +{ + String copy = s.copy(using); + copy.convert_ascii_to_lower(); + return copy; +} + +fn void String.convert_ascii_to_upper(String s) +{ + foreach (&c : s) if (*c >= 'a' && *c <= 'z') *c -= 'a' - 'A'; +} + +fn String String.ascii_to_upper(String s, Allocator* using = mem::heap()) +{ + String copy = s.copy(using); + copy.convert_ascii_to_upper(); + return copy; +} + fn String! from_utf32(Char32[] utf32, Allocator* using = mem::heap()) { usz len = conv::utf8len_for_utf32(utf32); diff --git a/lib/std/hash/fnv32a.c3 b/lib/std/hash/fnv32a.c3 index 8f1e12c7a..073850f49 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; -typedef Fnv32a = distinct uint; +def Fnv32a = distinct uint; const FNV32A_START @private = 0x811c9dc5; const FNV32A_MUL @private = 0x01000193; diff --git a/lib/std/io/io_printf.c3 b/lib/std/io/io_printf.c3 index 221334aad..588b890af 100644 --- a/lib/std/io/io_printf.c3 +++ b/lib/std/io/io_printf.c3 @@ -21,10 +21,10 @@ fault FormattingFault INVALID_FORMAT_TYPE, } -typedef OutputFn = fn void!(char c, void* buffer); -typedef ToStringFunction = fn String(void* value, Allocator *using); -typedef ToFormatFunction = fn void!(void* value, Formatter* formatter); -typedef FloatType = double; +def OutputFn = fn void!(char c, void* buffer); +def ToStringFunction = fn String(void* value, Allocator *using); +def ToFormatFunction = fn void!(void* value, Formatter* formatter); +def FloatType = double; fn usz! printf(String format, args...) @maydiscard { @@ -472,8 +472,8 @@ fn usz! Formatter.vprintf(Formatter* this, String format, any[] anys) return this.idx; } -typedef StringFunctionMap @private = HashMap; -typedef FormatterFunctionMap @private = HashMap; +def StringFunctionMap @private = HashMap; +def FormatterFunctionMap @private = HashMap; FormatterFunctionMap toformat_functions @private; StringFunctionMap tostring_functions @private; diff --git a/lib/std/io/io_stream.c3 b/lib/std/io/io_stream.c3 index 689ff8839..b0fa75c57 100644 --- a/lib/std/io/io_stream.c3 +++ b/lib/std/io/io_stream.c3 @@ -1,18 +1,18 @@ module std::io; -typedef CloseStreamFn = fn void!(Stream*); -typedef FlushStreamFn = fn void!(Stream*); -typedef SeekStreamFn = fn usz!(Stream*, isz offset, Seek seek); -typedef LenStreamFn = fn usz(Stream*); -typedef AvailableStreamFn = fn usz(Stream*); -typedef ReadStreamFn = fn usz!(Stream*, char[] bytes); -typedef ReadFromStreamFn = fn usz!(Stream*, Stream*); -typedef ReadByteStreamFn = fn char!(Stream*); -typedef PushbackByteStreamFn = fn void!(Stream*); -typedef WriteStreamFn = fn usz!(Stream*, char[] bytes); -typedef WriteToStreamFn = fn usz!(Stream*, Stream* out); -typedef WriteByteStreamFn = fn void!(Stream*, char c); -typedef DestroyStreamFn = fn void!(Stream*); +def CloseStreamFn = fn void!(Stream*); +def FlushStreamFn = fn void!(Stream*); +def SeekStreamFn = fn usz!(Stream*, isz offset, Seek seek); +def LenStreamFn = fn usz(Stream*); +def AvailableStreamFn = fn usz(Stream*); +def ReadStreamFn = fn usz!(Stream*, char[] bytes); +def ReadFromStreamFn = fn usz!(Stream*, Stream*); +def ReadByteStreamFn = fn char!(Stream*); +def PushbackByteStreamFn = fn void!(Stream*); +def WriteStreamFn = fn usz!(Stream*, char[] bytes); +def WriteToStreamFn = fn usz!(Stream*, Stream* out); +def WriteByteStreamFn = fn void!(Stream*, char c); +def DestroyStreamFn = fn void!(Stream*); struct StreamInterface { diff --git a/lib/std/io/os/file.c3 b/lib/std/io/os/file.c3 index 63c60599b..1c40a8ebf 100644 --- a/lib/std/io/os/file.c3 +++ b/lib/std/io/os/file.c3 @@ -1,13 +1,13 @@ module std::io::os; import libc; -typedef FopenFn = fn void*!(String, String); -typedef FreopenFn = fn void*!(void*, String, String); -typedef FcloseFn = fn void!(void*); -typedef FseekFn = fn void!(void*, isz, Seek); -typedef FtellFn = fn usz!(void*); -typedef FwriteFn = fn usz!(void*, char[] buffer); -typedef FreadFn = fn usz!(void*, char[] buffer); +def FopenFn = fn void*!(String, String); +def FreopenFn = fn void*!(void*, String, String); +def FcloseFn = fn void!(void*); +def FseekFn = fn void!(void*, isz, Seek); +def FtellFn = fn usz!(void*); +def FwriteFn = fn usz!(void*, char[] buffer); +def FreadFn = fn usz!(void*, char[] buffer); $if !$defined(native_fopen_fn): FopenFn native_fopen_fn @weak; diff --git a/lib/std/io/path.c3 b/lib/std/io/path.c3 index c73cc54bb..39ebe46e1 100644 --- a/lib/std/io/path.c3 +++ b/lib/std/io/path.c3 @@ -6,7 +6,7 @@ const char PREFERRED_SEPARATOR_WIN32 = '\\'; const char PREFERRED_SEPARATOR_POSIX = '/'; const char PREFERRED_SEPARATOR = env::os_is_win32() ? PREFERRED_SEPARATOR_WIN32 : PREFERRED_SEPARATOR_POSIX; -typedef PathList = List; +def PathList = List; fault PathResult { diff --git a/lib/std/libc/libc.c3 b/lib/std/libc/libc.c3 index bc4c50eb7..64edd4549 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); } -typedef TerminateFunction = fn void(); -typedef CompareFunction = fn int(void*, void*); -typedef JmpBuf = uptr[$$JMP_BUF_SIZE]; +def TerminateFunction = fn void(); +def CompareFunction = fn int(void*, void*); +def JmpBuf = uptr[$$JMP_BUF_SIZE]; $if env::COMPILER_LIBC_AVAILABLE: @@ -148,8 +148,8 @@ $endif // stdio -typedef Fpos = long; -typedef CFile = void*; +def Fpos = long; +def CFile = void*; $switch $case env::COMPILER_LIBC_AVAILABLE && env::OS_TYPE == LINUX: @@ -202,8 +202,8 @@ const int EOF = -1; const int FOPEN_MAX = 20; const int FILENAME_MAX = 1024; -typedef Errno = distinct CInt; -typedef SeekIndex = CLong; +def Errno = distinct CInt; +def SeekIndex = CLong; $if env::COMPILER_LIBC_AVAILABLE: @@ -338,11 +338,11 @@ $switch (env::OS_TYPE) $case WIN32: -typedef Tm = TmCommon; +def Tm = TmCommon; $case WASI: -typedef TimeOffset = int; +def TimeOffset = int; struct Tm { inline TmCommon common; @@ -359,7 +359,7 @@ $case OPENBSD: $case FREEBSD: $default: -typedef TimeOffset = CLong; +def TimeOffset = CLong; struct Tm { inline TmCommon common; @@ -378,8 +378,8 @@ struct TimeSpec ulong ns; } -typedef Time_t = long; -typedef Clock_t = ulong; +def Time_t = long; +def Clock_t = ulong; $else @@ -389,8 +389,8 @@ struct TimeSpec CLong ns; } -typedef Time_t = CLong; -typedef Clock_t = CULong; +def Time_t = CLong; +def Clock_t = CULong; $endif @@ -432,7 +432,7 @@ extern fn usz strftime(char* str, usz maxsize, char* format, Tm *timeptr); extern fn Time_t time(Time_t *timer); // signal -typedef SignalFunction = fn void(int); +def 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 12017be8a..3e406a908 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -85,33 +85,33 @@ fault MatrixError MATRIX_INVERSE_DOESNT_EXIST, } -typedef Complexf = Complex; -typedef Complex = Complex; -define complexf_identity = complex::identity; -define complex_identity = complex::identity; - -typedef Quaternionf = Quaternion; -typedef Quaternion = Quaternion; -define quaternionf_identity = quaternion::identity; -define quaternion_identity = quaternion::identity; - -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; -define matrix4f_perspective = matrix::perspective; - -define MATRIX2_IDENTITY = matrix::IDENTITY2; -define MATRIX2F_IDENTITY = matrix::IDENTITY2; -define MATRIX3_IDENTITY = matrix::IDENTITY3; -define MATRIX3F_IDENTITY = matrix::IDENTITY3; -define MATRIX4_IDENTITY = matrix::IDENTITY4; -define MATRIX4F_IDENTITY = matrix::IDENTITY4; +def Complexf = Complex; +def Complex = Complex; +def complexf_identity = complex::identity; +def complex_identity = complex::identity; + +def Quaternionf = Quaternion; +def Quaternion = Quaternion; +def quaternionf_identity = quaternion::identity; +def quaternion_identity = quaternion::identity; + +def Matrix2f = Matrix2x2; +def Matrix2 = Matrix2x2; +def Matrix3f = Matrix3x3; +def Matrix3 = Matrix3x3; +def Matrix4f = Matrix4x4; +def Matrix4 = Matrix4x4; +def matrix4_ortho = matrix::ortho; +def matrix4_perspective = matrix::perspective; +def matrix4f_ortho = matrix::ortho; +def matrix4f_perspective = matrix::perspective; + +def MATRIX2_IDENTITY = matrix::IDENTITY2; +def MATRIX2F_IDENTITY = matrix::IDENTITY2; +def MATRIX3_IDENTITY = matrix::IDENTITY3; +def MATRIX3F_IDENTITY = matrix::IDENTITY3; +def MATRIX4_IDENTITY = matrix::IDENTITY4; +def MATRIX4F_IDENTITY = matrix::IDENTITY4; /** * @require types::is_numerical($typeof(x)) `The input must be a numerical value or numerical vector` diff --git a/lib/std/math/math.random.c3 b/lib/std/math/math.random.c3 index c74e1d9b6..9f6982bec 100644 --- a/lib/std/math/math.random.c3 +++ b/lib/std/math/math.random.c3 @@ -6,9 +6,9 @@ struct Random void* state; } -typedef RandomSeedFn = fn void(Random*, char[] seed); -typedef RandomNextBytesFn = fn void(Random*, char[] buffer); -typedef RandomNextFn = fn uint(Random*, int bits); +def RandomSeedFn = fn void(Random*, char[] seed); +def RandomNextBytesFn = fn void(Random*, char[] buffer); +def RandomNextFn = fn uint(Random*, int bits); struct RandomInterface { diff --git a/lib/std/math/math_vector.c3 b/lib/std/math/math_vector.c3 index 24b6830b8..cb273a029 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; -typedef Vec2f = float[<2>]; -typedef Vec3f = float[<3>]; -typedef Vec4f = float[<4>]; +def Vec2f = float[<2>]; +def Vec3f = float[<3>]; +def Vec4f = float[<4>]; -typedef Vec2 = double[<2>]; -typedef Vec3 = double[<3>]; -typedef Vec4 = double[<4>]; +def Vec2 = double[<2>]; +def Vec3 = double[<3>]; +def 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/math/random/math.simple_random.c3 b/lib/std/math/random/math.simple_random.c3 index c52cdb4c6..1691b6192 100644 --- a/lib/std/math/random/math.simple_random.c3 +++ b/lib/std/math/random/math.simple_random.c3 @@ -1,6 +1,6 @@ module std::math; -typedef SimpleRandom = distinct ulong; +def SimpleRandom = distinct ulong; const long SIMPLE_RANDOM_MULTIPLIER @local = 0x5DEECE66D; const long SIMPLE_RANDOM_ADDEND @local = 0xB; diff --git a/lib/std/net/os/posix.c3 b/lib/std/net/os/posix.c3 index a9925d1f3..9468d447c 100644 --- a/lib/std/net/os/posix.c3 +++ b/lib/std/net/os/posix.c3 @@ -6,7 +6,7 @@ $if !env::os_is_win32() && $defined(AddrInfo): const int F_GETFL = 3; const int F_SETFL = 4; -typedef NativeSocket = distinct int; +def 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 53afc1de7..b8bd90e60 100644 --- a/lib/std/net/os/win32.c3 +++ b/lib/std/net/os/win32.c3 @@ -22,7 +22,7 @@ struct AddrInfo AddrInfo* ai_next; } -typedef NativeSocket = distinct uptr; +def 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 ab8a0b9a2..905e19838 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_is_darwin(): -typedef CFAllocatorRef = distinct void*; -typedef CFAllocatorContextRef = distinct void*; -typedef CFOptionFlags = usz; +def CFAllocatorRef = distinct void*; +def CFAllocatorContextRef = distinct void*; +def 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 1a777572c..61f0e51ac 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_is_darwin(): -typedef CFArrayRef = distinct void*; -typedef CFArrayCallBacksRef = distinct void*; -typedef CFMutableArrayRef = distinct void*; +def CFArrayRef = distinct void*; +def CFArrayCallBacksRef = distinct void*; +def 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 35b38e0ef..839eacbe9 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_is_darwin(): -typedef CFTypeRef = distinct void*; -typedef CFIndex = isz; +def CFTypeRef = distinct void*; +def CFIndex = isz; struct CFRange { CFIndex location; diff --git a/lib/std/os/macos/objc.c3 b/lib/std/os/macos/objc.c3 index 259470684..b524cb990 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_is_darwin(): -typedef Class = distinct void*; -typedef Method = distinct void*; -typedef Ivar = distinct void*; -typedef Selector = distinct void*; +def Class = distinct void*; +def Method = distinct void*; +def Ivar = distinct void*; +def Selector = distinct void*; fault ObjcFailure { diff --git a/lib/std/os/win32/files.c3 b/lib/std/os/win32/files.c3 index aee32b974..eb38d3473 100644 --- a/lib/std/os/win32/files.c3 +++ b/lib/std/os/win32/files.c3 @@ -39,7 +39,7 @@ struct Win32_WIN32_FIND_DATAW Win32_WORD wFinderFlags; // Obsolete. Do not use } -typedef Win32_LPWIN32_FIND_DATAW = Win32_WIN32_FIND_DATAW*; +def Win32_LPWIN32_FIND_DATAW = Win32_WIN32_FIND_DATAW*; extern fn Win32_BOOL win32_CloseHandle(Win32_HANDLE) @extern("CloseHandle"); extern fn Win32_BOOL win32_CreatePipe(Win32_PHANDLE hReadPipe, Win32_PHANDLE hWritePipe, Win32_LPSECURITY_ATTRIBUTES lpPipeAttributes, Win32_DWORD nSize) @extern("CreatePipe"); diff --git a/lib/std/os/win32/types.c3 b/lib/std/os/win32/types.c3 index c2f41b315..342c79611 100644 --- a/lib/std/os/win32/types.c3 +++ b/lib/std/os/win32/types.c3 @@ -1,172 +1,172 @@ module std::os::win32; -typedef Win32_BOOL = int; -typedef Win32_BOOLEAN = Win32_BYTE; -typedef Win32_BYTE = char; -typedef Win32_CCHAR = cinterop::CChar; -typedef Win32_CHAR = cinterop::CChar; -typedef Win32_COLORREF = Win32_DWORD; -typedef Win32_DWORD = uint; -typedef Win32_DWORDLONG = ulong; -typedef Win32_DWORD_PTR = Win32_ULONG_PTR; -typedef Win32_DWORD32 = uint; -typedef Win32_DWORD64 = ulong; -typedef Win32_FLOAT = float; -typedef Win32_HACCEL = Win32_HANDLE; -typedef Win32_HALF_PTR = int; -typedef Win32_HANDLE = Win32_PVOID; -typedef Win32_HBITMAP = Win32_HANDLE; -typedef Win32_HBRUSH = Win32_HANDLE; -typedef Win32_HCOLORSPACE = Win32_HANDLE; -typedef Win32_HCONV = Win32_HANDLE; -typedef Win32_HCONVLIST = Win32_HANDLE; -typedef Win32_HCURSOR = Win32_HICON; -typedef Win32_HDC = Win32_HANDLE; -typedef Win32_HDDEDATA = Win32_HANDLE; -typedef Win32_HDESK = Win32_HANDLE; -typedef Win32_HDROP = Win32_HANDLE; -typedef Win32_HDWP = Win32_HANDLE; -typedef Win32_HFILE = int; -typedef Win32_HFONT = Win32_HANDLE; -typedef Win32_HGDIOBJ = Win32_HANDLE; -typedef Win32_HGLOBAL = Win32_HANDLE; -typedef Win32_HHOOK = Win32_HANDLE; -typedef Win32_HICON = Win32_HANDLE; -typedef Win32_HINSTANCE = Win32_HANDLE; -typedef Win32_HKEY = Win32_HANDLE; -typedef Win32_HKL = Win32_HANDLE; -typedef Win32_HLOCAL = Win32_HANDLE; -typedef Win32_HMENU = Win32_HANDLE; -typedef Win32_HMETAFILE = Win32_HANDLE; -typedef Win32_HMODULE = Win32_HANDLE; -typedef Win32_HMONITOR = Win32_HANDLE; -typedef Win32_HPALETTE = Win32_HANDLE; -typedef Win32_HPEN = Win32_HANDLE; -typedef Win32_HRESULT = Win32_LONG; -typedef Win32_HRGN = Win32_HANDLE; -typedef Win32_HRSRC = Win32_HANDLE; -typedef Win32_HSZ = Win32_HANDLE; -typedef Win32_HWINSTA = Win32_HANDLE; -typedef Win32_HWND = Win32_HANDLE; -typedef Win32_INT = int; -typedef Win32_INT_PTR = iptr; -typedef Win32_INT8 = ichar; -typedef Win32_INT16 = short; -typedef Win32_INT32 = int; -typedef Win32_INT64 = long; -typedef Win32_LANGID = Win32_WORD; -typedef Win32_LCID = Win32_DWORD; -typedef Win32_LCTYPE = Win32_DWORD; -typedef Win32_LGRPID = Win32_DWORD; -typedef Win32_LONG = int; -typedef Win32_LONGLONG = long; -typedef Win32_LONG_PTR = iptr; -typedef Win32_LONG32 = int; -typedef Win32_LONG64 = long; -typedef Win32_LPARAM = Win32_LONG_PTR; -typedef Win32_LPBOOL = Win32_BOOL*; -typedef Win32_LPBYTE = Win32_BYTE*; -typedef Win32_LPCOLORREF = Win32_DWORD*; -typedef Win32_LPCSTR = Win32_CCHAR*; -typedef Win32_LPCTSTR = Win32_LPCWSTR; -typedef Win32_LPCVOID = void*; -typedef Win32_LPCWSTR = Win32_WCHAR*; -typedef Win32_LPDWORD = Win32_DWORD*; -typedef Win32_LPHANDLE = Win32_HANDLE*; -typedef Win32_LPINT = int*; -typedef Win32_LPLONG = int*; -typedef Win32_LPSTR = Win32_CCHAR*; -typedef Win32_LPTSTR = Win32_LPWSTR; -typedef Win32_LPVOID = void*; -typedef Win32_LPWORD = Win32_WORD*; -typedef Win32_LPWSTR = Win32_WCHAR*; -typedef Win32_LRESULT = Win32_LONG_PTR; -typedef Win32_PBOOL = Win32_BOOL*; -typedef Win32_PBOOLEAN = Win32_BOOLEAN*; -typedef Win32_PBYTE = Win32_BYTE*; -typedef Win32_PCHAR = Win32_CHAR*; -typedef Win32_PCSTR = Win32_CHAR*; -typedef Win32_PCTSTR = Win32_LPCWSTR; -typedef Win32_PCUNICODE_STRING = Win32_UNICODE_STRING*; -typedef Win32_PCWSTR = Char16*; -typedef Win32_PDWORD = Win32_DWORD*; -typedef Win32_PDWORDLONG = Win32_DWORDLONG*; -typedef Win32_PDWORDPTR = Win32_DWORD_PTR*; -typedef Win32_PDWORD32 = Win32_DWORD32*; -typedef Win32_PDWORD64 = Win32_DWORD64*; -typedef Win32_PFLOAT = Win32_FLOAT*; -typedef Win32_PHALFPTR = Win32_HALF_PTR*; -typedef Win32_PHANDLE = Win32_HANDLE*; -typedef Win32_PHKEY = Win32_HKEY*; -typedef Win32_PINT = int*; -typedef Win32_PINTPTR = Win32_INT_PTR*; -typedef Win32_PINT8 = Win32_INT8*; -typedef Win32_PINT16 = Win32_INT16*; -typedef Win32_PINT32 = Win32_INT32*; -typedef Win32_PINT64 = Win32_INT64*; -typedef Win32_PLCID = Win32_PDWORD; -typedef Win32_PLONG = Win32_LONG*; -typedef Win32_PLONGLONG = Win32_LONGLONG*; -typedef Win32_PLONG_PTR = Win32_LONG_PTR*; -typedef Win32_PLONG32 = Win32_LONG32*; -typedef Win32_PLONG64 = Win32_LONG64*; -typedef Win32_POINTER_32 = uint; -typedef Win32_POINTER_64 = uptr; -typedef Win32_POINTER_SIGNED = iptr; -typedef Win32_POINTER_UNSIGNED = uptr; -typedef Win32_PSHORT = Win32_SHORT*; -typedef Win32_PSIZE_T = usz*; -typedef Win32_PSSIZE_T = isz*; -typedef Win32_PSTR = Win32_CHAR*; -typedef Win32_PTBYTE = Win32_TBYTE*; -typedef Win32_PTCHAR = Win32_TCHAR*; -typedef Win32_PTSTR = Win32_LPWSTR; -typedef Win32_PUCHAR = Win32_UCHAR*; -typedef Win32_PUHALFPTR = Win32_UHALF_PTR*; -typedef Win32_PUINT = Win32_UINT*; -typedef Win32_PUINTPTR = Win32_UINT_PTR*; -typedef Win32_PUINT8 = Win32_UINT8*; -typedef Win32_PUINT16 = Win32_UINT16*; -typedef Win32_PUINT32 = Win32_UINT32*; -typedef Win32_PUINT64 = Win32_UINT64*; -typedef Win32_PULONG = Win32_ULONG*; -typedef Win32_PULONGLONG = Win32_ULONGLONG*; -typedef Win32_PULONG_PTR = Win32_ULONG_PTR*; -typedef Win32_PULONG32 = Win32_ULONG32*; -typedef Win32_PULONG64 = Win32_ULONG64*; -typedef Win32_PUNICODE_STRING = Win32_UNICODE_STRING*; -typedef Win32_PUSHORT = Win32_USHORT*; -typedef Win32_PVOID = void*; -typedef Win32_PWCHAR = Win32_WCHAR*; -typedef Win32_PWORD = Win32_WORD*; -typedef Win32_PWSTR = Win32_WCHAR*; -typedef Win32_QWORD = ulong; -typedef Win32_SC_HANDLE = Win32_HANDLE; -typedef Win32_SC_LOCK = Win32_LPVOID; -typedef Win32_SERVICE_STATUS_HANDLE = Win32_HANDLE; -typedef Win32_SHORT = short; -typedef Win32_SIZE_T = usz; -typedef Win32_SSIZE_T = isz; -typedef Win32_TBYTE = Win32_WCHAR; -typedef Win32_TCHAR = Win32_WCHAR; -typedef Win32_UCHAR = char; -typedef Win32_UHALF_PTR = uint; -typedef Win32_UINT = uint; -typedef Win32_UINT_PTR = uptr; -typedef Win32_UINT8 = char; -typedef Win32_UINT16 = ushort; -typedef Win32_UINT32 = uint; -typedef Win32_UINT64 = ulong; -typedef Win32_ULONG = uint; -typedef Win32_ULONGLONG = ulong; -typedef Win32_ULONG_PTR = ulong; -typedef Win32_ULONG32 = uint; -typedef Win32_ULONG64 = ulong; -typedef Win32_USHORT = ushort; -typedef Win32_USN = Win32_LONGLONG; -typedef Win32_WCHAR = Char16; -typedef Win32_WORD = ushort; -typedef Win32_WPARAM = Win32_UINT_PTR; +def Win32_BOOL = int; +def Win32_BOOLEAN = Win32_BYTE; +def Win32_BYTE = char; +def Win32_CCHAR = cinterop::CChar; +def Win32_CHAR = cinterop::CChar; +def Win32_COLORREF = Win32_DWORD; +def Win32_DWORD = uint; +def Win32_DWORDLONG = ulong; +def Win32_DWORD_PTR = Win32_ULONG_PTR; +def Win32_DWORD32 = uint; +def Win32_DWORD64 = ulong; +def Win32_FLOAT = float; +def Win32_HACCEL = Win32_HANDLE; +def Win32_HALF_PTR = int; +def Win32_HANDLE = Win32_PVOID; +def Win32_HBITMAP = Win32_HANDLE; +def Win32_HBRUSH = Win32_HANDLE; +def Win32_HCOLORSPACE = Win32_HANDLE; +def Win32_HCONV = Win32_HANDLE; +def Win32_HCONVLIST = Win32_HANDLE; +def Win32_HCURSOR = Win32_HICON; +def Win32_HDC = Win32_HANDLE; +def Win32_HDDEDATA = Win32_HANDLE; +def Win32_HDESK = Win32_HANDLE; +def Win32_HDROP = Win32_HANDLE; +def Win32_HDWP = Win32_HANDLE; +def Win32_HFILE = int; +def Win32_HFONT = Win32_HANDLE; +def Win32_HGDIOBJ = Win32_HANDLE; +def Win32_HGLOBAL = Win32_HANDLE; +def Win32_HHOOK = Win32_HANDLE; +def Win32_HICON = Win32_HANDLE; +def Win32_HINSTANCE = Win32_HANDLE; +def Win32_HKEY = Win32_HANDLE; +def Win32_HKL = Win32_HANDLE; +def Win32_HLOCAL = Win32_HANDLE; +def Win32_HMENU = Win32_HANDLE; +def Win32_HMETAFILE = Win32_HANDLE; +def Win32_HMODULE = Win32_HANDLE; +def Win32_HMONITOR = Win32_HANDLE; +def Win32_HPALETTE = Win32_HANDLE; +def Win32_HPEN = Win32_HANDLE; +def Win32_HRESULT = Win32_LONG; +def Win32_HRGN = Win32_HANDLE; +def Win32_HRSRC = Win32_HANDLE; +def Win32_HSZ = Win32_HANDLE; +def Win32_HWINSTA = Win32_HANDLE; +def Win32_HWND = Win32_HANDLE; +def Win32_INT = int; +def Win32_INT_PTR = iptr; +def Win32_INT8 = ichar; +def Win32_INT16 = short; +def Win32_INT32 = int; +def Win32_INT64 = long; +def Win32_LANGID = Win32_WORD; +def Win32_LCID = Win32_DWORD; +def Win32_LCTYPE = Win32_DWORD; +def Win32_LGRPID = Win32_DWORD; +def Win32_LONG = int; +def Win32_LONGLONG = long; +def Win32_LONG_PTR = iptr; +def Win32_LONG32 = int; +def Win32_LONG64 = long; +def Win32_LPARAM = Win32_LONG_PTR; +def Win32_LPBOOL = Win32_BOOL*; +def Win32_LPBYTE = Win32_BYTE*; +def Win32_LPCOLORREF = Win32_DWORD*; +def Win32_LPCSTR = Win32_CCHAR*; +def Win32_LPCTSTR = Win32_LPCWSTR; +def Win32_LPCVOID = void*; +def Win32_LPCWSTR = Win32_WCHAR*; +def Win32_LPDWORD = Win32_DWORD*; +def Win32_LPHANDLE = Win32_HANDLE*; +def Win32_LPINT = int*; +def Win32_LPLONG = int*; +def Win32_LPSTR = Win32_CCHAR*; +def Win32_LPTSTR = Win32_LPWSTR; +def Win32_LPVOID = void*; +def Win32_LPWORD = Win32_WORD*; +def Win32_LPWSTR = Win32_WCHAR*; +def Win32_LRESULT = Win32_LONG_PTR; +def Win32_PBOOL = Win32_BOOL*; +def Win32_PBOOLEAN = Win32_BOOLEAN*; +def Win32_PBYTE = Win32_BYTE*; +def Win32_PCHAR = Win32_CHAR*; +def Win32_PCSTR = Win32_CHAR*; +def Win32_PCTSTR = Win32_LPCWSTR; +def Win32_PCUNICODE_STRING = Win32_UNICODE_STRING*; +def Win32_PCWSTR = Char16*; +def Win32_PDWORD = Win32_DWORD*; +def Win32_PDWORDLONG = Win32_DWORDLONG*; +def Win32_PDWORDPTR = Win32_DWORD_PTR*; +def Win32_PDWORD32 = Win32_DWORD32*; +def Win32_PDWORD64 = Win32_DWORD64*; +def Win32_PFLOAT = Win32_FLOAT*; +def Win32_PHALFPTR = Win32_HALF_PTR*; +def Win32_PHANDLE = Win32_HANDLE*; +def Win32_PHKEY = Win32_HKEY*; +def Win32_PINT = int*; +def Win32_PINTPTR = Win32_INT_PTR*; +def Win32_PINT8 = Win32_INT8*; +def Win32_PINT16 = Win32_INT16*; +def Win32_PINT32 = Win32_INT32*; +def Win32_PINT64 = Win32_INT64*; +def Win32_PLCID = Win32_PDWORD; +def Win32_PLONG = Win32_LONG*; +def Win32_PLONGLONG = Win32_LONGLONG*; +def Win32_PLONG_PTR = Win32_LONG_PTR*; +def Win32_PLONG32 = Win32_LONG32*; +def Win32_PLONG64 = Win32_LONG64*; +def Win32_POINTER_32 = uint; +def Win32_POINTER_64 = uptr; +def Win32_POINTER_SIGNED = iptr; +def Win32_POINTER_UNSIGNED = uptr; +def Win32_PSHORT = Win32_SHORT*; +def Win32_PSIZE_T = usz*; +def Win32_PSSIZE_T = isz*; +def Win32_PSTR = Win32_CHAR*; +def Win32_PTBYTE = Win32_TBYTE*; +def Win32_PTCHAR = Win32_TCHAR*; +def Win32_PTSTR = Win32_LPWSTR; +def Win32_PUCHAR = Win32_UCHAR*; +def Win32_PUHALFPTR = Win32_UHALF_PTR*; +def Win32_PUINT = Win32_UINT*; +def Win32_PUINTPTR = Win32_UINT_PTR*; +def Win32_PUINT8 = Win32_UINT8*; +def Win32_PUINT16 = Win32_UINT16*; +def Win32_PUINT32 = Win32_UINT32*; +def Win32_PUINT64 = Win32_UINT64*; +def Win32_PULONG = Win32_ULONG*; +def Win32_PULONGLONG = Win32_ULONGLONG*; +def Win32_PULONG_PTR = Win32_ULONG_PTR*; +def Win32_PULONG32 = Win32_ULONG32*; +def Win32_PULONG64 = Win32_ULONG64*; +def Win32_PUNICODE_STRING = Win32_UNICODE_STRING*; +def Win32_PUSHORT = Win32_USHORT*; +def Win32_PVOID = void*; +def Win32_PWCHAR = Win32_WCHAR*; +def Win32_PWORD = Win32_WORD*; +def Win32_PWSTR = Win32_WCHAR*; +def Win32_QWORD = ulong; +def Win32_SC_HANDLE = Win32_HANDLE; +def Win32_SC_LOCK = Win32_LPVOID; +def Win32_SERVICE_STATUS_HANDLE = Win32_HANDLE; +def Win32_SHORT = short; +def Win32_SIZE_T = usz; +def Win32_SSIZE_T = isz; +def Win32_TBYTE = Win32_WCHAR; +def Win32_TCHAR = Win32_WCHAR; +def Win32_UCHAR = char; +def Win32_UHALF_PTR = uint; +def Win32_UINT = uint; +def Win32_UINT_PTR = uptr; +def Win32_UINT8 = char; +def Win32_UINT16 = ushort; +def Win32_UINT32 = uint; +def Win32_UINT64 = ulong; +def Win32_ULONG = uint; +def Win32_ULONGLONG = ulong; +def Win32_ULONG_PTR = ulong; +def Win32_ULONG32 = uint; +def Win32_ULONG64 = ulong; +def Win32_USHORT = ushort; +def Win32_USN = Win32_LONGLONG; +def Win32_WCHAR = Char16; +def Win32_WORD = ushort; +def Win32_WPARAM = Win32_UINT_PTR; const INVALID_HANDLE_VALUE = (Win32_HANDLE)(uptr)-1; @@ -187,7 +187,7 @@ union Win32_LARGE_INTEGER ulong quadPart; } -typedef Win32_CRITICAL_SECTION = distinct ulong[5]; +def Win32_CRITICAL_SECTION = distinct ulong[5]; struct Win32_SECURITY_ATTRIBUTES { @@ -196,8 +196,8 @@ struct Win32_SECURITY_ATTRIBUTES Win32_BOOL bInheritHandle; } -typedef Win32_LPSECURITY_ATTRIBUTES = Win32_SECURITY_ATTRIBUTES*; -typedef Win32_PSECURITY_ATTRIBUTES = Win32_SECURITY_ATTRIBUTES*; +def Win32_LPSECURITY_ATTRIBUTES = Win32_SECURITY_ATTRIBUTES*; +def Win32_PSECURITY_ATTRIBUTES = Win32_SECURITY_ATTRIBUTES*; struct Win32_STARTUPINFOW { @@ -221,7 +221,7 @@ struct Win32_STARTUPINFOW Win32_HANDLE hStdError; } -typedef Win32_LPSTARTUPINFOW = Win32_STARTUPINFOW*; +def Win32_LPSTARTUPINFOW = Win32_STARTUPINFOW*; struct Win32_STARTUPINFOEXW { @@ -229,8 +229,8 @@ struct Win32_STARTUPINFOEXW Win32_LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; } -typedef Win32_LPPROC_THREAD_ATTRIBUTE_LIST = void*; -typedef Win32_LPSTARTUPINFOEXW = Win32_STARTUPINFOEXW*; +def Win32_LPPROC_THREAD_ATTRIBUTE_LIST = void*; +def Win32_LPSTARTUPINFOEXW = Win32_STARTUPINFOEXW*; struct Win32_FILETIME { @@ -246,5 +246,5 @@ struct Win32_PROCESS_INFORMATION Win32_DWORD dwThreadId; } -typedef Win32_PPROCESS_INFORMATION = Win32_PROCESS_INFORMATION*; -typedef Win32_LPPROCESS_INFORMATION = Win32_PROCESS_INFORMATION*; +def Win32_PPROCESS_INFORMATION = Win32_PROCESS_INFORMATION*; +def Win32_LPPROCESS_INFORMATION = Win32_PROCESS_INFORMATION*; diff --git a/lib/std/os/win32/wsa.c3 b/lib/std/os/win32/wsa.c3 index 96cd3330a..e893cb63c 100644 --- a/lib/std/os/win32/wsa.c3 +++ b/lib/std/os/win32/wsa.c3 @@ -1,6 +1,6 @@ module std::os::win32; -typedef WSAError = distinct int; +def WSAError = distinct int; $if env::os_is_win32(): diff --git a/lib/std/threads/os/thread_none.c3 b/lib/std/threads/os/thread_none.c3 index e44f48dca..633c55e18 100644 --- a/lib/std/threads/os/thread_none.c3 +++ b/lib/std/threads/os/thread_none.c3 @@ -1,6 +1,6 @@ module std::thread; -typedef NativeMutex = distinct int; -typedef NativeConditionVariable = distinct int; -typedef NativeOnceFlag = distinct int; -typedef NativeThread = distinct int; \ No newline at end of file +def NativeMutex = distinct int; +def NativeConditionVariable = distinct int; +def NativeOnceFlag = distinct int; +def 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 77b2c84a5..e9ac6581d 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; -typedef NativeMutex = PthreadMutex; -typedef NativeConditionVariable = PthreadCond; -typedef NativeThread = Pthread; -typedef NativeOnceFlag = PthreadOnce; +def NativeMutex = PthreadMutex; +def NativeConditionVariable = PthreadCond; +def NativeThread = Pthread; +def NativeOnceFlag = PthreadOnce; -typedef Pthread = distinct void*; +def Pthread = distinct void*; $if env::OS_TYPE == LINUX: -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; +def PthreadMutex = distinct ulong[5]; +def PthreadAttribute = distinct ulong[7]; +def PthreadMutexAttribute = distinct uint; +def PthreadCondAttribute = distinct uint; +def PthreadCond = distinct ulong[6]; +def PthreadOnce = distinct uint; $else -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]; +def PthreadMutex = distinct ulong[8]; +def PthreadMutexAttribute = distinct ulong[2]; +def PthreadAttribute = distinct ulong[8]; +def PthreadCond = distinct ulong[6]; +def PthreadCondAttribute = distinct ulong[8]; +def PthreadOnce = distinct ulong[2]; $endif -typedef PosixThreadFn = fn void*(void*); +def 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/thread.c3 b/lib/std/threads/thread.c3 index c292e4f40..b0bdc0a3c 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_is_win32() ? ThreadModel.WIN32 : ThreadModel.POSIX) : ThreadModel.NONE; -typedef MutexType = distinct int; +def MutexType = distinct int; const MutexType MUTEX_PLAIN = 0; const MutexType MUTEX_TIMED = 1; const MutexType MUTEX_RECURSIVE = 2; -typedef Mutex = distinct NativeMutex; -typedef ConditionVariable = distinct NativeConditionVariable; -typedef Thread = distinct NativeThread; -typedef OnceFlag = distinct NativeOnceFlag; -typedef OnceFn = fn void(); +def Mutex = distinct NativeMutex; +def ConditionVariable = distinct NativeConditionVariable; +def Thread = distinct NativeThread; +def OnceFlag = distinct NativeOnceFlag; +def OnceFn = fn void(); -typedef ThreadFn = fn int(void* arg); +def ThreadFn = fn int(void* arg); fault ThreadFault { diff --git a/src/compiler/codegen_internal.h b/src/compiler/codegen_internal.h index 50328fa9f..79d81ea3f 100644 --- a/src/compiler/codegen_internal.h +++ b/src/compiler/codegen_internal.h @@ -43,6 +43,36 @@ static inline Type *type_lowering(Type *type) continue; case TYPE_WILDCARD: type = type_void; + break; + case TYPE_POINTER: + { + Type *pointer = type->pointer; + Type *flat = type_lowering(pointer); + if (flat == pointer) return type; + return type_get_ptr(flat); + } + case TYPE_SUBARRAY: + case TYPE_ARRAY: + case TYPE_VECTOR: + case TYPE_FLEXIBLE_ARRAY: + { + Type *arr_type = type->array.base; + Type *flat = type_lowering(arr_type); + if (flat == arr_type) return type; + switch (type->type_kind) + { + case TYPE_SUBARRAY: + return type_get_subarray(flat); + case TYPE_ARRAY: + return type_get_array(flat, type->array.len); + case TYPE_VECTOR: + return type_get_vector(flat, type->array.len); + case TYPE_FLEXIBLE_ARRAY: + return type_get_flexible_array(flat); + default: + UNREACHABLE + } + } default: return type; } diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index a91840594..7405a9dac 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -144,6 +144,31 @@ void **tilde_gen(Module** modules, unsigned module_count) #endif +static const char *build_base_name(void) +{ + const char *name; + if (active_target.name) + { + name = active_target.name; + } + else + { + assert(vec_size(global_context.module_list)); + Path *path = global_context.module_list[0]->name; + size_t first = 0; + for (size_t i = path->len; i > 0; i--) + { + if (path->module[i - 1] == ':') + { + first = i; + break; + } + } + name = &path->module[first]; + } + return name; +} + static const char *exe_name(void) { assert(global_context.main || active_target.no_entry); @@ -178,30 +203,26 @@ static const char *exe_name(void) } } -static const char *dynamic_lib_name(void) { return NULL; } - -static const char *static_lib_name(void) +static const char *dynamic_lib_name(void) { - const char *name; - if (active_target.name) - { - name = active_target.name; - } - else + const char *name = build_base_name(); + switch (active_target.arch_os_target) { - assert(vec_size(global_context.module_list)); - Path *path = global_context.module_list[0]->name; - size_t first = 0; - for (size_t i = path->len; i > 0; i--) - { - if (path->module[i - 1] == ':') - { - first = i; - break; - } - } - name = &path->module[first]; + case WINDOWS_AARCH64: + case WINDOWS_X64: + case MINGW_X64: + return str_cat(name, ".dll"); + case MACOS_X64: + case MACOS_AARCH64: + return str_cat(name, ".dylib"); + default: + return str_cat(name, ".a"); } +} + +static const char *static_lib_name(void) +{ + const char *name = build_base_name(); switch (active_target.arch_os_target) { case WINDOWS_AARCH64: diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 67244b377..b5a637171 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -792,6 +792,7 @@ typedef struct bool is_func_ref : 1; bool attr_pure : 1; bool result_unused : 1; + bool no_return : 1; AstId body; union { @@ -2576,7 +2577,7 @@ INLINE CanonicalType *type_pointer_type(Type *type) { CanonicalType *res = type->canonical; if (res->type_kind != TYPE_POINTER) return NULL; - return res->pointer ; + return res->pointer; } INLINE bool type_is_pointer(Type *type) diff --git a/src/compiler/linker.c b/src/compiler/linker.c index 01c3f9d1e..716be0bb5 100644 --- a/src/compiler/linker.c +++ b/src/compiler/linker.c @@ -461,21 +461,39 @@ static void linker_setup_freebsd(const char ***args_ref, LinkerType linker_type) static bool linker_setup(const char ***args_ref, const char **files_to_link, unsigned file_count, const char *output_file, LinkerType linker_type) { + bool is_dylib = active_target.type == TARGET_TYPE_DYNAMIC_LIB; bool use_win = linker_type == LINKER_LINK_EXE; - if (use_win) + if (!use_win) { - add_arg2("/OUT:", output_file); - if (active_target.no_entry) add_arg("/NOENTRY"); - } - else - { - if (linker_type == LINKER_WASM) - { - if (active_target.no_entry) add_arg("--no-entry"); - } add_arg("-o"); add_arg(output_file); } + switch (linker_type) + { + case LINKER_WASM: + if (!is_dylib && active_target.no_entry) add_arg("--no-entry"); + break; + case LINKER_LD64: + if (is_dylib) vec_add(*args_ref, "-dylib"); + break; + case LINKER_LD: + if (is_dylib) vec_add(*args_ref, "-shared"); + break; + case LINKER_LINK_EXE: + add_arg2("/OUT:", output_file); + if (is_dylib) + { + add_arg("/DLL"); + } + else + { + if (active_target.no_entry) add_arg("/NOENTRY"); + } + case LINKER_CC: + break; + default: + UNREACHABLE + } const char *lib_path_opt = use_win ? "/LIBPATH:" : "-L"; switch (platform_target.os) @@ -792,6 +810,46 @@ const char *platform_compiler(const char *file, const char *flags) bool dynamic_lib_linker(const char *output_file, const char **files, unsigned file_count) { + DEBUG_LOG("Using linker directly."); + const char **args = NULL; + LinkerType linker_type = linker_find_linker_type(); + linker_setup(&args, files, file_count, output_file, linker_type); + + const char *error = NULL; + // This isn't used in most cases, but its contents should get freed after linking. + + bool success; + const char *arg_list = ""; + VECEACH(args, i) + { + arg_list = str_cat(arg_list, " "); + arg_list = str_cat(arg_list, args[i]); + } + DEBUG_LOG("Linker arguments: %s to %d", arg_list, platform_target.object_format); + switch (platform_target.object_format) + { + case OBJ_FORMAT_COFF: + success = llvm_link_coff(args, (int)vec_size(args), &error); + break; + case OBJ_FORMAT_ELF: + success = llvm_link_elf(args, (int)vec_size(args), &error); + break; + case OBJ_FORMAT_MACHO: + success = llvm_link_macho(args, (int)vec_size(args), &error); + break; + case OBJ_FORMAT_WASM: + success = llvm_link_wasm(args, (int)vec_size(args), &error); + break; + default: + UNREACHABLE + } + if (!success) + { + error_exit("Failed to create an executable: %s", error); + } + DEBUG_LOG("Linking complete."); + return true; + error_exit("Apologies, dynamic libs are still not supported."); } diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index d8fa3696b..46762f3ae 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -1535,12 +1535,12 @@ void llvm_emit_cast(GenContext *c, CastKind cast_kind, Expr *expr, BEValue *valu { value->value = llvm_emit_extract_value(c, value->value, 1); } - value->type = type_usz->canonical; + value->type = type_lowering(type_usz); llvm_value_rvalue(c, value); llvm_emit_int_comp_zero(c, value, value, BINARYOP_NE); break; } - value->type = to_type; + value->type = type_lowering(to_type); } static inline void llvm_emit_cast_expr(GenContext *context, BEValue *be_value, Expr *expr) diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 042bde988..c0e24a3c9 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1532,6 +1532,8 @@ static inline bool sema_call_analyse_func_invocation(SemaContext *context, Type bool is_unused = expr->call_expr.result_unused; + if (sig->attrs.noreturn) expr->call_expr.no_return = true; + if (!sema_call_analyse_invocation(context, expr, callee, &optional)) return false; Type *rtype = type->function.prototype->rtype; diff --git a/src/compiler/sema_name_resolution.c b/src/compiler/sema_name_resolution.c index b61db37c2..2732b47e6 100644 --- a/src/compiler/sema_name_resolution.c +++ b/src/compiler/sema_name_resolution.c @@ -356,6 +356,7 @@ static Decl *sema_resolve_path_symbol(SemaContext *context, NameResolve *name_re // 0. std module special handling. if (path->module == global_context.std_module_path.module) { + name_resolve->path_found = true; return module_find_symbol(&global_context.std_module, symbol); } @@ -366,6 +367,7 @@ static Decl *sema_resolve_path_symbol(SemaContext *context, NameResolve *name_re { // 2. If so try to locally get the symbol. if ((decl = module_find_symbol(unit->module, symbol))) return decl; + name_resolve->path_found = true; } // 3. Loop over imports. @@ -539,7 +541,33 @@ INLINE Decl *sema_resolve_symbol_common(SemaContext *context, NameResolve *name_ if (!decl && !name_resolve->maybe_decl && !name_resolve->path_found) { if (name_resolve->suppress_error) return NULL; - SEMA_ERROR(name_resolve->path, "Unknown module '%.*s', did you type it right?", name_resolve->path->len, name_resolve->path->module); + bool path_found = false; + Module *module_with_path = NULL; + FOREACH_BEGIN(Module *module, global_context.module_list) + if (matches_subpath(module->name, name_resolve->path)) + { + module_with_path = module; + break; + } + FOREACH_END(); + if (!module_with_path) + { + FOREACH_BEGIN(Module *module, global_context.generic_module_list) + if (matches_subpath(module->name, name_resolve->path)) + { + module_with_path = module; + break; + } + FOREACH_END(); + } + if (module_with_path) + { + sema_error_at(name_resolve->span, "'%s' could be found in %s.", name_resolve->symbol, module_with_path->name->module); + } + else + { + SEMA_ERROR(name_resolve->path, "Unknown module '%.*s', did you type it right?", name_resolve->path->len, name_resolve->path->module); + } return poisoned_decl; } } diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 69be74b38..378b5457f 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -1047,6 +1047,7 @@ static inline bool sema_analyse_expr_stmt(SemaContext *context, Ast *statement) expr->call_expr.result_unused = true; } if (!sema_analyse_expr(context, expr)) return false; + if (expr->expr_kind == EXPR_CALL && expr->call_expr.no_return) context->active_scope.jump_end = true; // Remove all const statements. if (expr_is_const(expr)) { diff --git a/src/version.h b/src/version.h index d52494b4f..9b1fbe88b 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.512" \ No newline at end of file +#define COMPILER_VERSION "0.4.513" \ No newline at end of file diff --git a/test/test_suite/attributes/attribute_params.c3 b/test/test_suite/attributes/attribute_params.c3 index 714a915d3..dbad2720e 100644 --- a/test/test_suite/attributes/attribute_params.c3 +++ b/test/test_suite/attributes/attribute_params.c3 @@ -1,5 +1,5 @@ -define @Foo() = { @inline }; // #error: At least one parameter was expected -define @Bar = { @inline }; +def @Foo() = { @inline }; // #error: At least one parameter was expected +def @Bar = { @inline }; fn void test1() @Foo { } fn void test2() @Foo() { } // #error: An expression was diff --git a/test/test_suite/attributes/recursive_attributes.c3 b/test/test_suite/attributes/recursive_attributes.c3 index d2082850d..bba90fcf1 100644 --- a/test/test_suite/attributes/recursive_attributes.c3 +++ b/test/test_suite/attributes/recursive_attributes.c3 @@ -1,8 +1,8 @@ module test; -define @Align(y) = { @Align16(y / 2) }; -define @Align16(x) = { @align(4) @Align(8 * x) }; // #error: Recursive declaration of attribute -define @Test = { @noinline }; +def @Align(y) = { @Align16(y / 2) }; +def @Align16(x) = { @align(4) @Align(8 * x) }; // #error: Recursive declaration of attribute +def @Test = { @noinline }; struct Foo { int z; diff --git a/test/test_suite/cast/cast_subarray.c3t b/test/test_suite/cast/cast_subarray.c3t index 4e5cb3cb5..89e6fd1dc 100644 --- a/test/test_suite/cast/cast_subarray.c3t +++ b/test/test_suite/cast/cast_subarray.c3t @@ -17,8 +17,8 @@ entry: %abc = alloca %"int*[]", align 8 %bcd = alloca %"void*[]", align 8 %cde = alloca %"int[]", align 8 - %xyz = alloca %"Foo[]", align 8 - %xyz2 = alloca %"Foo[]", align 8 + %xyz = alloca %"int[]", align 8 + %xyz2 = alloca %"int[]", align 8 %literal = alloca [2 x i32], align 4 store %"int*[]" zeroinitializer, ptr %abc, align 8 call void @llvm.memcpy.p0.p0.i32(ptr align 8 %bcd, ptr align 8 %abc, i32 16, i1 false) @@ -28,8 +28,8 @@ entry: store i32 1, ptr %0, align 4 %1 = getelementptr inbounds [2 x i32], ptr %literal, i64 0, i64 1 store i32 2, ptr %1, align 4 - %2 = insertvalue %"Foo[]" undef, ptr %literal, 0 - %3 = insertvalue %"Foo[]" %2, i64 2, 1 - store %"Foo[]" %3, ptr %xyz2, align 8 + %2 = insertvalue %"int[]" undef, ptr %literal, 0 + %3 = insertvalue %"int[]" %2, i64 2, 1 + store %"int[]" %3, ptr %xyz2, align 8 ret void } diff --git a/test/test_suite/define/common.c3 b/test/test_suite/define/common.c3 index f4eaea3f4..e91a52091 100644 --- a/test/test_suite/define/common.c3 +++ b/test/test_suite/define/common.c3 @@ -1,17 +1,17 @@ module foo; // define = -define standard_foo = __stdin; -define someFunctionIntBool = someFunction; -typedef FooInt = Foo; -define A_CONST_INT = A_CONST; +def standard_foo = __stdin; +def someFunctionIntBool = someFunction; +def FooInt = Foo; +def A_CONST_INT = A_CONST; -define standard_foo = ofke; // #error: Expected '=' -define fn foo = fef; // #error: A variable, constant or attribute name was expected here. -define feokfe = fn void(int); // #error: Expected a function or variable name here -define AOFKE = ofek; // #error: Expected a constant name here -define okfoe = OFKEOK; // #error: Expected a function or variable name here -typedef Helo = helo; // #error: A type name was expected here -typedef Helo = OFKE; // #error: A type name was expected here -define helo = Helo; // #error: A type alias must start with an uppercase letter and contain at least one lower case letter. -define HELO = Helo; // #error: A type alias must start with an uppercase letter and contain at least one lower case letter. +def standard_foo = ofke; // #error: Expected '=' +def fn foo = fef; // #error: A variable, constant or attribute name was expected here. +def feokfe = fn void(int); // #error: Expected a function or variable name here +def AOFKE = ofek; // #error: Expected a constant name here +def okfoe = OFKEOK; // #error: Expected a function or variable name here +def Helo = helo; // #error: A type name was expected here +def Helo = OFKE; // #error: A type name was expected here +def helo = Helo; // #error: A type alias must start with an uppercase letter and contain at least one lower case letter. +def HELO = Helo; // #error: A type alias must start with an uppercase letter and contain at least one lower case letter. diff --git a/test/test_suite/define/define_name_errors.c3 b/test/test_suite/define/define_name_errors.c3 index 55a0f98f7..d41693ac5 100644 --- a/test/test_suite/define/define_name_errors.c3 +++ b/test/test_suite/define/define_name_errors.c3 @@ -1,6 +1,6 @@ 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. +def main = foo; // #error: 'main' is reserved and cannot be used as an alias. typedef hello = int; // #error: uppercase letter typedef hello = Foo; // #error: uppercase letter diff --git a/test/test_suite/define/test_at.c3 b/test/test_suite/define/test_at.c3 index 621b2871a..ee6fa3941 100644 --- a/test/test_suite/define/test_at.c3 +++ b/test/test_suite/define/test_at.c3 @@ -9,8 +9,8 @@ module bar; import foo @public; -define intHello = foo::@hello; // #error: cannot be aliased -define @intHello = foo::hello; // #error: cannot use +def intHello = foo::@hello; // #error: cannot be aliased +def @intHello = foo::hello; // #error: cannot use fn void main(String[] args) { @intHello(42); diff --git a/test/test_suite/define/test_at_alias.c3 b/test/test_suite/define/test_at_alias.c3 index 612b6dadf..aca1f202e 100644 --- a/test/test_suite/define/test_at_alias.c3 +++ b/test/test_suite/define/test_at_alias.c3 @@ -9,7 +9,7 @@ module bar; import foo @public; -define @intHello = foo::@hello; +def @intHello = foo::@hello; fn void main(String[] args) { @intHello(42); diff --git a/test/test_suite/enumerations/enum_associated_values_other.c3t b/test/test_suite/enumerations/enum_associated_values_other.c3t index 9f5bd2e5f..cea7a2a0b 100644 --- a/test/test_suite/enumerations/enum_associated_values_other.c3t +++ b/test/test_suite/enumerations/enum_associated_values_other.c3t @@ -52,7 +52,7 @@ enum Foo : int(String val) define void @test.main(ptr %0, i64 %1) #0 { entry: - %args = alloca %"String[]", align 8 + %args = alloca %"char[][]", align 8 %y = alloca i64, align 8 %x = alloca ptr, align 8 %a = alloca i32, align 4 diff --git a/test/test_suite/enumerations/enum_values.c3t b/test/test_suite/enumerations/enum_values.c3t index 7b5938446..615499013 100644 --- a/test/test_suite/enumerations/enum_values.c3t +++ b/test/test_suite/enumerations/enum_values.c3t @@ -18,11 +18,9 @@ fn void test(int x) /* #expect: test.ll -%"Foo[]" = type { ptr, i64 } - @test.zfok = local_unnamed_addr global i32 0, align 4 @.taddr = private global [2 x i32] [i32 0, i32 1], align 4 -@test.zw = local_unnamed_addr global %"Foo[]" { ptr @.taddr, i64 2 }, align 8 +@test.zw = local_unnamed_addr global %"int[]" { ptr @.taddr, i64 2 }, align 8 define void @test.test(i32 %0) #0 { entry: diff --git a/test/test_suite/errors/error_introspect.c3t b/test/test_suite/errors/error_introspect.c3t index 4084093dd..af4a88c1e 100644 --- a/test/test_suite/errors/error_introspect.c3t +++ b/test/test_suite/errors/error_introspect.c3t @@ -36,7 +36,7 @@ fn void main() @"$ct.long" = linkonce constant %.introspect { i8 2, i64 8, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8 entry: - %x = alloca %"String[]", align 8 + %x = alloca %"char[][]", align 8 %literal = alloca [2 x %"char[]"], align 16 %retparam = alloca i64, align 8 %varargslots = alloca [1 x %any], align 16 @@ -50,9 +50,9 @@ entry: store %"char[]" { ptr @.str, i64 3 }, ptr %0, align 8 %1 = getelementptr inbounds [2 x %"char[]"], ptr %literal, i64 0, i64 1 store %"char[]" { ptr @.str.2, i64 3 }, ptr %1, align 8 - %2 = insertvalue %"String[]" undef, ptr %literal, 0 - %3 = insertvalue %"String[]" %2, i64 2, 1 - store %"String[]" %3, ptr %x, align 8 + %2 = insertvalue %"char[][]" undef, ptr %literal, 0 + %3 = insertvalue %"char[][]" %2, i64 2, 1 + store %"char[][]" %3, ptr %x, align 8 %4 = insertvalue %any undef, ptr %x, 0 %5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.sa$String" to i64), 1 %6 = getelementptr inbounds [1 x %any], ptr %varargslots, i64 0, i64 0 diff --git a/test/test_suite/expressions/addr_of_fails.c3 b/test/test_suite/expressions/addr_of_fails.c3 index b5df5a2cf..8cdb55fbc 100644 --- a/test/test_suite/expressions/addr_of_fails.c3 +++ b/test/test_suite/expressions/addr_of_fails.c3 @@ -48,7 +48,7 @@ struct Foo int y; } -define heh = he; +def heh = he; fn void test6() { diff --git a/test/unit/stdlib/collections/list.c3 b/test/unit/stdlib/collections/list.c3 index 8f7e569d8..952a72292 100644 --- a/test/unit/stdlib/collections/list.c3 +++ b/test/unit/stdlib/collections/list.c3 @@ -1,8 +1,8 @@ module listtests @test; import std::collections::list; -typedef IntList = List; -typedef PtrList = List; +def IntList = List; +def PtrList = List; fn void! test_delete_contains_index() {