Esempio n. 1
0
        public void testInputIndex()
        {
            Program p = new Program("( 1 input.index 1 input.index 0 input.index " +
                                    "0 input.index 2 input.index 2 input.index 1000 input.index -1 input.index)");

            interpreter.InputStack().Push(true);
            interpreter.InputStack().Push(3);
            interpreter.InputStack().Push(2.0f);

            interpreter.Execute(p);

            istack.Push(3);
            istack.Push(3);

            fstack.Push(2.0f);
            fstack.Push(2.0f);
            fstack.Push(2.0f);

            bstack.Push(true);
            bstack.Push(true);
            bstack.Push(true);

            ObjectStack inputs = new ObjectStack();

            inputs.Push(true);
            inputs.Push(3);
            inputs.Push(2.0f);

            Assert.AreEqual(istack, interpreter.IntStack());
            Assert.AreEqual(fstack, interpreter.FloatStack());
            Assert.AreEqual(bstack, interpreter.BoolStack());
            Assert.AreEqual(inputs, interpreter.InputStack());
        }
Esempio n. 2
0
        // Begin exec iteration functions
        public override void Execute(Interpreter inI)
        {
            IntStack    istack = inI.IntStack();
            ObjectStack estack = inI.ExecStack();

            if (_stack.Size() > 0 && istack.Size() > 1)
            {
                int    stop  = istack.Pop();
                int    start = istack.Pop();
                object code  = _stack.Pop();
                if (start == stop)
                {
                    istack.Push(start);
                    estack.Push(code);
                }
                else
                {
                    istack.Push(start);
                    start = (start < stop) ? (start + 1) : (start - 1);
                    // trh//Made changes to correct errors with code.do*range
                    try {
                        Program recursiveCallProgram = new Program();
                        recursiveCallProgram.Push(start);
                        recursiveCallProgram.Push(stop);
                        recursiveCallProgram.Push("exec.do*range");
                        recursiveCallProgram.Push(code);
                        estack.Push(recursiveCallProgram);
                    } catch (Exception) {
                        Console.Error.WriteLine("Error while initializing a program.");
                    }
                    estack.Push(code);
                }
            }
        }
Esempio n. 3
0
        public override void Execute(Interpreter inI)
        {
            IntStack    istack = inI.IntStack();
            ObjectStack estack = inI.ExecStack();

            if (_stack.Size() > 0 && istack.Size() > 0)
            {
                if (istack.Top() > 0)
                {
                    int    stop    = istack.Pop() - 1;
                    object bodyObj = _stack.Pop();
                    try {
                        Program doRangeMacroProgram = new Program();
                        doRangeMacroProgram.Push(0);
                        doRangeMacroProgram.Push(stop);
                        doRangeMacroProgram.Push("code.quote");
                        doRangeMacroProgram.Push(bodyObj);
                        doRangeMacroProgram.Push("code.do*range");
                        estack.Push(doRangeMacroProgram);
                    } catch (Exception) {
                        Console.Error.WriteLine("Error while initializing a program.");
                    }
                }
            }
        }
Esempio n. 4
0
        public void Execute(Interpreter inI)
        {
            ObjectStack cstack = inI.CodeStack();
            ObjectStack estack = inI.ExecStack();

            if (estack.Size() > 0)
            {
                cstack.Push(estack.Pop());
            }
        }
Esempio n. 5
0
        public void Execute(Interpreter inI)
        {
            ObjectStack codeStack = inI.CodeStack();
            FloatStack  fStack    = inI.FloatStack();

            if (fStack.Size() > 0)
            {
                codeStack.Push(fStack.Pop());
            }
        }
Esempio n. 6
0
        public void Execute(Interpreter inI)
        {
            ObjectStack codeStack = inI.CodeStack();
            IntStack    iStack    = inI.IntStack();

            if (iStack.Size() > 0)
            {
                codeStack.Push(iStack.Pop());
            }
        }
Esempio n. 7
0
        // End code iteration functions
        //
        // Conversion instructions to code
        //
        public void Execute(Interpreter inI)
        {
            ObjectStack  codeStack = inI.CodeStack();
            BooleanStack bStack    = inI.BoolStack();

            if (bStack.Size() > 0)
            {
                codeStack.Push(bStack.Pop());
            }
        }
Esempio n. 8
0
        public override void Execute(Interpreter inI)
        {
            BooleanStack bstack = inI.BoolStack();
            ObjectStack  estack = inI.ExecStack();

            if (_stack.Size() > 1 && bstack.Size() > 0)
            {
                bool   istrue  = bstack.Pop();
                object iftrue  = _stack.Pop();
                object iffalse = _stack.Pop();
                if (istrue)
                {
                    estack.Push(iftrue);
                }
                else
                {
                    estack.Push(iffalse);
                }
            }
        }
Esempio n. 9
0
        public override void Execute(Interpreter inI)
        {
            IntStack    istack = inI.IntStack();
            ObjectStack estack = inI.ExecStack();

            if (_stack.Size() > 0 && istack.Size() > 0)
            {
                if (istack.Top() > 0)
                {
                    object bodyObj = _stack.Pop();
                    if (bodyObj is Program)
                    {
                        // insert integer.pop in front of program
                        ((Program)bodyObj).Shove("integer.pop", ((Program)bodyObj)._size);
                    }
                    else
                    {
                        // create a new program with integer.pop in front of
                        // the popped object
                        Program newProgram = new Program();
                        newProgram.Push("integer.pop");
                        newProgram.Push(bodyObj);
                        bodyObj = newProgram;
                    }
                    int stop = istack.Pop() - 1;
                    try {
                        Program doRangeMacroProgram = new Program();
                        doRangeMacroProgram.Push(0);
                        doRangeMacroProgram.Push(stop);
                        doRangeMacroProgram.Push("code.quote");
                        doRangeMacroProgram.Push(bodyObj);
                        doRangeMacroProgram.Push("code.do*range");
                        estack.Push(doRangeMacroProgram);
                    } catch (Exception) {
                        Console.Error.WriteLine("Error while initializing a program.");
                    }
                }
            }
        }
Esempio n. 10
0
 /// <summary>Loads a Push program into the interpreter's exec and code stacks.</summary>
 /// <param name="inProgram">The program to load.</param>
 public void LoadProgram(Program inProgram)
 {
     _codeStack.Push(inProgram);
     _execStack.Push(inProgram);
 }