...
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
namespace Compiler;
|
||||
|
||||
public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, ModuleGraph moduleGraph)
|
||||
public sealed class TypeChecker(string fileName, string moduleName, NodeDefinitionFunc function, ModuleGraph moduleGraph)
|
||||
{
|
||||
public static TypedNodeDefinitionFunc? CheckFunction(string fileName, NodeDefinitionFunc function, ModuleGraph moduleGraph, out List<Diagnostic> diagnostics)
|
||||
public static TypedNodeDefinitionFunc? CheckFunction(string fileName, string moduleName, NodeDefinitionFunc function, ModuleGraph moduleGraph, out List<Diagnostic> diagnostics)
|
||||
{
|
||||
return new TypeChecker(fileName, function, moduleGraph).CheckFunction(out diagnostics);
|
||||
return new TypeChecker(fileName, moduleName, function, moduleGraph).CheckFunction(out diagnostics);
|
||||
}
|
||||
|
||||
private readonly Scope scope = new(null);
|
||||
@@ -52,7 +52,7 @@ public sealed class TypeChecker(string fileName, NodeDefinitionFunc function, Mo
|
||||
if (body == null || returnType == null || invalidParameter)
|
||||
return null;
|
||||
|
||||
return new TypedNodeDefinitionFunc(function.Tokens, function.Name, parameters, body, returnType);
|
||||
return new TypedNodeDefinitionFunc(function.Tokens, moduleName, function.Name, parameters, body, returnType);
|
||||
}
|
||||
|
||||
private TypedNodeDefinitionFunc.Param CheckDefinitionFuncParameter(NodeDefinitionFunc.Param node)
|
||||
@@ -409,15 +409,28 @@ public abstract class TypedNode(List<Token> tokens)
|
||||
public List<Token> Tokens { get; } = tokens;
|
||||
}
|
||||
|
||||
public abstract class TypedNodeDefinition(List<Token> tokens) : TypedNode(tokens);
|
||||
public abstract class TypedNodeDefinition(List<Token> tokens, string module) : TypedNode(tokens)
|
||||
{
|
||||
public string Module { get; } = module;
|
||||
}
|
||||
|
||||
public sealed class TypedNodeDefinitionFunc(List<Token> tokens, TokenIdent name, List<TypedNodeDefinitionFunc.Param> parameters, TypedNodeStatement body, NubType returnType) : TypedNodeDefinition(tokens)
|
||||
public sealed class TypedNodeDefinitionFunc(List<Token> tokens, string module, TokenIdent name, List<TypedNodeDefinitionFunc.Param> parameters, TypedNodeStatement body, NubType returnType) : TypedNodeDefinition(tokens, module)
|
||||
{
|
||||
public TokenIdent Name { get; } = name;
|
||||
public List<Param> Parameters { get; } = parameters;
|
||||
public TypedNodeStatement Body { get; } = body;
|
||||
public NubType ReturnType { get; } = returnType;
|
||||
|
||||
public NubTypeFunc GetNubType()
|
||||
{
|
||||
return NubTypeFunc.Get(Parameters.Select(x => x.Type).ToList(), ReturnType);
|
||||
}
|
||||
|
||||
public string GetMangledName()
|
||||
{
|
||||
return SymbolNameGen.Exported(Module, Name.Ident, GetNubType());
|
||||
}
|
||||
|
||||
public sealed class Param(List<Token> tokens, TokenIdent name, NubType type) : TypedNode(tokens)
|
||||
{
|
||||
public TokenIdent Name { get; } = name;
|
||||
|
||||
Reference in New Issue
Block a user