From 4921141a9ef6b015d88454ccc8a579949bca0b80 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 18 Mar 2024 17:49:44 +0200 Subject: [PATCH] Data - Nah screw this --- source/tlang/compiler/symbols/data.d | 79 ++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/source/tlang/compiler/symbols/data.d b/source/tlang/compiler/symbols/data.d index 6f7acef..e0d375c 100644 --- a/source/tlang/compiler/symbols/data.d +++ b/source/tlang/compiler/symbols/data.d @@ -317,6 +317,9 @@ public class Function : TypedEntity, Container return weightReorder(bodyStatements); } + // Bring in regularly used implementations + mixin ContainerCommonImpl!(Statement, this.bodyStatements); + /** * This will sift through all the `Statement[]`'s in held * within this Function and will find those which are Variable @@ -1096,6 +1099,9 @@ public final class IfStatement : Entity, Container return cast(Statement[])branches; } + // Bring in regularly used implementations + mixin ContainerCommonImpl!(Branch, this.branches); + public override string toString() { return "IfStmt"; @@ -1228,6 +1234,37 @@ public final class WhileLoop : Entity, Container return cast(Statement[])[branch]; } + public override long indexOf(Statement statement) + { + return statement is this.branch ? 0 : -1; + } + + public override bool removeAt(ulong index) + { + if(index != 0) + { + return false; + } + + this.branch = null; + return true; + } + + public bool insertAt(ulong index, Statement statement) + { + if(index != 0) + { + return false; + } + else if(this.branch !is null) + { + return false; + } + + this.branch = statement; + return true; + } + public override string toString() { return "WhileLoop"; @@ -1345,6 +1382,45 @@ public final class ForLoop : Entity, Container branch = (cast(Branch[])statements)[0]; } + public override long indexOf(Statement statement) + { + if(statement is this.preLoopStatement) + { + return 0; + } + else if(statement is this.branch) + { + return 1; + } + else + { + return -1; + } + } + + public override bool removeAt(ulong index) + { + if(index == 0 && this.preLoopStatement !is null) + { + return true; + } + else if(index == 1 && this.branch !is null) + { + return true; + } + else + { + return false; + } + } + + public override bool insertAt(ulong index, Statement statement) + { + // if(index == 0) + // TODO: Are we really going to implement this? + return false; + } + public override Statement[] getStatements() { // If there is a pre-run statement then prepend it @@ -1501,6 +1577,9 @@ public final class Branch : Entity, Container return branchBody; } + // Bring in regularly used implementations + mixin ContainerCommonImpl!(Statement, this.branchBody); + public override string toString() { return "Branch";