Esempio n. 1
0
        /*
         *      - Returning null if chain length = 0 because there should be no scope if there
         *              is no chain.
         *      - Check if the chainLink is a AHK node or assembly type/instance.
         *      - TODO : Add functions as a valid chainLink (already supporeted by parser)
         */
        object scopeChain(List <BaseAHKNode> chain, IndexedNode startingScope)
        {
            if (chain.Count == 0)
            {
                return(null);
            }

            object scope = startingScope;

            foreach (var chainLink in chain)
            {
                if (chainLink is variableClass v)
                {
                    object retVal = null;

                    if (scope is IndexedNode ind)
                    {
                        retVal = scopeAHKVariable(ind, v);
                    }
                    if (retVal == null)
                    {
                        retVal = scopeAssemblyVariable(scope, v);
                    }

                    if (retVal == null)
                    {
                        return(null);
                    }
                    scope = retVal;
                }
            }

            return(scope);
        }
Esempio n. 2
0
        public void Execute(int i)
        {
            var retryCount = 0;
            var rng        = rands[i];

exec:
            var current = new IndexedNode(rootIndex[0], tree[rootIndex[0]]);

            var depth = 0;

            while (current.node.children.length > 0)
            {
                depth++;
                if (depth >= pieceQueue.Length)
                {
                    if (retryCount++ > 10)
                    {
                        retryCounts[i] = retryCount;
                        return;
                    }

                    goto exec;
                }

                Select(ref current, ref rng);
            }

            var selectResult = new SelectResult(current, pieceQueue[depth]);

            selected[i]    = selectResult;
            depths[i]      = depth;
            retryCounts[i] = retryCount;
        }
		private static CompositeNode GetParamsNode(int expectedValue)
		{
			var paramsNode = new CompositeNode("root");
			var listNode = new IndexedNode("myList");
			paramsNode.AddChildNode(listNode);
			listNode.AddChildNode(new LeafNode(typeof (int), "", expectedValue));
			return paramsNode;
		}
		public void ArrayBindingWithIndexedNodes()
		{
			var node = new CompositeNode("unnamed");
			var indexNode = new IndexedNode("emails");
			node.AddChildNode(indexNode);
			indexNode.AddChildNode(new LeafNode(typeof (String), "", "e1"));
			indexNode.AddChildNode(new LeafNode(typeof (String), "", "e2"));
			Assert.AreEqual(new[] {"e1", "e2"}, binder.BindParameter(typeof (String[]), "emails", node));
		}
        private static CompositeNode GetParamsNode(int expectedValue)
        {
            var paramsNode = new CompositeNode("root");
            var listNode   = new IndexedNode("myList");

            paramsNode.AddChildNode(listNode);
            listNode.AddChildNode(new LeafNode(typeof(int), "", expectedValue));
            return(paramsNode);
        }
        public void ArrayBindingWithIndexedNodes()
        {
            var node      = new CompositeNode("unnamed");
            var indexNode = new IndexedNode("emails");

            node.AddChildNode(indexNode);
            indexNode.AddChildNode(new LeafNode(typeof(String), "", "e1"));
            indexNode.AddChildNode(new LeafNode(typeof(String), "", "e2"));
            Assert.AreEqual(new[] { "e1", "e2" }, binder.BindParameter(typeof(String[]), "emails", node));
        }
        void autoExec(IndexedNode ind)
        {
            var oIndex = indexed;

            indexed = ind;

            foreach (var node in ind.AutoExecute)
            {
                traverser.objectDispatcher(node);
            }

            indexed = oIndex;
        }
        public MockSimpleDataSet AddData(int id, Dictionary <string, string> rowData)
        {
            var nodeDefinition = new IndexedNode {
                NodeId = id, Type = Type
            };

            ListOfSimpleData.Add(
                new SimpleDataSet
            {
                NodeDefinition = nodeDefinition,
                RowData        = rowData
            });
            return(this);
        }
        functionCallClass createNewInstanceAHK(functionCallClass context)
        {
            var baseClass = ((IndexedNode)context.extraInfo).Classes[context.functionName];
            var newScope  = new IndexedNode();

            newScope.Functions   = baseClass.Functions;
            newScope.Classes     = baseClass.Classes;
            newScope.AutoExecute = baseClass.AutoExecute;

            autoExec(newScope);
            autoExecuted[newScope] = true;

            context.extraInfo = newScope;
            return(context);
        }
