Esempio n. 1
0
        /// <summary>
        /// Executes one step of the Processor
        /// </summary>
        private void Execute()
        {
            FLInstructionData data = this.data.ParsedSource[currentIndex];

            if (data.InstructionType == FLInstructionType.Nop || data.InstructionType == FLInstructionType.Unknown)
            {
                currentIndex++;
                currentWord = 0;
            }
            else
            {
                FLLineAnalysisResult ret = AnalyzeLine(data);
                if (ret != FLLineAnalysisResult.Jump)
                {
                    currentIndex++;
                    currentWord = 0;
                }
            }

            DetectEnd();
        }
Esempio n. 2
0
        private FLLineAnalysisResult AnalyzeLine(FLInstructionData data)
        {
            if (data.InstructionType != FLInstructionType.FlFunction &&
                data.InstructionType != FLInstructionType.ClKernel)
            {
                return(FLLineAnalysisResult.ParseError);
            }

            if (leaveStack) //This keeps the stack when returning from a "function"
            {
                leaveStack = false;
            }
            else
            {
                currentArgStack = new Stack <object>();
            }

            FLLineAnalysisResult ret = FLLineAnalysisResult.IncreasePc;

            for (;
                 currentWord < data.Arguments.Count;
                 currentWord++) //loop through the words. start value can be != 0 when returning from a function specified as an argument to a kernel
            {
                if (data.Arguments[currentWord].argType == FLArgumentType.Function)
                {
                    bool keepBuffer = data.InstructionType == FLInstructionType.FlFunction &&
                                      ((FLInterpreterFunctionInfo)data.Instruction).LeaveStack;
                    JumpTo((int)data.Arguments[currentWord].value, keepBuffer);
                    ret = FLLineAnalysisResult.Jump; //We Jumped to another point in the code.
                    currentArgStack
                    .Push(null);                     //Push null to signal the interpreter that he returned before assigning the right value.
                    break;
                }

                if (data.Arguments[currentWord].argType != FLArgumentType.Unknown)
                {
                    currentArgStack.Push(data.Arguments[currentWord].value);
                }
            }


            if (currentWord == data.Arguments.Count && ret != FLLineAnalysisResult.Jump)
            {
                if (data.InstructionType == FLInstructionType.FlFunction)
                {
                    ((FLInterpreterFunctionInfo)data.Instruction).Run();
                    return(FLLineAnalysisResult.IncreasePc);
                }

                CLKernel k = (CLKernel)data.Instruction;
                if (k == null || data.Arguments.Count != k.Parameter.Count - FL_HEADER_ARG_COUNT)
                {
                    throw new FLInvalidFunctionUseException(this.data.Source[currentIndex],
                                                            "Not the right amount of arguments.");
                }

                //Execute filter
                for (int i = k.Parameter.Count - 1; i >= FL_HEADER_ARG_COUNT; i--)
                {
                    object obj = currentArgStack.Pop(); //Get the arguments and set them to the kernel
                    if (obj is CLBufferInfo buf)        //Unpack the Buffer from the CLBuffer Object.
                    {
                        obj = buf.Buffer;
                    }

                    k.SetArg(i, obj);
                }

                Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level8, "Running kernel: " + k.Name);
                CLAPI.Run(instance, k, currentBuffer.Buffer, new int3(width, height, depth),
                          KernelParameter.GetDataMaxSize(kernelDb.GenDataType), activeChannelBuffer,
                          channelCount); //Running the kernel
            }

            return(ret);
        }