/// <summary> /// Registers all the native functions in this set to a VM. /// </summary> /// <param name="virtualMachine">VM to register native functions to.</param> public void RegisterToVirtualMachine(VirtualMachine virtualMachine) { foreach (NativeFunction function in _nativeFunctions) virtualMachine.RegisterNativeFunction(function); }
/// <summary> /// Copys the given processes data to this process. /// </summary> /// <param name="vm">Virtual machine this oricess us associated with.</param> /// <param name="process">Process to recieve data from.</param> public ScriptProcess(VirtualMachine vm, ScriptProcess process) { HighPreformanceTimer timer = new HighPreformanceTimer(); // Store virtual machine for layer use. _virtualMachine = vm; // Load the given script into this process. process.CopyTo(this); // Create a default thread that should run this process. ScriptThread newThread = new ScriptThread(this); // Attach console commands / exported command to this thread. // TODO: What if they already exist? foreach (Symbol symbol in _symbolList) if (symbol != null && symbol.Type == SymbolType.Function) { if (((FunctionSymbol)symbol).IsConsole == true) new ScriptConsoleCommand((FunctionSymbol)symbol, newThread); else if (((FunctionSymbol)symbol).IsExport == true) new ScriptExportFunction((FunctionSymbol)symbol, newThread); else if (((FunctionSymbol)symbol).IsImport == true) { // Find the functions parameter types. DataTypeValue[] parameterTypes = new DataTypeValue[((FunctionSymbol)symbol).ParameterCount]; for (int i = 0; i < ((FunctionSymbol)symbol).ParameterCount; i++) parameterTypes[(((FunctionSymbol)symbol).ParameterCount - 1) - i] = ((VariableSymbol)symbol.Symbols[i]).DataType; ((FunctionSymbol)symbol).NativeFunction = _virtualMachine.FindNativeFunction(symbol.Identifier, parameterTypes); } } }
/// Registers all the native functions in all the global sets to a VM. /// </summary> /// <param name="virtualMachine">VM to register native functions to.</param> public static void RegisterCommandSetsToVirtualMachine(VirtualMachine virtualMachine) { foreach (NativeFunctionSet set in _globalFunctionSets) { Debug.DebugLogger.WriteLog("Registering "+set.ToString()+" set..."); set.RegisterToVirtualMachine(virtualMachine); } }
/// Registers all the native functions in all the global sets to a VM. /// </summary> /// <param name="virtualMachine">VM to register native functions to.</param> public static void RegisterCommandSetsToVirtualMachine(VirtualMachine virtualMachine) { foreach (NativeFunctionSet set in _globalFunctionSets) set.RegisterToVirtualMachine(virtualMachine); }