Skip to content

Commit

Permalink
convert to file scoped namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
WalkerCodeRanger committed Sep 4, 2023
1 parent 050c14b commit 9928659
Show file tree
Hide file tree
Showing 277 changed files with 12,019 additions and 12,299 deletions.
193 changes: 96 additions & 97 deletions Compiler.API/AzothCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,107 +12,106 @@
using Azoth.Tools.Bootstrap.Compiler.Semantics;
using Azoth.Tools.Bootstrap.Framework;

namespace Azoth.Tools.Bootstrap.Compiler.API
namespace Azoth.Tools.Bootstrap.Compiler.API;

public class AzothCompiler
{
public class AzothCompiler
/// <summary>
/// Whether to store the liveness analysis for each function and method.
/// Default Value: false
/// </summary>
public bool SaveLivenessAnalysis { get; set; }

/// <summary>
/// Whether to store the borrow checker claims for each function and method.
/// Default Value: false
/// </summary>
public bool SaveReachabilityGraphs { get; set; }

public Task<Package> CompilePackageAsync(
Name name,
IEnumerable<ICodeFileSource> files,
FixedDictionary<Name, Task<Package>> referenceTasks)
=> CompilePackageAsync(name, files, referenceTasks, TaskScheduler.Default);

public async Task<Package> CompilePackageAsync(
Name name,
IEnumerable<ICodeFileSource> fileSources,
FixedDictionary<Name, Task<Package>> referenceTasks,
TaskScheduler taskScheduler)
{
/// <summary>
/// Whether to store the liveness analysis for each function and method.
/// Default Value: false
/// </summary>
public bool SaveLivenessAnalysis { get; set; }

/// <summary>
/// Whether to store the borrow checker claims for each function and method.
/// Default Value: false
/// </summary>
public bool SaveReachabilityGraphs { get; set; }

public Task<Package> CompilePackageAsync(
Name name,
IEnumerable<ICodeFileSource> files,
FixedDictionary<Name, Task<Package>> referenceTasks)
=> CompilePackageAsync(name, files, referenceTasks, TaskScheduler.Default);

public async Task<Package> CompilePackageAsync(
Name name,
IEnumerable<ICodeFileSource> fileSources,
FixedDictionary<Name, Task<Package>> referenceTasks,
TaskScheduler taskScheduler)
{
var lexer = new Lexer();
var parser = new CompilationUnitParser();
var parseBlock = new TransformBlock<ICodeFileSource, ICompilationUnitSyntax>(
async (fileSource) =>
{
var file = await fileSource.LoadAsync().ConfigureAwait(false);
var context = new ParseContext(file, new Diagnostics());
var tokens = lexer.Lex(context).WhereNotTrivia();
return parser.Parse(tokens);
}, new ExecutionDataflowBlockOptions()
{
TaskScheduler = taskScheduler,
EnsureOrdered = false,
});

foreach (var fileSource in fileSources)
parseBlock.Post(fileSource);

parseBlock.Complete();

await parseBlock.Completion.ConfigureAwait(false);

if (!parseBlock.TryReceiveAll(out var compilationUnits))
throw new Exception("Not all compilation units are ready");

var referencePairs = await Task
.WhenAll(referenceTasks.Select(async kv =>
(alias: kv.Key, package: await kv.Value.ConfigureAwait(false))))
.ConfigureAwait(false);
var references = referencePairs.ToFixedDictionary(r => r.alias, r => r.package);

// TODO add the references to the package syntax
var packageSyntax = new PackageSyntax<Package>(name, compilationUnits.ToFixedSet(), references);

var analyzer = new SemanticAnalyzer()
var lexer = new Lexer();
var parser = new CompilationUnitParser();
var parseBlock = new TransformBlock<ICodeFileSource, ICompilationUnitSyntax>(
async (fileSource) =>
{
SaveLivenessAnalysis = SaveLivenessAnalysis,
SaveReachabilityGraphs = SaveReachabilityGraphs,
};

return analyzer.Check(packageSyntax);
}

public Package CompilePackage(
string name,
IEnumerable<ICodeFileSource> fileSources,
FixedDictionary<Name, Package> references)
=> CompilePackage(name, fileSources.Select(s => s.Load()), references);

public Package CompilePackage(
string name,
IEnumerable<CodeFile> files,
FixedDictionary<Name, Package> references)
{
var lexer = new Lexer();
var parser = new CompilationUnitParser();
var compilationUnits = files
.Select(file =>
{
var context = new ParseContext(file, new Diagnostics());
var tokens = lexer.Lex(context).WhereNotTrivia();
return parser.Parse(tokens);
})
.ToFixedSet();
var packageSyntax = new PackageSyntax<Package>(name, compilationUnits, references);

var analyzer = new SemanticAnalyzer()
var file = await fileSource.LoadAsync().ConfigureAwait(false);
var context = new ParseContext(file, new Diagnostics());
var tokens = lexer.Lex(context).WhereNotTrivia();
return parser.Parse(tokens);
}, new ExecutionDataflowBlockOptions()
{
SaveLivenessAnalysis = SaveLivenessAnalysis,
SaveReachabilityGraphs = SaveReachabilityGraphs,
};
TaskScheduler = taskScheduler,
EnsureOrdered = false,
});

foreach (var fileSource in fileSources)
parseBlock.Post(fileSource);

parseBlock.Complete();

await parseBlock.Completion.ConfigureAwait(false);

if (!parseBlock.TryReceiveAll(out var compilationUnits))
throw new Exception("Not all compilation units are ready");

var referencePairs = await Task
.WhenAll(referenceTasks.Select(async kv =>
(alias: kv.Key, package: await kv.Value.ConfigureAwait(false))))
.ConfigureAwait(false);
var references = referencePairs.ToFixedDictionary(r => r.alias, r => r.package);

// TODO add the references to the package syntax
var packageSyntax = new PackageSyntax<Package>(name, compilationUnits.ToFixedSet(), references);

var analyzer = new SemanticAnalyzer()
{
SaveLivenessAnalysis = SaveLivenessAnalysis,
SaveReachabilityGraphs = SaveReachabilityGraphs,
};

return analyzer.Check(packageSyntax);
}

