mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-09 18:31:23 +00:00
Implemented constant pointer detection - allowing for efficient NULL-code using const byte* NULL = $00. Closes #79
This commit is contained in:
parent
3a0a8f450d
commit
43395567af
@ -6,6 +6,7 @@ import dk.camelot64.kickc.model.types.SymbolTypeSimple;
|
|||||||
import dk.camelot64.kickc.model.values.ConstantBool;
|
import dk.camelot64.kickc.model.values.ConstantBool;
|
||||||
import dk.camelot64.kickc.model.values.ConstantInteger;
|
import dk.camelot64.kickc.model.values.ConstantInteger;
|
||||||
import dk.camelot64.kickc.model.values.ConstantLiteral;
|
import dk.camelot64.kickc.model.values.ConstantLiteral;
|
||||||
|
import dk.camelot64.kickc.model.values.ConstantPointer;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -20,7 +21,10 @@ public class OperatorNotEqual extends OperatorBinary {
|
|||||||
public ConstantLiteral calculateLiteral(ConstantLiteral left, ConstantLiteral right) {
|
public ConstantLiteral calculateLiteral(ConstantLiteral left, ConstantLiteral right) {
|
||||||
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
|
if(left instanceof ConstantInteger && right instanceof ConstantInteger) {
|
||||||
return new ConstantBool(!Objects.equals(((ConstantInteger) left).getInteger(), ((ConstantInteger) right).getInteger()));
|
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);
|
throw new CompileError("Calculation not implemented " + left + " " + getOperator() + " " + right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,11 @@ public class TestPrograms {
|
|||||||
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
|
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConstPointer() throws IOException, URISyntaxException {
|
||||||
|
compileAndCompare("const-pointer");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVarForwardProblem() throws IOException, URISyntaxException {
|
public void testVarForwardProblem() throws IOException, URISyntaxException {
|
||||||
compileAndCompare("var-forward-problem");
|
compileAndCompare("var-forward-problem");
|
||||||
|
13
src/test/java/dk/camelot64/kickc/test/kc/const-pointer.kc
Normal file
13
src/test/java/dk/camelot64/kickc/test/kc/const-pointer.kc
Normal 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] = '.';
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user