Skip to content

Commit

Permalink
Some PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuinox committed Nov 1, 2024
1 parent 1d0e05f commit e987b77
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ private void EncodeModule(IModule module, TypeDefinitionHandle? parent, ref int
++procIndex;

// We encode every class
foreach (var @class in module.Types.Values)
foreach (var @class in module.Classes.Values)
{
this.EncodeClass(@class, parent: createdModule, fieldIndex: ref fieldIndex, procIndex: ref procIndex);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Draco.Compiler/Internal/OptimizingIr/Model/IClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Draco.Compiler.Internal.OptimizingIr.Model;

/// <summary>
/// Read-only interface if a <see cref="Class"/>
/// </summary>
internal interface IClass
{
/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Draco.Compiler/Internal/OptimizingIr/Model/IModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ internal interface IModule
public IReadOnlyDictionary<FunctionSymbol, IProcedure> Procedures { get; }

/// <summary>
/// The compiled types within this module.
/// The compiled classes within this module.
/// </summary>
public IReadOnlyDictionary<TypeSymbol, IClass> Types { get; }
public IReadOnlyDictionary<TypeSymbol, IClass> Classes { get; }

/// <summary>
/// The procedure performing global initialization.
Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/OptimizingIr/Model/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class Module : IModule
IReadOnlyDictionary<ModuleSymbol, IModule> IModule.Submodules => this.submodules;

public IDictionary<TypeSymbol, IClass> Types => this.types;
IReadOnlyDictionary<TypeSymbol, IClass> IModule.Types => this.types;
IReadOnlyDictionary<TypeSymbol, IClass> IModule.Classes => this.types;

public IReadOnlySet<FieldSymbol> Fields => this.fields;
public IReadOnlySet<PropertySymbol> Properties => this.properties;
Expand Down
5 changes: 2 additions & 3 deletions src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ public Procedure(Module declaringModule, Class? declaringType, FunctionSymbol sy

public int GetParameterIndex(ParameterSymbol symbol)
{
if (symbol is SourceThisParameterSymbol) return 0;
var isStaticMethod = symbol.ContainingSymbol.IsStatic;
if (symbol.IsThis) return 0;
var idx = this.Symbol.Parameters.IndexOf(symbol);
if (idx == -1) throw new System.ArgumentOutOfRangeException(nameof(symbol));
return isStaticMethod ? idx : idx + 1;
return symbol.ContainingSymbol.IsStatic ? idx : idx + 1;
}

public BasicBlock DefineBasicBlock(LabelSymbol symbol)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
namespace Draco.Compiler.Internal.Symbols.Error;

internal class ErrorThisParameterSymbol(TypeSymbol type, FunctionSymbol containingSymbol) : ParameterSymbol
/// <summary>
/// An error this parameter symbol.
/// </summary>
/// <param name="type"></param>
/// <param name="containingSymbol"></param>
internal sealed class ErrorThisParameterSymbol(TypeSymbol type, FunctionSymbol containingSymbol) : ParameterSymbol
{
public override TypeSymbol Type { get; } = type;
public override FunctionSymbol ContainingSymbol { get; } = containingSymbol;
Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/Symbols/FunctionSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public delegate IOperand CodegenDelegate(
/// <summary>
/// The receiver of this function, if it has one.
/// </summary>
public TypeSymbol? Receiver => this.IsStatic
public TypeSymbol? ReceiverType => this.IsStatic
? null
: this.ContainingSymbol as TypeSymbol;

Expand Down
2 changes: 2 additions & 0 deletions src/Draco.Compiler/Internal/Symbols/ParameterSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal abstract partial class ParameterSymbol : LocalSymbol
public virtual bool IsVariadic => false;

public override bool IsMutable => false;

public virtual bool IsThis => false;
// NOTE: Override for covariant return type
public override ParameterSymbol? GenericDefinition => null;
public override SymbolKind Kind => SymbolKind.Parameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal sealed class SourceThisParameterSymbol(FunctionSymbol containingSymbol,
public override string Name => "this";
public override FunctionSymbol ContainingSymbol { get; } = containingSymbol;
public override bool IsVariadic => false;
public override bool IsThis => true;
public override ThisParameterSyntax DeclaringSyntax { get; } = syntax;

public override ImmutableArray<AttributeInstance> Attributes => [];
Expand Down

0 comments on commit e987b77

Please sign in to comment.