1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-08 14:37:40 +00:00

Fixed problem with post-increment causing java exception. Closes #538

This commit is contained in:
jespergravgaard 2020-10-11 15:56:17 +02:00
parent cb1ae7bd30
commit a4e62009d0
5 changed files with 48 additions and 2 deletions

View File

@ -2766,7 +2766,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
List<PrePostModifier> modifiers,
StatementSource source) {
for(PrePostModifier mod : modifiers) {
if(mod.child instanceof ConstantRef) {
if(mod.child instanceof ConstantValue) {
throw new CompileError("Constants can not be modified " + mod.child.toString(), source);
}
Statement stmt = new StatementAssignment((LValue) mod.child, mod.operator, copyLValue((LValue) mod.child), false, source, Comment.NO_COMMENTS);

View File

@ -666,6 +666,11 @@ public class TestPrograms {
compileAndCompare("examples/conio/nacht-screen.c");
}
@Test
public void testPostIncrementProblem5() throws IOException, URISyntaxException {
assertError("post-increment-problem-5.c", "Constants can not be modified");
}
@Test
public void testPostIncrementProblem4() throws IOException, URISyntaxException {
compileAndCompare("post-increment-problem-4.c");
@ -1447,7 +1452,7 @@ public class TestPrograms {
@Test
public void testDyppa2() throws IOException, URISyntaxException {
compileAndCompare("complex/dyppa2/dyppa2.c", log());
compileAndCompare("complex/dyppa2/dyppa2.c");
}
@Test

View File

@ -0,0 +1,33 @@
// Chunky DYPP with arbitrary sinus
// First implemented as dyppa.asm in 2011
#pragma emulator("C64Debugger")
#include <c64.h>
#include <string.h>
// The DYPPA charset containing the sloped offset characters
char __address(0x2000) DYPPA_CHARSET[0x0800] = kickasm(resource "dyppacharset.bin") {{
.var dyppaFile = LoadBinary("dyppacharset.bin", "Charset=$000,Tables=$800")
.fill dyppaFile.getCharsetSize(), dyppaFile.getCharset(i)
}};
// The DYPPA tables mapping the slopes, offsets and pixels to the right character in the charset
// for(offset:0..7) for(slope:0..f) for(pixels: 0..f) glyph_id(offset,slope,pixels)
char align(0x100) DYPPA_TABLE[0x0800] = kickasm(resource "dyppacharset.bin") {{
.var dyppaFile2 = LoadBinary("dyppacharset.bin", "Charset=$000,Tables=$800")
.fill dyppaFile2.getTablesSize(), dyppaFile2.getTables(i)
}};
void main() {
VICII->MEMORY = toD018(DEFAULT_SCREEN, DYPPA_CHARSET);
memset(DEFAULT_SCREEN, DYPPA_TABLE[0], 1000);
for(;;) {
(*(DEFAULT_SCREEN+999))++;
}
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
// Post-increment expression causes java.lang.ClassCastException: class dk.camelot64.kickc.model.values.ConstantBinary cannot be cast to class dk.camelot64.kickc.model.values.LValue
// Should result in a proper error
char* const SCREEN = 0x0400;
void main() {
*(SCREEN+999)++;
}