Cleanup use of macro inspection to use @typekind and @typeid macros.

This commit is contained in:
Christoffer Lerno
2023-11-18 23:35:11 +01:00
parent 87fdb5956e
commit d5281b10dd
13 changed files with 30 additions and 29 deletions

View File

@@ -4,7 +4,7 @@ module std::sort;
* Perform a binary search over the sorted array and return the index
* in [0, array.len) where x would be inserted or cmp(i) is true and cmp(j) is true for j in [i, array.len).
* @require $defined(list[0]) && $defined(list.len) "The list must be indexable"
* @require $or($typeof(cmp).typeid == void*.typeid, @is_comparer(cmp, list)) "Expected a comparison function which compares values"
* @require $or(@typeid(cmp) == void*.typeid, @is_comparer(cmp, list)) "Expected a comparison function which compares values"
**/
macro usz binarysearch(list, x, cmp = null) @builtin
{
@@ -13,7 +13,7 @@ macro usz binarysearch(list, x, cmp = null) @builtin
for (usz j = len; i < j;)
{
usz half = i + (j - i) / 2;
$if $typeof(cmp).typeid == void*.typeid:
$if @typeid(cmp) == void*.typeid:
switch
{
case greater(list[half], x): j = half;
@@ -22,7 +22,7 @@ macro usz binarysearch(list, x, cmp = null) @builtin
}
$else
$switch
$case $typeof(cmp).params[0] == $typeof(list[0]).typeid:
$case $typeof(cmp).params[0] == @typeid(list[0]):
int res = cmp(list[half], x);
$default:
int res = cmp(&list[half], &x);

View File

@@ -4,7 +4,7 @@ import std::sort::qs;
/**
* Sort list using the quick sort algorithm.
* @require $defined(list[0]) && $defined(list.len) "The list must be indexable and support .len or .len()"
* @require $or($typeof(cmp).typeid == void*.typeid, @is_comparer(cmp, list)) "Expected a comparison function which compares values"
* @require $or(@typeid(cmp) == void*.typeid, @is_comparer(cmp, list)) "Expected a comparison function which compares values"
**/
macro quicksort(list, cmp = null) @builtin
{
@@ -31,7 +31,7 @@ def Stack = StackElementItem[64] @private;
fn void qsort(Type list, isz low, isz high, Comparer cmp)
{
var $no_cmp = Comparer.typeid == void*.typeid;
var $cmp_by_value = $and(!$no_cmp, Comparer.params[0] == $typeof(list[0]).typeid);
var $cmp_by_value = $and(!$no_cmp, Comparer.params[0] == @typeid(list[0]));
if (low >= 0 && high >= 0 && low < high)
{
Stack stack;

View File

@@ -19,7 +19,7 @@ macro bool @is_comparer(#cmp, #list)
$if $params[0] != $params[1]:
return false;
$else
var $element = $typeof(#list[0]).typeid;
var $element = @typeid(#list[0]);
$switch
$case $element == $params[0]:
return true;