Improved #foo resolution inside of the compiler.

Deprecation of several `&` macros.
This commit is contained in:
Christoffer Lerno
2025-01-08 12:55:13 +01:00
parent ff33cc4dad
commit dad97fc2d9
24 changed files with 247 additions and 187 deletions

View File

@@ -10,7 +10,7 @@ in [0, array.len) where x would be inserted or cmp(i) is true and cmp(j) is true
macro usz binarysearch(list, x, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
{
usz i;
usz len = @len_from_list(list);
usz len = len_from_list(list);
var $no_cmp = @is_empty_macro_slot(cmp);
var $has_context = @is_valid_macro_slot(context);
for (usz j = len; i < j;)

View File

@@ -10,7 +10,7 @@ Sort list using the counting sort algorithm.
*>
macro countingsort(list, key_fn = EMPTY_MACRO_SLOT) @builtin
{
usz len = sort::@len_from_list(list);
usz len = sort::len_from_list(list);
cs::csort(<$typeof(list), $typeof(key_fn)>)(list, 0, len, key_fn, ~((uint)0));
}

View File

@@ -8,7 +8,7 @@ Sort list using the quick sort algorithm.
*>
macro insertionsort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
{
usz len = sort::@len_from_list(list);
usz len = sort::len_from_list(list);
is::isort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len, cmp, context);
}

View File

@@ -9,7 +9,7 @@ Sort list using the quick sort algorithm.
*>
macro quicksort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
{
usz len = sort::@len_from_list(list);
usz len = sort::len_from_list(list);
qs::qsort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len - 1, cmp, context);
}
@@ -24,7 +24,7 @@ list will be partially sorted.
*>
macro quickselect(list, isz k, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
{
usz len = sort::@len_from_list(list);
usz len = sort::len_from_list(list);
return qs::qselect(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len - 1, k, cmp, context);
}

View File

@@ -1,6 +1,11 @@
module std::sort;
macro usz @len_from_list(&list)
macro usz @len_from_list(&list) @deprecated
{
return len_from_list(*list);
}
macro usz len_from_list(list)
{
$if $defined(list.len()):
return list.len();

View File

@@ -9,7 +9,7 @@ Returns true if list is sorted in either ascending or descending order.
macro bool is_sorted(list, cmp = EMPTY_MACRO_SLOT, ctx = EMPTY_MACRO_SLOT) @builtin
{
var $Type = $typeof(list);
usz len = sort::@len_from_list(list);
usz len = sort::len_from_list(list);
if (len <= 1) return true;
var check_sort = fn bool($Type list, usz start, usz end, $typeof(cmp) cmp, $typeof(ctx) ctx)
{