Skip to content

Commit

Permalink
Fixes optimization for the POKE byte.
Browse files Browse the repository at this point in the history
This fixes restoring of the left-margin on exit from the editor.
  • Loading branch information
dmsc committed Jul 28, 2024
1 parent b6c79c7 commit 07ecd4a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/compiler/peephole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 21 additions & 0 deletions testsuite/tests/opt-poke.bas
Original file line number Diff line number Diff line change
@@ -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)

14 changes: 14 additions & 0 deletions testsuite/tests/opt-poke.chk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Name: Test statement "POKE"/"DPOKE"
Test: run-int
Output:
Start
10
52
10
52
10
500
21554
10
500
21554

0 comments on commit 07ecd4a

Please sign in to comment.