Clean errors in compilation when VERBOSE > 0

This commit is contained in:
2024-06-19 19:07:50 +01:00
parent 002b21b649
commit 11f79a84a3
4 changed files with 18 additions and 16 deletions

View File

@@ -72,6 +72,8 @@ typedef struct
darr_t page_vec;
} heap_t;
#define HEAP_SIZE(HEAP) ((HEAP).page_vec.used / sizeof(page_t *))
/**
@brief Instantiate a new heap structure

View File

@@ -10,14 +10,10 @@
* Description: Entrypoint to program
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <lib/inst.h>
#include "./runtime.h"
#include "./struct.h"
#include <vm/runtime.h>
#include <vm/struct.h>
void usage(const char *program_name, FILE *out)
{

View File

@@ -14,6 +14,10 @@
#include <inttypes.h>
#include <stdio.h>
#if VERBOSE >= 2
#include <string.h>
#endif
#include "./runtime.h"
const char *err_as_cstr(err_t err)
@@ -286,10 +290,10 @@ err_t vm_execute_all(vm_t *vm)
"----------\n",
stdout);
}
if (prev_pages != vm->heap.pages)
if (prev_pages != HEAP_SIZE(vm->heap))
{
vm_print_heap(vm, stdout);
prev_pages = vm->heap.pages;
prev_pages = HEAP_SIZE(vm->heap);
fputs("------------------------------------------------------------------"
"----"
"----------\n",

View File

@@ -65,21 +65,21 @@ void vm_stop(vm_t *vm)
printf("\n");
}
}
if (vm->heap.pages > 0)
if (HEAP_SIZE(vm->heap) > 0)
{
leaks = true;
page_t *cur = vm->heap.beg;
size_t capacities[vm->heap.pages], total_capacity = 0;
for (size_t i = 0; i < vm->heap.pages; ++i)
const size_t size_pages = HEAP_SIZE(vm->heap);
leaks = true;
size_t capacities[size_pages], total_capacity = 0;
for (size_t i = 0; i < size_pages; ++i)
{
page_t *cur = DARR_AT(page_t *, vm->heap.page_vec.data, i);
capacities[i] = cur->available;
total_capacity += capacities[i];
}
printf("\t[" TERM_RED "DATA" TERM_RESET
"]: Heap: %luB (over %lu %s) not reclaimed\n",
total_capacity, vm->heap.pages,
vm->heap.pages == 1 ? "page" : "pages");
for (size_t i = 0; i < vm->heap.pages; i++)
total_capacity, size_pages, size_pages == 1 ? "page" : "pages");
for (size_t i = 0; i < size_pages; i++)
printf("\t\t[%lu]: %luB lost\n", i, capacities[i]);
}
if (vm->stack.ptr > 0)