From ede5e83c4f19932125cbeba82c2ea860833d3b46 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 4 Feb 2022 18:39:07 -0800 Subject: [PATCH] Inline memory words. --- ueforth/common/blocks.fs | 2 +- ueforth/common/boot.fs | 6 ------ ueforth/common/extra.fs | 6 ++++++ ueforth/common/extra_opcodes.h | 9 +++++++-- ueforth/common/forth_namespace_tests.fs | 11 ++++++----- ueforth/posix/httpd.fs | 2 +- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ueforth/common/blocks.fs b/ueforth/common/blocks.fs index 32edb5c..dd07798 100644 --- a/ueforth/common/blocks.fs +++ b/ueforth/common/blocks.fs @@ -14,7 +14,7 @@ ( Block Files ) internals definitions -: clobber-line ( a -- a' ) dup 63 bl fill 63 + nl over c! 1+ ; +: clobber-line ( a -- a' ) dup 63 blank 63 + nl over c! 1+ ; : clobber ( a -- ) 15 for clobber-line next drop ; 0 value block-dirty create block-data 1024 allot diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 7d5a541..58f69e8 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -183,12 +183,6 @@ variable hld : s>z ( a n -- z ) here >r zplace r> ; : z>s ( z -- a n ) 0 over begin dup c@ while 1+ swap 1+ swap repeat drop ; -( Fill, Move ) -: cmove ( a a n -- ) for aft >r dup c@ r@ c! 1+ r> 1+ then next 2drop ; -: cmove> ( a a n -- ) for aft 2dup swap r@ + c@ swap r@ + c! then next 2drop ; -: fill ( a n ch -- ) swap for swap aft 2dup c! 1 + then next 2drop ; -: erase ( a n -- ) 0 fill ; : blank ( a n -- ) bl fill ; - ( Better Errors ) : notfound ( a n n -- ) if cr ." ERROR: " type ." NOT FOUND!" cr -1 throw then ; diff --git a/ueforth/common/extra.fs b/ueforth/common/extra.fs index e2e8911..742d648 100644 --- a/ueforth/common/extra.fs +++ b/ueforth/common/extra.fs @@ -48,3 +48,9 @@ : 2dup ( a b -- a b a b ) over over ; : 2@ ( a -- lo hi ) dup @ swap cell+ @ ; : 2! ( lo hi a -- ) dup >r cell+ ! r> ! ; + +( Fill, Move ) +: cmove ( a a n -- ) for aft >r dup c@ r@ c! 1+ r> 1+ then next 2drop ; +: cmove> ( a a n -- ) for aft 2dup swap r@ + c@ swap r@ + c! then next 2drop ; +: fill ( a n ch -- ) swap for swap aft 2dup c! 1 + then next 2drop ; +: erase ( a n -- ) 0 fill ; : blank ( a n -- ) bl fill ; diff --git a/ueforth/common/extra_opcodes.h b/ueforth/common/extra_opcodes.h index bcd7f7d..048194b 100644 --- a/ueforth/common/extra_opcodes.h +++ b/ueforth/common/extra_opcodes.h @@ -44,8 +44,13 @@ X("cell+", CELLPLUS, tos += sizeof(cell_t)) \ X("cells", CELLSTAR, tos *= sizeof(cell_t)) \ X("cell/", CELLSLASH, DUP; tos = sizeof(cell_t); DUP; *sp = 1; SSMOD_FUNC; NIP) \ - X("2drop", TWODROP, DROP; DROP) \ + X("2drop", TWODROP, NIP; DROP) \ X("2dup", TWODUP, DUP; tos = sp[-1]; DUP; tos = sp[-1]) \ X("2@", TWOAT, DUP; *sp = ((cell_t *) tos)[1]; tos = *(cell_t *) tos) \ X("2!", TWOSTORE, DUP; ((cell_t *) tos)[0] = sp[-1]; \ - ((cell_t *) tos)[1] = *sp; DROP; DROP; DROP) + ((cell_t *) tos)[1] = *sp; sp -= 2; DROP) \ + Y(cmove, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \ + X("cmove>", cmove2, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \ + Y(fill, memset((void *) sp[-1], tos, *sp); sp -= 2; DROP) \ + Y(erase, memset((void *) *sp, 0, tos); NIP; DROP) \ + Y(blank, memset((void *) *sp, ' ', tos); NIP; DROP) diff --git a/ueforth/common/forth_namespace_tests.fs b/ueforth/common/forth_namespace_tests.fs index 1ba6489..dcde57c 100644 --- a/ueforth/common/forth_namespace_tests.fs +++ b/ueforth/common/forth_namespace_tests.fs @@ -55,11 +55,6 @@ e: check-boot out: tib out: accept out: echo - out: blank - out: erase - out: fill - out: cmove> - out: cmove out: z>s out: s>z out: r~ @@ -175,6 +170,12 @@ e: check-boot ;e e: check-extra-opcodes + out: blank + out: erase + out: fill + out: cmove> + out: cmove + out: 2! out: 2@ out: 2dup diff --git a/ueforth/posix/httpd.fs b/ueforth/posix/httpd.fs index 47f6c09..367570c 100644 --- a/ueforth/posix/httpd.fs +++ b/ueforth/posix/httpd.fs @@ -37,7 +37,7 @@ sockaddr httpd-port sockaddr client variable client-len sockfd client client-len sockaccept dup 0< if drop 0 exit then to clientfd - chunk chunk-size 0 fill + chunk chunk-size erase chunk chunk-size clientfd read-file throw to chunk-filled -1 ;