...
This commit is contained in:
@@ -4,45 +4,55 @@ namespace NubLang.Modules;
|
||||
|
||||
public class Module
|
||||
{
|
||||
private readonly List<ModuleStructType> _structs = [];
|
||||
private readonly List<ModuleInterfaceType> _interfaces = [];
|
||||
private readonly List<ModuleFuncType> _functions = [];
|
||||
private readonly List<ModuleStruct> _structs = [];
|
||||
private readonly List<ModuleInterface> _interfaces = [];
|
||||
private readonly List<ModuleFunction> _functions = [];
|
||||
|
||||
public void RegisterStruct(bool exported, string name, List<ModuleStructTypeField> fields)
|
||||
public void RegisterStruct(bool exported, string name, List<ModuleStructField> fields, List<ModuleStructFunction> functions)
|
||||
{
|
||||
_structs.Add(new ModuleStructType(exported, name, fields));
|
||||
_structs.Add(new ModuleStruct(exported, name, fields, functions));
|
||||
}
|
||||
|
||||
public void RegisterInterface(bool exported, string name)
|
||||
public void RegisterInterface(bool exported, string name, List<ModuleInterfaceFunction> functions)
|
||||
{
|
||||
_interfaces.Add(new ModuleInterfaceType(exported, name));
|
||||
_interfaces.Add(new ModuleInterface(exported, name, functions));
|
||||
}
|
||||
|
||||
public void RegisterFunction(bool exported, string name, string? externSymbol, FuncTypeSyntax type)
|
||||
public void RegisterFunction(bool exported, string name, string? externSymbol, List<ModuleFunctionParameter> parameters, TypeSyntax returnType)
|
||||
{
|
||||
_functions.Add(new ModuleFuncType(exported, name, externSymbol, type));
|
||||
_functions.Add(new ModuleFunction(exported, name, externSymbol, parameters, returnType));
|
||||
}
|
||||
|
||||
public List<ModuleStructType> StructTypes(bool includePrivate)
|
||||
public List<ModuleStruct> StructTypes(bool includePrivate)
|
||||
{
|
||||
return _structs.Where(x => x.Exported || includePrivate).ToList();
|
||||
}
|
||||
|
||||
public List<ModuleInterfaceType> InterfaceTypes(bool includePrivate)
|
||||
public List<ModuleInterface> InterfaceTypes(bool includePrivate)
|
||||
{
|
||||
return _interfaces.Where(x => x.Exported || includePrivate).ToList();
|
||||
}
|
||||
|
||||
public List<ModuleFuncType> Functions(bool includePrivate)
|
||||
public List<ModuleFunction> Functions(bool includePrivate)
|
||||
{
|
||||
return _functions.Where(x => x.Exported || includePrivate).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public record ModuleStructTypeField(string Name, TypeSyntax Type, bool HasDefaultValue);
|
||||
public record ModuleStructField(string Name, TypeSyntax Type, bool HasDefaultValue);
|
||||
|
||||
public record ModuleStructType(bool Exported, string Name, List<ModuleStructTypeField> Fields);
|
||||
public record ModuleStructFunctionParameter(string Name, TypeSyntax Type);
|
||||
|
||||
public record ModuleInterfaceType(bool Exported, string Name);
|
||||
public record ModuleStructFunction(string Name, List<ModuleStructFunctionParameter> Parameters, TypeSyntax ReturnType);
|
||||
|
||||
public record ModuleFuncType(bool Exported, string Name, string? ExternSymbol, FuncTypeSyntax FuncType);
|
||||
public record ModuleStruct(bool Exported, string Name, List<ModuleStructField> Fields, List<ModuleStructFunction> Functions);
|
||||
|
||||
public record ModuleInterfaceFunctionParameter(string Name, TypeSyntax Type);
|
||||
|
||||
public record ModuleInterfaceFunction(string Name, List<ModuleInterfaceFunctionParameter> Parameters, TypeSyntax ReturnType);
|
||||
|
||||
public record ModuleInterface(bool Exported, string Name, List<ModuleInterfaceFunction> Functions);
|
||||
|
||||
public record ModuleFunctionParameter(string Name, TypeSyntax Type);
|
||||
|
||||
public record ModuleFunction(bool Exported, string Name, string? ExternSymbol, List<ModuleFunctionParameter> Parameters, TypeSyntax ReturnType);
|
||||
@@ -24,20 +24,34 @@ public class ModuleRepository
|
||||
{
|
||||
case FuncSyntax funcDef:
|
||||
{
|
||||
var parameters = funcDef.Signature.Parameters.Select(x => x.Type).ToList();
|
||||
var type = new FuncTypeSyntax([], parameters, funcDef.Signature.ReturnType);
|
||||
module.RegisterFunction(funcDef.Exported, funcDef.Name, funcDef.ExternSymbol, type);
|
||||
var parameters = funcDef.Signature.Parameters.Select(x => new ModuleFunctionParameter(x.Name, x.Type)).ToList();
|
||||
module.RegisterFunction(funcDef.Exported, funcDef.Name, funcDef.ExternSymbol, parameters, funcDef.Signature.ReturnType);
|
||||
break;
|
||||
}
|
||||
case StructSyntax structDef:
|
||||
{
|
||||
var fields = structDef.Fields.Select(x => new ModuleStructTypeField(x.Name, x.Type, x.Value.HasValue)).ToList();
|
||||
module.RegisterStruct(structDef.Exported, structDef.Name, fields);
|
||||
var fields = structDef.Fields.Select(x => new ModuleStructField(x.Name, x.Type, x.Value.HasValue)).ToList();
|
||||
|
||||
var functions = new List<ModuleStructFunction>();
|
||||
foreach (var function in structDef.Functions)
|
||||
{
|
||||
var parameters = function.Signature.Parameters.Select(x => new ModuleStructFunctionParameter(x.Name, x.Type)).ToList();
|
||||
functions.AddRange(new ModuleStructFunction(function.Name, parameters, function.Signature.ReturnType));
|
||||
}
|
||||
|
||||
module.RegisterStruct(structDef.Exported, structDef.Name, fields, functions);
|
||||
break;
|
||||
}
|
||||
case InterfaceSyntax interfaceDef:
|
||||
{
|
||||
module.RegisterInterface(interfaceDef.Exported, interfaceDef.Name);
|
||||
var functions = new List<ModuleInterfaceFunction>();
|
||||
foreach (var function in interfaceDef.Functions)
|
||||
{
|
||||
var parameters = function.Signature.Parameters.Select(x => new ModuleInterfaceFunctionParameter(x.Name, x.Type)).ToList();
|
||||
functions.AddRange(new ModuleInterfaceFunction(function.Name, parameters, function.Signature.ReturnType));
|
||||
}
|
||||
|
||||
module.RegisterInterface(interfaceDef.Exported, interfaceDef.Name, functions);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user