This commit is contained in:
nub31
2025-06-15 01:47:10 +02:00
parent 7c05870e24
commit 3f7499d2b9
10 changed files with 63 additions and 50 deletions

View File

@@ -670,6 +670,11 @@ public static class Parser
return new NubArrayType(NubPrimitiveType.U8);
}
if (name.Value == "cstring")
{
return new NubCStringType();
}
if (NubPrimitiveType.TryParse(name.Value, out var primitiveTypeKind))
{
return new NubPrimitiveType(primitiveTypeKind.Value);

View File

@@ -48,6 +48,24 @@ public abstract class NubType
public abstract override string ToString();
}
public class NubCStringType : NubType
{
public override bool Equals(object? obj)
{
return obj is NubCStringType other;
}
public override int GetHashCode()
{
return "cstring".GetHashCode();
}
public override string ToString()
{
return "cstring";
}
}
public class NubFuncType(NubType returnType, List<NubType> parameters) : NubType
{
public NubType ReturnType { get; } = returnType;
@@ -163,7 +181,7 @@ public class NubAnyType : NubType
public override int GetHashCode()
{
return GetType().GetHashCode();
return "any".GetHashCode();
}
}

View File

@@ -422,12 +422,6 @@ public static class TypeChecker
var exprType = CheckExpression(addressOf.Expression);
if (exprType == null) return null;
if (addressOf.Expression is not (IdentifierNode or MemberAccessNode))
{
ReportError($"Cannot take the address of {exprType}", addressOf.Expression);
return null;
}
return new NubPointerType(exprType);
}
@@ -569,13 +563,18 @@ public static class TypeChecker
switch (expressionType)
{
case NubArrayType:
case NubArrayType arrayType:
{
if (memberAccess.Member == "count")
{
return NubPrimitiveType.I64;
}
if (arrayType.ElementType is NubPrimitiveType { Kind: PrimitiveTypeKind.U8 } && memberAccess.Member == "cstring")
{
return new NubCStringType();
}
break;
}
case NubStructType structType: