From de7a57e53d6b9dce2c9d97f647c683947b888689 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sat, 5 Feb 2022 21:35:11 -0800 Subject: [PATCH] Inline dictionary words. --- ueforth/common/boot.fs | 7 ------- ueforth/common/core.h | 2 +- ueforth/common/extra.fs | 6 ++++++ ueforth/common/extra_opcodes.h | 6 ++++++ ueforth/common/forth_namespace_tests.fs | 10 +++++----- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 87d6e11..8be8767 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -16,13 +16,6 @@ : \ 10 parse drop drop ; immediate ( Now can do comments! ) -( Dictionary ) -: here ( -- a ) 'sys @ ; -: allot ( n -- ) 'sys +! ; -: align here aligned here - allot ; -: , ( n -- ) here ! cell allot ; -: c, ( ch -- ) here c! 1 allot ; - ( Constants and Variables ) : constant ( n "name" -- ) create , does> @ ; : variable ( "name" -- ) create 0 , ; diff --git a/ueforth/common/core.h b/ueforth/common/core.h index ba704dd..4d05ed1 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -18,7 +18,7 @@ #define CELL_LEN(n) (((n) + CELL_MASK) / sizeof(cell_t)) #define FIND(name) find((name), sizeof(name) - 1) #define UPPER(ch) (((ch) >= 'a' && (ch) <= 'z') ? ((ch) & 0x5F) : (ch)) -#define CELL_ALIGNED(a) (((cell_t) (a) + CELL_MASK) & ~CELL_MASK) +#define CELL_ALIGNED(a) ((((cell_t) (a)) + CELL_MASK) & ~CELL_MASK) #define IMMEDIATE 1 #define SMUDGE 2 diff --git a/ueforth/common/extra.fs b/ueforth/common/extra.fs index f602ad7..233f975 100644 --- a/ueforth/common/extra.fs +++ b/ueforth/common/extra.fs @@ -60,7 +60,13 @@ : max 2dup < if nip else drop then ; : abs ( n -- +n ) dup 0< if negate then ; +( Dictionary ) +: here ( -- a ) 'sys @ ; +: allot ( n -- ) 'sys +! ; : aligned ( a -- a ) cell 1 - dup >r + r> invert and ; +: align here aligned here - allot ; +: , ( n -- ) here ! cell allot ; +: c, ( ch -- ) here c! 1 allot ; ( Dictionary Format ) : >flags& ( xt -- a ) cell - ; : >flags ( xt -- flags ) >flags& c@ ; diff --git a/ueforth/common/extra_opcodes.h b/ueforth/common/extra_opcodes.h index f9545e1..075ac78 100644 --- a/ueforth/common/extra_opcodes.h +++ b/ueforth/common/extra_opcodes.h @@ -57,7 +57,13 @@ Y(min, tos = tos < *sp ? tos : *sp; NIP) \ Y(max, tos = tos > *sp ? tos : *sp; NIP) \ Y(abs, tos = tos < 0 ? -tos : tos) \ + Y(here, DUP; tos = (cell_t) g_sys.heap) \ + Y(allot, g_sys.heap = (cell_t *) (tos + (cell_t) g_sys.heap); DROP) \ Y(aligned, tos = CELL_ALIGNED(tos)) \ + Y(align, g_sys.heap = (cell_t *) CELL_ALIGNED(g_sys.heap)) \ + X(",", COMMA, *g_sys.heap++ = tos; DROP) \ + X("c,", CCOMMA, *((uint8_t *) g_sys.heap) = tos; DROP; \ + g_sys.heap = (cell_t *) (1 + ((cell_t) g_sys.heap))) \ X(">flags", TOFLAGS, tos = *TOFLAGS(tos)) \ X(">params", TOPARAMS, tos = *TOPARAMS(tos)) \ X(">size", TOSIZE, tos = TOSIZE(tos)) \ diff --git a/ueforth/common/forth_namespace_tests.fs b/ueforth/common/forth_namespace_tests.fs index e7e54af..1035539 100644 --- a/ueforth/common/forth_namespace_tests.fs +++ b/ueforth/common/forth_namespace_tests.fs @@ -132,11 +132,6 @@ e: check-boot out: current out: variable out: constant - out: c, - out: , - out: align - out: allot - out: here out: \ out: ( ;e @@ -150,7 +145,12 @@ e: check-extra-opcodes out: >params out: >flags + out: c, + out: , + out: align out: aligned + out: allot + out: here out: abs out: max