From 07ecd4acac34739a71d96fe092f47ea9fe868d54 Mon Sep 17 00:00:00 2001 From: Daniel Serpell Date: Sat, 27 Jul 2024 20:58:26 -0400 Subject: [PATCH] Fixes optimization for the POKE byte. This fixes restoring of the left-margin on exit from the editor. --- src/compiler/peephole.cc | 10 ++++------ testsuite/tests/opt-poke.bas | 21 +++++++++++++++++++++ testsuite/tests/opt-poke.chk | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 testsuite/tests/opt-poke.bas create mode 100644 testsuite/tests/opt-poke.chk diff --git a/src/compiler/peephole.cc b/src/compiler/peephole.cc index fe41c6e..20138b8 100644 --- a/src/compiler/peephole.cc +++ b/src/compiler/peephole.cc @@ -819,14 +819,12 @@ class peephole if(mtok(0, "TOK_BYTE") && mtok(2, "TOK_SADDR") && mtok(3, "TOK_VAR_LOAD") && mtok(5, "TOK_POKE")) { - copy(4, 1, 1); - copy(1, 5, 1); - del(6); - set_tok(0, "TOK_VAR_LOAD"); - set_tok(3, "TOK_BYTE_POKE"); + copy(0, 3, 2); + set_tok(2, "TOK_BYTE_POKE"); + del(7); del(6); del(5); - del(2); + del(4); i--; continue; } diff --git a/testsuite/tests/opt-poke.bas b/testsuite/tests/opt-poke.bas new file mode 100644 index 0000000..0e445d5 --- /dev/null +++ b/testsuite/tests/opt-poke.bas @@ -0,0 +1,21 @@ +' Test optimizations on "POKE" and "DPOKE" statements +? "Start" + +' Test using compile time constants, constant numbers +' are tested in stmt-poke.bas + +I=$34 + +POKE @@TMPCHR, 10 : ? PEEK(@@TMPCHR) +POKE @@TMPCHR, I : ? PEEK(@@TMPCHR) +POKE @RUNAD, 10 : ? PEEK(@RUNAD) +POKE @RUNAD, I : ? PEEK(@RUNAD) + +I=$5432 +DPOKE @@TMPCHR, 10 : ? DPEEK(@@TMPCHR) +DPOKE @@TMPCHR, 500 : ? DPEEK(@@TMPCHR) +DPOKE @@TMPCHR, I : ? DPEEK(@@TMPCHR) +DPOKE @RUNAD, 10 : ? DPEEK(@RUNAD) +DPOKE @RUNAD, 500 : ? DPEEK(@RUNAD) +DPOKE @RUNAD, I : ? DPEEK(@RUNAD) + diff --git a/testsuite/tests/opt-poke.chk b/testsuite/tests/opt-poke.chk new file mode 100644 index 0000000..7e26cc6 --- /dev/null +++ b/testsuite/tests/opt-poke.chk @@ -0,0 +1,14 @@ +Name: Test statement "POKE"/"DPOKE" +Test: run-int +Output: +Start +10 +52 +10 +52 +10 +500 +21554 +10 +500 +21554