added garbage collector draft

This commit is contained in:
Francesco Cozzuto
2021-12-06 00:12:02 +01:00
parent 60b871be55
commit dbcf50c71b
21 changed files with 389 additions and 48 deletions
+20
View File
@@ -54,6 +54,26 @@ void *Stack_Top(Stack *s, int n)
return s->body[s->used + n - 1];
}
void **Stack_TopRef(Stack *s, int n)
{
assert(n <= 0);
if(Stack_IsReadOnlyCopy(s))
return NULL;
// Remove readonly bit.
s = unmark(s);
if(s->used == 0)
return NULL;
if((int) s->used + n - 1 < 0)
return NULL;
return &s->body[s->used + n - 1];
}
_Bool Stack_Pop(Stack *s, unsigned int n)
{
if(Stack_IsReadOnlyCopy(s))
+1
View File
@@ -8,6 +8,7 @@ _Bool Stack_Push(Stack *s, void *item);
void Stack_Free(Stack *s);
unsigned int Stack_Size(Stack *s);
Stack *Stack_Copy(Stack *s, _Bool readonly);
void **Stack_TopRef(Stack *s, int n);
unsigned int Stack_Capacity(Stack *s);
_Bool Stack_IsReadOnlyCopy(Stack *s);
#endif