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 ef1720195d ...
2025-09-12 16:58:09 +02:00

48 lines
1.6 KiB
C#

using NubLang.Parsing.Syntax;
namespace NubLang.Modules;
public class Module
{
private readonly List<ModuleStructType> _structs = [];
private readonly List<ModuleInterfaceType> _interfaces = [];
private readonly List<ModuleFuncType> _functions = [];
public void RegisterStruct(bool exported, string name, IReadOnlyList<ModuleStructTypeField> fields)
{
_structs.Add(new ModuleStructType(exported, name, fields));
}
public void RegisterInterface(bool exported, string name)
{
_interfaces.Add(new ModuleInterfaceType(exported, name));
}
public void RegisterFunction(bool exported, string name, string? externSymbol, FuncTypeSyntax type)
{
_functions.Add(new ModuleFuncType(exported, name, externSymbol, type));
}
public IReadOnlyList<ModuleStructType> StructTypes(bool includePrivate)
{
return _structs.Where(x => x.Exported || includePrivate).ToList();
}
public IReadOnlyList<ModuleInterfaceType> InterfaceTypes(bool includePrivate)
{
return _interfaces.Where(x => x.Exported || includePrivate).ToList();
}
public IReadOnlyList<ModuleFuncType> Functions(bool includePrivate)
{
return _functions.Where(x => x.Exported || includePrivate).ToList();
}
}
public record ModuleStructTypeField(string Name, TypeSyntax Type, bool HasDefaultValue);
public record ModuleStructType(bool Exported, string Name, IReadOnlyList<ModuleStructTypeField> Fields);
public record ModuleInterfaceType(bool Exported, string Name);
public record ModuleFuncType(bool Exported, string Name, string? ExternSymbol, FuncTypeSyntax FuncType);