From 5b131c84fe6aa7d15d8d4ea56cb0284c9345e9b2 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 9 Jan 2022 14:20:50 -0800 Subject: [PATCH] Add more memory diagnostics. --- ueforth/common/boot.fs | 5 ++++- ueforth/common/core.h | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 59efd6c..6c72c5b 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -74,6 +74,7 @@ sys: 'argc sys: 'argv sys: 'runner : context ( -- a ) 'context @ cell+ ; : remaining ( -- n ) 'heap-start @ 'heap-size @ + 'heap @ - ; +: used ( -- n ) 'heap @ sp@ 'stack-cells @ cells + - 28 + ; ( Compilation State ) : [ 0 state ! ; immediate @@ -258,5 +259,7 @@ create input-buffer input-limit allot if 0 state ! sp0 sp! fp0 fp! rp0 rp! ." ERROR" cr then prompt refill drop again ; : raw-ok ." v{{VERSION}} - rev {{REVISION}}" cr - remaining . ." bytes heap free" cr + remaining . ." bytes heap free " + used . ." bytes dictionary used " + 'stack-cells @ cells . ." bytes x 3 stacks" cr prompt refill drop quit ; diff --git a/ueforth/common/core.h b/ueforth/common/core.h index a36a80c..0fb8ebb 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -24,7 +24,7 @@ #define VOCABULARY_DEPTH 16 #if PRINT_ERRORS -#include +#include #endif static struct { @@ -180,8 +180,9 @@ static cell_t *evaluate1(cell_t *sp, float **fp) { } } else { #if PRINT_ERRORS - write(2, (void *) name, len); - write(2, "\n", 1); + fprintf(stderr, "CANT FIND: "); + fwrite((void *) name, 1, len, stderr); + fprintf(stderr, "\n"); #endif *++sp = name; *++sp = len; @@ -219,7 +220,6 @@ static void forth_init(int argc, char *argv[], void *heap, for (int i = 0; i < VOCABULARY_DEPTH; ++i) { *g_sys.heap++ = 0; } forth_run(0); - (*g_sys.current)[-1] |= IMMEDIATE; // Make last word ; IMMEDIATE g_sys.DOLIT_XT = FIND("DOLIT"); g_sys.DOFLIT_XT = FIND("DOFLIT"); g_sys.DOEXIT_XT = FIND("EXIT");