Type instancing
This commit is contained in:
@@ -183,7 +183,7 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
if (right.Type is not NubTypeSInt and not NubTypeUInt)
|
||||
throw new CompileException(Diagnostic.Error($"Unsupported type for right hand side of comparison: {right.Type}").At(fileName, right).Build());
|
||||
|
||||
type = new NubTypeBool();
|
||||
type = NubTypeBool.Instance;
|
||||
break;
|
||||
}
|
||||
case NodeExpressionBinary.Op.LogicalAnd:
|
||||
@@ -195,7 +195,7 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
if (right.Type is not NubTypeBool)
|
||||
throw new CompileException(Diagnostic.Error($"Unsupported type for right hand side of logical operation: {right.Type}").At(fileName, right).Build());
|
||||
|
||||
type = new NubTypeBool();
|
||||
type = NubTypeBool.Instance;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -248,7 +248,7 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
if (target.Type is not NubTypeBool)
|
||||
throw new CompileException(Diagnostic.Error($"Unsupported type for inversion: {target.Type}").At(fileName, target).Build());
|
||||
|
||||
type = new NubTypeBool();
|
||||
type = NubTypeBool.Instance;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -270,7 +270,7 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
|
||||
private TypedNodeExpressionBoolLiteral CheckExpressionBoolLiteral(NodeExpressionBoolLiteral expression)
|
||||
{
|
||||
return new TypedNodeExpressionBoolLiteral(expression.Tokens, new NubTypeBool(), expression.Value);
|
||||
return new TypedNodeExpressionBoolLiteral(expression.Tokens, NubTypeBool.Instance, expression.Value);
|
||||
}
|
||||
|
||||
private TypedNodeExpressionLocalIdent CheckExpressionIdent(NodeExpressionLocalIdent expression)
|
||||
@@ -295,7 +295,7 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
|
||||
private TypedNodeExpressionIntLiteral CheckExpressionIntLiteral(NodeExpressionIntLiteral expression)
|
||||
{
|
||||
return new TypedNodeExpressionIntLiteral(expression.Tokens, new NubTypeSInt(32), expression.Value);
|
||||
return new TypedNodeExpressionIntLiteral(expression.Tokens, NubTypeSInt.Get(32), expression.Value);
|
||||
}
|
||||
|
||||
private TypedNodeExpressionMemberAccess CheckExpressionMemberAccess(NodeExpressionMemberAccess expression)
|
||||
@@ -313,7 +313,7 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
|
||||
private TypedNodeExpressionStringLiteral CheckExpressionStringLiteral(NodeExpressionStringLiteral expression)
|
||||
{
|
||||
return new TypedNodeExpressionStringLiteral(expression.Tokens, new NubTypeString(), expression.Value);
|
||||
return new TypedNodeExpressionStringLiteral(expression.Tokens, NubTypeString.Instance, expression.Value);
|
||||
}
|
||||
|
||||
private TypedNodeExpressionStructLiteral CheckExpressionStructLiteral(NodeExpressionStructLiteral expression)
|
||||
@@ -348,14 +348,14 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
{
|
||||
return node switch
|
||||
{
|
||||
NodeTypeBool => new NubTypeBool(),
|
||||
NodeTypeBool => NubTypeBool.Instance,
|
||||
NodeTypeCustom type => ResolveCustomType(type),
|
||||
NodeTypeFunc type => new NubTypeFunc(type.Parameters.Select(ResolveType).ToList(), ResolveType(type.ReturnType)),
|
||||
NodeTypePointer type => new NubTypePointer(ResolveType(type.To)),
|
||||
NodeTypeSInt type => new NubTypeSInt(type.Width),
|
||||
NodeTypeUInt type => new NubTypeUInt(type.Width),
|
||||
NodeTypeString => new NubTypeString(),
|
||||
NodeTypeVoid => new NubTypeVoid(),
|
||||
NodeTypeFunc type => NubTypeFunc.Get(type.Parameters.Select(ResolveType).ToList(), ResolveType(type.ReturnType)),
|
||||
NodeTypePointer type => NubTypePointer.Get(ResolveType(type.To)),
|
||||
NodeTypeSInt type => NubTypeSInt.Get(type.Width),
|
||||
NodeTypeUInt type => NubTypeUInt.Get(type.Width),
|
||||
NodeTypeString => NubTypeString.Instance,
|
||||
NodeTypeVoid => NubTypeVoid.Instance,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(node))
|
||||
};
|
||||
}
|
||||
@@ -365,7 +365,7 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
if (!moduleGraph.TryResolveModule(type.Module.Ident, out var module))
|
||||
throw new CompileException(Diagnostic.Error($"Module '{type.Module.Ident}' not found").At(fileName, type.Module).Build());
|
||||
|
||||
if (!module.TryResolveCustomType(type.Module.Ident, out var customType))
|
||||
if (!module.TryResolveCustomType(type.Name.Ident, out var customType))
|
||||
throw new CompileException(Diagnostic.Error($"Custom type '{type.Module.Ident}::{type.Name.Ident}' not found").At(fileName, type.Name).Build());
|
||||
|
||||
return customType;
|
||||
|
||||
Reference in New Issue
Block a user