This commit is contained in:
nub31
2025-07-04 17:48:56 +02:00
parent 9a21ec5d8d
commit cea72bf846
11 changed files with 346 additions and 78 deletions

View File

@@ -41,12 +41,53 @@ public static class Binder
return node switch
{
ExternFuncDefinitionNode definition => BindExternFuncDefinition(definition),
ImplementationDefinitionNode definition => BindImplementation(definition),
InterfaceDefinitionNode definition => BindInterfaceDefinition(definition),
LocalFuncDefinitionNode definition => BindLocalFuncDefinition(definition),
StructDefinitionNode definition => BindStruct(definition),
_ => throw new ArgumentOutOfRangeException(nameof(node))
};
}
private static BoundImplementationDefinitionNode BindImplementation(ImplementationDefinitionNode node)
{
_variables.Clear();
var functions = new List<BoundImplementationFunc>();
foreach (var function in node.Functions)
{
var parameters = new List<BoundFuncParameter>();
foreach (var parameter in function.Parameters)
{
parameters.Add(new BoundFuncParameter(parameter.Name, parameter.Type));
_variables[parameter.Name] = parameter.Type;
}
functions.Add(new BoundImplementationFunc(function.Name, parameters, function.ReturnType, BindBlock(function.Body)));
}
return new BoundImplementationDefinitionNode(node.Tokens, node.Documentation, node.Namespace, node.Type, node.Interface, functions);
}
private static BoundInterfaceDefinitionNode BindInterfaceDefinition(InterfaceDefinitionNode node)
{
var functions = new List<BoundInterfaceFunc>();
foreach (var func in node.Functions)
{
var parameters = new List<BoundFuncParameter>();
foreach (var parameter in func.Parameters)
{
parameters.Add(new BoundFuncParameter(parameter.Name, parameter.Type));
}
functions.Add(new BoundInterfaceFunc(func.Name, parameters, func.ReturnType));
}
return new BoundInterfaceDefinitionNode(node.Tokens, node.Documentation, node.Namespace, node.Name, functions);
}
private static BoundStructDefinitionNode BindStruct(StructDefinitionNode node)
{
var defOpt = _definitionTable.LookupStruct(node.Namespace, node.Name);
@@ -354,6 +395,12 @@ public static class Binder
NubType? type = null;
var implementation = _definitionTable.GetImplementations().FirstOrDefault(x => x.Type.Equals(boundExpression.Type));
if (implementation != null)
{
if (implementation.Interface.)
}
switch (boundExpression.Type)
{
case NubArrayType: