-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bind literals & do some other shit
- Loading branch information
Showing
19 changed files
with
184 additions
and
48 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
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
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
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,29 @@ | ||
using Heir.Syntax; | ||
using Heir.Types; | ||
|
||
namespace Heir.BoundAST | ||
{ | ||
public class BoundBinaryOp(BoundExpression left, Token op, BoundExpression right) : BoundExpression | ||
{ | ||
public override BaseType Type => throw new NotImplementedException(); | ||
public BoundExpression Left { get; } = left; | ||
public Token Operator { get; } = op; | ||
public BoundExpression Right { get; } = right; | ||
|
||
public override R Accept<R>(Visitor<R> visitor) => visitor.VisitBoundBinaryOpExpression(this); | ||
public override List<Token> GetTokens() => Left.GetTokens().Append(Operator).Concat(Right.GetTokens()).ToList(); | ||
|
||
public override void Display(int indent) | ||
{ | ||
Console.WriteLine($"{string.Concat(Enumerable.Repeat(" ", indent))}BinaryOp("); | ||
Console.WriteLine($"{string.Concat(Enumerable.Repeat(" ", indent + 1))}Left ->"); | ||
Left.Display(indent + 2); | ||
Console.WriteLine(","); | ||
Console.WriteLine($"{string.Concat(Enumerable.Repeat(" ", indent + 1))}Operator: {Operator.Text},"); | ||
Console.WriteLine($"{string.Concat(Enumerable.Repeat(" ", indent + 1))}Right ->"); | ||
Right.Display(indent + 2); | ||
Console.WriteLine(); | ||
Console.Write($"{string.Concat(Enumerable.Repeat(" ", indent))})"); | ||
} | ||
} | ||
} |
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,23 @@ | ||
using Heir.Syntax; | ||
using Heir.Types; | ||
|
||
namespace Heir.BoundAST | ||
{ | ||
public class BoundLiteral(Token token) : BoundExpression | ||
{ | ||
public override PrimitiveType Type => PrimitiveType.FromValue(Token.Value); | ||
public Token Token { get; } = token; | ||
|
||
public override R Accept<R>(Visitor<R> visitor) => visitor.VisitBoundLiteralExpression(this); | ||
public override List<Token> GetTokens() => [Token]; | ||
|
||
public override void Display(int indent) | ||
{ | ||
var valueText = Token.Value?.ToString() ?? "none"; | ||
if (Token.IsKind(SyntaxKind.BoolLiteral)) | ||
valueText = valueText.ToLower(); | ||
|
||
Console.Write($"{string.Concat(Enumerable.Repeat(" ", indent))}BoundLiteral({Token.Kind}, {valueText})"); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
namespace Heir.AST | ||
namespace Heir.BoundAST | ||
{ | ||
public class BoundSyntaxTree(List<BoundSyntaxNode> statements) : BoundBlock(statements) | ||
{ | ||
public override void Display(int indent = 0) | ||
{ | ||
foreach (var statement in Statements) | ||
statement.Display(indent); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.