1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Added test cases for problems #199 #281 #282

This commit is contained in:
jespergravgaard 2019-08-21 20:04:11 +02:00
parent 8bbddf5651
commit ea7df4761f
5 changed files with 80 additions and 2 deletions

View File

@ -94,10 +94,12 @@ public class PassNTypeInference extends Pass2SsaOptimization {
if(type == null) {
type = valueType;
} else if(!type.equals(valueType))
if(valueType instanceof SymbolTypeInteger && type instanceof SymbolTypeInteger) {
if(type.equals(SymbolType.VAR) && valueType!=null) {
type = valueType;
} else if(valueType instanceof SymbolTypeInteger && type instanceof SymbolTypeInteger) {
type = SymbolTypeConversion.convertedMathType((SymbolTypeInteger) valueType, (SymbolTypeInteger) type);
} else {
throw new CompileError("Phi value has type mismatch " + phiRValue.toString() + " not matching type " + type.getTypeName());
throw new CompileError("Phi value has type mismatch " + rValue.toString() + " not matching type " + type.getTypeName());
}
}
if(!SymbolType.VAR.equals(symbol.getType()) && !type.equals(symbol.getType())) {

View File

@ -81,11 +81,20 @@ public class TestPrograms {
compileAndCompare("string-escapes-0");
}
// TODO: Fix loop head problem!
//@Test
//public void testLoopheadProblem() throws IOException, URISyntaxException {
// compileAndCompare("loophead-problem");
//}
// TODO: Fail with proper error when continue is encountered without a loop
/*
@Test
public void testSwitch3Err() throws IOException, URISyntaxException {
compileAndCompare("switch-3-err");
}
*/
@Test
public void testSwitch2() throws IOException, URISyntaxException {
compileAndCompare("switch-2");
@ -331,6 +340,14 @@ public class TestPrograms {
compileAndCompare("font-hex-show");
}
// TODO: Fix string not converted to void* properly https://gitlab.com/camelot/kickc/issues/281
/*
@Test
public void testMemcpy1() throws IOException, URISyntaxException {
compileAndCompare("memcpy-1", log());
}
*/
@Test
public void testMemcpy0() throws IOException, URISyntaxException {
compileAndCompare("memcpy-0");
@ -1294,6 +1311,14 @@ public class TestPrograms {
compileAndCompare("examples/plasma/plasma");
}
// TODO: Fix number type conversion https://gitlab.com/camelot/kickc/issues/199
/*
@Test
public void testTernary4() throws IOException, URISyntaxException {
compileAndCompare("ternary-4");
}
*/
@Test
public void testTernary3() throws IOException, URISyntaxException {
compileAndCompare("ternary-3");

25
src/test/kc/memcpy-1.kc Normal file
View File

@ -0,0 +1,25 @@
// Test memcpy on strings (
import "string"
const char* SCREEN = 0x0400;
const char[] CAMELOT = "camelot";
void main() {
// Working memory copy of string
char* sc = SCREEN;
char* camelot= CAMELOT;
for( char i: 0..6) {
*sc++ = *camelot++;
}
char* sc2 = SCREEN+40;
char* reigns = "reigns";
for( char i: 0..5) {
*sc2++ = *reigns++;
}
// Not working
memcpy(SCREEN+10, CAMELOT, 7);
memcpy(SCREEN+50, "rules", 5);
}

View File

@ -0,0 +1,13 @@
// Tests simple switch()-statement - including a continue statement for the enclosing loop
void main() {
char* SCREEN = 0x0400;
char b=0;
char v64 = 0;
switch(v64){
case 0: b = 1; break;
default:
continue;
}
SCREEN[0] = b;
}

13
src/test/kc/ternary-4.kc Normal file
View File

@ -0,0 +1,13 @@
// Tests the ternary operator - complex nested conditional operators
void main() {
const char* SCREEN = $400;
char i=0;
for(char b: 0..3) {
for( char v: 0..3) {
char x = (b) ? 24 + (v & 2 ? 8 : 13) * 8 : 0;
SCREEN[i++] = x;
}
}
}