This repository has been archived on 2025-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nub-lang-archive-2/compiler/NubLang/Modules/Module.cs
nub31 1eeeb67d88 ...
2025-09-12 17:31:40 +02:00

58 lines
2.3 KiB
C#

using NubLang.Parsing.Syntax;
namespace NubLang.Modules;
public class Module
{
private readonly List<ModuleStruct> _structs = [];
private readonly List<ModuleInterface> _interfaces = [];
private readonly List<ModuleFunction> _functions = [];
public void RegisterStruct(bool exported, string name, List<ModuleStructField> fields, List<ModuleStructFunction> functions)
{
_structs.Add(new ModuleStruct(exported, name, fields, functions));
}
public void RegisterInterface(bool exported, string name, List<ModuleInterfaceFunction> functions)
{
_interfaces.Add(new ModuleInterface(exported, name, functions));
}
public void RegisterFunction(bool exported, string name, string? externSymbol, List<ModuleFunctionParameter> parameters, TypeSyntax returnType)
{
_functions.Add(new ModuleFunction(exported, name, externSymbol, parameters, returnType));
}
public List<ModuleStruct> StructTypes(bool includePrivate)
{
return _structs.Where(x => x.Exported || includePrivate).ToList();
}
public List<ModuleInterface> InterfaceTypes(bool includePrivate)
{
return _interfaces.Where(x => x.Exported || includePrivate).ToList();
}
public List<ModuleFunction> Functions(bool includePrivate)
{
return _functions.Where(x => x.Exported || includePrivate).ToList();
}
}
public record ModuleStructField(string Name, TypeSyntax Type, bool HasDefaultValue);
public record ModuleStructFunctionParameter(string Name, TypeSyntax Type);
public record ModuleStructFunction(string Name, List<ModuleStructFunctionParameter> Parameters, TypeSyntax ReturnType);
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);