Skip to content

Commit

Permalink
Merge pull request #331 from Draco-lang/stackification
Browse files Browse the repository at this point in the history
Stackification
  • Loading branch information
LPeter1997 authored Oct 13, 2023
2 parents 2e0da4a + fd9b883 commit 3b09bfa
Show file tree
Hide file tree
Showing 69 changed files with 1,002 additions and 679 deletions.
1 change: 0 additions & 1 deletion src/Draco.Compiler.Benchmarks/SyntaxBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using BenchmarkDotNet.Attributes;
using Draco.Compiler.Api.Syntax;
using Draco.Compiler.Internal.Syntax;
using CompilationUnitSyntax = Draco.Compiler.Internal.Syntax.CompilationUnitSyntax;
using SyntaxToken = Draco.Compiler.Internal.Syntax.SyntaxToken;

namespace Draco.Compiler.Benchmarks;
Expand Down
8 changes: 4 additions & 4 deletions src/Draco.Compiler.Tests/Semantics/SymbolResolutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ public static class FooModule{

var diags = semanticModel.Diagnostics;
var xSym = GetInternalSymbol<VariableSymbol>(semanticModel.GetDeclaredSymbol(xDecl));
var fooSym = GetMemberSymbol<FieldSymbol>(GetInternalSymbol<ModuleSymbol>(semanticModel.GetReferencedSymbol(fooModuleRef)), "foo");
var fooSym = GetMemberSymbol<GlobalSymbol>(GetInternalSymbol<ModuleSymbol>(semanticModel.GetReferencedSymbol(fooModuleRef)), "foo");
var fooDecl = GetMetadataSymbol(compilation, null, "FooModule", "foo");

// Assert
Expand Down Expand Up @@ -1857,7 +1857,7 @@ public static class FooModule{

var diags = semanticModel.Diagnostics;
var xSym = GetInternalSymbol<VariableSymbol>(semanticModel.GetDeclaredSymbol(xDecl));
var fooSym = GetInternalSymbol<FieldSymbol>(semanticModel.GetReferencedSymbol(fooNameRef));
var fooSym = GetInternalSymbol<GlobalSymbol>(semanticModel.GetReferencedSymbol(fooNameRef));
var fooDecl = GetMetadataSymbol(compilation, null, "FooModule", "foo");

// Assert
Expand Down Expand Up @@ -1951,7 +1951,7 @@ public static class FooModule{
var semanticModel = compilation.GetSemanticModel(main);

var diags = semanticModel.Diagnostics;
var fooSym = GetMemberSymbol<FieldSymbol>(GetInternalSymbol<ModuleSymbol>(semanticModel.GetReferencedSymbol(fooModuleRef)), "foo");
var fooSym = GetMemberSymbol<GlobalSymbol>(GetInternalSymbol<ModuleSymbol>(semanticModel.GetReferencedSymbol(fooModuleRef)), "foo");
var fooDecl = GetMetadataSymbol(compilation, null, "FooModule", "foo");

// Assert
Expand Down Expand Up @@ -1996,7 +1996,7 @@ public static class FooModule{
var semanticModel = compilation.GetSemanticModel(main);

var diags = semanticModel.Diagnostics;
var fooSym = GetMemberSymbol<FieldSymbol>(GetInternalSymbol<ModuleSymbol>(semanticModel.GetReferencedSymbol(fooModuleRef)), "foo");
var fooSym = GetMemberSymbol<GlobalSymbol>(GetInternalSymbol<ModuleSymbol>(semanticModel.GetReferencedSymbol(fooModuleRef)), "foo");
var fooDecl = GetMetadataSymbol(compilation, null, "FooModule", "foo");

// Assert
Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler.Tests/Semantics/TypeCheckingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ public void AccessingField()
var semanticModel = compilation.GetSemanticModel(tree);

var xSym = GetInternalSymbol<LocalSymbol>(semanticModel.GetDeclaredSymbol(xDecl));
var stringEmptySym = GetMemberSymbol<FieldSymbol>(GetInternalSymbol<TypeSymbol>(semanticModel.GetReferencedSymbol(consoleRef)), "Empty");
var stringEmptySym = GetMemberSymbol<GlobalSymbol>(GetInternalSymbol<TypeSymbol>(semanticModel.GetReferencedSymbol(consoleRef)), "Empty");

// Assert
Assert.Empty(semanticModel.Diagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private BoundExpression TypeGlobalExpression(UntypedGlobalExpression global, Con

private BoundExpression TypeFieldExpression(UntypedFieldExpression field, ConstraintSolver constraints, DiagnosticBag diagnostics)
{
var receiver = field.Reciever is null ? null : this.TypeExpression(field.Reciever, constraints, diagnostics);
var receiver = this.TypeExpression(field.Reciever, constraints, diagnostics);
return new BoundFieldExpression(field.Syntax, receiver, field.Field);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/Binding/Binder_BoundLvalue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private BoundLvalue TypeGlobalLvalue(UntypedGlobalLvalue global, ConstraintSolve

private BoundLvalue TypeFieldLvalue(UntypedFieldLvalue field, ConstraintSolver constraints, DiagnosticBag diagnostics)
{
var receiver = field.Reciever is null ? null : this.TypeExpression(field.Reciever, constraints, diagnostics);
var receiver = this.TypeExpression(field.Reciever, constraints, diagnostics);
return new BoundFieldLvalue(field.Syntax, receiver, field.Field);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,6 @@ private UntypedExpression SymbolToExpression(SyntaxNode syntax, Symbol symbol, C
return new UntypedLocalExpression(syntax, local, constraints.GetLocalType(local));
case GlobalSymbol global:
return new UntypedGlobalExpression(syntax, global);
case FieldSymbol field:
return new UntypedFieldExpression(syntax, null, field);
case PropertySymbol prop:
var getter = GetGetterSymbol(syntax, prop, diagnostics);
return new UntypedPropertyGetExpression(syntax, null, getter);
Expand Down
4 changes: 2 additions & 2 deletions src/Draco.Compiler/Internal/Binding/Binder_UntypedLvalue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ private UntypedLvalue SymbolToLvalue(SyntaxNode syntax, Symbol symbol, Constrain
{
switch (symbol)
{
case FieldSymbol field:
return new UntypedFieldLvalue(syntax, null, field);
case GlobalSymbol global:
return new UntypedGlobalLvalue(syntax, global);
case PropertySymbol prop:
var setter = GetSetterSymbol(syntax, prop, diagnostics);
return new UntypedPropertySetLvalue(syntax, null, setter);
Expand Down
4 changes: 2 additions & 2 deletions src/Draco.Compiler/Internal/BoundTree/BoundNodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
</Node>

<Node Name="BoundFieldExpression" Base="BoundExpression">
<Field Name="Receiver" Type="BoundExpression?"/>
<Field Name="Receiver" Type="BoundExpression"/>
<Field Name="Field" Type="FieldSymbol" />
</Node>

Expand Down Expand Up @@ -280,7 +280,7 @@
</Node>

<Node Name="BoundFieldLvalue" Base="BoundLvalue">
<Field Name="Receiver" Type="BoundExpression?"/>
<Field Name="Receiver" Type="BoundExpression"/>
<Field Name="Field" Type="FieldSymbol" />
</Node>

Expand Down
13 changes: 2 additions & 11 deletions src/Draco.Compiler/Internal/Codegen/AllocatedLocal.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
using Draco.Compiler.Internal.OptimizingIr.Model;
using Draco.Compiler.Internal.Symbols;

namespace Draco.Compiler.Internal.Codegen;

/// <summary>
/// Some method-local variable allocation.
/// </summary>
/// <param name="Operand">The corresponding IR operand.</param>
/// <param name="Symbol">The corresponding local symbol.</param>
/// <param name="Index">The index of the local within the method.</param>
internal readonly record struct AllocatedLocal(
IOperand Operand,
int Index)
{
/// <summary>
/// The symbol associated with this local, if any.
/// </summary>
public LocalSymbol? Symbol => this.Operand is Local local ? local.Symbol : null;
}
internal readonly record struct AllocatedLocal(LocalSymbol Symbol, int Index);
Loading

0 comments on commit 3b09bfa

Please sign in to comment.