Skip to content

Conversation

@stakx
Copy link
Member

@stakx stakx commented Jan 25, 2021

ExpressionStatement is an adapter type that turns an Expression into a Statement. Its mere existence demonstrates that a strict distinction between expressions and statements is more of a stumbling block than it is helpful. Some AST node types (such as MethodInvocationExpression) need to act as either.

We can model this at the type system level by converting Expression and Statement to interfaces. AST node types can then implement both interfaces, which renders adapter types ExpressionStatement and ReferenceExpression redundant. Removing those from AST trees means fewer allocations and thus slightly less GC pressure.

Outlook

I'd like to follow this up with another PR that will introduce an interface ILocation for modelling storage locations. The Load / Store methods of Reference would end up there. I expect this would both simplify by-ref handling and indirect loads / stores.

@stakx stakx marked this pull request as draft January 25, 2021 03:00
@stakx stakx marked this pull request as ready for review January 25, 2021 03:27
@stakx stakx requested a review from jonorossi January 25, 2021 03:28
@stakx stakx force-pushed the simple-ast branch 2 times, most recently from cd9448d to e656530 Compare January 31, 2021 23:56
Copy link
Member

@jonorossi jonorossi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. That definitely tidies up the code, especially that the stack based runtime rarely cares about the difference between C# level statements and expressions.

using System.Reflection.Emit;

internal class MultiStatementExpression : Expression
internal class BlockStatement : IStatement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MultiStatementExpression, haha, yer that shows things were not quite right 👍

stakx added 6 commits February 3, 2021 18:52
Now that `IExpression` and `IStatement` are interfaces, AST nodes like
e.g. `MethodInvocationExpression` can be both at the same time, so there
is no more need to bridge the two types with `ExpressionStatement`.
because `Reference` can simply implement `IExpression` instead.
@stakx stakx merged commit 4076c5d into castleproject:master Feb 3, 2021
@stakx stakx deleted the simple-ast branch February 3, 2021 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants