fix incorrect formats and output memory usage on call stack warning

This commit is contained in:
2025-08-05 01:00:07 +01:00
parent a8acafffe9
commit c3c41e0336
4 changed files with 19 additions and 10 deletions

8
app.py
View File

@@ -1,4 +1,4 @@
def factorial(x): def f():
if x==1: return 1 f()
return factorial(x-1) + x
factorial(10000) f()

View File

@@ -111,11 +111,11 @@ void output_err(ArErr err) {
dyefg(stderr, DYE_GRAY); dyefg(stderr, DYE_GRAY);
fprintf(stderr, ":"); fprintf(stderr, ":");
dyefg(stderr, DYE_YELLOW); dyefg(stderr, DYE_YELLOW);
fprintf(stderr, "%zu", err.line); fprintf(stderr, "%lld", err.line);
dyefg(stderr, DYE_GRAY); dyefg(stderr, DYE_GRAY);
fprintf(stderr, ":"); fprintf(stderr, ":");
dyefg(stderr, DYE_YELLOW); dyefg(stderr, DYE_YELLOW);
fprintf(stderr, "%zu", err.column); fprintf(stderr, "%lld", err.column);
dye_style(stderr, DYE_STYLE_RESET); dye_style(stderr, DYE_STYLE_RESET);
dyefg(stderr, DYE_RESET); dyefg(stderr, DYE_RESET);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@@ -123,7 +123,7 @@ void output_err(ArErr err) {
if (file) { if (file) {
dye_style(stderr, DYE_STYLE_RESET); dye_style(stderr, DYE_STYLE_RESET);
dyefg(stderr, DYE_RESET); dyefg(stderr, DYE_RESET);
int line_number_width = snprintf(NULL, 0, "%zu", err.line); int line_number_width = snprintf(NULL, 0, "%lld", err.line);
char *buffer = NULL; char *buffer = NULL;
size_t size = 0; size_t size = 0;
int current_line = 1; int current_line = 1;
@@ -154,7 +154,7 @@ void output_err(ArErr err) {
err.column--; err.column--;
skipped_chars++; skipped_chars++;
} }
fprintf(stderr, " %zu | ", err.line); fprintf(stderr, " %lld | ", err.line);
if (err.length) { if (err.length) {
fprintf(stderr, "%.*s", (int)err.column - 1, line_starts); fprintf(stderr, "%.*s", (int)err.column - 1, line_starts);
dyefg(stderr, DYE_RED); dyefg(stderr, DYE_RED);

View File

@@ -99,10 +99,17 @@ void run_call(Translated *translated, RuntimeState *state) {
if (floor(logval) == logval) { if (floor(logval) == logval) {
SourceLocation *source_location = SourceLocation *source_location =
darray_get(&translated->source_locations, source_location_index); darray_get(&translated->source_locations, source_location_index);
double memoryUsage = get_memory_usage_mb();
fprintf(stderr, fprintf(stderr,
"Warning: %s:%zu:%zu the call stack depth has exceeded %zu\n", "Warning: %s:%llu:%llu the call stack depth has exceeded %llu",
state->path, source_location->line, source_location->column, state->path, source_location->line, source_location->column,
(*state->currentStackFramePointer)->depth); (*state->currentStackFramePointer)->depth);
if (memoryUsage) {
fprintf(stderr, ", memory usage at %f MB\n", memoryUsage);
} else {
fprintf(stderr, "\n");
}
} }
}; };
*state->currentStackFramePointer = checked_malloc(sizeof(StackFrame)); *state->currentStackFramePointer = checked_malloc(sizeof(StackFrame));

View File

@@ -1,5 +1,7 @@
# SPDX-FileCopyrightText: 2025 William Bell # SPDX-FileCopyrightText: 2025 William Bell
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
let f()=f() let f()=g()
let g()=h()
let h()=f()
f() f()