Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add anonymous function #53

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/Aquila.CodeAnalysis/CodeGen/Graph/BoundExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ internal override TypeSymbol Emit(CodeGenerator cg)
return Place().EmitLoad(cg.Builder);
}
}

public partial class BoundPropertyRef
{
internal override IVariableReference BindPlace(CodeGenerator cg)
{
return new PropertyReference(this._instance, (PropertySymbol)_property);
}

internal override IPlace Place()
{
return new PropertyPlace(null, (PropertySymbol)_property);
}

internal override TypeSymbol Emit(CodeGenerator cg)
{
return cg.EmitCall(ILOpCode.Call, (MethodSymbol)Property.GetMethod, this.Instance,
ImmutableArray<BoundArgument>.Empty);
}
}

partial class BoundBinaryEx
{
Expand Down Expand Up @@ -795,25 +814,6 @@ internal override TypeSymbol Emit(CodeGenerator cg)
}
}

public partial class BoundPropertyRef
{
internal override IVariableReference BindPlace(CodeGenerator cg)
{
return new PropertyReference(this._instance, (PropertySymbol)_property);
}

internal override IPlace Place()
{
return new PropertyPlace(null, (PropertySymbol)_property);
}

internal override TypeSymbol Emit(CodeGenerator cg)
{
return cg.EmitCall(ILOpCode.Call, (MethodSymbol)Property.GetMethod, this.Instance,
ImmutableArray<BoundArgument>.Empty);
}
}

partial class BoundThrowEx
{
internal override TypeSymbol Emit(CodeGenerator cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ internal IPlace GetThisPlace()
/// <returns>List of additional overloads.</returns>
internal virtual IList<MethodSymbol> SynthesizeStubs(PEModuleBuilder module, DiagnosticBag diagnostic)
{
//
EmitParametersDefaultValue(module, diagnostic);

// TODO: resolve this already in SourceTypeSymbol.GetMembers(), now it does not get overloaded properly
return SynthesizeOverloadsWithOptionalParameters(module, diagnostic);
}

Expand Down
5 changes: 2 additions & 3 deletions src/Aquila.CodeAnalysis/CodeGen/VariableReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ public static LhsStack EmitReceiver(ILBuilder il, IPlace receiver)

/// <summary>
/// An object specifying a reference to a variable, a field, a property, an array item (a value in general).
/// Used by <see cref="BoundReferenceExpression"/>.
/// </summary>
interface IVariableReference
{
Expand All @@ -267,7 +266,7 @@ interface IVariableReference
/// Gets native type of the variable.
/// </summary>
TypeSymbol Type { get; }

/// <summary>
/// Gets value indicating the native value can be accessed by address (<c>ref</c>).
/// </summary>
Expand Down Expand Up @@ -778,6 +777,6 @@ public TypeSymbol EmitLoadAddress(CodeGenerator cg, ref LhsStack lhsStack)
throw ExceptionUtilities.Unreachable;
}
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ partial class AquilaCompilation
/// <summary>
/// Gets global semantics. To be replaced once we implement SyntaxNode (<see cref="CommonGetSemanticModel"/>).
/// </summary>
internal GlobalSymbolProvider GlobalSemantics => _model ?? (_model = new GlobalSymbolProvider(this));
internal GlobalSymbolProvider GlobalSemantics => _model ??= new GlobalSymbolProvider(this);

/// <summary>
/// Merges two CLR types into one
/// </summary>
/// <param name="first">First type.</param>
/// <param name="second">Second type.</param>
/// <returns>One type convering both <paramref name="first"/> and <paramref name="second"/> types.</returns>
/// <returns>One type covering both <paramref name="first"/> and <paramref name="second"/> types.</returns>
internal TypeSymbol Merge(TypeSymbol first, TypeSymbol second)
{
Contract.ThrowIfNull(first);
Expand Down
42 changes: 20 additions & 22 deletions src/Aquila.CodeAnalysis/Compilation/AquilaCompilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -900,21 +900,26 @@ internal override CommonReferenceManager CommonGetBoundReferenceManager()

internal new ReferenceManager GetBoundReferenceManager()
{
if (_lazyAssemblySymbol == null)
if (_lazyAssemblySymbol != null)
return _referenceManager;

lock (_referenceManager)
{
lock (_referenceManager)
{
_lazyAssemblySymbol = _referenceManager.CreateSourceAssemblyForCompilation(this);
}

Debug.Assert(_lazyAssemblySymbol != null);
_lazyAssemblySymbol = _referenceManager.CreateSourceAssemblyForCompilation(this);
}

Debug.Assert(_lazyAssemblySymbol != null);

// referenceManager can only be accessed after we initialized the lazyAssemblySymbol.
// In fact, initialization of the assembly symbol might change the reference manager.
return _referenceManager;
}

internal void EnsureSourceAssembly()
{
this.GetBoundReferenceManager();
}

internal override ISymbolInternal CommonGetWellKnownTypeMember(WellKnownMember member)
{
return GetWellKnownTypeMember(member);
Expand Down Expand Up @@ -964,7 +969,7 @@ public async Task<IEnumerable<Diagnostic>> BindAndAnalyseTask(CancellationToken
{
if (_lazyAnalysisTask == null)
{
_lazyAnalysisTask = Task.Run(() => SourceCompiler.BindAndAnalyze(this, cancellationToken));
_lazyAnalysisTask = Task.Run(() => SourceCompiler.BindAndAnalyze(this, cancellationToken), cancellationToken);
}

return await _lazyAnalysisTask.ConfigureAwait(false);
Expand All @@ -986,15 +991,12 @@ public async Task<IEnumerable<Diagnostic>> BindAndAnalyseTask(CancellationToken
throw new NotImplementedException();
}

if (emittingPdb)
if (emittingPdb && !CreateDebugDocuments(
moduleBeingBuilt.DebugDocumentsBuilder,
moduleBeingBuilt.EmbeddedTexts.Concat(CollectAdditionalEmbeddedTexts()),
diagnostics))
{
if (!CreateDebugDocuments(
moduleBeingBuilt.DebugDocumentsBuilder,
moduleBeingBuilt.EmbeddedTexts.Concat(CollectAdditionalEmbeddedTexts()),
diagnostics))
{
return false;
}
return false;
}

// Use a temporary bag so we don't have to refilter pre-existing diagnostics.
Expand All @@ -1016,12 +1018,8 @@ public async Task<IEnumerable<Diagnostic>> BindAndAnalyseTask(CancellationToken
bool hasMethodBodyErrorOrWarningAsError =
!FilterAndAppendAndFreeDiagnostics(diagnostics, ref methodBodyDiagnosticBag, cancellationToken);

if (hasDeclarationErrors || hasMethodBodyErrorOrWarningAsError)
{
return false;
}

return true;
var hasErrors = hasDeclarationErrors || hasMethodBodyErrorOrWarningAsError;
return !hasErrors;
}
catch (Exception ex)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Aquila.CodeAnalysis/Compilation/CompilationState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using Aquila.CodeAnalysis.Symbols;

namespace Aquila.CodeAnalysis;


/// <summary>
/// Compilation state.
/// </summary>
internal sealed class CompilationState
{
private readonly List<SourceMethodSymbolBase> _methodsToEmit = new();

public IEnumerable<SourceMethodSymbolBase> MethodsToEmit => _methodsToEmit;

public void RegisterMethodToEmit(SourceMethodSymbolBase method)
{
_methodsToEmit.Add(method);
}
}
Loading