From 0980766d9a5939c9c7b008a9dd1c6e20338773bb Mon Sep 17 00:00:00 2001 From: Udayshankar Ravikumar Date: Tue, 17 Dec 2024 20:43:56 +0530 Subject: [PATCH] Added special handling for statements instead of just being arrays. --- docs/index.md | 5 ++-- src/Runtime/Interpreter.cs | 22 ++++++++++++++++ .../Nodes/CollectionNodes/StatementsNode.cs | 26 +++++++++++++++++++ src/Syntax/Parser/Parser.cs | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/Runtime/Nodes/CollectionNodes/StatementsNode.cs diff --git a/docs/index.md b/docs/index.md index 72743ce..7884733 100644 --- a/docs/index.md +++ b/docs/index.md @@ -126,9 +126,10 @@ For other OSes you can clone the [***branch***](https://github.com/Uralstech/ezr The offline documentation is included as an optional component in the installers. You can also download them from here: -[![ezr² RE v0.11.3 documentation](https://img.shields.io/badge/ezr%C2%B2_RE_v0.11.3_%28documentation%29-32CD32?style=for-the-badge&logo=jekyll&logoColor=white)](https://uralstech.github.io/ezrSquared/docsrc/QuickStartDocumentation.pdf) -[![ezr² RE v0.11.3 API reference manual](https://img.shields.io/badge/ezr%C2%B2_RE_v0.11.3_%28API_reference_manual%29-32CD32?style=for-the-badge&logo=jekyll&logoColor=white)](https://uralstech.github.io/ezrSquared/api/APIReferenceManual.pdf) +This is documentation for the latest, bleeding-edge version of ezr² RE, so some things may not match up with the latest release: +[![ezr² RE documentation](https://img.shields.io/badge/ezr%C2%B2_RE_documentation-32CD32?style=for-the-badge&logo=jekyll&logoColor=white)](https://uralstech.github.io/ezrSquared/docsrc/QuickStartDocumentation.pdf) +[![ezr² RE API reference manual](https://img.shields.io/badge/ezr%C2%B2_RE_API_reference_manual-32CD32?style=for-the-badge&logo=jekyll&logoColor=white)](https://uralstech.github.io/ezrSquared/api/APIReferenceManual.pdf) ## Contributing diff --git a/src/Runtime/Interpreter.cs b/src/Runtime/Interpreter.cs index 27423af..9efac64 100644 --- a/src/Runtime/Interpreter.cs +++ b/src/Runtime/Interpreter.cs @@ -57,6 +57,9 @@ internal void VisitNode(Node astNode, Context executionContext, Context? calling case ValueNode node: VisitValueNode(node, executionContext); break; + case StatementsNode node: + VisitStatementsNode(node, executionContext, callingContext, accessibilityModifiers); + break; case ArrayLikeNode node when node.CreateList: VisitArrayLikeNodeList(node, executionContext, callingContext, accessibilityModifiers); break; @@ -202,6 +205,25 @@ private void VisitValueNode(ValueNode node, Context executionContext) } } + /// + /// Interprets multiple statements. + /// + /// The to execute. + /// The under which the statements will be executed. + /// The calling on the execution of the statements. + /// The accessibility modifiers for objects that will be assigned from executing the statements. + private void VisitStatementsNode(StatementsNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers) + { + foreach (Node statement in node.Statements) + { + VisitNode(statement, executionContext, callingContext, accessibilityModifiers); + if (RuntimeResult.ShouldReturn) + return; + } + + RuntimeResult.Success(node.Statements.Count > 0 ? RuntimeResult.Reference : ReferencePool.Get(EzrConstants.Nothing, AccessMod.PrivateConstant)); + } + #region VisitArrayLikeNode /// diff --git a/src/Runtime/Nodes/CollectionNodes/StatementsNode.cs b/src/Runtime/Nodes/CollectionNodes/StatementsNode.cs new file mode 100644 index 0000000..b96616f --- /dev/null +++ b/src/Runtime/Nodes/CollectionNodes/StatementsNode.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +namespace EzrSquared.Runtime.Nodes; + +/// +/// The structure for holding multiple statements. +/// +/// The statements. +/// The starting of the . +/// The ending of the . +public class StatementsNode(List statements, Position startPosition, Position endPosition) : Node(startPosition, endPosition) +{ + /// + /// The statements being held by the node. + /// + public List Statements = statements; + + /// + public override string ToString() + { + string[] elements = new string[Statements.Count]; + for (int i = 0; i < Statements.Count; i++) + elements[i] = Statements[i].ToString(); + + return $"{nameof(StatementsNode)}([{string.Join(", ", elements)}])"; + } +} diff --git a/src/Syntax/Parser/Parser.cs b/src/Syntax/Parser/Parser.cs index ac96a35..9f01088 100644 --- a/src/Syntax/Parser/Parser.cs +++ b/src/Syntax/Parser/Parser.cs @@ -227,7 +227,7 @@ or TokenType.KeywordElse statements.Add(_result.Node); } - _result.Success(new ArrayLikeNode(statements, false, startPosition, statements[^1].EndPosition)); + _result.Success(new StatementsNode(statements, startPosition, statements[^1].EndPosition)); } ///