Skip to content

Commit

Permalink
Stackification (#332)
Browse files Browse the repository at this point in the history
* Factored out value instruction interface

* Hammering call instructions

* Added operands sequence to instructions

* Create Stackifier.cs

* Update CilCodegen.cs

* Update Stackifier.cs

* Almost working stackifier

* Update CilCodegen.cs

* Update CilCodegen.cs

* Eliminated most of symbol ref

* YEET

* Update CilCodegen.cs

* YES

* MUHAHAHA

* YES, YES!

* One less faulty file

* Update CilCodegen.cs

* WE COMPILE

* Update CilCodegen.cs

* Lots of fixes

* Fix

* Update CilCodegen.cs

* Update MetadataCodegen.cs

* Update FunctionBodyCodegen.cs

* No less errors, but no crash

* Update CilCodegen.cs

* Split out static fields

* Killed static field logic

* Added AddressOf

* Addresses work

* Update CilCodegen.cs

* Update CilCodegen.cs

* Update CilCodegen.cs

* Update MetadataStaticFieldSymbol.cs

* Merge pull request #330 from Draco-lang/rip-and-tear

Cleanup before stackification

* Added tree instruction

* Update TreeInstruction.cs

* Update TreeInstruction.cs

* Fixes in tree instr

* Update Stackifier.cs

* Really basic stackification

* Nicer print

* Update CilCodegen.cs

* Update CilCodegen.cs

* Stackification works

* Removed unused regs

* Update CilCodegen.cs

* Update CilCodegen.cs

* Cleanup

* Update FunctionBodyCodegen.cs

* Lowered unary and binary nodes

* Fix

* Cleanup

* Update FunctionBodyCodegen.cs

* Simplification

* Update FunctionBodyCodegen.cs
  • Loading branch information
LPeter1997 authored Oct 13, 2023
1 parent 2e0da4a commit faf4445
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 faf4445

Please sign in to comment.