From 8da6d94212a40b7ab9b9ca8f9a1232f3f95e0b6a Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Mon, 7 Jun 2021 14:27:36 +0200 Subject: [PATCH] I wonder if that worked --- source/tlang/compiler/typecheck/dependancy.d | 80 ++++++++++++++++++++ todo1.md | 3 +- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/source/tlang/compiler/typecheck/dependancy.d b/source/tlang/compiler/typecheck/dependancy.d index 1c6ce88..63cff23 100644 --- a/source/tlang/compiler/typecheck/dependancy.d +++ b/source/tlang/compiler/typecheck/dependancy.d @@ -276,8 +276,61 @@ public final class StructuralOrganizer { gprintln(node, DebugType.WARNING); } + + foreach(TreeNode node; nodePool) + { + figureOut(node); + } + + + gprintln("InitQueue: "~to!(string)(initQueue)); } + public Entity[] initQueue; + + public void figureOut(TreeNode node) + { + /** + * If there are no dependencies then + * initialize it now (mark as completed) + * and add to init queue + */ + if(!hasDeps(node)) + { + node.markCompleted(); + initQueue ~= node.getEntity(); + } + /** + * If there are dependencies then mark it + * as busy + */ + else + { + node.markBusy(); + + /* Get the dependencies */ + TreeNode[] nodeDeps = node.getDeps(); + + /** + * + */ + foreach(TreeNode nodeDep; nodeDeps) + { + /* Initialize any non-busy node */ + if(!nodeDep.isBusy()) + { + figureOut(nodeDep); + } + } + } + } + + public bool hasDeps(TreeNode node) + { + return cast(bool)node.getDeps().length; + } + + /** * Given a path determine if it is accessible (in a static context) * @@ -293,6 +346,28 @@ public class TreeNode private Entity entity; private TreeNode[] deps; private TypeChecker tc; + private bool isBusyB; + private bool isCompletedB; + + public bool isCompleted() + { + return isCompletedB; + } + + public void markCompleted() + { + isCompletedB = true; + } + + public bool isBusy() + { + return isBusyB; + } + + public void markBusy() + { + isBusyB = true; + } this(TypeChecker tc, Entity entity) { @@ -332,6 +407,11 @@ public class TreeNode return entity; } + public TreeNode[] getDeps() + { + return deps; + } + public override string toString() { string[] names; diff --git a/todo1.md b/todo1.md index d72c8aa..902ab3e 100644 --- a/todo1.md +++ b/todo1.md @@ -25,7 +25,8 @@ TODO List ## Typechecking - [ ] Dependency generation - - [ ] Classes declared at the module level should be ~~marked~~ seen as static in `parse()` (not in `parseBody()` <- this is a note we don't do this) + - [ ] Classes declared at the module level should be marked as static in `parse()` + - [ ] `parseClass()` should not use - [ ] Structs declared at the module level should be marked as ~~marked~~ seen in `parse()` (not in `parseBody()` <- this is a note we don't do this) - [ ] Functions (?) declared at the module level should be ~~marked~~ seen as static in `parse()` (not in `parseBody()` <- this is a note we don't do this) - [ ] Variables declared at the module level should be marked as ~~marked~~ seen in `parse()` (not in `parseBody()` <- this is a note we don't do this)