From 00119678edc7a2a4cc7aab96a6e53d07f98ec46b Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Tue, 5 Jul 2022 22:01:35 -0700 Subject: [PATCH] Fix bugs in 2! and 2@. --- common/base_tests.fs | 9 +++++++++ common/extra_opcodes.h | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/base_tests.fs b/common/base_tests.fs index f7bdd24..68ced6b 100644 --- a/common/base_tests.fs +++ b/common/base_tests.fs @@ -148,3 +148,12 @@ e: test-arshift $1234 4 arshift $123 =assert -1 cell 8 * 1- arshift -1 =assert ;e + +e: test-2@2! + create foo 2 cells allot + 123 456 foo 2! + 999 foo 2@ + 456 =assert + 123 =assert + 999 =assert +;e diff --git a/common/extra_opcodes.h b/common/extra_opcodes.h index a0fae87..6a37675 100644 --- a/common/extra_opcodes.h +++ b/common/extra_opcodes.h @@ -47,8 +47,8 @@ X("cell/", CELLSLASH, DUP; tos = sizeof(cell_t); DUP; *sp = 1; SSMOD_FUNC; NIP) \ 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]; \ + X("2@", TWOAT, DUP; *sp = *(cell_t *) tos; tos = ((cell_t *) tos)[1]) \ + X("2!", TWOSTORE, ((cell_t *) tos)[0] = sp[-1]; \ ((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) \