From c3c41e0336063d0cf96460ce392725c02cee6004 Mon Sep 17 00:00:00 2001 From: William Bell Date: Tue, 5 Aug 2025 01:00:07 +0100 Subject: [PATCH] fix incorrect formats and output memory usage on call stack warning --- app.py | 8 ++++---- src/err.c | 8 ++++---- src/runtime/call/call.c | 9 ++++++++- testing.ar | 4 +++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index e348cb2..ca74a71 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -def factorial(x): - if x==1: return 1 - return factorial(x-1) + x -factorial(10000) \ No newline at end of file +def f(): + f() + +f() \ No newline at end of file diff --git a/src/err.c b/src/err.c index 45a060c..a98c456 100644 --- a/src/err.c +++ b/src/err.c @@ -111,11 +111,11 @@ void output_err(ArErr err) { dyefg(stderr, DYE_GRAY); fprintf(stderr, ":"); dyefg(stderr, DYE_YELLOW); - fprintf(stderr, "%zu", err.line); + fprintf(stderr, "%lld", err.line); dyefg(stderr, DYE_GRAY); fprintf(stderr, ":"); dyefg(stderr, DYE_YELLOW); - fprintf(stderr, "%zu", err.column); + fprintf(stderr, "%lld", err.column); dye_style(stderr, DYE_STYLE_RESET); dyefg(stderr, DYE_RESET); fprintf(stderr, "\n"); @@ -123,7 +123,7 @@ void output_err(ArErr err) { if (file) { dye_style(stderr, DYE_STYLE_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; size_t size = 0; int current_line = 1; @@ -154,7 +154,7 @@ void output_err(ArErr err) { err.column--; skipped_chars++; } - fprintf(stderr, " %zu | ", err.line); + fprintf(stderr, " %lld | ", err.line); if (err.length) { fprintf(stderr, "%.*s", (int)err.column - 1, line_starts); dyefg(stderr, DYE_RED); diff --git a/src/runtime/call/call.c b/src/runtime/call/call.c index 15e243b..e35aae7 100644 --- a/src/runtime/call/call.c +++ b/src/runtime/call/call.c @@ -99,10 +99,17 @@ void run_call(Translated *translated, RuntimeState *state) { if (floor(logval) == logval) { SourceLocation *source_location = darray_get(&translated->source_locations, source_location_index); + double memoryUsage = get_memory_usage_mb(); 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->currentStackFramePointer)->depth); + if (memoryUsage) { + fprintf(stderr, ", memory usage at %f MB\n", memoryUsage); + + } else { + fprintf(stderr, "\n"); + } } }; *state->currentStackFramePointer = checked_malloc(sizeof(StackFrame)); diff --git a/testing.ar b/testing.ar index 5768164..93c6d33 100644 --- a/testing.ar +++ b/testing.ar @@ -1,5 +1,7 @@ # SPDX-FileCopyrightText: 2025 William Bell # SPDX-License-Identifier: GPL-3.0-or-later -let f()=f() +let f()=g() +let g()=h() +let h()=f() f() \ No newline at end of file