mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-08 13:31:03 +00:00
Working on casts
This commit is contained in:
parent
c200eaa535
commit
9f27006540
@ -14,10 +14,7 @@ import dk.camelot64.kickc.model.symbols.ConstantVar;
|
||||
import dk.camelot64.kickc.model.symbols.Label;
|
||||
import dk.camelot64.kickc.model.symbols.Symbol;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeProcedure;
|
||||
import dk.camelot64.kickc.model.types.*;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@ -89,6 +86,7 @@ public class AsmFragmentInstanceSpecFactory {
|
||||
|
||||
/**
|
||||
* Get the created ASM fragment instance specification
|
||||
*
|
||||
* @return The ASM fragment instance specification
|
||||
*/
|
||||
public AsmFragmentInstanceSpec getAsmFragmentInstanceSpec() {
|
||||
@ -233,19 +231,35 @@ public class AsmFragmentInstanceSpecFactory {
|
||||
OperatorUnary castUnary = Operators.getCastUnary(toType);
|
||||
RValue castValue = cast.getValue();
|
||||
SymbolType castValueType = SymbolTypeInference.inferType(this.program.getScope(), castValue);
|
||||
if(castValueType.getSizeBytes()==toType.getSizeBytes()) {
|
||||
if(castValueType.getSizeBytes() == toType.getSizeBytes()) {
|
||||
return bind(castValue, toType);
|
||||
} else {
|
||||
return getOperatorFragmentName(castUnary) + bind(castValue);
|
||||
}
|
||||
} else if(value instanceof ConstantCastValue) {
|
||||
ConstantCastValue castVal = (ConstantCastValue) value;
|
||||
if(castType==null) {
|
||||
// TODO: If value literal not matching cast type then add expression code to transform it into the value space ( eg. value & 0xff )
|
||||
ConstantValue val = castVal.getValue();
|
||||
if(castType == null) {
|
||||
SymbolType toType = castVal.getToType();
|
||||
// If value literal not matching cast type then add expression code to transform it into the value space ( eg. value & 0xff )
|
||||
ConstantLiteral constantLiteral = val.calculateLiteral(program.getScope());
|
||||
if(constantLiteral instanceof ConstantInteger) {
|
||||
if(toType instanceof SymbolTypeIntegerFixed) {
|
||||
if(!((SymbolTypeIntegerFixed) toType).contains(((ConstantInteger) constantLiteral).getValue())) {
|
||||
if(toType.getSizeBytes() == 1) {
|
||||
val = new ConstantBinary(new ConstantInteger(0xffL, SymbolType.BYTE), Operators.BOOL_AND, val);
|
||||
} else if(toType.getSizeBytes() == 2) {
|
||||
val = new ConstantBinary(new ConstantInteger(0xffffL, SymbolType.WORD), Operators.BOOL_AND, val);
|
||||
} else {
|
||||
throw new InternalError("Not implemented!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bind(castVal.getValue(), castVal.getToType());
|
||||
return bind(val, toType);
|
||||
} else {
|
||||
return bind(castVal.getValue(), castType);
|
||||
return bind(val, castType);
|
||||
}
|
||||
} else if(value instanceof PointerDereference) {
|
||||
PointerDereference deref = (PointerDereference) value;
|
||||
@ -357,7 +371,7 @@ public class AsmFragmentInstanceSpecFactory {
|
||||
Registers.RegisterType.ZP_BYTE.equals(register.getType()) ||
|
||||
Registers.RegisterType.ZP_WORD.equals(register.getType()) ||
|
||||
Registers.RegisterType.ZP_DWORD.equals(register.getType())
|
||||
) {
|
||||
) {
|
||||
// Examine if the ZP register is already bound
|
||||
Registers.RegisterZp registerZp = (Registers.RegisterZp) register;
|
||||
String zpNameIdx = null;
|
||||
|
@ -63,8 +63,6 @@ public class TestPrograms {
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testFragmentVariations() throws IOException, URISyntaxException {
|
||||
compileAndCompare("fragment-variations");
|
||||
@ -117,7 +115,7 @@ public class TestPrograms {
|
||||
|
||||
@Test
|
||||
public void testNumberType() throws IOException, URISyntaxException {
|
||||
compileAndCompare("number-type", log());
|
||||
compileAndCompare("number-type");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -12,7 +12,7 @@ const word SIN_SIZE = 512;
|
||||
|
||||
signed word[512] align($100) sin;
|
||||
|
||||
signed word* sin2 = $1400;
|
||||
signed word* sin2 = $1500;
|
||||
|
||||
kickasm(pc sin2) {{
|
||||
.for(var i=0; i<512; i++) {
|
||||
|
@ -3,25 +3,25 @@
|
||||
|
||||
void main() {
|
||||
testBytes();
|
||||
//testSBytes();
|
||||
testSBytes();
|
||||
}
|
||||
|
||||
void testBytes() {
|
||||
// Constant values resolvable to bytes
|
||||
const byte* SCREEN = 0x0400;
|
||||
byte idx = 0;
|
||||
//SCREEN[idx++] = 12;
|
||||
//SCREEN[idx++] = 6+6;
|
||||
//SCREEN[idx++] = 18-6;
|
||||
//SCREEN[idx++] = 1812-1800;
|
||||
//SCREEN[idx++] = 1+2+3+6;
|
||||
//SCREEN[idx++] = 2*6;
|
||||
//SCREEN[idx++] = 3<<2;
|
||||
//SCREEN[idx++] = 24>>1;
|
||||
//SCREEN[idx++] = 15&28;
|
||||
//SCREEN[idx++] = 4|8;
|
||||
//SCREEN[idx++] = 5^9;
|
||||
//SCREEN[idx++] = (2+2)*(15/5);
|
||||
SCREEN[idx++] = 12;
|
||||
SCREEN[idx++] = 6+6;
|
||||
SCREEN[idx++] = 18-6;
|
||||
SCREEN[idx++] = 1812-1800;
|
||||
SCREEN[idx++] = 1+2+3+6;
|
||||
SCREEN[idx++] = 2*6;
|
||||
SCREEN[idx++] = 3<<2;
|
||||
SCREEN[idx++] = 24>>1;
|
||||
SCREEN[idx++] = 15&28;
|
||||
SCREEN[idx++] = 4|8;
|
||||
SCREEN[idx++] = 5^9;
|
||||
SCREEN[idx++] = (2+2)*(15/5);
|
||||
SCREEN[idx++] = (byte)(4096+12);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user