diff --git a/src/OneScript.Core/Compilation/Binding/ScopeBindingDescriptor.cs b/src/OneScript.Core/Compilation/Binding/ScopeBindingDescriptor.cs index c8127c84d..d32f62785 100644 --- a/src/OneScript.Core/Compilation/Binding/ScopeBindingDescriptor.cs +++ b/src/OneScript.Core/Compilation/Binding/ScopeBindingDescriptor.cs @@ -41,8 +41,8 @@ private ScopeBindingDescriptor(ScopeBindingKind kind, IAttachableContext target, public static ScopeBindingDescriptor Static(IAttachableContext target) => new ScopeBindingDescriptor(ScopeBindingKind.Static, target, -1); - public static ScopeBindingDescriptor ThisScope() - => new ScopeBindingDescriptor(ScopeBindingKind.ThisScope, null, -1); + public static ScopeBindingDescriptor ThisScope(IAttachableContext target=null) + => new ScopeBindingDescriptor(ScopeBindingKind.ThisScope, target, -1); public static ScopeBindingDescriptor FrameScope(int index) => new ScopeBindingDescriptor(ScopeBindingKind.FrameScope, null, index); diff --git a/src/OneScript.Core/Compilation/CompilerFrontendBase.cs b/src/OneScript.Core/Compilation/CompilerFrontendBase.cs index a3272ebe0..4bb811116 100644 --- a/src/OneScript.Core/Compilation/CompilerFrontendBase.cs +++ b/src/OneScript.Core/Compilation/CompilerFrontendBase.cs @@ -4,9 +4,8 @@ This Source Code Form is subject to the terms of the was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ -using System; -using System.Collections.Generic; using OneScript.Compilation.Binding; +using OneScript.Contexts; using OneScript.DependencyInjection; using OneScript.Execution; using OneScript.Language; @@ -14,6 +13,8 @@ This Source Code Form is subject to the terms of the using OneScript.Language.SyntaxAnalysis; using OneScript.Language.SyntaxAnalysis.AstNodes; using OneScript.Sources; +using System; +using System.Collections.Generic; namespace OneScript.Compilation { @@ -64,6 +65,17 @@ public IExecutableModule Compile(SourceCode source, IBslProcess process, Type cl return CompileInternal(symbols, parsedModule, classType, process); } + public IExecutableModule Compile(SourceCode source, IBslProcess process, T target) + where T : IAttachableContext + { + var lexer = CreatePreprocessor(source); + var symbols = PrepareSymbols(target); + var parsedModule = ParseSyntaxConstruction(lexer, source, p => p.ParseStatefulModule()); + + return CompileInternal(symbols, parsedModule, typeof(T), process); + } + + public IExecutableModule CompileExpression(SourceCode source) { var lexer = new DefaultLexer @@ -91,7 +103,7 @@ public IExecutableModule CompileBatch(SourceCode source) protected abstract IExecutableModule CompileBatchInternal(SymbolTable symbols, ModuleNode parsedModule); - private SymbolTable PrepareSymbols() + private SymbolTable PrepareSymbols(IAttachableContext target = null) { var actualTable = new SymbolTable(); if (SharedSymbols != default) @@ -104,7 +116,7 @@ private SymbolTable PrepareSymbols() } ModuleSymbols ??= new SymbolScope(); - actualTable.PushScope(ModuleSymbols, ScopeBindingDescriptor.ThisScope()); + actualTable.PushScope(ModuleSymbols, ScopeBindingDescriptor.ThisScope(target)); return actualTable; } diff --git a/src/OneScript.Core/Compilation/ICompilerFrontend.cs b/src/OneScript.Core/Compilation/ICompilerFrontend.cs index 809acac6a..30294bdfb 100644 --- a/src/OneScript.Core/Compilation/ICompilerFrontend.cs +++ b/src/OneScript.Core/Compilation/ICompilerFrontend.cs @@ -4,12 +4,13 @@ This Source Code Form is subject to the terms of the was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ -using System; -using System.Collections.Generic; using OneScript.Compilation.Binding; +using OneScript.Contexts; using OneScript.Execution; using OneScript.Language; using OneScript.Sources; +using System; +using System.Collections.Generic; namespace OneScript.Compilation { @@ -27,9 +28,13 @@ public interface ICompilerFrontend IErrorSink ErrorSink { get; } - IExecutableModule Compile(SourceCode source, IBslProcess process, Type classType = null); - - IExecutableModule CompileExpression(SourceCode source); + IExecutableModule Compile(SourceCode source, IBslProcess process, Type classType = null); + + public IExecutableModule Compile(SourceCode source, IBslProcess process, T target) + where T : IAttachableContext; + + + IExecutableModule CompileExpression(SourceCode source); IExecutableModule CompileBatch(SourceCode source); } diff --git a/src/OneScript.Core/Exceptions/IExceptionInfoFactory.cs b/src/OneScript.Core/Exceptions/IExceptionInfoFactory.cs index c623b4c0a..6fdb45233 100644 --- a/src/OneScript.Core/Exceptions/IExceptionInfoFactory.cs +++ b/src/OneScript.Core/Exceptions/IExceptionInfoFactory.cs @@ -16,7 +16,7 @@ namespace OneScript.Exceptions /// public interface IExceptionInfoFactory { - BslObjectValue GetExceptionInfo(Exception exception); + BslValue GetExceptionInfo(Exception exception); string GetExceptionDescription(IRuntimeContextInstance exceptionInfo); diff --git a/src/OneScript.Native/Compiler/ExpressionHelpers.cs b/src/OneScript.Native/Compiler/ExpressionHelpers.cs index 8ed0f479e..32ead529f 100644 --- a/src/OneScript.Native/Compiler/ExpressionHelpers.cs +++ b/src/OneScript.Native/Compiler/ExpressionHelpers.cs @@ -297,6 +297,11 @@ private static Expression TryFindConversionOp(Expression value, Type targetType) // если будет ненадежно - поиграем с поиском статических конверсий try { + if (targetType == typeof(string)) + { + return Expression.Call(value, "ToString", null, null); + } + return Expression.Convert(value, targetType); } catch (InvalidOperationException) @@ -595,18 +600,12 @@ public static Expression CallOfInstanceMethod(Expression instance, string name, public static Expression AccessModuleVariable(ParameterExpression thisArg, int variableIndex) { - var contextProperty = PropertiesCache.GetOrAdd( - typeof(NativeClassInstanceWrapper), - nameof(NativeClassInstanceWrapper.Context), - BindingFlags.Instance | BindingFlags.Public); - - var contextAccess = Expression.Property(thisArg, contextProperty); var getVariableMethod = OperationsCache.GetOrAdd( typeof(IAttachableContext), nameof(IAttachableContext.GetVariable), BindingFlags.Instance | BindingFlags.Public); - var iVariable = Expression.Call(contextAccess, getVariableMethod, Expression.Constant(variableIndex)); + var iVariable = Expression.Call(thisArg, getVariableMethod, Expression.Constant(variableIndex)); var valueProperty = PropertiesCache.GetOrAdd( typeof(IValueReference), nameof(IValueReference.BslValue), diff --git a/src/OneScript.Native/Compiler/MethodCompiler.cs b/src/OneScript.Native/Compiler/MethodCompiler.cs index a2be74b8c..c925b8bf8 100644 --- a/src/OneScript.Native/Compiler/MethodCompiler.cs +++ b/src/OneScript.Native/Compiler/MethodCompiler.cs @@ -142,7 +142,7 @@ private void CompileFragment(BslSyntaxNode node, Action visitor) private void FillParameterVariables() { _declaredParameters = _method.GetBslParameters(); - _thisParameter = _method.IsInstance ? Expression.Parameter(typeof(NativeClassInstanceWrapper), "$this") : null; + _thisParameter = _method.IsInstance ? Expression.Parameter(typeof(IAttachableContext), "$this") : null; var localScope = Symbols.GetScope(Symbols.ScopeCount-1); foreach (var parameter in _declaredParameters) @@ -1107,56 +1107,13 @@ private static bool InjectedProcessNeeded(MethodInfo methodInfo) } protected override void VisitObjectProcedureCall(BslSyntaxNode node) - { - var target = _statementBuildParts.Pop(); - var call = (CallNode) node; - - var targetType = target.Type; - var name = call.Identifier.GetIdentifier(); - if (targetType.IsObjectValue()) - { - var methodInfo = FindMethodOfType(node, targetType, name); - var injectProcess = InjectedProcessNeeded(methodInfo); - var args = PrepareCallArguments(call.ArgumentList, methodInfo.GetParameters(), injectProcess); - - _blocks.Add(Expression.Call(target, methodInfo, args)); - } - else if (targetType.IsContext()) - { - var contextCall = ExpressionHelpers.CallContextMethod(target, name, _processParameter, - PrepareDynamicCallArguments(call.ArgumentList)); - _blocks.Add(contextCall); - } - else if (targetType.IsValue()) - { - var contextCall = ExpressionHelpers.TryCallContextMethod(target, name, _processParameter, - PrepareDynamicCallArguments(call.ArgumentList)); - _blocks.Add(contextCall); - } - else if (target is DynamicExpression) - { - var args = new List(); - args.Add(target); - args.AddRange(PrepareDynamicCallArguments(call.ArgumentList)); - - var csharpArgs = new List(); - csharpArgs.Add(CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, default)); - csharpArgs.AddRange(args.Select(x => CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, default))); - - var binder = Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember( - CSharpBinderFlags.InvokeSimpleName, - name, - null, - typeof(BslObjectValue), - csharpArgs); + { + _blocks.Add(CreateObjectMethodCall(node)); + } - var objectExpr = Expression.Dynamic(binder, typeof(object), args); - _blocks.Add(ExpressionHelpers.ConvertToType(objectExpr, typeof(BslValue))); - } - else - { - AddError(NativeCompilerErrors.TypeIsNotAnObjectType(targetType), node.Location); - } + protected override void VisitObjectFunctionCall(BslSyntaxNode node) + { + _statementBuildParts.Push(CreateObjectMethodCall(node, true)); } private IEnumerable PrepareDynamicCallArguments(BslSyntaxNode argList) @@ -1167,44 +1124,49 @@ private IEnumerable PrepareDynamicCallArguments(BslSyntaxNode argLis : Expression.Constant(BslSkippedParameterValue.Instance)); } - protected override void VisitObjectFunctionCall(BslSyntaxNode node) - { + private Expression CreateObjectMethodCall(BslSyntaxNode node, bool asFunction = false) + { var target = _statementBuildParts.Pop(); - var call = (CallNode) node; - + var call = (CallNode)node; var targetType = target.Type; var name = call.Identifier.GetIdentifier(); - if (targetType.IsObjectValue()) - { - var methodInfo = FindMethodOfType(node, targetType, name); - if (methodInfo.ReturnType == typeof(void)) - { - throw new NativeCompilerException(BilingualString.Localize( - $"Метод {targetType}.{name} не является функцией", - $"Method {targetType}.{name} is not a function"), ToCodePosition(node.Location)); - } - var args = PrepareCallArguments(call.ArgumentList, methodInfo.GetParameters(), InjectedProcessNeeded(methodInfo)); - _statementBuildParts.Push(Expression.Call(target, methodInfo, args)); + if (targetType.IsObjectValue() + && TryFindMethodOfType(targetType, name, out var methodInfo)) + { + if (asFunction && methodInfo?.ReturnType == typeof(void)) + { + throw new NativeCompilerException(BilingualString.Localize( + $"Метод {targetType}.{name} не является функцией", + $"Method {targetType}.{name} is not a function"), ToCodePosition(node.Location)); + } + + var args = PrepareCallArguments(call.ArgumentList, methodInfo.GetParameters(), InjectedProcessNeeded(methodInfo)); + return Expression.Call(target, methodInfo, args); } - else if (targetType.IsContext()) + + if (targetType.IsContext()) { - _statementBuildParts.Push(ExpressionHelpers.CallContextMethod(target, name, _processParameter, PrepareDynamicCallArguments(call.ArgumentList))); + return ExpressionHelpers.CallContextMethod(target, name, _processParameter, + PrepareDynamicCallArguments(call.ArgumentList)); } else if (targetType.IsValue()) { - var contextCall = ExpressionHelpers.TryCallContextMethod(target, name, _processParameter, + return ExpressionHelpers.TryCallContextMethod(target, name, _processParameter, PrepareDynamicCallArguments(call.ArgumentList)); - _statementBuildParts.Push(contextCall); } else if (target is DynamicExpression) { - var args = new List(); - args.Add(target); + var args = new List + { + target + }; args.AddRange(PrepareDynamicCallArguments(call.ArgumentList)); - var csharpArgs = new List(); - csharpArgs.Add(CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, default)); + var csharpArgs = new List + { + CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, default) + }; csharpArgs.AddRange(args.Select(x => CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, default))); var binder = Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember( @@ -1215,12 +1177,11 @@ protected override void VisitObjectFunctionCall(BslSyntaxNode node) csharpArgs); var objectExpr = Expression.Dynamic(binder, typeof(object), args); - _statementBuildParts.Push(ExpressionHelpers.ConvertToType(objectExpr, typeof(BslValue))); - } - else - { - AddError(NativeCompilerErrors.TypeIsNotAnObjectType(targetType), node.Location); + return ExpressionHelpers.ConvertToType(objectExpr, typeof(BslValue)); } + + AddError(NativeCompilerErrors.TypeIsNotAnObjectType(targetType), node.Location); + return null; } private MethodInfo FindMethodOfType(BslSyntaxNode node, Type targetType, string name) @@ -1240,6 +1201,21 @@ private MethodInfo FindMethodOfType(BslSyntaxNode node, Type targetType, string return methodInfo; } + private bool TryFindMethodOfType(Type targetType, string name, out MethodInfo methodInfo) + { + try + { + methodInfo = _methodsCache.GetOrAdd(targetType, name); + } + catch (InvalidOperationException) + { + methodInfo = null; + return false; + } + + return true; + } + private PropertyInfo TryFindPropertyOfType(BslSyntaxNode node, Type targetType, string name) { PropertyInfo propertyInfo; @@ -1281,15 +1257,21 @@ private Expression CreateMethodCall(CallNode node) } var symbol = Symbols.GetScope(binding.ScopeNumber).Methods[binding.MemberNumber]; - var args = PrepareCallArguments(node.ArgumentList, symbol.Method.GetParameters(), InjectedProcessNeeded(symbol.Method)); + var args = PrepareCallArguments(node.ArgumentList, symbol.Method.GetParameters(), + InjectedProcessNeeded(symbol.Method), IsModuleScope(binding.ScopeNumber)); var methodInfo = symbol.Method; if (methodInfo is ContextMethodInfo contextMethod) { - return DirectClrCall( + var call = DirectClrCall( GetMethodBinding(binding, symbol), contextMethod.GetWrappedMethod(), args); + + if (call.Type == typeof(IValue)) + return Expression.TypeAs(call, typeof(BslValue)); + + return call; } if (methodInfo is BslNativeMethodInfo nativeMethod) @@ -1328,9 +1310,8 @@ private Expression CreateBuiltInFunctionCall(CallNode node) result = DirectConversionCall(node, typeof(DateTime)); break; case Token.Type: - CheckArgumentsCount(node.ArgumentList, 1); - result = ExpressionHelpers.TypeByNameCall(CurrentTypeManager, - ConvertToExpressionTree(node.ArgumentList.Children[0].Children[0])); + var strType = DirectConversionCall(node, typeof(string)); + result = ExpressionHelpers.TypeByNameCall(CurrentTypeManager, strType); break; case Token.ExceptionInfo: CheckArgumentsCount(node.ArgumentList, 0); @@ -1364,7 +1345,9 @@ private Expression GetRuntimeExceptionDescription() var excVariable = _blocks.GetCurrentBlock().CurrentException; Expression factoryArgument; // нас вызвали вне попытки-исключения - factoryArgument = excVariable == null ? Expression.Constant(null, typeof(IRuntimeContextInstance)) : GetRuntimeExceptionObject(); + //factoryArgument = excVariable == null ? Expression.Constant(null, typeof(IRuntimeContextInstance)) : GetRuntimeExceptionObject(); + factoryArgument = excVariable == null ? Expression.Constant(null, typeof(IRuntimeContextInstance)) + : ExpressionHelpers.ConvertToType(GetRuntimeExceptionObject(), typeof(IRuntimeContextInstance)); var factory = Expression.Constant(ExceptionInfoFactory); return ExpressionHelpers.CallOfInstanceMethod( @@ -1417,9 +1400,10 @@ private Expression DirectConversionCall(CallNode node, Type type) return ExpressionHelpers.ConvertToType( ConvertToExpressionTree(node.ArgumentList.Children[0].Children[0]), type); - } - - private List PrepareCallArguments(BslSyntaxNode argList, ParameterInfo[] declaredParameters, bool injectsProcess) + } + + private List PrepareCallArguments(BslSyntaxNode argList, ParameterInfo[] declaredParameters, + bool injectsProcess, bool passUndef = false) { var factArguments = new List(); @@ -1474,6 +1458,10 @@ private List PrepareCallArguments(BslSyntaxNode argList, ParameterIn { factArguments.Add(Expression.Constant(declaredParam.DefaultValue, declaredParam.ParameterType)); } + else if (passUndef) + { + factArguments.Add(Expression.Constant(BslUndefinedValue.Instance, declaredParam.ParameterType)); + } else { var errText = new BilingualString( @@ -1544,12 +1532,12 @@ protected override void VisitNewObjectCreation(NewObjectNode node) } else { - parameters = new Expression[0]; + parameters = []; } if (node.IsDynamic) { - var typeName = ConvertToExpressionTree(node.TypeNameNode); + var typeName = ExpressionHelpers.ConvertToType(ConvertToExpressionTree(node.TypeNameNode), typeof(string)); var call = ExpressionHelpers.ConstructorCall(CurrentTypeManager, services, typeName, _processParameter, parameters); _statementBuildParts.Push(call); } diff --git a/src/OneScript.Native/Runtime/CallableMethod.cs b/src/OneScript.Native/Runtime/CallableMethod.cs index f61237aad..f44f3b138 100644 --- a/src/OneScript.Native/Runtime/CallableMethod.cs +++ b/src/OneScript.Native/Runtime/CallableMethod.cs @@ -27,7 +27,7 @@ internal class CallableMethod { private readonly BslNativeMethodInfo _method; - private delegate BslValue NativeCallable(NativeClassInstanceWrapper target, BslValue[] args, IBslProcess process); + private delegate BslValue NativeCallable(IAttachableContext target, BslValue[] args, IBslProcess process); private NativeCallable _delegate; @@ -47,23 +47,16 @@ public BslValue Invoke(IBslProcess process, object target, BslValue[] args) return _delegate.Invoke(callableWrapper, args, process); } - private NativeClassInstanceWrapper GetCallableWrapper(object obj) + private IAttachableContext GetCallableWrapper(object obj) { - NativeClassInstanceWrapper callableWrapper; + IAttachableContext callableWrapper; if (_method.IsInstance) { if (obj == null) throw new InvalidOperationException($"Method {_method.Name} is not static and requires target"); - if (obj is NativeClassInstanceWrapper w) + if (obj is IAttachableContext context) { - callableWrapper = w; - } - else if (obj is IAttachableContext context) - { - callableWrapper = new NativeClassInstanceWrapper - { - Context = context - }; + callableWrapper = context; } else { @@ -86,7 +79,7 @@ private static NativeCallable CreateDelegate(BslNativeMethodInfo method) if (method.Implementation == default) throw new InvalidOperationException("Method has no implementation"); - var targetParam = Expression.Parameter(typeof(NativeClassInstanceWrapper)); + var targetParam = Expression.Parameter(typeof(IAttachableContext)); var arrayOfValuesParam = Expression.Parameter(typeof(BslValue[])); var processParam = Expression.Parameter(typeof(IBslProcess)); var convertedAccessList = new List(); diff --git a/src/OneScript.Native/Runtime/DynamicOperations.cs b/src/OneScript.Native/Runtime/DynamicOperations.cs index 13289a4c2..af8c9ca86 100644 --- a/src/OneScript.Native/Runtime/DynamicOperations.cs +++ b/src/OneScript.Native/Runtime/DynamicOperations.cs @@ -134,7 +134,7 @@ public static T StrictConstructorCall(ITypeManager typeManager, IServiceConta where T : BslValue => (T)ConstructorCall(typeManager, services, typeName, process, args); - public static BslObjectValue GetExceptionInfo(IExceptionInfoFactory factory, Exception e) + public static BslValue GetExceptionInfo(IExceptionInfoFactory factory, Exception e) => factory.GetExceptionInfo(e); public static BslTypeValue GetTypeByName(ITypeManager manager, string name) diff --git a/src/OneScript.Native/Runtime/NativeClassInstanceWrapper.cs b/src/OneScript.Native/Runtime/NativeClassInstanceWrapper.cs deleted file mode 100644 index 4a69fef6e..000000000 --- a/src/OneScript.Native/Runtime/NativeClassInstanceWrapper.cs +++ /dev/null @@ -1,20 +0,0 @@ -/*---------------------------------------------------------- -This Source Code Form is subject to the terms of the -Mozilla Public License, v.2.0. If a copy of the MPL -was not distributed with this file, You can obtain one -at http://mozilla.org/MPL/2.0/. -----------------------------------------------------------*/ -using System; -using OneScript.Contexts; - -namespace OneScript.Native.Runtime -{ - /// - /// Этот класс можно удалить, заменив все обращения к нему на IAttachableContext - /// - [Obsolete("This class can be removed, replace all usages with IAttachableContext")] - internal class NativeClassInstanceWrapper - { - public IAttachableContext Context { get; set; } - } -} diff --git a/src/ScriptEngine.HostedScript/LibraryLoader.cs b/src/ScriptEngine.HostedScript/LibraryLoader.cs index 7a5cea07d..ff43efffe 100644 --- a/src/ScriptEngine.HostedScript/LibraryLoader.cs +++ b/src/ScriptEngine.HostedScript/LibraryLoader.cs @@ -5,19 +5,20 @@ This Source Code Form is subject to the terms of the at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ -using ScriptEngine.Machine; -using ScriptEngine.Machine.Contexts; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using OneScript.Commons; using OneScript.Compilation; using OneScript.Contexts; using OneScript.Exceptions; using OneScript.Execution; +using OneScript.Sources; using OneScript.Values; using ScriptEngine.Libraries; +using ScriptEngine.Machine; +using ScriptEngine.Machine.Contexts; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; namespace ScriptEngine.HostedScript { @@ -28,7 +29,7 @@ public class LibraryLoader : AutoScriptDrivenObject private readonly ScriptingEngine _engine; private readonly bool _customized; - private readonly Stack _librariesInProgress = new Stack(); + private readonly Stack _librariesInProgress = []; private struct DelayLoadedScriptData { @@ -70,17 +71,30 @@ private LibraryLoader(IRuntimeEnvironment env, _libManager = libManager; _engine = engine; _customized = false; - } - + } + + private LibraryLoader(ScriptingEngine engine) : base(EmptyModule.Instance,true) + { + _env = engine.Environment; + _libManager = engine.LibraryManager; + _engine = engine; + _customized = true; + } + #region Static part - + public static LibraryLoader Create(ScriptingEngine engine, string processingScript, IBslProcess process) { var compiler = engine.GetCompilerService(); var code = engine.Loader.FromFile(processingScript); - var module = CompileModule(compiler, code, typeof(LibraryLoader), process); - - return new LibraryLoader(module, engine.Environment, engine.LibraryManager, engine, process); + + var loader = new LibraryLoader(engine); + CompileModule(compiler, code, loader, process); + + loader.InitOwnData(); + loader._engine.InitializeSDO(loader, process); + + return loader; } public static LibraryLoader Create(ScriptingEngine engine, IBslProcess process) @@ -200,7 +214,7 @@ private bool CustomizedProcessing(string libraryPath, IBslProcess process) return DefaultProcessing(libraryPath, process); } - CallScriptMethod(eventIdx, new[] { libPathValue, defaultLoading, cancelLoading }, process); + CallScriptMethod(eventIdx, [libPathValue, defaultLoading, cancelLoading], process); if (cancelLoading.AsBoolean()) // Отказ = Ложь return false; @@ -209,7 +223,6 @@ private bool CustomizedProcessing(string libraryPath, IBslProcess process) return DefaultProcessing(libraryPath, process); return true; - } private bool DefaultProcessing(string libraryPath, IBslProcess process) diff --git a/src/ScriptEngine/Machine/Contexts/AutoScriptDrivenObject.cs b/src/ScriptEngine/Machine/Contexts/AutoScriptDrivenObject.cs index cbd910a61..c8395189a 100644 --- a/src/ScriptEngine/Machine/Contexts/AutoScriptDrivenObject.cs +++ b/src/ScriptEngine/Machine/Contexts/AutoScriptDrivenObject.cs @@ -152,6 +152,15 @@ public static IExecutableModule CompileModule(ICompilerFrontend compiler, Source compiler.FillSymbols(typeof(AutoScriptDrivenObject)); return compiler.Compile(src, process, type); } + + public static IExecutableModule CompileModule(ICompilerFrontend compiler, SourceCode src, T instance, IBslProcess process) + { + compiler.FillSymbols(typeof(AutoScriptDrivenObject)); + + var module = compiler.Compile(src, process, instance); + instance.SetModule(module); + return module; + } } } diff --git a/src/ScriptEngine/Machine/Contexts/ScriptDrivenObject.cs b/src/ScriptEngine/Machine/Contexts/ScriptDrivenObject.cs index 49d473c3a..8721bcb39 100644 --- a/src/ScriptEngine/Machine/Contexts/ScriptDrivenObject.cs +++ b/src/ScriptEngine/Machine/Contexts/ScriptDrivenObject.cs @@ -45,7 +45,7 @@ protected ScriptDrivenObject() { } - protected void SetModule(StackRuntimeModule module) + protected void SetModule(IExecutableModule module) { _module = module; } diff --git a/src/ScriptEngine/Machine/ExceptionInfoFactory.cs b/src/ScriptEngine/Machine/ExceptionInfoFactory.cs index bcbd04ed3..aa7eed7cd 100644 --- a/src/ScriptEngine/Machine/ExceptionInfoFactory.cs +++ b/src/ScriptEngine/Machine/ExceptionInfoFactory.cs @@ -27,7 +27,7 @@ public ExceptionInfoFactory(IBslProcessFactory processFactory) _processFactory = processFactory; } - public BslObjectValue GetExceptionInfo(Exception exception) + public BslValue GetExceptionInfo(Exception exception) { if (exception == null) {