Core Compiler: Fix type incomplete polymorph, work on RTS
This commit is contained in:
@@ -26,12 +26,27 @@ Free :: (a: *Array($T))
|
||||
Reset :: (a: *Array($T))
|
||||
a.len = 0
|
||||
|
||||
Insert :: (a: *Array($T), item: T, index: int)
|
||||
if index == a.len
|
||||
Add(a, item)
|
||||
return
|
||||
|
||||
Assert(index < a.len)
|
||||
Assert(index >= 0)
|
||||
|
||||
TryGrowing(a)
|
||||
right_len := (a.len - index)->size_t
|
||||
memmove(a.data + index + 1, a.data + index, SizeOf(T) * right_len)
|
||||
a.data[index] = item
|
||||
a.len += 1
|
||||
|
||||
GetIndex :: (a: *Array($T), item: *T): int
|
||||
Assert(a.len > 0)
|
||||
Assert(item >= a.data && item < a.data + a.len)
|
||||
|
||||
// @reproduction: compiler hangs
|
||||
// index := (item - a.data)->*void->size_t
|
||||
|
||||
index := (item - a.data)->int
|
||||
Assert(index >= 0 && index < a.len)
|
||||
return index
|
||||
@@ -52,7 +67,6 @@ OrderedRemove :: (a: *Array($T), item: *T)
|
||||
memmove(a.data + index, a.data + index + 1, length_right_of_item * SizeOf(T))
|
||||
a.len -= 1
|
||||
|
||||
|
||||
TryGrowing :: (a: *Array($T))
|
||||
if a.cap == 0
|
||||
a.cap = 16
|
||||
@@ -61,11 +75,25 @@ TryGrowing :: (a: *Array($T))
|
||||
a.cap *= 2
|
||||
a.data = realloc(a.data, SizeOf(T) * a.cap->size_t)
|
||||
|
||||
|
||||
Add :: (a: *Array($T), item: T)
|
||||
TryGrowing(a)
|
||||
a.data[a.len++] = item
|
||||
|
||||
BoundedAdd :: (a: *Array($T), item: T)
|
||||
Assert(a.len + 1 <= a.cap)
|
||||
Add(a, item)
|
||||
|
||||
InsertSortedDecreasing :: (a: *Array($T), item: T)
|
||||
insert_index := -1
|
||||
for i := 0, i < a.len, i += 1
|
||||
it := a.data + i
|
||||
if it.value_to_sort_by <= item.value_to_sort_by
|
||||
Insert(a, item, i)
|
||||
break
|
||||
|
||||
if insert_index == -1
|
||||
Add(a, item)
|
||||
|
||||
Reserve :: (a: *Array($T), size: int)
|
||||
Assert(size > a.cap)
|
||||
a.cap = size
|
||||
|
||||
Reference in New Issue
Block a user