shithub: femtolisp

Download patch

ref: 34c738365a86c051874e506eafb8759b489748fd
parent: 62389c8990cafb8e99ae29b2bccbcd100ce4c7f0
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Jan 13 23:54:34 EST 2025

heap: use uintptr_t for its size

--- a/flisp.c
+++ b/flisp.c
@@ -525,7 +525,7 @@
 	// if we're using > 80% of the space, resize tospace so we have
 	// more space to fill next time. if we grew tospace last time,
 	// grow the other half of the heap this time to catch up.
-	if(FL(grew) || ((FL(lim)-FL(curheap)) < (int)(FL(heapsize)/5)) || mustgrow){
+	if(FL(grew) || ((intptr_t)(FL(lim)-FL(curheap)) < (intptr_t)FL(heapsize)/5) || mustgrow){
 		temp = MEM_REALLOC(FL(tospace), FL(heapsize)*2);
 		if(fl_unlikely(temp == nil))
 			fl_raise(FL(memory_exception_value));
@@ -1265,9 +1265,9 @@
 {
 	USED(args);
 	argcount(nargs, 0);
-	ios_printf(ios_stderr, "heap total     %10"PRIu32"\n", FL(heapsize));
-	ios_printf(ios_stderr, "heap free      %10"PRIu32"\n", (uint32_t)(FL(lim)-FL(curheap)));
-	ios_printf(ios_stderr, "heap used      %10"PRIu32"\n", (uint32_t)(FL(curheap)-FL(fromspace)));
+	ios_printf(ios_stderr, "heap total     %10"PRIuPTR"\n", FL(heapsize));
+	ios_printf(ios_stderr, "heap free      %10"PRIuPTR"\n", (uintptr_t)(FL(lim)-FL(curheap)));
+	ios_printf(ios_stderr, "heap used      %10"PRIuPTR"\n", (uintptr_t)(FL(curheap)-FL(fromspace)));
 	ios_printf(ios_stderr, "stack          %10"PRIu64"\n", (uint64_t)FL(nstack)*sizeof(value_t));
 	ios_printf(ios_stderr, "gc calls       %10"PRIu64"\n", (uint64_t)FL(gccalls));
 	ios_printf(ios_stderr, "max finalizers %10"PRIu32"\n", (uint32_t)FL(maxfinalizers));
--- a/flisp.h
+++ b/flisp.h
@@ -348,10 +348,10 @@
 struct Fl {
 	value_t *stack;
 	uint32_t sp;
-	uint32_t heapsize;//bytes
+	uint32_t nstack;
+	uintptr_t heapsize;//bytes
 	uint8_t *fromspace;
 	uint32_t curr_frame;
-	uint32_t nstack;
 
 	uint8_t *tospace;
 	uint8_t *curheap;