mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-05 06:34:11 -08:00
C backend: fix bug in type inference, fix code generation for small int and long values
This commit is contained in:
parent
4530167061
commit
899725b6bd
|
@ -30,15 +30,22 @@ public final class CodeGeneratorUtil {
|
||||||
} else if (value instanceof Integer) {
|
} else if (value instanceof Integer) {
|
||||||
int i = (Integer) value;
|
int i = (Integer) value;
|
||||||
long v = i;
|
long v = i;
|
||||||
|
if (i == Integer.MIN_VALUE) {
|
||||||
|
writer.print("(int32_t) INT32_C(0x80000000)");
|
||||||
|
} else {
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
writer.print("-");
|
writer.print("-");
|
||||||
v = -i;
|
v = -v;
|
||||||
}
|
}
|
||||||
writer.print("INT32_C(");
|
writer.print("INT32_C(");
|
||||||
writeLongConstant(writer, v);
|
writeLongConstant(writer, v);
|
||||||
writer.print(")");
|
writer.print(")");
|
||||||
|
}
|
||||||
} else if (value instanceof Long) {
|
} else if (value instanceof Long) {
|
||||||
long v = (Long) value;
|
long v = (Long) value;
|
||||||
|
if (v == Long.MIN_VALUE) {
|
||||||
|
writer.print("(int64_t) INT64_C(0x8000000000000000)");
|
||||||
|
} else {
|
||||||
if (v < 0) {
|
if (v < 0) {
|
||||||
writer.print("-");
|
writer.print("-");
|
||||||
v = -v;
|
v = -v;
|
||||||
|
@ -46,6 +53,7 @@ public final class CodeGeneratorUtil {
|
||||||
writer.print("INT64_C(");
|
writer.print("INT64_C(");
|
||||||
writeLongConstant(writer, v);
|
writeLongConstant(writer, v);
|
||||||
writer.print(")");
|
writer.print(")");
|
||||||
|
}
|
||||||
} else if (value instanceof Float) {
|
} else if (value instanceof Float) {
|
||||||
float f = (Float) value;
|
float f = (Float) value;
|
||||||
if (Float.isInfinite(f)) {
|
if (Float.isInfinite(f)) {
|
||||||
|
|
|
@ -90,7 +90,8 @@ public class TypeInferer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public VariableType typeOf(int variableIndex) {
|
public VariableType typeOf(int variableIndex) {
|
||||||
return types[variableIndex];
|
VariableType result = types[variableIndex];
|
||||||
|
return result != null ? result : VariableType.OBJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
VariableType convert(ValueType type) {
|
VariableType convert(ValueType type) {
|
||||||
|
@ -183,11 +184,6 @@ public class TypeInferer {
|
||||||
types[receiver.getIndex()] = VariableType.OBJECT;
|
types[receiver.getIndex()] = VariableType.OBJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void nullConstant(VariableReader receiver) {
|
|
||||||
types[receiver.getIndex()] = VariableType.OBJECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void nullCheck(VariableReader receiver, VariableReader value) {
|
public void nullCheck(VariableReader receiver, VariableReader value) {
|
||||||
builder.addEdge(value.getIndex(), receiver.getIndex());
|
builder.addEdge(value.getIndex(), receiver.getIndex());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user