private void CallHost(StrongIdentifierValue methodName, KindOfFunctionParameters kindOfParameters, Dictionary <StrongIdentifierValue, Value> namedParameters, List <Value> positionedParameters, bool isSync) { #if DEBUG //Log($"methodName = {methodName}"); //Log($"kindOfParameters = {kindOfParameters}"); //Log($"namedParameters = {namedParameters.WriteDict_1_ToString()}"); //Log($"positionedParameters = {positionedParameters.WriteListToString()}"); //Log($"isSync = {isSync}"); #endif var command = new Command(); command.Name = methodName; switch (kindOfParameters) { case KindOfFunctionParameters.NoParameters: break; case KindOfFunctionParameters.NamedParameters: command.ParamsDict = namedParameters.ToDictionary(p => p.Key, p => p.Value); break; case KindOfFunctionParameters.PositionedParameters: command.ParamsList = positionedParameters.ToList(); break; default: throw new ArgumentOutOfRangeException(nameof(kindOfParameters), kindOfParameters, null); } #if DEBUG //Log($"command = {command}"); #endif var processCreatingResult = _hostListener.CreateProcess(command); #if DEBUG //Log($"processCreatingResult = {processCreatingResult}"); #endif if (processCreatingResult.IsSuccessful) { var processInfo = processCreatingResult.Process; processInfo.ParentProcessInfo = _currentCodeFrame.ProcessInfo; _instancesStorage.AppendAndTryStartProcessInfo(processInfo); if (isSync) { ProcessInfoHelper.Wait(processInfo); } _currentCodeFrame.CurrentPosition++; return; } throw new NotImplementedException(); }
private void CallPointRefValue(PointRefValue caller, KindOfFunctionParameters kindOfParameters, Dictionary <StrongIdentifierValue, Value> namedParameters, List <Value> positionedParameters, bool isSync) { #if DEBUG //Log($"caller.LeftOperand = {caller.LeftOperand}"); #endif if (caller.LeftOperand.IsHostValue) { CallHost(caller.RightOperand.AsStrongIdentifierValue, kindOfParameters, namedParameters, positionedParameters, isSync); return; } throw new NotImplementedException(); }
private void CallStrongIdentifierValue(StrongIdentifierValue methodName, KindOfFunctionParameters kindOfParameters, Dictionary <StrongIdentifierValue, Value> namedParameters, List <Value> positionedParameters, bool isSync) { #if DEBUG //Log($"methodName = {methodName}"); //Log($"kindOfParameters = {kindOfParameters}"); //Log($"namedParameters = {namedParameters.WriteDict_1_ToString()}"); //Log($"positionedParameters = {positionedParameters.WriteListToString()}"); //Log($"isSync = {isSync}"); #endif NamedFunction method = null; switch (kindOfParameters) { case KindOfFunctionParameters.NoParameters: method = _methodsResolver.Resolve(methodName, _currentCodeFrame.LocalContext); break; case KindOfFunctionParameters.NamedParameters: method = _methodsResolver.Resolve(methodName, namedParameters, _currentCodeFrame.LocalContext); break; case KindOfFunctionParameters.PositionedParameters: method = _methodsResolver.Resolve(methodName, positionedParameters, _currentCodeFrame.LocalContext); break; default: throw new ArgumentOutOfRangeException(nameof(kindOfParameters), kindOfParameters, null); } #if DEBUG //Log($"method = {method}"); #endif CallExecutable(method, kindOfParameters, namedParameters, positionedParameters, isSync); }
private CodeFrame ConvertExecutableToCodeFrame(IExecutable function, KindOfFunctionParameters kindOfParameters, Dictionary <StrongIdentifierValue, Value> namedParameters, List <Value> positionedParameters) { #if DEBUG //Log($"kindOfParameters = {kindOfParameters}"); //Log($"namedParameters = {namedParameters.WriteDict_1_ToString()}"); //Log($"positionedParameters = {positionedParameters.WriteListToString()}"); #endif var currentLocalContext = _currentCodeFrame.LocalContext; var storagesList = currentLocalContext.Storage.GetStorages(); #if DEBUG //Log($"storagesList.Count = {storagesList.Count}"); //foreach(var tmpStorage in storagesList) //{ // Log($"tmpStorage = {tmpStorage}"); //} #endif var localCodeExecutionContext = new LocalCodeExecutionContext(); var localStorageSettings = RealStorageSettingsHelper.Create(_context, storagesList.ToList()); var newStorage = new LocalStorage(localStorageSettings); localCodeExecutionContext.Storage = newStorage; switch (kindOfParameters) { case KindOfFunctionParameters.NoParameters: if (function.Arguments.Any()) { throw new NotImplementedException(); } break; case KindOfFunctionParameters.PositionedParameters: FillUpPositionedParameters(localCodeExecutionContext, function, positionedParameters); break; case KindOfFunctionParameters.NamedParameters: FillUpNamedParameters(localCodeExecutionContext, function, namedParameters); break; default: throw new ArgumentOutOfRangeException(nameof(kindOfParameters), kindOfParameters, null); } localCodeExecutionContext.Holder = currentLocalContext.Holder; var codeFrame = new CodeFrame(); codeFrame.CompiledFunctionBody = function.CompiledFunctionBody; codeFrame.LocalContext = localCodeExecutionContext; var processInfo = new ProcessInfo(); codeFrame.ProcessInfo = processInfo; processInfo.CodeFrame = codeFrame; codeFrame.Metadata = function.CodeEntity; #if DEBUG //Log($"codeFrame = {codeFrame}"); #endif return(codeFrame); }
private void CallFunction(KindOfFunctionParameters kindOfparameters, int parametersCount, bool isSync) { #if DEBUG //Log($"kindOfparameters = {kindOfparameters}"); //Log($"parametersCount = {parametersCount}"); //Log($"isSync = {isSync}"); #endif var valueStack = _currentCodeFrame.ValuesStack; var annotation = valueStack.Pop(); #if DEBUG //Log($"annotation = {annotation}"); //Log($"_currentCodeFrame = {_currentCodeFrame.ToDbgString()}"); #endif var caller = valueStack.Pop(); #if DEBUG //Log($"caller = {caller}"); //Log($"_currentCodeFrame = {_currentCodeFrame.ToDbgString()}"); #endif Dictionary <StrongIdentifierValue, Value> namedParameters = null; List <Value> positionedParameters = null; switch (kindOfparameters) { case KindOfFunctionParameters.NoParameters: break; case KindOfFunctionParameters.NamedParameters: namedParameters = TakeNamedParameters(parametersCount); break; case KindOfFunctionParameters.PositionedParameters: positionedParameters = TakePositionedParameters(parametersCount); break; default: throw new ArgumentOutOfRangeException(nameof(kindOfparameters), kindOfparameters, null); } #if DEBUG //Log($"_currentCodeFrame = {_currentCodeFrame.ToDbgString()}"); //Log($"namedParameters = {namedParameters.WriteDict_1_ToString()}"); //Log($"caller.IsPointRefValue = {caller.IsPointRefValue}"); #endif if (caller.IsPointRefValue) { CallPointRefValue(caller.AsPointRefValue, kindOfparameters, namedParameters, positionedParameters, isSync); return; } if (caller.IsStrongIdentifierValue) { CallStrongIdentifierValue(caller.AsStrongIdentifierValue, kindOfparameters, namedParameters, positionedParameters, isSync); return; } throw new NotImplementedException(); }
private void CallExecutable(IExecutable executable, KindOfFunctionParameters kindOfParameters, Dictionary <StrongIdentifierValue, Value> namedParameters, List <Value> positionedParameters, bool isSync) { if (executable.IsSystemDefined) { Value result = null; switch (kindOfParameters) { case KindOfFunctionParameters.PositionedParameters: result = executable.SystemHandler.Call(positionedParameters, _currentCodeFrame.LocalContext); break; default: throw new ArgumentOutOfRangeException(nameof(kindOfParameters), kindOfParameters, null); } #if DEBUG //Log($"result = {result}"); #endif _currentCodeFrame.ValuesStack.Push(result); #if DEBUG //Log($"_currentCodeFrame = {_currentCodeFrame.ToDbgString()}"); #endif return; } else { var newCodeFrame = ConvertExecutableToCodeFrame(executable, kindOfParameters, namedParameters, positionedParameters); #if DEBUG //Log($"newCodeFrame = {newCodeFrame}"); #endif _context.InstancesStorage.AppendProcessInfo(newCodeFrame.ProcessInfo); #if DEBUG //Log($"isSync = {isSync}"); #endif if (isSync) { _currentCodeFrame.CurrentPosition++; SetCodeFrame(newCodeFrame); } else { _currentCodeFrame.CurrentPosition++; var threadExecutor = new AsyncThreadExecutor(_context); threadExecutor.SetCodeFrame(newCodeFrame); var task = threadExecutor.Start(); _currentCodeFrame.ValuesStack.Push(task); } } }