public Package CompilePackage(
string name,
IEnumerable<ICodeFileSource> fileSources,
FixedDictionary<Name, Package> references)
=> CompilePackage(name, fileSources.Select(s => s.Load()), references);

public Package CompilePackage(
string name,
IEnumerable<CodeFile> files,
FixedDictionary<Name, Package> references)
{
var lexer = new Lexer();
var parser = new CompilationUnitParser();
var compilationUnits = files
.Select(file =>
{
var context = new ParseContext(file, new Diagnostics());
var tokens = lexer.Lex(context).WhereNotTrivia();
return parser.Parse(tokens);
})
.ToFixedSet();
var packageSyntax = new PackageSyntax<Package>(name, compilationUnits, references);

var analyzer = new SemanticAnalyzer()
{
SaveLivenessAnalysis = SaveLivenessAnalysis,
SaveReachabilityGraphs = SaveReachabilityGraphs,
};

return analyzer.Check(packageSyntax);
}
return analyzer.Check(packageSyntax);
}
}
19 changes: 9 additions & 10 deletions Compiler.AST.Interpreter/AzothTreeInterpreter.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using System;
using System.Diagnostics.CodeAnalysis;

namespace Azoth.Tools.Bootstrap.Compiler.AST.Interpreter
namespace Azoth.Tools.Bootstrap.Compiler.AST.Interpreter;

public class AzothTreeInterpreter
{
public class AzothTreeInterpreter
[SuppressMessage("Performance", "CA1822:Mark members as static",
Justification = "OO")]
public InterpreterProcess Execute(Package package)
{
[SuppressMessage("Performance", "CA1822:Mark members as static",
Justification = "OO")]
public InterpreterProcess Execute(Package package)
{
if (package.EntryPoint is null)
throw new ArgumentException("Cannot execute package without an entry point");
if (package.EntryPoint is null)
throw new ArgumentException("Cannot execute package without an entry point");

return new InterpreterProcess(package);
}
return new InterpreterProcess(package);
}
}
17 changes: 8 additions & 9 deletions Compiler.AST.Interpreter/ControlFlow/Break.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using Azoth.Tools.Bootstrap.Compiler.AST.Interpreter.MemoryLayout;

namespace Azoth.Tools.Bootstrap.Compiler.AST.Interpreter.ControlFlow
namespace Azoth.Tools.Bootstrap.Compiler.AST.Interpreter.ControlFlow;

internal class Break : Exception
{
internal class Break : Exception
{
public AzothValue Value { get; }
public AzothValue Value { get; }

public Break() { }
public Break() { }

public Break(AzothValue value)
{
Value = value;
}
public Break(AzothValue value)
{
Value = value;
}
}
7 changes: 3 additions & 4 deletions Compiler.AST.Interpreter/ControlFlow/Next.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;

namespace Azoth.Tools.Bootstrap.Compiler.AST.Interpreter.ControlFlow
namespace Azoth.Tools.Bootstrap.Compiler.AST.Interpreter.ControlFlow;

internal class Next : Exception
{
internal class Next : Exception
{
}
}
21 changes: 10 additions & 11 deletions Compiler.AST.Interpreter/ControlFlow/Return.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;
using Azoth.Tools.Bootstrap.Compiler.AST.Interpreter.MemoryLayout;

namespace Azoth.Tools.Bootstrap.Compiler.AST.Interpreter.ControlFlow
namespace Azoth.Tools.Bootstrap.Compiler.AST.Interpreter.ControlFlow;

internal class Return : Exception
{
internal class Return : Exception
{
public AzothValue Value { get; }
public AzothValue Value { get; }

public Return()
{
}
public Return()
{
}

public Return(AzothValue value)
{
Value = value;
}
public Return(AzothValue value)
{
Value = value;
}
}
Loading

0 comments on commit 9928659

Please sign in to comment.