- Change distinct -> typedef.

- Order of attribute declaration is changed for `alias`.
- Added `LANGUAGE_DEV_VERSION` env constant.
- Rename `anyfault` -> `fault`.
- Changed `fault` -> `faultdef`.
- Added `attrdef` instead of `alias` for attribute aliases.
This commit is contained in:
Christoffer Lerno
2025-03-15 15:21:55 +01:00
committed by Christoffer Lerno
parent fc5615a7a1
commit 5c77c9a754
221 changed files with 649 additions and 684 deletions

View File

@@ -8,10 +8,10 @@
module std::collections::enumset{Enum};
import std::io;
alias EnumSetType = $typefrom(type_for_enum_elements(Enum.elements)) @private;
alias EnumSetType @private = $typefrom(type_for_enum_elements(Enum.elements));
const IS_CHAR_ARRAY = Enum.elements > 128;
distinct EnumSet (Printable) = EnumSetType;
typedef EnumSet (Printable) = EnumSetType;
fn void EnumSet.add(&self, Enum v)
{

View File

@@ -535,8 +535,8 @@ struct HashMapIterator
Entry* current_entry;
}
distinct HashMapValueIterator = HashMapIterator;
distinct HashMapKeyIterator = HashMapIterator;
typedef HashMapValueIterator = HashMapIterator;
typedef HashMapKeyIterator = HashMapIterator;
<*

View File

@@ -462,7 +462,7 @@ fn Object* Object.get_or_create_obj(&self, String key)
return container;
}
alias ObjectInternalMap = HashMap{String, Object*} @private;
alias ObjectInternalList = List{Object*} @private;
alias ObjectInternalMapEntry = Entry{String, Object*} @private;
alias ObjectInternalMap @private = HashMap {String, Object*};
alias ObjectInternalList @private = List {Object*};
alias ObjectInternalMapEntry @private = Entry {String, Object*};

View File

@@ -23,8 +23,8 @@
module std::collections::priorityqueue{Type};
import std::collections::priorityqueue::private;
distinct PriorityQueue = inline PrivatePriorityQueue{Type, false};
distinct PriorityQueueMax = inline PrivatePriorityQueue{Type, true};
typedef PriorityQueue = inline PrivatePriorityQueue{Type, false};
typedef PriorityQueueMax = inline PrivatePriorityQueue{Type, true};
module std::collections::priorityqueue::private{Type, MAX};
import std::collections::list, std::io;

View File

