Add lambdas.

This commit is contained in:
Christoffer Lerno
2023-01-23 00:41:05 +01:00
committed by Christoffer Lerno
parent c9e1e2d763
commit b508a43f8f
47 changed files with 1116 additions and 487 deletions

View File

@@ -164,14 +164,14 @@ macro bool @convertible(#expr, $To) @builtin
return $checks($To x = #expr);
}
macro uint int.hash(int i) = i;
macro uint uint.hash(uint i) = i;
macro uint short.hash(short s) = s;
macro uint ushort.hash(ushort s) = s;
macro uint char.hash(char c) = c;
macro uint ichar.hash(ichar c) = c;
macro uint long.hash(long i) = (uint)((i >> 32) ^ i);
macro uint ulong.hash(ulong i) = (uint)((i >> 32) ^ i);
macro uint bool.hash(bool b) = (uint)b;
macro uint typeid.hash(typeid t) = (uint)(((uptr)t >> 32) ^ (uptr)t);
macro uint String.hash(String c) = (uint)fnv32a::encode(c);
macro uint int.hash(int i) => i;
macro uint uint.hash(uint i) => i;
macro uint short.hash(short s) => s;
macro uint ushort.hash(ushort s) => s;
macro uint char.hash(char c) => c;
macro uint ichar.hash(ichar c) => c;
macro uint long.hash(long i) => (uint)((i >> 32) ^ i);
macro uint ulong.hash(ulong i) => (uint)((i >> 32) ^ i);
macro uint bool.hash(bool b) => (uint)b;
macro uint typeid.hash(typeid t) => (uint)(((uptr)t >> 32) ^ (uptr)t);
macro uint String.hash(String c) => (uint)fnv32a::encode(c);

View File

@@ -123,17 +123,17 @@ private macro to_integer($Type, String string)
return value;
}
fn int128! to_int128(String string) = to_integer(int128, string);
fn long! to_long(String string) = to_integer(long, string);
fn int! to_int(String string) = to_integer(int, string);
fn short! to_short(String string) = to_integer(short, string);
fn ichar! to_ichar(String string) = to_integer(ichar, string);
fn int128! to_int128(String string) => to_integer(int128, string);
fn long! to_long(String string) => to_integer(long, string);
fn int! to_int(String string) => to_integer(int, string);
fn short! to_short(String string) => to_integer(short, string);
fn ichar! to_ichar(String string) => to_integer(ichar, string);
fn uint128! to_uint128(String str) = to_integer(uint128, str);
fn ulong! to_ulong(String str) = to_integer(ulong, str);
fn uint! to_uint(String str) = to_integer(uint, str);
fn ushort! to_ushort(String str) = to_integer(ushort, str);
fn char! to_uchar(String str) = to_integer(char, str);
fn uint128! to_uint128(String str) => to_integer(uint128, str);
fn ulong! to_ulong(String str) => to_integer(ulong, str);
fn uint! to_uint(String str) => to_integer(uint, str);
fn ushort! to_ushort(String str) => to_integer(ushort, str);
fn char! to_uchar(String str) => to_integer(char, str);
fn String trim(String string, String to_trim = "\t\n\r ")
{
@@ -156,7 +156,7 @@ fn bool starts_with(String s, String needle)
return true;
}
fn String[] tsplit(String s, String needle) = split(s, needle, mem::temp_allocator()) @inline;
fn String[] tsplit(String s, String needle) => split(s, needle, mem::temp_allocator()) @inline;
fn String[] split(String s, String needle, Allocator* allocator = mem::current_allocator())
{

View File

@@ -139,7 +139,7 @@ fn void VarString.append_char32(VarString* str, Char32 c)
data.chars[data.len++] = (char)(0x80 | (c & 0x3F));
}
fn VarString VarString.tcopy(VarString* str) = str.copy(mem::temp_allocator());
fn VarString VarString.tcopy(VarString* str) => str.copy(mem::temp_allocator());
fn VarString VarString.copy(VarString* str, Allocator* allocator = null)
{
@@ -174,7 +174,7 @@ fn String VarString.copy_str(VarString* str, Allocator* allocator = mem::current
return (String)str.copy_zstr(allocator)[:str.len()];
}
fn String VarString.tcopy_str(VarString* str) = str.copy_str(mem::temp_allocator()) @inline;
fn String VarString.tcopy_str(VarString* str) => str.copy_str(mem::temp_allocator()) @inline;
fn bool VarString.equals(VarString str, VarString other_string)
{

View File

@@ -123,7 +123,7 @@ macro bool is_subarray_convertable($Type)
$endswitch;
}
macro bool is_int($Type) = $Type.kindof == TypeKind.SIGNED_INT || $Type.kindof == TypeKind.UNSIGNED_INT;
macro bool is_int($Type) => $Type.kindof == TypeKind.SIGNED_INT || $Type.kindof == TypeKind.UNSIGNED_INT;
macro bool is_intlike($Type)
{
@@ -139,7 +139,7 @@ macro bool is_intlike($Type)
}
macro bool is_float($Type) = $Type.kindof == TypeKind.FLOAT;
macro bool is_float($Type) => $Type.kindof == TypeKind.FLOAT;
macro bool is_floatlike($Type)
{
@@ -182,7 +182,7 @@ macro bool @has_same(#a, #b, ...)
return true;
}
macro bool is_promotable_to_floatlike($Type) = types::is_floatlike($Type) || types::is_int($Type);
macro bool is_promotable_to_floatlike($Type) => types::is_floatlike($Type) || types::is_int($Type);
macro bool is_same_vector_type($Type1, $Type2)

View File

@@ -1,11 +1,11 @@
module std::core::values;
macro bool @is_int(#value) = types::is_int($typeof(#value));
macro bool @convertable_to(#a, #b) = $checks($typeof(#b) x = #a);
macro bool @is_floatlike(#value) = types::is_floatlike($typeof(#value));
macro bool @is_float(#value) = types::is_float($typeof(#value));
macro bool @is_promotable_to_floatlike(#value) = types::is_promotable_to_floatlike($typeof(#value));
macro bool @is_same_vector_type(#value1, #value2) = types::is_same_vector_type($typeof(#value1), $typeof(#value2));
macro bool @is_int(#value) => types::is_int($typeof(#value));
macro bool @convertable_to(#a, #b) => $checks($typeof(#b) x = #a);
macro bool @is_floatlike(#value) => types::is_floatlike($typeof(#value));
macro bool @is_float(#value) => types::is_float($typeof(#value));
macro bool @is_promotable_to_floatlike(#value) => types::is_promotable_to_floatlike($typeof(#value));
macro bool @is_same_vector_type(#value1, #value2) => types::is_same_vector_type($typeof(#value1), $typeof(#value2));
macro promote_int(x)
{
$if (values::@is_int(x)):