...
This commit is contained in:
@@ -86,16 +86,16 @@ public class ModuleGraph
|
|||||||
{
|
{
|
||||||
case Manifest.Module.TypeInfoStruct s:
|
case Manifest.Module.TypeInfoStruct s:
|
||||||
{
|
{
|
||||||
var info = new Module.TypeInfoStruct(Module.DefinitionSource.Imported, true, s.Packed);
|
var info = new Module.TypeInfoStruct(Module.DefinitionSource.Imported, s.Exported, s.Packed);
|
||||||
var fields = s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList();
|
var fields = s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList();
|
||||||
info.SetFields(fields);
|
info.SetFields(fields);
|
||||||
module.AddType(name, info);
|
module.AddType(name, info);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Manifest.Module.TypeInfoEnum s:
|
case Manifest.Module.TypeInfoEnum e:
|
||||||
{
|
{
|
||||||
var info = new Module.TypeInfoEnum(Module.DefinitionSource.Imported, true);
|
var info = new Module.TypeInfoEnum(Module.DefinitionSource.Imported, e.Exported);
|
||||||
var variants = s.Variants.Select(v => new Module.TypeInfoEnum.Variant(v.Name, v.Type)).ToList();
|
var variants = e.Variants.Select(v => new Module.TypeInfoEnum.Variant(v.Name, v.Type)).ToList();
|
||||||
info.SetVariants(variants);
|
info.SetVariants(variants);
|
||||||
module.AddType(name, info);
|
module.AddType(name, info);
|
||||||
break;
|
break;
|
||||||
@@ -107,7 +107,7 @@ public class ModuleGraph
|
|||||||
|
|
||||||
foreach (var (name, identifier) in manifestModule.Identifiers)
|
foreach (var (name, identifier) in manifestModule.Identifiers)
|
||||||
{
|
{
|
||||||
module.AddIdentifier(name, new Module.IdentifierInfo(Module.DefinitionSource.Imported, true, true, identifier.Type, identifier.MangledName));
|
module.AddIdentifier(name, new Module.IdentifierInfo(Module.DefinitionSource.Imported, identifier.Exported, identifier.Extern, identifier.Type, identifier.MangledName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,25 +70,8 @@ public record Manifest(Dictionary<string, Manifest.Module> Modules)
|
|||||||
|
|
||||||
foreach (var module in moduleGraph.GetModules())
|
foreach (var module in moduleGraph.GetModules())
|
||||||
{
|
{
|
||||||
var types = new Dictionary<string, Module.TypeInfo>();
|
var types = module.GetTypes().ToDictionary(x => x.Key, x => ConvertType(x.Value));
|
||||||
var identifiers = new Dictionary<string, Module.IdentifierInfo>();
|
var identifiers = module.GetIdentifiers().ToDictionary(x => x.Key, x => new Module.IdentifierInfo(x.Value.Type, x.Value.Exported, x.Value.Extern, x.Value.MangledName));
|
||||||
|
|
||||||
foreach (var (name, typeInfo) in module.GetTypes())
|
|
||||||
{
|
|
||||||
if (typeInfo.Exported)
|
|
||||||
{
|
|
||||||
types.Add(name, ConvertType(typeInfo));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var (name, identifierInfo) in module.GetIdentifiers())
|
|
||||||
{
|
|
||||||
if (identifierInfo.Exported)
|
|
||||||
{
|
|
||||||
identifiers.Add(name, new Module.IdentifierInfo(identifierInfo.Type, identifierInfo.MangledName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
modules[module.Name] = new Module(types, identifiers);
|
modules[module.Name] = new Module(types, identifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,8 +81,8 @@ public record Manifest(Dictionary<string, Manifest.Module> Modules)
|
|||||||
{
|
{
|
||||||
return typeInfo switch
|
return typeInfo switch
|
||||||
{
|
{
|
||||||
Compiler.Module.TypeInfoStruct s => new Module.TypeInfoStruct(s.Packed, s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList()),
|
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.TypeInfoEnum e => new Module.TypeInfoEnum(e.Variants.Select(v => new Module.TypeInfoEnum.Variant(v.Name, v.Type)).ToList()),
|
Compiler.Module.TypeInfoEnum e => new Module.TypeInfoEnum(e.Exported, e.Variants.Select(v => new Module.TypeInfoEnum.Variant(v.Name, v.Type)).ToList()),
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(typeInfo))
|
_ => throw new ArgumentOutOfRangeException(nameof(typeInfo))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -108,18 +91,18 @@ public record Manifest(Dictionary<string, Manifest.Module> Modules)
|
|||||||
|
|
||||||
public record Module(Dictionary<string, Module.TypeInfo> Types, Dictionary<string, Module.IdentifierInfo> Identifiers)
|
public record Module(Dictionary<string, Module.TypeInfo> Types, Dictionary<string, Module.IdentifierInfo> Identifiers)
|
||||||
{
|
{
|
||||||
public record IdentifierInfo(NubType Type, string MangledName);
|
public record IdentifierInfo(NubType Type, bool Exported, bool Extern, string MangledName);
|
||||||
|
|
||||||
[JsonDerivedType(typeof(TypeInfoStruct), "struct")]
|
[JsonDerivedType(typeof(TypeInfoStruct), "struct")]
|
||||||
[JsonDerivedType(typeof(TypeInfoEnum), "enum")]
|
[JsonDerivedType(typeof(TypeInfoEnum), "enum")]
|
||||||
public abstract record TypeInfo;
|
public abstract record TypeInfo(bool Exported);
|
||||||
|
|
||||||
public record TypeInfoStruct(bool Packed, IReadOnlyList<TypeInfoStruct.Field> Fields) : TypeInfo
|
public record TypeInfoStruct(bool Exported, bool Packed, IReadOnlyList<TypeInfoStruct.Field> Fields) : TypeInfo(Exported)
|
||||||
{
|
{
|
||||||
public record Field(string Name, NubType Type);
|
public record Field(string Name, NubType Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public record TypeInfoEnum(IReadOnlyList<TypeInfoEnum.Variant> Variants) : TypeInfo
|
public record TypeInfoEnum(bool Exported, IReadOnlyList<TypeInfoEnum.Variant> Variants) : TypeInfo(Exported)
|
||||||
{
|
{
|
||||||
public record Variant(string Name, NubType Type);
|
public record Variant(string Name, NubType Type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
pushd core
|
pushd core
|
||||||
dotnet run --project ../../compiler print.nub --type=lib
|
dotnet run --project ../../compiler mem.nub print.nub --type=lib
|
||||||
popd
|
popd
|
||||||
|
|
||||||
pushd math
|
pushd math
|
||||||
|
|||||||
4
examples/core/mem.nub
Normal file
4
examples/core/mem.nub
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module core
|
||||||
|
|
||||||
|
export extern func malloc(size: u64): ^void
|
||||||
|
export extern func free(size: ^void)
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
module core
|
module core
|
||||||
|
|
||||||
export extern func malloc(size: u64): ^void
|
|
||||||
export extern func free(size: ^void)
|
|
||||||
|
|
||||||
extern func puts(text: ^u8)
|
extern func puts(text: ^u8)
|
||||||
|
|
||||||
export func print(text: string)
|
export func print(text: string)
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
module main
|
|
||||||
|
|
||||||
let global: i32
|
|
||||||
|
|
||||||
func main(): i32 {
|
|
||||||
let x: i32 = 23
|
|
||||||
x = 24
|
|
||||||
|
|
||||||
if !true {
|
|
||||||
x = 49
|
|
||||||
return x
|
|
||||||
} else {
|
|
||||||
x = 3
|
|
||||||
}
|
|
||||||
|
|
||||||
let i: i32 = 0
|
|
||||||
|
|
||||||
x = 1 + 2 * 34
|
|
||||||
while i < 10 {
|
|
||||||
i = i + 1
|
|
||||||
x = i
|
|
||||||
}
|
|
||||||
|
|
||||||
let me: test::person = struct test::person { age = 21 name = "Oliver" }
|
|
||||||
|
|
||||||
x = test::do_something(me.name)
|
|
||||||
test::do_something(me.name)
|
|
||||||
|
|
||||||
main::global = 123
|
|
||||||
|
|
||||||
return main::global
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
module test
|
|
||||||
|
|
||||||
export packed struct person {
|
|
||||||
age: i32
|
|
||||||
name: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export func do_something(name: string): i32 {
|
|
||||||
return 3
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user