예제 #1
0
        private JSProgram CreateProgramWithWhileStatement(int whileTimes)
        {
            JSProgram program = new JSProgram();

            program.Render = true;
            program.AddInputBlock("a", 1);
            program.AddHeaterDeclarationBlock("z");

            string times      = program.AddConstantBlock(whileTimes);
            string zero       = program.AddConstantBlock(whileTimes);
            string logicCheck = program.AddBoolOPBlock(BoolOPTypes.EQ, times, zero);

            string scopeName = program.GetUniqueName();

            program.AddScope(scopeName);
            program.SetScope(scopeName);
            string guardedBlock = AddFluidBlock(program, "a", "k");

            program.SetScope(JSProgram.DEFAULT_SCOPE_NAME);

            program.AddRepeatSegment(times, guardedBlock);
            AddFluidBlock(program, "k", "k");

            program.Finish();
            return(program);
        }
예제 #2
0
        private void nestRepeats(JSProgram program, string prevScopeName, Queue <int> repeatTimes, string from, string to)
        {
            string times = program.AddConstantBlock(repeatTimes.Dequeue());

            string scopeName = program.GetUniqueName();

            program.AddScope(scopeName);
            program.SetScope(scopeName);
            string guardedBlock = AddFluidBlock(program, from, to);

            if (repeatTimes.Count > 0)
            {
                nestRepeats(program, scopeName, repeatTimes, to, to);
            }
            program.SetScope(prevScopeName);

            program.AddRepeatSegment(times, guardedBlock);
            AddFluidBlock(program, to, to);
        }
예제 #3
0
        private void nestIfs(JSProgram program, string prevScopeName, Queue <bool> enableIf, string from, string to)
        {
            string left             = program.AddConstantBlock(enableIf.Dequeue() ? 3 : 2);
            string right            = program.AddConstantBlock(3);
            string conditionalBlock = program.AddBoolOPBlock(BoolOPTypes.EQ, left, right);

            string scopeName = program.GetUniqueName();

            program.AddScope(scopeName);
            program.SetScope(scopeName);
            string guardedBlock = AddFluidBlock(program, from, to);

            if (enableIf.Count > 0)
            {
                nestIfs(program, scopeName, enableIf, to, to);
            }
            program.SetScope(prevScopeName);

            program.AddIfSegment(conditionalBlock, guardedBlock);
            AddFluidBlock(program, to, to);
        }