...
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
using NubLang.Parsing.Syntax;
|
||||
using NubLang.TypeChecking.Node;
|
||||
|
||||
namespace NubLang.Modules;
|
||||
|
||||
public class Module
|
||||
{
|
||||
private readonly List<ModuleStruct> _structs = [];
|
||||
private readonly List<ModuleStructTemplate> _structTemplates = [];
|
||||
private readonly List<ModuleFunction> _functions = [];
|
||||
|
||||
public void RegisterStruct(bool exported, string name, List<ModuleStructField> fields, List<ModuleStructFunction> functions)
|
||||
@@ -12,6 +14,11 @@ public class Module
|
||||
_structs.Add(new ModuleStruct(exported, name, fields, functions));
|
||||
}
|
||||
|
||||
public void RegisterStructTemplate(bool exported, string name, List<string> templateArguments, List<StructFieldNode> fields, List<StructFuncNode> functions)
|
||||
{
|
||||
_structTemplates.Add(new ModuleStructTemplate(exported, name, templateArguments, fields, functions));
|
||||
}
|
||||
|
||||
public void RegisterFunction(bool exported, string name, string? externSymbol, List<ModuleFunctionParameter> parameters, TypeSyntax returnType)
|
||||
{
|
||||
_functions.Add(new ModuleFunction(exported, name, externSymbol, parameters, returnType));
|
||||
@@ -30,12 +37,12 @@ public class Module
|
||||
|
||||
public record ModuleStructField(string Name, TypeSyntax Type, bool HasDefaultValue);
|
||||
|
||||
public record ModuleStructFunctionParameter(string Name, TypeSyntax Type);
|
||||
|
||||
public record ModuleStructFunction(string Name, string? Hook, List<ModuleStructFunctionParameter> Parameters, TypeSyntax ReturnType);
|
||||
public record ModuleStructFunction(string Name, string? Hook, List<ModuleFunctionParameter> Parameters, TypeSyntax ReturnType);
|
||||
|
||||
public record ModuleStruct(bool Exported, string Name, List<ModuleStructField> Fields, List<ModuleStructFunction> Functions);
|
||||
|
||||
public record ModuleFunctionParameter(string Name, TypeSyntax Type);
|
||||
|
||||
public record ModuleFunction(bool Exported, string Name, string? ExternSymbol, List<ModuleFunctionParameter> Parameters, TypeSyntax ReturnType);
|
||||
|
||||
public record ModuleStructTemplate(bool Exported, string Name, List<string> TemplateArguments, List<StructFieldNode> Fields, List<StructFuncNode> Functions);
|
||||
@@ -24,20 +24,29 @@ public class ModuleRepository
|
||||
{
|
||||
case FuncSyntax funcDef:
|
||||
{
|
||||
var parameters = funcDef.Signature.Parameters.Select(x => new ModuleFunctionParameter(x.Name, x.Type)).ToList();
|
||||
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 ModuleStructField(x.Name, x.Type, x.Value.HasValue)).ToList();
|
||||
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, function.Hook, parameters, function.Signature.ReturnType));
|
||||
}
|
||||
var functions = structDef.Functions
|
||||
.Select(x =>
|
||||
{
|
||||
var parameters = x.Signature.Parameters
|
||||
.Select(y => new ModuleFunctionParameter(y.Name, y.Type))
|
||||
.ToList();
|
||||
|
||||
return new ModuleStructFunction(x.Name, x.Hook, parameters, x.Signature.ReturnType);
|
||||
})
|
||||
.ToList();
|
||||
|
||||
module.RegisterStruct(structDef.Exported, structDef.Name, fields, functions);
|
||||
break;
|
||||
|
||||
@@ -837,13 +837,13 @@ public sealed class TypeChecker
|
||||
BoolTypeSyntax => new NubBoolType(),
|
||||
CStringTypeSyntax => new NubCStringType(),
|
||||
IntTypeSyntax i => new NubIntType(i.Signed, i.Width),
|
||||
CustomTypeSyntax c => ResolveCustomType(c),
|
||||
FloatTypeSyntax f => new NubFloatType(f.Width),
|
||||
FuncTypeSyntax func => new NubFuncType(func.Parameters.Select(ResolveType).ToList(), ResolveType(func.ReturnType)),
|
||||
ArrayTypeSyntax arr => new NubArrayType(ResolveType(arr.BaseType)),
|
||||
PointerTypeSyntax ptr => new NubPointerType(ResolveType(ptr.BaseType)),
|
||||
StringTypeSyntax => new NubStringType(),
|
||||
TemplateTypeSyntax template => throw new NotImplementedException(),
|
||||
CustomTypeSyntax c => ResolveCustomType(c),
|
||||
TemplateTypeSyntax t => ResolveTemplateType(t),
|
||||
VoidTypeSyntax => new NubVoidType(),
|
||||
_ => throw new NotSupportedException($"Unknown type syntax: {type}")
|
||||
};
|
||||
@@ -907,6 +907,11 @@ public sealed class TypeChecker
|
||||
_resolvingTypes.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
private NubType ResolveTemplateType(TemplateTypeSyntax template)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public enum VariableKind
|
||||
|
||||
Reference in New Issue
Block a user