...
This commit is contained in:
@@ -3,11 +3,11 @@ extern func puts(text: cstring)
|
|||||||
|
|
||||||
func main(args: []cstring): i64
|
func main(args: []cstring): i64
|
||||||
{
|
{
|
||||||
let x: i32 = 23
|
let x: u32 = 23
|
||||||
test(x)
|
test(x)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func test(test: u8)
|
func test(test: u32)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -1124,7 +1124,7 @@ public class QBEGenerator
|
|||||||
{
|
{
|
||||||
var value = EmitExpression(convertInt.Value);
|
var value = EmitExpression(convertInt.Value);
|
||||||
|
|
||||||
if (convertInt.ValueType == convertInt.TargetType || convertInt.ValueType.Width > convertInt.TargetType.Width)
|
if (convertInt.ValueType.Width >= convertInt.TargetType.Width)
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -1156,7 +1156,7 @@ public class QBEGenerator
|
|||||||
{
|
{
|
||||||
var value = EmitExpression(convertFloat.Value);
|
var value = EmitExpression(convertFloat.Value);
|
||||||
|
|
||||||
if (convertFloat.ValueType == convertFloat.TargetType)
|
if (convertFloat.ValueType.Width == convertFloat.TargetType.Width)
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,6 @@ public record DereferenceNode(TypeNode Type, ExpressionNode Expression) : RValue
|
|||||||
|
|
||||||
public record InterfaceInitializerNode(TypeNode Type, InterfaceTypeNode InterfaceType, StructTypeNode StructType, ExpressionNode Implementation) : LValueExpressionNode(Type);
|
public record InterfaceInitializerNode(TypeNode Type, InterfaceTypeNode InterfaceType, StructTypeNode StructType, ExpressionNode Implementation) : LValueExpressionNode(Type);
|
||||||
|
|
||||||
public record ConvertIntNode(TypeNode Type, ExpressionNode Value, IntTypeNode TargetType, IntTypeNode ValueType) : RValueExpressionNode(Type);
|
public record ConvertIntNode(TypeNode Type, ExpressionNode Value, IntTypeNode ValueType, IntTypeNode TargetType) : RValueExpressionNode(Type);
|
||||||
|
|
||||||
public record ConvertFloatNode(TypeNode Type, ExpressionNode Value, FloatTypeNode TargetType, FloatTypeNode ValueType) : RValueExpressionNode(Type);
|
public record ConvertFloatNode(TypeNode Type, ExpressionNode Value, FloatTypeNode ValueType, FloatTypeNode TargetType) : RValueExpressionNode(Type);
|
||||||
|
|||||||
@@ -286,38 +286,33 @@ public sealed class TypeChecker
|
|||||||
_ => throw new ArgumentOutOfRangeException(nameof(node))
|
_ => throw new ArgumentOutOfRangeException(nameof(node))
|
||||||
};
|
};
|
||||||
|
|
||||||
if (expectedType != null && result.Type != expectedType)
|
if (expectedType == null || result.Type == expectedType)
|
||||||
{
|
{
|
||||||
return CheckConversion(expectedType, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExpressionNode CheckConversion(TypeNode targetType, ExpressionNode expression)
|
if (result.Type is StructTypeNode structType && expectedType is InterfaceTypeNode interfaceType)
|
||||||
{
|
{
|
||||||
if (expression.Type is StructTypeNode structType && targetType is InterfaceTypeNode interfaceType)
|
return new InterfaceInitializerNode(interfaceType, interfaceType, structType, result);
|
||||||
{
|
|
||||||
return new InterfaceInitializerNode(interfaceType, interfaceType, structType, expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expression.Type is IntTypeNode sourceIntType && targetType is IntTypeNode targetIntType)
|
if (result.Type is IntTypeNode sourceIntType && expectedType is IntTypeNode targetIntType)
|
||||||
{
|
{
|
||||||
// if ((sourceIntType.Width < targetIntType.Width) || (sourceIntType.Width == targetIntType.Width && sourceIntType.Signed != targetIntType.Signed))
|
if (sourceIntType.Signed == targetIntType.Signed && sourceIntType.Width < targetIntType.Width)
|
||||||
// {
|
{
|
||||||
return new ConvertIntNode(targetIntType, expression, targetIntType, sourceIntType);
|
return new ConvertIntNode(targetIntType, result, sourceIntType, targetIntType);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expression.Type is FloatTypeNode sourceFloatType && targetType is FloatTypeNode targetFloatType)
|
if (result.Type is FloatTypeNode sourceFloatType && expectedType is FloatTypeNode targetFloatType)
|
||||||
{
|
{
|
||||||
// if (sourceFloatType.Width < targetFloatType.Width)
|
if (sourceFloatType.Width < targetFloatType.Width)
|
||||||
// {
|
{
|
||||||
return new ConvertFloatNode(targetFloatType, expression, targetFloatType, sourceFloatType);
|
return new ConvertFloatNode(targetFloatType, result, sourceFloatType, targetFloatType);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new TypeCheckerException(Diagnostic.Error($"Cannot convert {expression.Type} to {targetType}").Build());
|
throw new TypeCheckerException(Diagnostic.Error($"Cannot convert {result.Type} to {expectedType}").Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private AddressOfNode CheckAddressOf(AddressOfSyntax expression)
|
private AddressOfNode CheckAddressOf(AddressOfSyntax expression)
|
||||||
|
|||||||
Reference in New Issue
Block a user