コード例 #1
0
        /// <summary>
        ///     Invokes a export function from a given script.
        /// </summary>
        /// <param name="symbol">Symbol of function to call.</param>
        /// <param name="toThread">Thread to call function.</param>
        /// <param name="fromThread">Thread to call function from.</param>
        /// <returns>Memory index of new array.</returns>
        public void InvokeExportFunction(FunctionSymbol symbol, ScriptThread toThread, ScriptThread fromThread)
        {
            // Can't invoke functions if debugging :S.
            if (_debugger != null && _debugger.AllowInvokedFunctions == false && toThread == this)
                return;

            // Find the functions parameter types.
            DataTypeValue[] parameterTypes = new DataTypeValue[symbol.ParameterCount];
            for (int i = 0; i < symbol.ParameterCount; i++)
                parameterTypes[i] = ((VariableSymbol)symbol.Symbols[i]).DataType;

            // Push any parameters we have been given.
            for (int i = 0; i < parameterTypes.Length; i++)
            {
                RuntimeValue parameter = fromThread._runtimeStack[(fromThread._runtimeStack.TopIndex - parameterTypes.Length) + i];
                parameter.DataType = parameterTypes[i];

                if (parameterTypes[i].IsArray == true)
                    toThread.PassParameterArray(CopyValueArrayFromThread(parameter, toThread, fromThread));
                else
                    toThread.PassParameter(CopyValueFromThread(parameter, toThread, fromThread));
            }

            // Call the function.
            toThread.InvokeFunction(symbol.Identifier, true, true);

            // Copy the return register.
            fromThread._registers[(int)Register.Return].DataType = symbol.ReturnType;
            if (symbol.ReturnType.IsArray == true)
                SetMemoryIndexValue(fromThread._registers[(int)Register.Return], CopyValueArrayFromThread(toThread._registers[(int)Register.Return], fromThread, toThread));
            else
                fromThread._registers[(int)Register.Return] = CopyValueFromThread(toThread._registers[(int)Register.Return], fromThread, toThread);
        }
コード例 #2
0
 /// <summary>
 ///		Creates a new thread attached to the given function.
 /// </summary>
 /// <param name="symbol">The symbol of the function to execute from.</param>
 private void SpawnThread(FunctionSymbol symbol)
 {
     ScriptThread thread = new ScriptThread(_process);
     thread.InvokeFunction(symbol.Identifier, false, true);
 }
コード例 #3
0
 /// <summary>
 ///		Creates a new thread and attaches it to this process.
 /// </summary>
 /// <param name="entryPoint">Entry point where the thread should start.</param>
 /// <returns>New instance of ScriptThread.</returns>
 public ScriptThread CreateThread(string functionIdent)
 {
     ScriptThread thread = new ScriptThread(this);
     thread.InvokeFunction(functionIdent);
     return thread;
 }