-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Unluau.IL.Instructions; | ||
|
||
namespace Unluau.IL | ||
{ | ||
/// <summary> | ||
/// Represents a basic block in the program. | ||
/// </summary> | ||
/// <param name="instructions">A list of instructions.</param> | ||
public class BasicBlock(Instruction[] instructions) : Node | ||
{ | ||
/// <summary> | ||
/// The instructions within the block. | ||
/// </summary> | ||
public Instruction[] Instructions { get; set; } = instructions; | ||
|
||
/// <summary> | ||
/// Recursive visitor method. | ||
/// </summary> | ||
/// <param name="visitor">The visitor.</param> | ||
public override void Visit(Visitor visitor) | ||
{ | ||
if (visitor.Visit(this)) | ||
{ | ||
foreach (Instruction instruction in Instructions) | ||
instruction.Visit(visitor); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Unluau.IL | ||
{ | ||
/// <summary> | ||
/// Provides information on parameters and contents of a closure. | ||
/// </summary> | ||
public struct ClosureContext | ||
{ | ||
/// <summary> | ||
/// Basic line and instruction information. | ||
/// </summary> | ||
public Context Context { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a function (closure) within the code. | ||
/// </summary> | ||
public class Closure(ClosureContext context, BasicBlock[] blocks) : Node(context.Context) | ||
{ | ||
/// <summary> | ||
/// The children blocks of the closure. Each contain | ||
/// </summary> | ||
public BasicBlock[] Blocks { get; set; } = blocks; | ||
|
||
/// <summary> | ||
/// Visits the children of the closure. | ||
/// </summary> | ||
/// <param name="visitor">The visitor.</param> | ||
public override void Visit(Visitor visitor) | ||
{ | ||
if (visitor.Visit(this)) | ||
{ | ||
foreach (var block in Blocks) | ||
block.Visit(visitor); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Unluau.IL | ||
{ | ||
/// <summary> | ||
/// Contains information about location. | ||
/// </summary> | ||
public struct Context | ||
{ | ||
/// <summary> | ||
/// The start and end instruction the node was translated from. | ||
/// </summary> | ||
public (int, int) PcScope { get; private set; } | ||
|
||
/// <summary> | ||
/// The line number from the original script. | ||
/// </summary> | ||
public int? Line { get; private set; } | ||
} | ||
|
||
/// <summary> | ||
/// The base node for all IL components. | ||
/// </summary> | ||
/// <param name="context">Additional context on the node.</param> | ||
public class Node(Context context) | ||
{ | ||
/// <summary> | ||
/// Provides additional context on the current node. | ||
/// </summary> | ||
public Context Context { get; private set; } = context; | ||
|
||
/// <summary> | ||
/// Recursive visitor. | ||
/// </summary> | ||
/// <param name="visitor">The visitor.</param> | ||
public virtual void Visit(Visitor visitor) | ||
{ | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Unluau.IL | ||
{ | ||
public struct Variable | ||
{ | ||
/// <summary> | ||
/// The name of the variable. | ||
/// </summary> | ||
public string? Symbol { get; set; } | ||
|
||
/// <summary> | ||
/// The assigned register slot for the variable. | ||
/// </summary> | ||
public int Slot { get; set; } | ||
|
||
/// <summary> | ||
/// The | ||
/// </summary> | ||
public (int, int) PcScope { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Unluau.IL.Instructions; | ||
|
||
namespace Unluau.IL | ||
{ | ||
public class Visitor | ||
{ | ||
public virtual bool Visit(Node node) => true; | ||
|
||
public virtual bool Visit(Instruction node) => Visit(node as Node); | ||
} | ||
} |