From 4d0f7c715f7a292548e18a82ec16617a9608cc30 Mon Sep 17 00:00:00 2001 From: nub31 Date: Sun, 15 Feb 2026 03:14:09 +0100 Subject: [PATCH] Only add exported and not external functions and types to manifest --- compiler/ModuleGraph.cs | 11 ++++++----- compiler/NubLib.cs | 29 +++++++++++++++++++++++------ examples/math/math.nub | 5 +++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/compiler/ModuleGraph.cs b/compiler/ModuleGraph.cs index 860f135..36feaee 100644 --- a/compiler/ModuleGraph.cs +++ b/compiler/ModuleGraph.cs @@ -85,7 +85,7 @@ public class ModuleGraph switch (type) { case Manifest.Module.TypeInfoStruct s: - var info = new Module.TypeInfoStruct(s.Exported, s.Packed); + var info = new Module.TypeInfoStruct(true, s.Packed, true); var fields = s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList(); info.SetFields(fields); module.AddType(name, info); @@ -97,7 +97,7 @@ public class ModuleGraph foreach (var (name, identifier) in manifestModule.Identifiers) { - module.AddIdentifier(name, new Module.IdentifierInfo(identifier.Exported, identifier.Type, identifier.MangledName, true)); + module.AddIdentifier(name, new Module.IdentifierInfo(true, identifier.Type, identifier.MangledName, true)); } } } @@ -108,7 +108,7 @@ public class ModuleGraph foreach (var structDef in ast.Definitions.OfType()) { - module.AddType(structDef.Name.Ident, new Module.TypeInfoStruct(structDef.Exported, structDef.Packed)); + module.AddType(structDef.Name.Ident, new Module.TypeInfoStruct(structDef.Exported, structDef.Packed, false)); } } @@ -269,12 +269,13 @@ public class Module(string name) public bool External { get; } = external; } - public abstract class TypeInfo(bool exported) + public abstract class TypeInfo(bool exported, bool external) { public bool Exported { get; } = exported; + public bool External { get; } = external; } - public class TypeInfoStruct(bool exported, bool packed) : TypeInfo(exported) + public class TypeInfoStruct(bool exported, bool packed, bool external) : TypeInfo(exported, external) { private IReadOnlyList? fields; diff --git a/compiler/NubLib.cs b/compiler/NubLib.cs index ed7e4dd..91f9c37 100644 --- a/compiler/NubLib.cs +++ b/compiler/NubLib.cs @@ -70,8 +70,25 @@ public record Manifest(Dictionary Modules) foreach (var module in moduleGraph.GetModules()) { - var types = module.GetTypes().ToDictionary(x => x.Key, x => ConvertType(x.Value)); - var identifiers = module.GetIdentifiers().ToDictionary(x => x.Key, x => new Module.IdentifierInfo(x.Value.Exported, x.Value.Type, x.Value.MangledName)); + var types = new Dictionary(); + var identifiers = new Dictionary(); + + foreach (var (name, typeInfo) in module.GetTypes()) + { + if (typeInfo.Exported && !typeInfo.External) + { + types.Add(name, ConvertType(typeInfo)); + } + } + + foreach (var (name, identifierInfo) in module.GetIdentifiers()) + { + if (identifierInfo.Exported && !identifierInfo.External) + { + identifiers.Add(name, new Module.IdentifierInfo(identifierInfo.Type, identifierInfo.MangledName)); + } + } + modules[module.Name] = new Module(types, identifiers); } @@ -81,7 +98,7 @@ public record Manifest(Dictionary Modules) { return typeInfo switch { - Compiler.Module.TypeInfoStruct s => new Module.TypeInfoStruct(s.Exported, s.Packed, s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList()), + Compiler.Module.TypeInfoStruct s => new Module.TypeInfoStruct(s.Packed, s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList()), _ => throw new ArgumentOutOfRangeException(nameof(typeInfo)) }; } @@ -90,12 +107,12 @@ public record Manifest(Dictionary Modules) public record Module(Dictionary Types, Dictionary Identifiers) { - public record IdentifierInfo(bool Exported, NubType Type, string MangledName); + public record IdentifierInfo(NubType Type, string MangledName); [JsonDerivedType(typeof(TypeInfoStruct), "struct")] - public abstract record TypeInfo(bool Exported); + public abstract record TypeInfo; - public record TypeInfoStruct(bool Exported, bool Packed, IReadOnlyList Fields) : TypeInfo(Exported) + public record TypeInfoStruct(bool Packed, IReadOnlyList Fields) : TypeInfo { public record Field(string Name, NubType Type); } diff --git a/examples/math/math.nub b/examples/math/math.nub index 0f28512..8791dd7 100644 --- a/examples/math/math.nub +++ b/examples/math/math.nub @@ -6,6 +6,11 @@ struct color { r: i32 g: i32 b: i32 a: i32 } struct example { a: math::vec2 b: math::vec3 c: math::color } export func add(a: i32 b: i32): i32 +{ + return math::add_internal(a b) +} + +func add_internal(a: i32 b: i32): i32 { return a + b } \ No newline at end of file