Example #1
0
        public string Compile(CompilerContext context)
        {
            context.EnterNewScope("For loop");

            CurrentIndex.Value = LowerBound;
            string code = $"for {CurrentIndex.Compile(context)}, {UpperBound.Compile(context)} do\n" +
                          LoopBody.Compile(context) + "\n" +
                          $"end\n" +
                          LoopEnd.Compile(context) + "\n";

            context.LeaveScope();
            return(code);
        }
        //method for wrap around for loops, 0, 1, 2, 3, 4, ..., 0, 1, 2, 3
        public static void For(int start, LoopConditional condition, LoopBody body, LoopConclusion conclusion)
        {
            var events = new List<ManualResetEvent>();

            for (int i = start, j = 0; condition.Invoke(i); i++, j++) {
                var resetEvent = new ManualResetEvent(false);

                ThreadPool.QueueUserWorkItem((arg) => {
                    int value = (int)arg;
                    body.Invoke(value);
                    resetEvent.Set();
                }, i);
                events.Add(resetEvent);
                conclusion.Invoke(ref i);
            }//end loop

            WaitHandle.WaitAll(events.ToArray());
        }
Example #3
0
        //method for wrap around for loops, 0, 1, 2, 3, 4, ..., 0, 1, 2, 3
        public static void For(int start, LoopConditional condition, LoopBody body, LoopConclusion conclusion)
        {
            var events = new List <ManualResetEvent>();

            for (int i = start, j = 0; condition.Invoke(i); i++, j++)
            {
                var resetEvent = new ManualResetEvent(false);

                ThreadPool.QueueUserWorkItem((arg) => {
                    int value = (int)arg;
                    body.Invoke(value);
                    resetEvent.Set();
                }, i);
                events.Add(resetEvent);
                conclusion.Invoke(ref i);
            }//end loop

            WaitHandle.WaitAll(events.ToArray());
        } //end method
Example #4
0
 get => this.GetRequired(LoopBody, Expression.Parse);