...
This commit is contained in:
@@ -10,4 +10,5 @@ func main(args: []cstring): i64
|
||||
|
||||
func test(test: u32)
|
||||
{
|
||||
puts("test")
|
||||
}
|
||||
@@ -207,9 +207,9 @@ public class QBEGenerator
|
||||
EmitStructInitializer(structInitializer, destinationLValue);
|
||||
return true;
|
||||
}
|
||||
case InterfaceInitializerNode interfaceInitializer:
|
||||
case ConvertToInterfaceNode convertToInterface:
|
||||
{
|
||||
EmitInterfaceInitializer(interfaceInitializer, destinationLValue);
|
||||
EmitConvertToInterface(convertToInterface, destinationLValue);
|
||||
return true;
|
||||
}
|
||||
case LiteralNode { Kind: LiteralKind.String } literal:
|
||||
@@ -266,7 +266,6 @@ public class QBEGenerator
|
||||
{
|
||||
case ArrayInitializerNode:
|
||||
case StructInitializerNode:
|
||||
case InterfaceInitializerNode:
|
||||
case LiteralNode { Kind: LiteralKind.String }:
|
||||
{
|
||||
destination = EmitExpression(source);
|
||||
@@ -599,7 +598,7 @@ public class QBEGenerator
|
||||
BinaryExpressionNode binary => EmitBinaryExpression(binary),
|
||||
FuncCallNode funcCall => EmitFuncCall(funcCall),
|
||||
InterfaceFuncCallNode interfaceFuncCall => EmitInterfaceFuncCall(interfaceFuncCall),
|
||||
InterfaceInitializerNode interfaceInitializer => EmitInterfaceInitializer(interfaceInitializer),
|
||||
ConvertToInterfaceNode convertToInterface => EmitConvertToInterface(convertToInterface),
|
||||
ConvertIntNode convertInt => EmitConvertInt(convertInt),
|
||||
ConvertFloatNode convertFloat => EmitConvertFloat(convertFloat),
|
||||
ExternFuncIdentNode externFuncIdent => EmitExternFuncIdent(externFuncIdent),
|
||||
@@ -680,10 +679,7 @@ public class QBEGenerator
|
||||
return addressOf switch
|
||||
{
|
||||
ArrayIndexAccessNode arrayIndexAccess => EmitAddressOfArrayIndexAccess(arrayIndexAccess),
|
||||
ArrayInitializerNode arrayInitializer => EmitArrayInitializer(arrayInitializer),
|
||||
InterfaceInitializerNode interfaceInitializer => EmitInterfaceInitializer(interfaceInitializer),
|
||||
StructFieldAccessNode structFieldAccess => EmitAddressOfStructFieldAccess(structFieldAccess),
|
||||
StructInitializerNode structInitializer => EmitStructInitializer(structInitializer),
|
||||
VariableIdentNode variableIdent => EmitAddressOfVariableIdent(variableIdent),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(addressOf))
|
||||
};
|
||||
@@ -1088,14 +1084,14 @@ public class QBEGenerator
|
||||
}
|
||||
}
|
||||
|
||||
private string EmitInterfaceInitializer(InterfaceInitializerNode interfaceInitializer, string? destination = null)
|
||||
private string EmitConvertToInterface(ConvertToInterfaceNode convertToInterface, string? destination = null)
|
||||
{
|
||||
var implementation = EmitExpression(interfaceInitializer.Implementation);
|
||||
var implementation = EmitExpression(convertToInterface.Implementation);
|
||||
|
||||
var vtableOffset = 0;
|
||||
foreach (var interfaceImplementation in interfaceInitializer.StructType.InterfaceImplementations)
|
||||
foreach (var interfaceImplementation in convertToInterface.StructType.InterfaceImplementations)
|
||||
{
|
||||
if (interfaceImplementation == interfaceInitializer.InterfaceType)
|
||||
if (interfaceImplementation == convertToInterface.InterfaceType)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -1106,11 +1102,11 @@ public class QBEGenerator
|
||||
if (destination == null)
|
||||
{
|
||||
destination = TmpName();
|
||||
_writer.Indented($"{destination} =l alloc8 {SizeOf(interfaceInitializer.InterfaceType)}");
|
||||
_writer.Indented($"{destination} =l alloc8 {SizeOf(convertToInterface.InterfaceType)}");
|
||||
}
|
||||
|
||||
var interfaceVtablePointer = TmpName();
|
||||
_writer.Indented($"{interfaceVtablePointer} =l add {StructVtableName(interfaceInitializer.StructType.Name)}, {vtableOffset}");
|
||||
_writer.Indented($"{interfaceVtablePointer} =l add {StructVtableName(convertToInterface.StructType.Name)}, {vtableOffset}");
|
||||
_writer.Indented($"storel {interfaceVtablePointer}, {destination}");
|
||||
|
||||
var objectPointer = TmpName();
|
||||
|
||||
@@ -45,7 +45,7 @@ public record LocalFuncIdentNode(TypeNode Type, string Name) : RValueExpressionN
|
||||
|
||||
public record ExternFuncIdentNode(TypeNode Type, string Name) : RValueExpressionNode(Type);
|
||||
|
||||
public record ArrayInitializerNode(TypeNode Type, ExpressionNode Capacity, TypeNode ElementType) : LValueExpressionNode(Type);
|
||||
public record ArrayInitializerNode(TypeNode Type, ExpressionNode Capacity, TypeNode ElementType) : RValueExpressionNode(Type);
|
||||
|
||||
public record ArrayIndexAccessNode(TypeNode Type, ExpressionNode Target, ExpressionNode Index) : LValueExpressionNode(Type);
|
||||
|
||||
@@ -55,11 +55,11 @@ public record LiteralNode(TypeNode Type, string Value, LiteralKind Kind) : RValu
|
||||
|
||||
public record StructFieldAccessNode(TypeNode Type, StructTypeNode StructType, ExpressionNode Target, string Field) : LValueExpressionNode(Type);
|
||||
|
||||
public record StructInitializerNode(StructTypeNode StructType, Dictionary<string, ExpressionNode> Initializers) : LValueExpressionNode(StructType);
|
||||
public record StructInitializerNode(StructTypeNode StructType, Dictionary<string, ExpressionNode> Initializers) : RValueExpressionNode(StructType);
|
||||
|
||||
public record DereferenceNode(TypeNode Type, ExpressionNode Expression) : RValueExpressionNode(Type);
|
||||
|
||||
public record InterfaceInitializerNode(TypeNode Type, InterfaceTypeNode InterfaceType, StructTypeNode StructType, ExpressionNode Implementation) : LValueExpressionNode(Type);
|
||||
public record ConvertToInterfaceNode(TypeNode Type, InterfaceTypeNode InterfaceType, StructTypeNode StructType, ExpressionNode Implementation) : RValueExpressionNode(Type);
|
||||
|
||||
public record ConvertIntNode(TypeNode Type, ExpressionNode Value, IntTypeNode ValueType, IntTypeNode TargetType) : RValueExpressionNode(Type);
|
||||
|
||||
|
||||
@@ -293,7 +293,7 @@ public sealed class TypeChecker
|
||||
|
||||
if (result.Type is StructTypeNode structType && expectedType is InterfaceTypeNode interfaceType)
|
||||
{
|
||||
return new InterfaceInitializerNode(interfaceType, interfaceType, structType, result);
|
||||
return new ConvertToInterfaceNode(interfaceType, interfaceType, structType, result);
|
||||
}
|
||||
|
||||
if (result.Type is IntTypeNode sourceIntType && expectedType is IntTypeNode targetIntType)
|
||||
|
||||
Reference in New Issue
Block a user