Esempio n. 10
0
        private unsafe void Select(ref IndexedNode current, ref Random rng)
        {
            var children = current.node.children;
            var weights  = stackalloc float[children.length];
            // var weights = new NativeArray<float>(children.length,Allocator.Temp);
            var sum = 0f;
            var min = 0f;

            for (var j = 0; j < children.length; j++)
            {
                var child = tree[children.start + j];

                var q = 100f * (child.visits != 0 ? 10 * SumInt4(child.evalSum) / child.visits : 0);
                var u = 0.01f * math.sqrt(current.node.visits) / (1 + child.visits);
                var s = 1 * 4 * SumInt4(current.node.evalSelf);

                var a = q + u + s;
                weights[j] = a;
                sum       += a;
                if (a < min)
                {
                    min = a;
                }
            }

            sum += (100 - min) * children.length;

            for (var j = 0; j < children.length; j++)
            {
                weights[j] = (weights[j] - min + 100) / sum;
            }

            var rand = rng.NextFloat(0f, 1f);
            var val  = 0f;

            for (var j = 0; j < children.length; j++)
            {
                val += weights[j];
                if (val > rand)
                {
                    var idx = children.start + j;
                    current = new IndexedNode(idx, tree[idx]);
                    break;
                }
            }

            // weights.Dispose();
        }
Esempio n. 11
0
    public int WidthOfBinaryTree(TreeNode root)
    {
        Queue <IndexedNode> queue = new Queue <IndexedNode>();

        if (root == null)
        {
            return(0);
        }
        int max = 0;

        queue.Enqueue(new IndexedNode(root, 1));
        int size = queue.Count;

        while (size > 0)
        {
            int first = -1, last = -1;
            for (int i = 0; i < size; i++)
            {
                IndexedNode curr = queue.Dequeue();
                if (curr.node.left != null)
                {
                    IndexedNode left = new IndexedNode(curr.node.left, curr.index * 2);
                    queue.Enqueue(left);
                    if (first == -1)
                    {
                        first = left.index;
                    }
                    last = left.index;
                }
                if (curr.node.right != null)
                {
                    IndexedNode right = new IndexedNode(curr.node.right, curr.index * 2 + 1);
                    queue.Enqueue(right);
                    if (first == -1)
                    {
                        first = right.index;
                    }
                    last = right.index;
                }
            }
            max  = Math.Max(max, last - first + 1);
            size = queue.Count;
        }
        return(max);
    }
Esempio n. 12
0
        CompositeNode GetOrCreateIndexedNode(CompositeNode parent, string nodeName)
        {
            nodeName = NormalizeKey(nodeName);
            var node = parent.GetChildNode(nodeName);

            if (node != null && node.NodeType != NodeType.Indexed)
            {
                throw new BindingException("Attempt to create or obtain an indexed node " +
                                           "named {0}, but a node with the same exists with the type {1}", nodeName, node.NodeType);
            }

            if (node == null)
            {
                node = new IndexedNode(nodeName);
                parent.AddChildNode(node);
            }

            return((IndexedNode)node);
        }
Esempio n. 13
0
        internal ExamineSimpleDataSet AddData(int id, string name, string value)
        {
            var nodeDefinition = new IndexedNode {
                NodeId = id, Type = this.Type
            };

            var rowData = new Dictionary <string, string>
            {
                { name, value }
            };

            this.Source.Add(
                new SimpleDataSet
            {
                NodeDefinition = nodeDefinition,
                RowData        = rowData
            });
            return(this);
        }
Esempio n. 14
0
        public functionCallClass functionCallAHK(functionCallClass context)
        {
            IndexedNode scope    = (IndexedNode)context.extraInfo;
            var         function = getCorrectFunctionOverload(scope.Functions[context.functionName], context);

            if (function == null)
            {
            }                                   //incorrect overload error

            foreach (var exp in context.functionParameterList)
            {
                traverser.objectDispatcher(exp);
            }

            // var parameterVariableAssignList = addParams(context, function);
            // function.functionBody = parameterVariableAssignList.Concat(function.functionBody).ToList();

            var oIndexed = indexed;

            indexed           = new IndexedNode();
            indexed.Functions = oIndexed.Functions;
            indexed.Classes   = oIndexed.Classes;
            indexed.Parent    = scope;

            setParameters(context, function);

            foreach (var functionNode in function.functionBody)
            {
                var retVal = traverser.objectDispatcher(functionNode);
                if (retVal.extraInfo is returnBlockClass r)
                {
                    context.extraInfo = r.expression?.extraInfo;
                    break;
                }
            }

            indexed = oIndexed;
            return(context);
        }
Esempio n. 15
0
 IndexedNode scopeAHKVariable(IndexedNode scope, variableClass v)
 {
     if (scope.Variables.Exists(v.variableName))
     {
         variable(v);
         if (((VariableValue)v.extraInfo).Value is IndexedNode ind)
         {
             return(ind);
         }
         return(null);
         // if v.extraInfo is instance of a type, it will be resolved in scopeAssemblyVariable
     }
     else if (scope.Classes.Exists(v.variableName))
     {
         var newScope = scope.Classes[v.variableName];
         if (!autoExecuted.ContainsKey(newScope) || !autoExecuted[newScope])
         {
             autoExec(newScope);
             autoExecuted[newScope] = true;
         }
         return(newScope);
     }
     return(null);
 }