...
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using Nub.Lang.Backend;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Nub.Lang.Backend;
|
||||||
|
using Nub.Lang.Frontend;
|
||||||
using Nub.Lang.Frontend.Diagnostics;
|
using Nub.Lang.Frontend.Diagnostics;
|
||||||
using Nub.Lang.Frontend.Lexing;
|
using Nub.Lang.Frontend.Lexing;
|
||||||
using Nub.Lang.Frontend.Parsing;
|
using Nub.Lang.Frontend.Parsing;
|
||||||
@@ -42,22 +44,7 @@ internal static class Program
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ModuleNode> modules;
|
if (TryRunFrontend(input, out var definitions))
|
||||||
try
|
|
||||||
{
|
|
||||||
modules = RunFrontend(input);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var definitions = modules.SelectMany(f => f.Definitions).ToList();
|
|
||||||
|
|
||||||
var typeChecker = new TypeChecker(definitions);
|
|
||||||
var typeCheckResult = typeChecker.TypeCheck();
|
|
||||||
typeCheckResult.PrintAllDiagnostics();
|
|
||||||
if (typeCheckResult.HasErrors)
|
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -69,15 +56,22 @@ internal static class Program
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ModuleNode> RunFrontend(string rootFilePath)
|
private static bool TryRunFrontend(string rootFilePath, out List<DefinitionNode> definitions)
|
||||||
{
|
{
|
||||||
List<ModuleNode> modules = [];
|
List<ModuleNode> modules = [];
|
||||||
RunFrontend(rootFilePath, modules);
|
var error = TryRunFrontend(rootFilePath, modules);
|
||||||
return modules;
|
definitions = modules.SelectMany(f => f.Definitions).ToList();
|
||||||
|
|
||||||
|
var typeChecker = new TypeChecker(definitions);
|
||||||
|
var typeCheckResult = typeChecker.TypeCheck();
|
||||||
|
typeCheckResult.PrintAllDiagnostics();
|
||||||
|
error = error || typeCheckResult.HasErrors;
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RunFrontend(string rootFilePath, List<ModuleNode> modules)
|
private static bool TryRunFrontend(string rootFilePath, List<ModuleNode> modules)
|
||||||
{
|
{
|
||||||
|
var error = false;
|
||||||
var filePaths = Directory.EnumerateFiles(rootFilePath, "*.nub", SearchOption.TopDirectoryOnly);
|
var filePaths = Directory.EnumerateFiles(rootFilePath, "*.nub", SearchOption.TopDirectoryOnly);
|
||||||
|
|
||||||
List<Token> tokens = [];
|
List<Token> tokens = [];
|
||||||
@@ -89,10 +83,6 @@ internal static class Program
|
|||||||
|
|
||||||
var parseResult = Parser.ParseModule(tokens, rootFilePath);
|
var parseResult = Parser.ParseModule(tokens, rootFilePath);
|
||||||
parseResult.PrintAllDiagnostics();
|
parseResult.PrintAllDiagnostics();
|
||||||
if (parseResult.HasErrors)
|
|
||||||
{
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
modules.Add(parseResult.Value);
|
modules.Add(parseResult.Value);
|
||||||
|
|
||||||
@@ -101,8 +91,13 @@ internal static class Program
|
|||||||
var importPath = Path.GetFullPath(import, parseResult.Value.Path);
|
var importPath = Path.GetFullPath(import, parseResult.Value.Path);
|
||||||
if (modules.All(m => m.Path != importPath))
|
if (modules.All(m => m.Path != importPath))
|
||||||
{
|
{
|
||||||
RunFrontend(importPath, modules);
|
if (!TryRunFrontend(importPath, modules))
|
||||||
|
{
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user