@@ -37,12 +37,11 @@ struct QOIDesc
QOIChannels channels;
QOIColorspace colorspace;
}
<*
QOI Errors.
These are all the possible bad outcomes.
*>
fault INVALID_PARAMETERS, FILE_OPEN_FAILED, FILE_WRITE_FAILED, INVALID_DATA, TOO_MANY_PIXELS;
faultdef INVALID_PARAMETERS, FILE_OPEN_FAILED, FILE_WRITE_FAILED, INVALID_DATA, TOO_MANY_PIXELS;
// Let the user decide if they want to use std::io
@@ -417,7 +416,7 @@ macro @enumcast($Type, raw)
return INVALID_DATA?;
}
distinct Pixel = inline char[<4>];
typedef Pixel = inline char[<4>];
macro char Pixel.hash(Pixel p)
{
return (p.r * 3 + p.g * 5 + p.b * 7 + p.a * 11) % 64;

View File

@@ -7,7 +7,7 @@ import std::io;
import libc;
const LibcAllocator LIBC_ALLOCATOR = {};
distinct LibcAllocator (Allocator, Printable) = uptr;
typedef LibcAllocator (Allocator, Printable) = uptr;
fn String LibcAllocator.to_string(&self, Allocator allocator) @dynamic => "Libc allocator".copy(allocator);
fn usz? LibcAllocator.to_format(&self, Formatter *format) @dynamic => format.print("Libc allocator");

View File

@@ -25,24 +25,24 @@ macro foo(a, #b = EMPTY_MACRO_SLOT)
*>
const EmptySlot EMPTY_MACRO_SLOT @builtin = null;
distinct EmptySlot = void*;
typedef EmptySlot = void*;
macro @is_empty_macro_slot(#arg) @const @builtin => @typeis(#arg, EmptySlot);
macro @is_valid_macro_slot(#arg) @const @builtin => !@typeis(#arg, EmptySlot);
/*
Use `IteratorResult` when reading the end of an iterator, or accessing a result out of bounds.
*/
fault NO_MORE_ELEMENT @builtin;
faultdef NO_MORE_ELEMENT @builtin;
/*
Use `SearchResult` when trying to return a value from some collection but the element is missing.
*/
fault NOT_FOUND @builtin;
faultdef NOT_FOUND @builtin;
/*
Use `CastResult` when an attempt at conversion fails.
*/
fault TYPE_MISMATCH @builtin;
faultdef TYPE_MISMATCH @builtin;
alias VoidFn = fn void();
@@ -373,7 +373,7 @@ macro swizzle2(v, v2, ...) @builtin
@require @typekind(#expr) == OPTIONAL : `@catch expects an Optional value`
*>
macro anyfault @catch(#expr) @builtin
macro fault @catch(#expr) @builtin
{
if (catch f = #expr) return f;
return {};

View File

@@ -1,8 +1,8 @@
module std::core::dstring;
import std::io;
distinct DString (OutStream) = DStringOpaque*;
distinct DStringOpaque = void;
typedef DString (OutStream) = DStringOpaque*;
typedef DStringOpaque = void;
const usz MIN_CAPACITY @private = 16;

View File

@@ -157,6 +157,7 @@ const bool ADDRESS_SANITIZER = $$ADDRESS_SANITIZER;
const bool MEMORY_SANITIZER = $$MEMORY_SANITIZER;
const bool THREAD_SANITIZER = $$THREAD_SANITIZER;
const bool ANY_SANITIZER = ADDRESS_SANITIZER || MEMORY_SANITIZER || THREAD_SANITIZER;
const int LANGUAGE_DEV_VERSION = $$LANGUAGE_DEV_VERSION;
macro bool os_is_darwin() @const
{

View File

@@ -8,7 +8,7 @@ import std::math;
const MAX_MEMORY_ALIGNMENT = 0x1000_0000;
const DEFAULT_MEM_ALIGNMENT = (void*.alignof) * 2;
fault OUT_OF_MEMORY, INVALID_ALLOC_SIZE;
faultdef OUT_OF_MEMORY, INVALID_ALLOC_SIZE;
macro bool @constant_is_power_of_2($x) @const @private
{

View File

@@ -358,7 +358,7 @@ macro void*? @aligned_realloc(#calloc_fn, #free_fn, void* old_pointer, usz bytes
// All allocators
alias mem = thread_allocator @builtin;
alias mem @builtin = thread_allocator ;
tlocal Allocator thread_allocator @private = base_allocator();
Allocator temp_base_allocator @private = base_allocator();
@@ -444,7 +444,7 @@ fn TempAllocator* temp_allocator_next() @private
}
const NullAllocator NULL_ALLOCATOR = {};
distinct NullAllocator (Allocator) = uptr;
typedef NullAllocator (Allocator) = uptr;
fn void*? NullAllocator.acquire(&self, usz bytes, AllocInitType init_type, usz alignment) @dynamic
{

View File

@@ -1,6 +1,6 @@
module std::core::sanitizer::tsan;
distinct MutexFlags = inline CUInt;
typedef MutexFlags = inline CUInt;
const MutexFlags MUTEX_LINKER_INIT = 1 << 0;
const MutexFlags MUTEX_WRITE_REENTRANT = 1 << 1;

View File

@@ -2,14 +2,16 @@ module std::core::string;
import std::ascii;
import std::io;
distinct String @if(!$defined(String)) = inline char[];
distinct ZString = inline char*;
distinct WString = inline Char16*;
typedef String @if(!$defined(String)) = inline char[];
typedef ZString = inline char*;
typedef WString = inline Char16*;
alias Char32 = uint;
alias Char16 = ushort;
fault INVALID_UTF8, INVALID_UTF16, CONVERSION_FAILED, EMPTY_STRING, NEGATIVE_VALUE, MALFORMED_INTEGER,
INTEGER_OVERFLOW, MALFORMED_FLOAT, FLOAT_OUT_OF_RANGE;
faultdef INVALID_UTF8, INVALID_UTF16, CONVERSION_FAILED,
EMPTY_STRING, NEGATIVE_VALUE, MALFORMED_INTEGER,
INTEGER_OVERFLOW, MALFORMED_FLOAT, FLOAT_OUT_OF_RANGE;
const uint SURROGATE_OFFSET @private = 0x10000;
const uint SURROGATE_GENERIC_MASK @private = 0xF800;
@@ -19,7 +21,6 @@ const uint SURROGATE_BITS @private = 10;
const uint SURROGATE_LOW_VALUE @private = 0xDC00;
const uint SURROGATE_HIGH_VALUE @private = 0xD800;
macro Char32* @wstring32(String $string) @builtin
{
return (Char32*)&&$$wstr32($string);
@@ -279,7 +280,7 @@ fn String[] String.split(s, Allocator allocator, String needle, usz max = 0, boo
*>
fn String[] String.tsplit(s, String needle, usz max = 0, bool skip_empty = false) => s.split(tmem(), needle, max, skip_empty) @inline;
fault BUFFER_EXCEEDED;
faultdef BUFFER_EXCEEDED;
<*
Split a string into parts, e.g "a|b|c" split with "|" yields { "a", "b", "c" }

View File

@@ -8,10 +8,7 @@ Example:
module sample::m;
import std::io;
fault MathError
{
DIVISION_BY_ZERO
}
faultdef DIVISION_BY_ZERO;
fn double? divide(int a, int b)
{
@@ -87,7 +84,7 @@ macro @check(#condition, String format = "", args...)
@param error_expected : `expected error of function execution`
@require runtime::test_context != null : "Only allowed in @test functions"
*>
macro @error(#funcresult, anyfault error_expected)
macro @error(#funcresult, fault error_expected)
{
if (catch err = #funcresult)
{

View File

@@ -3,7 +3,7 @@ module std::core::types;
import libc;
fault VALUE_OUT_OF_RANGE, VALUE_OUT_OF_UNSIGNED_RANGE;
faultdef VALUE_OUT_OF_RANGE, VALUE_OUT_OF_UNSIGNED_RANGE;
<*
@require $Type.kindof.is_int() : "Type was not an integer"
@@ -356,7 +356,7 @@ enum TypeKind : char
UNSIGNED_INT,
FLOAT,
TYPEID,
ANYFAULT,
FAULT,
ANY,
ENUM,
STRUCT,

View File

@@ -242,7 +242,7 @@ const char INVALID @private = 0xff;
const int STD_PADDING = '=';
const int NO_PADDING = -1;
distinct Alphabet = char[32];
typedef Alphabet = char[32];
// Standard base32 Alphabet
const Alphabet STD_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
// Extended Hex Alphabet

View File

@@ -1,3 +1,3 @@
module std::encoding;
fault INVALID_CHARACTER, INVALID_PADDING;
faultdef INVALID_CHARACTER, INVALID_PADDING;

View File

@@ -6,7 +6,7 @@ import std::io;
import std::ascii;
import std::collections::object;
fault UNEXPECTED_CHARACTER, INVALID_ESCAPE_SEQUENCE, DUPLICATE_MEMBERS, INVALID_NUMBER;
faultdef UNEXPECTED_CHARACTER, INVALID_ESCAPE_SEQUENCE, DUPLICATE_MEMBERS, INVALID_NUMBER;
fn Object*? parse_string(Allocator allocator, String s)
{

View File

@@ -3,7 +3,7 @@
// a copy of which can be found in the LICENSE_STDLIB file.
module std::hash::fnv32a;
distinct Fnv32a = uint;
typedef Fnv32a = uint;
const FNV32A_START @private = 0x811c9dc5;
const FNV32A_MUL @private = 0x01000193;

View File

@@ -3,7 +3,7 @@
// a copy of which can be found in the LICENSE_STDLIB file.
module std::hash::fnv64a;
distinct Fnv64a = ulong;
typedef Fnv64a = ulong;
const FNV64A_START @private = 0xcbf29ce484222325;
const FNV64A_MUL @private = 0x00000100000001b3;

View File

@@ -10,8 +10,8 @@ interface Printable
fn usz? to_format(Formatter* formatter) @optional;
}
fault BUFFER_EXCEEDED, INTERNAL_BUFFER_EXCEEDED, INVALID_FORMAT, NOT_ENOUGH_ARGUMENTS,
INVALID_ARGUMENT;
faultdef BUFFER_EXCEEDED, INTERNAL_BUFFER_EXCEEDED, INVALID_FORMAT,
NOT_ENOUGH_ARGUMENTS, INVALID_ARGUMENT;
alias OutputFn = fn void?(void* buffer, char c);
alias FloatType = double;
@@ -70,7 +70,7 @@ struct Formatter
uint width;
uint prec;
usz idx;
anyfault first_fault;
fault first_fault;
}
}
@@ -146,8 +146,8 @@ fn usz? Formatter.out_str(&self, any arg) @private
return self.out_substr("typeid");
case VOID:
return self.out_substr("void");
case ANYFAULT:
return self.out_substr((*(anyfault*)arg.ptr).nameof);
case FAULT:
return self.out_substr((*(fault*)arg.ptr).nameof);
case INTERFACE:
case ANY:
return self.out_str(*(any*)arg);

View File

@@ -4,7 +4,7 @@ import std::math;
const char[16] XDIGITS_H = "0123456789ABCDEF";
const char[16] XDIGITS_L = "0123456789abcdef";
fault BAD_FORMAT;
faultdef BAD_FORMAT;
fn usz? print_hex_chars(Formatter* f, char[] out, bool uppercase) @inline
{
@@ -22,7 +22,7 @@ fn usz? print_hex_chars(Formatter* f, char[] out, bool uppercase) @inline
return len;
}
macro Formatter.first_err(&self, anyfault f)
macro Formatter.first_err(&self, fault f)
{
if (self.first_fault) return self.first_fault;
self.first_fault = f;

View File

@@ -11,7 +11,7 @@ enum Seek
END
}
fault
faultdef
ALREADY_EXISTS,
BUSY,
CANNOT_READ_DIR,

View File

@@ -76,7 +76,7 @@ fn usz? native_fread(CFile file, char[] buffer) @inline
return libc::fread(buffer.ptr, 1, buffer.len, file);
}
macro anyfault file_open_errno() @local
macro fault file_open_errno() @local
{
switch (libc::errno())
{
@@ -104,7 +104,7 @@ macro anyfault file_open_errno() @local
}
}
macro anyfault file_seek_errno() @local
macro fault file_seek_errno() @local
{
switch (libc::errno())
{

View File

@@ -9,7 +9,7 @@ const char PREFERRED_SEPARATOR = env::WIN32 ? PREFERRED_SEPARATOR_WIN32 : PREFER
alias PathList = List { Path };
fault INVALID_PATH, NO_PARENT;
faultdef INVALID_PATH, NO_PARENT;
alias Path = PathImp;

View File

@@ -46,12 +46,12 @@ fn void errno_set(Errno e)
os::errno_set((int)e);
}
distinct Errno = inline CInt;
typedef Errno = inline CInt;
alias TerminateFunction = fn void();
alias CompareFunction = fn int(void*, void*);
alias JmpBuf = uptr[$$JMP_BUF_SIZE];
alias Fd = CInt;
alias Fpos_t = long @if(env::WIN32);
alias Fpos_t @if(env::WIN32) = long;
alias SignalFunction = fn void(CInt);
const CInt SIGHUP = 1;
@@ -433,11 +433,11 @@ struct TimeSpec
}
alias Clock_t = int @if(env::WIN32);
alias Clock_t = CLong @if(!env::WIN32);
alias Clock_t @if(env::WIN32) = int;
alias Clock_t @if(!env::WIN32) = CLong;
alias TimeOffset = int @if(env::WASI) ;
alias TimeOffset = CLong @if(!env::WASI) ;
alias TimeOffset @if(env::WASI) = int;
alias TimeOffset @if(!env::WASI) = CLong ;
const int TIME_UTC = 1;

View File

@@ -27,8 +27,8 @@ const CUInt SA_RESTART = env::LINUX ? 0x10000000 : 0x0002;
const CUInt SA_RESETHAND = env::LINUX ? 0x80000000 : 0x0004;
const CUInt SA_SIGINFO = env::LINUX ? 0x00000004 : 0x0040;
alias Sigset_t = uint @if(!env::LINUX);
alias Sigset_t = ulong[16] @if(env::LINUX);
alias Sigset_t @if(!env::LINUX) = uint;
alias Sigset_t @if(env::LINUX) = ulong[16];
alias SigActionFunction = fn void(CInt, void*, void*);
struct Sigaction
@@ -64,10 +64,10 @@ extern fn CInt sigaction(CInt signum, Sigaction *action, Sigaction *oldaction);
module libc::termios @if(env::LIBC &&& env::POSIX);
distinct Cc = char;
distinct Speed = CUInt;
distinct Tcflags = CUInt;
distinct Tcactions = CInt;
typedef Cc = char;
typedef Speed = CUInt;
typedef Tcflags = CUInt;
typedef Tcactions = CInt;
const Tcactions TCOOFF = 0;
const Tcactions TCOON = 1;
@@ -187,14 +187,15 @@ extern fn CInt cfsetospeed(Termios* self, Speed speed);
extern fn CInt cfsetispeed(Termios* self, Speed speed);
const CInt NCCS = 32;
struct Termios {
Tcflags c_iflag;
Tcflags c_oflag;
Tcflags c_cflag;
Tcflags c_lflag;
Cc c_line;
Cc[NCCS] c_cc;
Speed c_ispeed;
Speed c_ospeed;
struct Termios
{
Tcflags c_iflag;
Tcflags c_oflag;
Tcflags c_cflag;
Tcflags c_lflag;
Cc c_line;
Cc[NCCS] c_cc;
Speed c_ispeed;
Speed c_ospeed;
}

View File

@@ -13,110 +13,112 @@ fn int Termios.setAttr(Termios* self, Fd fd, Tcactions optional_actions) => tcse
module libc::termios @if(!env::LIBC ||| !env::POSIX);
distinct Cc = char;
distinct Speed = CUInt;
distinct Tcflags = CUInt;
struct Termios {
void* dummy;
typedef Cc = char;
typedef Speed = CUInt;
typedef Tcflags = CUInt;
struct Termios
{
void* dummy;
}
fn CInt tcgetattr(Fd fd, Termios* self)
{
unreachable("tcgetattr unavailable");
unreachable("tcgetattr unavailable");
}
fn CInt tcsetattr(Fd fd, CInt optional_actions, Termios* self)
{
unreachable("tcsetattr unavailable");
unreachable("tcsetattr unavailable");
}
fn CInt tcsendbreak(Fd fd, CInt duration)
{
unreachable("tcsendbreak unavailable");
unreachable("tcsendbreak unavailable");
}
fn CInt tcdrain(Fd fd)
{
unreachable("tcdrain unavailable");
unreachable("tcdrain unavailable");
}
fn CInt tcflush(Fd fd, CInt queue_selector)
{
unreachable("tcflush unavailable");
unreachable("tcflush unavailable");
}
fn CInt tcflow(Fd fd, CInt action)
{
unreachable("tcflow unavailable");
unreachable("tcflow unavailable");
}
fn Speed cfgetospeed(Termios* self)
{
unreachable("cfgetospeed unavailable");
unreachable("cfgetospeed unavailable");
}
fn Speed cfgetispeed(Termios* self)
{
unreachable("cfgetispeed unavailable");
unreachable("cfgetispeed unavailable");
}
fn CInt cfsetospeed(Termios* self, Speed speed)
{
unreachable("cfsetospeed unavailable");
unreachable("cfsetospeed unavailable");
}
fn CInt cfsetispeed(Termios* self, Speed speed)
{
unreachable("cfsetispeed unavailable");
unreachable("cfsetispeed unavailable");
}
fn int sendBreak(Fd fd, int duration)
{
unreachable("sendBreak unavailable");
unreachable("sendBreak unavailable");
}
fn int drain(Fd fd)
{
unreachable("drain unavailable");
unreachable("drain unavailable");
}
fn int flush(Fd fd, int queue_selector)
{
unreachable("flush unavailable");
unreachable("flush unavailable");
}
fn int flow(Fd fd, int action)
{
unreachable("flow unavailable");
unreachable("flow unavailable");
}
fn Speed Termios.getOSpeed(Termios* self)
{
unreachable("Termios.getOSpeed unavailable");
unreachable("Termios.getOSpeed unavailable");
}
fn Speed Termios.getISpeed(Termios* self)
{
unreachable("Termios.getISpeed unavailable");
unreachable("Termios.getISpeed unavailable");
}
fn int Termios.setOSpeed(Termios* self, Speed speed)
{
unreachable("Termios.setOSpeed unavailable");
unreachable("Termios.setOSpeed unavailable");
}
fn int Termios.setISpeed(Termios* self, Speed speed)
{
unreachable("Termios.setISpeed unavailable");
unreachable("Termios.setISpeed unavailable");
}
fn int Termios.getAttr(Termios* self, Fd fd)
{
unreachable("Termios.getAttr unavailable");
unreachable("Termios.getAttr unavailable");
}
fn int Termios.setAttr(Termios* self, Fd fd, int optional_actions)
{
unreachable("Termios.setAttr unavailable");
unreachable("Termios.setAttr unavailable");
}

View File

@@ -80,43 +80,41 @@ enum RoundingMode : int
TOWARD_NEG_INFINITY
}
fault OVERFLOW, MATRIX_INVERSE_DOESNT_EXIST;
faultdef OVERFLOW, MATRIX_INVERSE_DOESNT_EXIST;
alias Complexf = Complex{float};
alias Complex = Complex{double};
alias COMPLEX_IDENTITY = complex::IDENTITY{double} @builtin;
alias COMPLEXF_IDENTITY = complex::IDENTITY{float} @builtin;
alias Complexf = Complex {float};
alias Complex = Complex {double};
alias COMPLEX_IDENTITY @builtin = complex::IDENTITY {double};
alias COMPLEXF_IDENTITY @builtin = complex::IDENTITY {float};
alias Quaternionf = Quaternion{float};
alias Quaternion = Quaternion{double};
alias QUATERNION_IDENTITY = quaternion::IDENTITY{double} @builtin;
alias QUATERNIONF_IDENTITY = quaternion::IDENTITY{float} @builtin;
alias Quaternionf = Quaternion {float};
alias Quaternion = Quaternion {double};
alias QUATERNION_IDENTITY @builtin = quaternion::IDENTITY {double};
alias QUATERNIONF_IDENTITY @builtin = quaternion::IDENTITY {float};
alias Matrix2f = Matrix2x2{float};
alias Matrix2 = Matrix2x2{double};
alias Matrix3f = Matrix3x3{float};
alias Matrix3 = Matrix3x3{double};
alias Matrix4f = Matrix4x4{float};
alias Matrix4 = Matrix4x4{double};
alias matrix4_ortho = matrix::ortho{double} @builtin;
alias matrix4_perspective = matrix::perspective{double} @builtin;
alias matrix4f_ortho = matrix::ortho{float} @builtin;
alias matrix4f_perspective = matrix::perspective{float} @builtin;
alias Matrix2f = Matrix2x2 {float};
alias Matrix2 = Matrix2x2 {double};
alias Matrix3f = Matrix3x3 {float};
alias Matrix3 = Matrix3x3 {double};
alias Matrix4f = Matrix4x4 {float};
alias Matrix4 = Matrix4x4 {double};
alias matrix4_ortho @builtin = matrix::ortho {double};
alias matrix4f_ortho @builtin = matrix::ortho {float};
alias matrix4_perspective @builtin = matrix::perspective {double};
alias matrix4f_perspective @builtin = matrix::perspective {float};
alias MATRIX2_IDENTITY = matrix::IDENTITY2{double} @builtin;
alias MATRIX2F_IDENTITY = matrix::IDENTITY2{float} @builtin;
alias MATRIX3_IDENTITY = matrix::IDENTITY3{double} @builtin;
alias MATRIX3F_IDENTITY = matrix::IDENTITY3{float} @builtin;
alias MATRIX4_IDENTITY = matrix::IDENTITY4{double} @builtin;
alias MATRIX4F_IDENTITY = matrix::IDENTITY4{float} @builtin;
alias MATRIX2_IDENTITY @builtin = matrix::IDENTITY2 {double};
alias MATRIX2F_IDENTITY @builtin = matrix::IDENTITY2 {float};
alias MATRIX3_IDENTITY @builtin = matrix::IDENTITY3 {double};
alias MATRIX3F_IDENTITY @builtin = matrix::IDENTITY3 {float};
alias MATRIX4_IDENTITY @builtin = matrix::IDENTITY4 {double};
alias MATRIX4F_IDENTITY @builtin = matrix::IDENTITY4 {float};
<*
@require types::is_numerical($typeof(x)) : `The input must be a numerical value or numerical vector`
*>
macro deg_to_rad(x) {
return x * PI / 180;
}
macro deg_to_rad(x) => x * PI / 180;
<*
@require types::is_numerical($typeof(x)) : `The input must be a numerical value or numerical vector`
@@ -209,7 +207,7 @@ macro sincos(x)
*>
macro atan(x)
{
$if @typeid(x) == float.typeid:
$if @typeis(x, float):
return _atanf(x);
$else
return _atan(x);
@@ -221,7 +219,7 @@ macro atan(x)
*>
macro atanh(x)
{
$if @typeid(x) == float.typeid:
$if @typeis(x, float):
return _atanhf(x);
$else
return _atanh(x);
@@ -233,7 +231,7 @@ macro atanh(x)
*>
macro acos(x)
{
$if @typeid(x) == float.typeid:
$if @typeis(x, float):
return _acosf(x);
$else
return _acos(x);
@@ -245,7 +243,7 @@ macro acos(x)
*>
macro acosh(x)
{
$if @typeid(x) == float.typeid:
$if @typeis(x, float):
return _acoshf(x);
$else
return _acosh(x);
@@ -257,7 +255,7 @@ macro acosh(x)
*>
macro asin(x)
{
$if @typeid(x) == float.typeid:
$if @typeis(x, float):
return _asinf(x);
$else
return _asin(x);
@@ -269,7 +267,7 @@ macro asin(x)
*>
macro asinh(x)
{
$if @typeid(x) == float.typeid:
$if @typeis(x, float):
return _asinhf(x);
$else
return _asinh(x);

View File

@@ -13,7 +13,7 @@ const MUL_LCG16 @local = 0x915d; // TODO: Find good constant
// Lcg128_64
distinct Lcg128Random (Random) = uint128;
typedef Lcg128Random (Random) = uint128;
fn void Lcg128Random.set_seed(&self, char[] input) @dynamic
{
@@ -40,7 +40,7 @@ fn char Lcg128Random.next_byte(&self) @dynamic => (char)self.next_long();
// -------------------------------- Lcg64_32 --------------------------------
distinct Lcg64Random (Random) = ulong;
typedef Lcg64Random (Random) = ulong;
fn void Lcg64Random.set_seed(&self, char[] seed) @dynamic
{
@@ -67,7 +67,7 @@ fn char Lcg64Random.next_byte(&self) @dynamic => (char)self.next_int();
// -------------------------------- Lcg32_16 --------------------------------
distinct Lcg32Random (Random) = uint;
typedef Lcg32Random (Random) = uint;
fn void Lcg32Random.set_seed(&self, char[] seed) @dynamic
{
@@ -90,7 +90,7 @@ fn char Lcg32Random.next_byte(&self) @dynamic => (char)self.next_short();
// -------------------------------- Lcg16_8 --------------------------------
distinct Lcg16Random (Random) = ushort;
typedef Lcg16Random (Random) = ushort;
fn void Lcg16Random.set_seed(&self, char[] seed) @dynamic
{

View File

@@ -7,7 +7,7 @@ const MUL_MCG16 @local = 0x93d5; // TODO: Find good constant
// Mcg128_64
distinct Mcg128Random (Random) = uint128;
typedef Mcg128Random (Random) = uint128;
fn void Mcg128Random.set_seed(&self, char[] seed) @dynamic
{
@@ -40,7 +40,7 @@ fn char Mcg128Random.next_byte(&self) @dynamic => (char)self.next_long();
// Mcg64RandomState
distinct Mcg64Random (Random) = ulong;
typedef Mcg64Random (Random) = ulong;
fn void Mcg64Random.set_seed(&self, char[] seed) @dynamic
{
@@ -71,7 +71,7 @@ fn char Mcg64Random.next_byte(&self) @dynamic => (char)self.next_int();
// Mcg32Random
distinct Mcg32Random (Random) = uint;
typedef Mcg32Random (Random) = uint;
fn void Mcg32Random.set_seed(&self, char[] seed) @dynamic
{
@@ -97,7 +97,7 @@ fn char Mcg32Random.next_byte(&self) @dynamic => (char)self.next_short();
// -------------------------------- Mcg16RandomState --------------------------------
distinct Mcg16Random (Random) = ushort;
typedef Mcg16Random (Random) = ushort;
fn void Mcg16Random.set_seed(&self, char[] seed) @dynamic
{

View File

@@ -15,7 +15,7 @@ const MUL_LCG16 @local = 0x915d; // TODO: Find good constant
// -------------------------------- Pcg128_64 --------------------------------
distinct Pcg128Random (Random) = uint128;
typedef Pcg128Random (Random) = uint128;
fn void Pcg128Random.set_seed(&self, char[] input) @dynamic
{
@@ -44,7 +44,7 @@ fn char Pcg128Random.next_byte(&self) @dynamic => (char)self.next_long();
// -------------------------------- Pcg64_32 --------------------------------
distinct Pcg64Random (Random) = ulong;
typedef Pcg64Random (Random) = ulong;
fn void Pcg64Random.set_seed(&self, char[] input) @dynamic
{
@@ -73,7 +73,7 @@ fn char Pcg64Random.next_byte(&self) @dynamic => (char)self.next_int();
// -------------------------------- Pcg32_16 --------------------------------
distinct Pcg32Random (Random) = uint;
typedef Pcg32Random (Random) = uint;
fn void Pcg32Random.set_seed(&self, char[] input) @dynamic
{
@@ -101,7 +101,7 @@ fn char Pcg32Random.next_byte(&self) @dynamic => (char)self.next_short();
// -------------------------------- Pcg16_8 --------------------------------
distinct Pcg16Random (Random) = ushort;
typedef Pcg16Random (Random) = ushort;
fn void Pcg16Random.set_seed(&self, char[] input) @dynamic
{

View File

@@ -10,9 +10,9 @@ const ODD_PHI8 @local = 0x9f;
// Sfc128
distinct Sfc128Random (Random) = uint128[4];
typedef Sfc128Random (Random) = uint128[4];
fn void Sfc128Random.set_seed(&self, char[] input) @dynamic
fn void Sfc128Random.set_seed(&self, char[] input) @dynamic
{
*self = (Sfc128Random)random::make_seed(uint128[4], input);
}
@@ -40,7 +40,7 @@ fn char Sfc128Random.next_byte(&self) @dynamic => (char)self.next_int128();
// -------------------------------- Sfc64 --------------------------------
distinct Sfc64Random (Random) = ulong[4];
typedef Sfc64Random (Random) = ulong[4];
fn void Sfc64Random.set_seed(&self, char[] input) @dynamic
{
@@ -69,7 +69,7 @@ fn char Sfc64Random.next_byte(&self) @dynamic => (char)self.next_long();
// -------------------------------- Sfc32 --------------------------------
distinct Sfc32Random (Random) = uint[4];
typedef Sfc32Random (Random) = uint[4];
fn void Sfc32Random.set_seed(&self, char[] input) @dynamic
{
@@ -98,7 +98,7 @@ fn char Sfc32Random.next_byte(&self) @dynamic => (char)self.next_int();
// -------------------------------- Sfc16 --------------------------------
distinct Sfc16Random (Random) = ushort[4];
typedef Sfc16Random (Random) = ushort[4];
fn void Sfc16Random.set_seed(&self, char[] input) @dynamic
{
@@ -129,7 +129,7 @@ fn char Sfc16Random.next_byte(&self) @dynamic => (char)self.next_short();
// -------------------------------- Sfc8 --------------------------------
distinct Sfc8Random (Random) = char[4];
typedef Sfc8Random (Random) = char[4];
fn void Sfc8Random.set_seed(&self, char[] input) @dynamic
{

View File

@@ -1,6 +1,6 @@
module std::math::random;
distinct SimpleRandom (Random) = ulong;
typedef SimpleRandom (Random) = ulong;
fn void SimpleRandom.set_seed(&self, char[] seed) @dynamic

View File

@@ -2,7 +2,7 @@ module std::math::uuid;
import std::math::random @public;
import std::io;
distinct Uuid (Printable) = char[16];
typedef Uuid (Printable) = char[16];
<*
Generate a version 4 UUID from the default random.

View File

@@ -1,7 +1,7 @@
module std::net;
import std::io;
fault
faultdef
INVALID_URL,
URL_TOO_LONG,
INVALID_SOCKET,

View File

@@ -1,15 +1,15 @@
module std::net::os;
const bool SUPPORTS_INET = env::LIBC && (env::WIN32 || env::DARWIN || env::LINUX);
distinct AIFamily = CInt;
distinct AIProtocol = CInt;
distinct AISockType = CInt;
distinct AIFlags = CInt;
typedef AIFamily = CInt;
typedef AIProtocol = CInt;
typedef AISockType = CInt;
typedef AIFlags = CInt;
alias Socklen_t = CUInt @if(!env::WIN32);
alias Socklen_t = usz @if(env::WIN32);
alias Socklen_t @if(!env::WIN32) = CUInt;
alias Socklen_t @if(env::WIN32) = usz;
distinct SockAddrPtr = void*;
typedef SockAddrPtr = void*;
struct AddrInfo
{

View File

@@ -4,7 +4,7 @@ import std::io, libc;
const int F_GETFL = 3;
const int F_SETFL = 4;
distinct NativeSocket = inline Fd;
typedef NativeSocket = inline Fd;
struct Posix_pollfd
{
@@ -30,7 +30,7 @@ const CUShort POLLERR = 0x0008;
const CUShort POLLHUP = 0x0010;
const CUShort POLLNVAL = 0x0020;
fn anyfault convert_error(Errno error)
fn fault convert_error(Errno error)
{
switch (error)
{
@@ -51,7 +51,7 @@ fn anyfault convert_error(Errno error)
}
}
fn anyfault socket_error()
fn fault socket_error()
{
return convert_error(libc::errno());
}

View File

@@ -12,7 +12,7 @@ const int FIONREAD = 1074030207;
const int FIONBIO = -2147195266;
const int FIOASYNC = -2147195267;
distinct NativeSocket = inline Win32_SOCKET;
typedef NativeSocket = inline Win32_SOCKET;
extern fn CInt ioctlsocket(NativeSocket, CLong cmd, CULong *argp);
extern fn WSAError closesocket(NativeSocket);
@@ -61,7 +61,7 @@ const int SO_RCVTIMEO = 0x1006;
const int SO_ERROR = 0x1007;
const int SO_TYPE = 0x1008;
fn anyfault convert_error(WSAError error)
fn fault convert_error(WSAError error)
{
switch (error)
{
@@ -86,7 +86,7 @@ fn anyfault convert_error(WSAError error)
}
}
fn anyfault socket_error()
fn fault socket_error()
{
return convert_error(win32_WSAGetLastError());
}

View File

@@ -25,8 +25,8 @@ macro void @loop_over_ai(AddrInfo* ai; @body(NativeSocket fd, AddrInfo* ai))
const Duration POLL_FOREVER = -1;
distinct PollSubscribes = ushort;
distinct PollEvents = ushort;
typedef PollSubscribes = ushort;
typedef PollEvents = ushort;
const PollSubscribes SUBSCRIBE_ANY_READ = os::POLLIN;
const PollSubscribes SUBSCRIBE_PRIO_READ = os::POLLPRI;

View File

@@ -2,8 +2,8 @@ module std::net::tcp @if(os::SUPPORTS_INET);
import std::net @public;
import std::time, libc;
distinct TcpSocket = inline Socket;
distinct TcpServerSocket = inline Socket;
typedef TcpSocket = inline Socket;
typedef TcpServerSocket = inline Socket;
fn TcpSocket? connect(String host, uint port, Duration timeout = 0, SocketOption... options, IpProtocol ip_protocol = UNSPECIFIED)
{

View File

@@ -1,7 +1,7 @@
module std::net::udp @if(os::SUPPORTS_INET);
import std::net @public;
distinct UdpSocket = inline Socket;
typedef UdpSocket = inline Socket;
fn UdpSocket? connect(String host, uint port, SocketOption... options, IpProtocol ip_protocol = UNSPECIFIED)
{

View File

@@ -2,7 +2,7 @@ module std::net::url;
import std::io, std::collections::map, std::collections::list;
fault
faultdef
EMPTY,
INVALID_SCHEME,
INVALID_USER,

View File

@@ -15,7 +15,7 @@ enum UrlEncodingMode : char (String allowed)
FRAGMENT = "$&+,/:;=?@!()*", // section 4.1
}
fault INVALID_HEX;
faultdef INVALID_HEX;
<*
Returns true if char c should be encoded according to RFC 3986.

View File

@@ -1,7 +1,8 @@
module std::os::backtrace;
import std::collections::list, std::os, std::io;
fault SEGMENT_NOT_FOUND, EXECUTABLE_PATH_NOT_FOUND, IMAGE_NOT_FOUND, NO_BACKTRACE_SYMBOLS, RESOLUTION_FAILED;
faultdef SEGMENT_NOT_FOUND, EXECUTABLE_PATH_NOT_FOUND, IMAGE_NOT_FOUND, NO_BACKTRACE_SYMBOLS,
RESOLUTION_FAILED;
const Backtrace BACKTRACE_UNKNOWN = { 0, "", "", "", 0, null, false };
@@ -86,9 +87,9 @@ fn void*[] capture_current(void*[] buffer)
alias BacktraceList = List{Backtrace};
alias symbolize_backtrace = linux::symbolize_backtrace @if(env::LINUX);
alias symbolize_backtrace = win32::symbolize_backtrace @if(env::WIN32);
alias symbolize_backtrace = darwin::symbolize_backtrace @if(env::DARWIN);
alias symbolize_backtrace @if(env::LINUX) = linux::symbolize_backtrace;
alias symbolize_backtrace @if(env::WIN32) = win32::symbolize_backtrace;
alias symbolize_backtrace @if(env::DARWIN) = darwin::symbolize_backtrace;
fn BacktraceList? symbolize_backtrace(Allocator allocator, void*[] backtrace) @if(!env::NATIVE_STACKTRACE)
{

View File

@@ -1,7 +1,7 @@
module std::os::macos::cf @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework");
distinct CFAllocatorRef = void*;
distinct CFAllocatorContextRef = void*;
typedef CFAllocatorRef = void*;
typedef CFAllocatorContextRef = void*;
alias CFOptionFlags = usz;
macro CFAllocatorRef default_allocator() => macos_CFAllocatorGetDefault();

View File

@@ -1,8 +1,8 @@
module std::os::macos::cf @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework");
distinct CFArrayRef = void*;
distinct CFArrayCallBacksRef = void*;
distinct CFMutableArrayRef = void*;
typedef CFArrayRef = void*;
typedef CFArrayCallBacksRef = void*;
typedef CFMutableArrayRef = void*;
extern fn CFArrayRef macos_CFArrayCreate(CFAllocatorRef allocator, void** values, CFIndex num_values, CFArrayCallBacksRef callBacks) @extern("CFArrayCreate") @builtin;
extern fn CFArrayRef macos_CFArrayCopy(CFAllocatorRef allocator, CFArrayRef array) @extern("CFArrayCopy") @builtin;
extern fn CFIndex macos_CFArrayGetCount(CFArrayRef array) @extern("CFArrayGetCount") @builtin;

View File

@@ -1,7 +1,8 @@
module std::os::macos::cf @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework");
distinct CFTypeRef = void*;
typedef CFTypeRef = void*;
alias CFIndex = isz;
struct CFRange
{
CFIndex location;

View File

@@ -1,13 +1,13 @@
module std::os::macos::objc @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework");
distinct ObjcClass = void*;
distinct ObjcMethod = void*;
distinct ObjcIvar = void*;
distinct ObjcSelector = void*;
typedef ObjcClass = void*;
typedef ObjcMethod = void*;
typedef ObjcIvar = void*;
typedef ObjcSelector = void*;
alias ObjcId = void*;
alias SendVoid = fn void*(void*, ObjcSelector);
fault CLASS_NOT_FOUND, UNKNOWN_EVENT;
faultdef CLASS_NOT_FOUND, UNKNOWN_EVENT;
macro ZString ObjcClass.name(ObjcClass cls) => class_getName(cls);
macro ObjcClass ObjcClass.superclass(ObjcClass cls) => class_getSuperclass(cls);

View File

@@ -2,7 +2,7 @@ module std::os::posix @if(env::POSIX);
import libc;
alias Mode_t = uint;
distinct DIRPtr = void*;
typedef DIRPtr = void*;
struct Posix_dirent
{

View File

@@ -7,7 +7,7 @@ const PTHREAD_MUTEX_ERRORCHECK = env::LINUX ? 2 : 1;
const PTHREAD_MUTEX_RECURSIVE = env::LINUX ? 1 : 2;
alias PosixThreadFn = fn void*(void*);
distinct Pthread_t = void*;
typedef Pthread_t = void*;
extern fn CInt pthread_create(Pthread_t*, Pthread_attr_t*, PosixThreadFn, void*);
extern fn CInt pthread_cancel(Pthread_t*);
@@ -89,25 +89,25 @@ extern fn void pthread_cleanup_push(PosixThreadFn routine, void* routine_arg);
extern fn int sched_yield();
module std::thread::os @if(env::POSIX && !env::LINUX);
distinct Pthread_attr_t = ulong[8];
distinct Pthread_cond_t = ulong[6];
distinct Pthread_condattr_t = ulong[8];
distinct Pthread_key_t = ulong;
distinct Pthread_mutex_t = ulong[8];
distinct Pthread_mutexattr_t = ulong[2];
distinct Pthread_once_t = ulong[2];
distinct Pthread_rwlock_t = ulong[25];
distinct Pthread_rwlockattr_t = ulong[3];
distinct Pthread_sched_param = ulong;
typedef Pthread_attr_t = ulong[8];
typedef Pthread_cond_t = ulong[6];
typedef Pthread_condattr_t = ulong[8];
typedef Pthread_key_t = ulong;
typedef Pthread_mutex_t = ulong[8];
typedef Pthread_mutexattr_t = ulong[2];
typedef Pthread_once_t = ulong[2];
typedef Pthread_rwlock_t = ulong[25];
typedef Pthread_rwlockattr_t = ulong[3];
typedef Pthread_sched_param = ulong;
module std::thread::os @if(env::LINUX);
distinct Pthread_attr_t = ulong[7]; // 24 on 32bit
distinct Pthread_cond_t = ulong[6];
distinct Pthread_condattr_t = uint;
distinct Pthread_key_t = uint;
distinct Pthread_mutex_t = ulong[5]; // 24 on 32 bit
distinct Pthread_mutexattr_t = uint;
distinct Pthread_once_t = int;
distinct Pthread_rwlock_t = ulong[7]; // 32 on 3bit
distinct Pthread_rwlockattr_t = uint;
distinct Pthread_sched_param = uint;
typedef Pthread_attr_t = ulong[7]; // 24 on 32bit
typedef Pthread_cond_t = ulong[6];
typedef Pthread_condattr_t = uint;
typedef Pthread_key_t = uint;
typedef Pthread_mutex_t = ulong[5]; // 24 on 32 bit
typedef Pthread_mutexattr_t = uint;
typedef Pthread_once_t = int;
typedef Pthread_rwlock_t = ulong[7]; // 32 on 3bit
typedef Pthread_rwlockattr_t = uint;
typedef Pthread_sched_param = uint;

View File

@@ -3,7 +3,7 @@ import std::io, libc, std::os;
// This code is based on https://github.com/sheredom/subprocess.h
fault
faultdef
FAILED_TO_CREATE_PIPE,
FAILED_TO_OPEN_STDIN,
FAILED_TO_OPEN_STDOUT,

View File

@@ -189,7 +189,7 @@ union Win32_LARGE_INTEGER
ulong quadPart;
}
distinct Win32_CRITICAL_SECTION = ulong[5];
typedef Win32_CRITICAL_SECTION = ulong[5];
struct Win32_SECURITY_ATTRIBUTES
{

View File

@@ -2,7 +2,7 @@ module std::os::win32 @if(env::WIN32);
// See https://github.com/wine-mirror/wine/blob/master/include/winsock2.h
distinct WSAError = int;
typedef WSAError = int;
struct Win32_pollfd
{

View File

@@ -26,21 +26,21 @@ macro quicksort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPT
module std::sort::cs{Type, KeyFn};
alias Counts = usz[256] @private;
alias Ranges = usz[257] @private;
alias Indexs = char[256] @private;
alias Counts @private = usz[256];
alias Ranges @private = usz[257];
alias Indexs @private = char[256];
alias ElementType = $typeof((Type){}[0]);
const bool NO_KEY_FN @private = types::is_same(KeyFn, EmptySlot);
const bool KEY_BY_VALUE @private = NO_KEY_FN ||| $assignable((Type){}[0], $typefrom(KeyFn.paramsof[0].type));
const bool LIST_HAS_REF @private = $defined(&(Type){}[0]);
alias KeyFnReturnType = $typefrom(KeyFn.returns) @if(!NO_KEY_FN);
alias KeyFnReturnType = ElementType @if(NO_KEY_FN);
alias CmpCallback = fn int(ElementType, ElementType) @if(KEY_BY_VALUE && NO_KEY_FN);
alias CmpCallback = fn int(ElementType*, ElementType*) @if(!KEY_BY_VALUE && NO_KEY_FN);
alias CmpCallback = fn int(ElementType, ElementType, KeyFn) @if(KEY_BY_VALUE && !NO_KEY_FN);
alias CmpCallback = fn int(ElementType*, ElementType*, KeyFn) @if(!KEY_BY_VALUE && !NO_KEY_FN);
alias KeyFnReturnType @if(!NO_KEY_FN) = $typefrom(KeyFn.returns) ;
alias KeyFnReturnType @if(NO_KEY_FN) = ElementType;
alias CmpCallback @if(KEY_BY_VALUE && NO_KEY_FN) = fn int(ElementType, ElementType) ;
alias CmpCallback @if(!KEY_BY_VALUE && NO_KEY_FN) = fn int(ElementType*, ElementType*);
alias CmpCallback @if(KEY_BY_VALUE && !NO_KEY_FN) = fn int(ElementType, ElementType, KeyFn);
alias CmpCallback @if(!KEY_BY_VALUE && !NO_KEY_FN) = fn int(ElementType*, ElementType*, KeyFn);
fn void csort(Type list, usz low, usz high, KeyFn key_fn, uint byte_idx)
{

View File

@@ -43,7 +43,7 @@ struct StackElementItem @private
isz high;
}
alias Stack = StackElementItem[64] @private;
alias Stack @private = StackElementItem[64];
// Based on https://alienryderflex.com/quicksort by Darel Rex Finley, Public Domain.

View File

@@ -1,7 +1,7 @@
/*module std::text::i18n;
import std::collections::map;
import std::hash::fnv32a;
distinct Language = char[];
typedef Language = char[];
const Language EN = "en";

View File

@@ -1,6 +1,6 @@
module std::thread::channel{Type};
distinct BufferedChannel = void*;
typedef BufferedChannel = void*;
struct BufferedChannelImpl @private
{
@@ -48,7 +48,7 @@ fn void? BufferedChannel.destroy(&self)
{
BufferedChannelImpl* channel = (BufferedChannelImpl*)(*self);
anyfault err = @catch(channel.mu.destroy());
fault err = @catch(channel.mu.destroy());
err = @catch(channel.send_cond.destroy()) ?: err;
err = @catch(channel.read_cond.destroy()) ?: err;
allocator::free(channel.allocator, channel);
@@ -147,7 +147,7 @@ fn void? BufferedChannel.close(self)
{
BufferedChannelImpl* channel = (BufferedChannelImpl*)self;
anyfault err = @catch(channel.mu.lock());
fault err = @catch(channel.mu.lock());
channel.closed = true;

View File

@@ -21,9 +21,9 @@ struct EventThreadTask
Event*[] events;
}
distinct EventQueue = void;
distinct EventHandler = void;
distinct EventMultiQueue = void;
typedef EventQueue = void;
typedef EventHandler = void;
typedef EventMultiQueue = void;
fn EventThreadTask EventQueue.wait_for_task(&self) => EventThreadTask {};

View File

@@ -1,5 +1,5 @@
module std::thread;
fault THREAD_QUEUE_FULL;
faultdef THREAD_QUEUE_FULL;
module std::thread::threadpool @if (env::POSIX || env::WIN32);
import std::thread;

View File

@@ -1,6 +1,6 @@
module std::thread::os @if (!env::POSIX && !env::WIN32);
distinct NativeMutex = int;
distinct NativeConditionVariable = int;
distinct NativeOnceFlag = int;
distinct NativeThread = int;
typedef NativeMutex = int;
typedef NativeConditionVariable = int;
typedef NativeOnceFlag = int;
typedef NativeThread = int;

View File

@@ -1,7 +1,7 @@
module std::thread::os @if(env::WIN32);
import std::os::win32, std::time;
distinct NativeThread = inline Win32_HANDLE;
typedef NativeThread = inline Win32_HANDLE;
struct NativeMutex
{

View File

@@ -2,24 +2,24 @@ module std::thread;
import std::thread::os;
import std::time;
distinct MutexType = int;
typedef MutexType = int;
const MutexType MUTEX_PLAIN = 0;
const MutexType MUTEX_TIMED = 1;
const MutexType MUTEX_RECURSIVE = 2;
distinct Mutex = NativeMutex;
distinct TimedMutex = inline Mutex;
distinct RecursiveMutex = inline Mutex;
distinct TimedRecursiveMutex = inline Mutex;
distinct ConditionVariable = NativeConditionVariable;
distinct Thread = inline NativeThread;
distinct OnceFlag = NativeOnceFlag;
typedef Mutex = NativeMutex;
typedef TimedMutex = inline Mutex;
typedef RecursiveMutex = inline Mutex;
typedef TimedRecursiveMutex = inline Mutex;
typedef ConditionVariable = NativeConditionVariable;
typedef Thread = inline NativeThread;
typedef OnceFlag = NativeOnceFlag;
alias OnceFn = fn void();
alias ThreadFn = fn int(void* arg);
fault
faultdef
INIT_FAILED,
DESTROY_FAILED,
LOCK_FAILED,

View File

@@ -1,6 +1,6 @@
module std::thread::channel {Type};
distinct UnbufferedChannel = void*;
typedef UnbufferedChannel = void*;
struct UnbufferedChannelImpl @private
{
@@ -44,7 +44,7 @@ fn void? UnbufferedChannel.destroy(&self)
{
UnbufferedChannelImpl* channel = (UnbufferedChannelImpl*)(*self);
anyfault err = @catch(channel.mu.destroy());
fault err = @catch(channel.mu.destroy());
err = @catch(channel.send_mu.destroy()) ?: err;
err = @catch(channel.send_cond.destroy()) ?: err;
err = @catch(channel.read_mu.destroy()) ?: err;
@@ -126,7 +126,7 @@ fn void? UnbufferedChannel.close(self)
{
UnbufferedChannelImpl* channel = (UnbufferedChannelImpl*)self;
anyfault err = @catch(channel.mu.lock());
fault err = @catch(channel.mu.lock());
channel.closed = true;

View File

@@ -1,10 +1,10 @@
module std::time;
import std::io, std::time::os;
distinct Time = long;
distinct Duration = long;
distinct Clock = ulong;
distinct NanoDuration (Printable) = long;
typedef Time = long;
typedef Duration = long;
typedef Clock = ulong;
typedef NanoDuration (Printable) = long;
const Time FAR_FUTURE = long.max;
const Time FAR_PAST = long.min;