示例#1
0
        Instruction AnalyseFunctionCall(Tokenizer.Token[] Tokens, int index, out int tokenCount)
        {
            InstructionFunction instructionFunction = new InstructionFunction();

            instructionFunction.FunctionName = Tokens[index].Value;

            Tokenizer.Token[]   tokensParametersBloc = GetTokensBetweenParentheses(Tokens, index + 1);
            Tokenizer.Token[][] tokensParameters     = SplitTokens(tokensParametersBloc, t => t.TokenName == Tokenizer.TokenName.ParameterSeparation);

            foreach (Tokenizer.Token[] tokensParameter in tokensParameters)
            {
                int         tokenCountParameter = 0;
                Instruction instruction         = AnalyseInstruction(tokensParameter, 0, out tokenCountParameter);
                instructionFunction.Parameters.Add(instruction);
            }

            tokenCount = 3 + tokensParametersBloc.Count();

            int tc = 0;

            instructionFunction.Path = AnalysePath(Tokens, index + tokenCount, out tc);
            tokenCount += tc;

            if (tokenCount < Tokens.Length && Tokens[index + tokenCount].TokenName == Tokenizer.TokenName.LineEnd)
            {
                tokenCount++;
            }

            return(instructionFunction);
        }
示例#2
0
        InstructionResult ExecuteInstructionFunction(Instruction instruction)
        {
            InstructionResult result = new InstructionResult();

            InstructionFunction instructionFunction = instruction as InstructionFunction;

            List <Value> values = new List <Value>();

            foreach (var parameter in instructionFunction.Parameters)
            {
                Value value = CopyValue(ExecuteInstruction(parameter).Value);
                values.Add(value);
            }

            if (_embededFunctions.ContainsKey(instructionFunction.FunctionName))
            {
                FunctionCallArgs functionCallArgs = new FunctionCallArgs()
                {
                    Interpreter = this,
                    Name        = instructionFunction.FunctionName,
                    Values      = values
                };

                result.Value = _embededFunctions[instructionFunction.FunctionName](functionCallArgs);
            }
            else
            {
                Function previousFunction = _currentFunction;
                _currentFunction = _program.Functions.FirstOrDefault(f => f.Name == instructionFunction.FunctionName);
                ThrowExceptionOnCondition(_currentFunction == null, instruction, 30002, new string[] { instructionFunction.FunctionName });

                _stack.AddRange(values);
                int numberOfValueToAdd = _currentFunction.Variables.Count - _currentFunction.ParametersCount;
                for (int i = 0; i < numberOfValueToAdd; i++)
                {
                    _stack.Add(new Value());
                }

                result = ExecuteBloc(_currentFunction.Instructions.ToArray());

                _stack.RemoveRange(_stack.Count - _currentFunction.Variables.Count, _currentFunction.Variables.Count);
                _currentFunction = previousFunction;
            }

            result.Value  = ResolvePath(result.Value, instructionFunction.Path);
            result.Return = false;

            return(result);
        }