From b4abb9394eb90077915f91c9cd7f88d5b0db6da9 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Thu, 19 Oct 2017 09:12:46 +0200 Subject: [PATCH] Fixed ClassCastException when attempting to removing a procedure with an empty start. Added a pointer conter increment test. --- .../kickc/passes/Pass1EliminateEmptyBlocks.java | 11 +++++++---- .../camelot64/kickc/test/TestCompilationOutput.java | 4 ++++ src/main/java/dk/camelot64/kickc/test/incd020.kc | 8 ++++++++ src/main/java/dk/camelot64/kickc/test/scroll.kc | 3 +-- 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/main/java/dk/camelot64/kickc/test/incd020.kc diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1EliminateEmptyBlocks.java b/src/main/java/dk/camelot64/kickc/passes/Pass1EliminateEmptyBlocks.java index cb75100f2..6451e1862 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1EliminateEmptyBlocks.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1EliminateEmptyBlocks.java @@ -43,10 +43,13 @@ public class Pass1EliminateEmptyBlocks { } } for (LabelRef labelRef : removeList) { - graph.remove(labelRef); - Label label = program.getScope().getLabel(labelRef); - label.getScope().remove(label); - log.append("Removing empty block "+labelRef); + Symbol removeSymbol = program.getScope().getSymbol(labelRef); + if(removeSymbol instanceof Label) { + Label label = (Label) removeSymbol; + graph.remove(labelRef); + label.getScope().remove(label); + log.append("Removing empty block "+labelRef); + } } return removeList.size()>0; } diff --git a/src/main/java/dk/camelot64/kickc/test/TestCompilationOutput.java b/src/main/java/dk/camelot64/kickc/test/TestCompilationOutput.java index d89269906..c162f3ba0 100644 --- a/src/main/java/dk/camelot64/kickc/test/TestCompilationOutput.java +++ b/src/main/java/dk/camelot64/kickc/test/TestCompilationOutput.java @@ -24,6 +24,10 @@ public class TestCompilationOutput extends TestCase { helper = new ReferenceHelper("dk/camelot64/kickc/test/ref/"); } + public void testIncD020() throws IOException, URISyntaxException { + compileAndCompare("incd020"); + } + public void testScroll() throws IOException, URISyntaxException { compileAndCompare("scroll"); } diff --git a/src/main/java/dk/camelot64/kickc/test/incd020.kc b/src/main/java/dk/camelot64/kickc/test/incd020.kc new file mode 100644 index 000000000..b42aefe14 --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/test/incd020.kc @@ -0,0 +1,8 @@ +byte* BGCOL = $d020; +main(); +void main() { + do { + ++*BGCOL; + (*BGCOL)++; + } while (true) +} \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/test/scroll.kc b/src/main/java/dk/camelot64/kickc/test/scroll.kc index 4ca67699c..1d4a27150 100644 --- a/src/main/java/dk/camelot64/kickc/test/scroll.kc +++ b/src/main/java/dk/camelot64/kickc/test/scroll.kc @@ -2,8 +2,7 @@ byte* SCREEN = $0400; byte* RASTER = $d012; byte* BGCOL = $d020; byte* SCROLL = $d016; -byte* TEXT = "this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. "; -byte[] STOP = { 0 }; +byte* TEXT = "-= this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. =- @"; main(); void main() {