1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-09 03:30:40 +00:00

Implemented constant pointer detection - allowing for efficient NULL-code using const byte* NULL = $00. Closes #79

This commit is contained in:
jespergravgaard 2018-04-22 11:24:02 +02:00
parent 3a0a8f450d
commit 43395567af
3 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import dk.camelot64.kickc.model.types.SymbolTypeSimple;
import dk.camelot64.kickc.model.values.ConstantBool;
import dk.camelot64.kickc.model.values.ConstantInteger;
import dk.camelot64.kickc.model.values.ConstantLiteral;
import dk.camelot64.kickc.model.values.ConstantPointer;
import java.util.Objects;
@ -20,7 +21,10 @@ public class OperatorNotEqual extends OperatorBinary {
public ConstantLiteral calculateLiteral(ConstantLiteral left, ConstantLiteral right) {
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
return new ConstantBool(!Objects.equals(((ConstantInteger) left).getInteger(), ((ConstantInteger) right).getInteger()));
} else if(left instanceof ConstantPointer && right instanceof ConstantPointer) {
return new ConstantBool(!Objects.equals(((ConstantPointer) left).getLocation(), ((ConstantPointer) right).getLocation()));
}
throw new CompileError("Calculation not implemented " + left + " " + getOperator() + " " + right);
}

View File

@ -44,6 +44,11 @@ public class TestPrograms {
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
}
@Test
public void testConstPointer() throws IOException, URISyntaxException {
compileAndCompare("const-pointer");
}
@Test
public void testVarForwardProblem() throws IOException, URISyntaxException {
compileAndCompare("var-forward-problem");

View File

@ -0,0 +1,13 @@
//Test that constant pointers are detected correctly
void main() {
byte* screen = $400;
byte* NULL = $0;
byte* rem = $ff;
if(rem!=NULL) {
screen[0] = '*';
} else {
screen[0] = '.';
}
}