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

            if (data.InstructionType == FLInstructionType.NOP || data.InstructionType == FLInstructionType.Unknown)
            {
                _currentIndex++;
                _currentWord = 0;
            }
            else
            {
                LineAnalysisResult ret = AnalyzeLine(data);
                if (ret != LineAnalysisResult.Jump)
                {
                    _currentIndex++;
                    _currentWord = 0;
                }
            }
            DetectEnd();
        }
Esempio n. 2
0
        private LineAnalysisResult AnalyzeLine(FLInstructionData data)
        {
            if (data.InstructionType != FLInstructionType.FLFunction && data.InstructionType != FLInstructionType.CLKernel)
            {
                Logger.Crash(new FLParseError(Data.Source[_currentIndex]), true);
                return(LineAnalysisResult.ParseError);
            }

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

            LineAnalysisResult ret = LineAnalysisResult.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 && ((FLFunctionInfo)data.Instruction).LeaveStack;
                    JumpTo((int)data.Arguments[_currentWord].value, KeepBuffer);
                    ret = LineAnalysisResult.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 != LineAnalysisResult.Jump)
            {
                if (data.InstructionType == FLInstructionType.FLFunction)
                {
                    ((FLFunctionInfo)data.Instruction).Run();
                    return(LineAnalysisResult.IncreasePC);
                }

                CLKernel K = (CLKernel)data.Instruction;
                if (K == null || data.Arguments.Count != K.Parameter.Count - FLHeaderArgCount)
                {
                    Logger.Crash(new FLInvalidFunctionUseException(Data.Source[_currentIndex], "Not the right amount of arguments."),
                                 true);
                    return(LineAnalysisResult.ParseError);
                }

                //Execute filter
                for (int i = K.Parameter.Count - 1; i >= FLHeaderArgCount; 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("Running kernel: " + K.Name, DebugChannel.Log | DebugChannel.OpenFL, 8);
                CLAPI.Run(K, _currentBuffer.Buffer, new int3(_width, _height, _depth),
                          KernelParameter.GetDataMaxSize(_kernelDb.GenDataType), _activeChannelBuffer,
                          _channelCount); //Running the kernel
            }
            return(ret);
        }