diff --git a/src/DynamoCore/Library/LibraryServices.cs b/src/DynamoCore/Library/LibraryServices.cs index a19de90d230..e3c8d6fe9f1 100644 --- a/src/DynamoCore/Library/LibraryServices.cs +++ b/src/DynamoCore/Library/LibraryServices.cs @@ -192,8 +192,24 @@ private void PreloadLibraries(IEnumerable preloadLibraries) { importedLibraries.AddRange(preloadLibraries); - foreach (var library in importedLibraries) - CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library); + //foreach (var library in importedLibraries) + //{ + // CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library); + //} + // generate import node for each library in input list + var importNodes = new List(); + foreach (string lib in importedLibraries) + { + var importNode = new ImportNode + { + ModuleName = lib + }; + + importNodes.Add(importNode); + } + var codeGen = new CodeGenDS(importNodes); + string code = codeGen.GenerateCode(); + CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, code); } internal bool FunctionSignatureNeedsAdditionalAttributes(string functionSignature) @@ -586,7 +602,8 @@ internal bool LoadNodeLibrary(string library, bool isExplicitlyImportedLib) var classTable = LibraryManagementCore.ClassTable; int classNumber = classTable.ClassNodes.Count; - CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library); + string importStatement = @"import (""" + CompilerUtils.ToLiteral(library) + @""");"; + CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, importStatement); if(functionTable == null) { diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index 7065d8a8659..31185dcbca4 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -706,7 +706,7 @@ protected DynamoModel(IStartConfiguration config) bool areAnalyticsDisabledFromConfig = false; if (!IsServiceMode) - { // Skip getting the value for areAnalyticsDisabledFromConfig because analytics is disabled for searvice mode anyway + { // Skip getting the value for areAnalyticsDisabledFromConfig because analytics is disabled for service mode anyway try { // Dynamo, behind a proxy server, has been known to have issues loading the Analytics binaries. @@ -798,7 +798,9 @@ protected DynamoModel(IStartConfiguration config) // is no additional location specified. Otherwise, update pathManager.PackageDirectories to include // PackageFolders if (PreferenceSettings.CustomPackageFolders.Count == 0) + { PreferenceSettings.CustomPackageFolders = new List { BuiltInPackagesToken, pathManager.UserDataDirectory }; + } if (!PreferenceSettings.CustomPackageFolders.Contains(BuiltInPackagesToken)) { @@ -813,52 +815,51 @@ protected DynamoModel(IStartConfiguration config) var userCommonPackageFolder = pathManager.CommonPackageDirectory; AddPackagePath(userCommonPackageFolder); - // Load Python Template - // The loading pattern is conducted in the following order - // 1) Set from DynamoSettings.XML - // 2) Set from API via the configuration file - // 3) Set from PythonTemplate.py located in 'C:\Users\USERNAME\AppData\Roaming\Dynamo\Dynamo Core\2.X' - // 4) Set from OOTB hard-coded default template - - // If a custom python template path doesn't already exists in the DynamoSettings.xml - if (string.IsNullOrEmpty(PreferenceSettings.PythonTemplateFilePath) || - !File.Exists(PreferenceSettings.PythonTemplateFilePath) && !IsServiceMode) - { - // To supply a custom python template host integrators should supply a 'DefaultStartConfiguration' config file - // or create a new struct that inherits from 'DefaultStartConfiguration' making sure to set the 'PythonTemplatePath' - // while passing the config to the 'DynamoModel' constructor. - if (config is DefaultStartConfiguration) - { - var configurationSettings = (DefaultStartConfiguration)config; - var templatePath = configurationSettings.PythonTemplatePath; + // Load Python Template + // The loading pattern is conducted in the following order + // 1) Set from DynamoSettings.XML + // 2) Set from API via the configuration file + // 3) Set from PythonTemplate.py located in 'C:\Users\USERNAME\AppData\Roaming\Dynamo\Dynamo Core\2.X' + // 4) Set from OOTB hard-coded default template - // If a custom python template path was set in the config apply that template - if (!string.IsNullOrEmpty(templatePath) && File.Exists(templatePath)) - { - PreferenceSettings.PythonTemplateFilePath = templatePath; - Logger.Log(Resources.PythonTemplateDefinedByHost + " : " + PreferenceSettings.PythonTemplateFilePath); - } + // If a custom python template path doesn't already exists in the DynamoSettings.xml + if (string.IsNullOrEmpty(PreferenceSettings.PythonTemplateFilePath) || + !File.Exists(PreferenceSettings.PythonTemplateFilePath) && !IsServiceMode) + { + // To supply a custom python template host integrators should supply a 'DefaultStartConfiguration' config file + // or create a new struct that inherits from 'DefaultStartConfiguration' making sure to set the 'PythonTemplatePath' + // while passing the config to the 'DynamoModel' constructor. + if (config is DefaultStartConfiguration) + { + var configurationSettings = (DefaultStartConfiguration)config; + var templatePath = configurationSettings.PythonTemplatePath; - // Otherwise fallback to the default - else - { - SetDefaultPythonTemplate(); - } + // If a custom python template path was set in the config apply that template + if (!string.IsNullOrEmpty(templatePath) && File.Exists(templatePath)) + { + PreferenceSettings.PythonTemplateFilePath = templatePath; + Logger.Log(Resources.PythonTemplateDefinedByHost + " : " + + PreferenceSettings.PythonTemplateFilePath); } + // Otherwise fallback to the default else { - // Fallback to the default SetDefaultPythonTemplate(); } } - else { - // A custom python template path already exists in the DynamoSettings.xml - Logger.Log(Resources.PythonTemplateUserFile + " : " + PreferenceSettings.PythonTemplateFilePath); + // Fallback to the default + SetDefaultPythonTemplate(); } - + } + else + { + // A custom python template path already exists in the DynamoSettings.xml + Logger.Log(Resources.PythonTemplateUserFile + " : " + PreferenceSettings.PythonTemplateFilePath); + } + pathManager.Preferences = PreferenceSettings; PreferenceSettings.RequestUserDataFolder += pathManager.GetUserDataFolder; @@ -930,8 +931,7 @@ protected DynamoModel(IStartConfiguration config) AuthenticationManager = new AuthenticationManager(config.AuthProvider); - Logger.Log(string.Format("Dynamo -- Build {0}", - Assembly.GetExecutingAssembly().GetName().Version)); + Logger.Log($"Dynamo -- Build {Assembly.GetExecutingAssembly().GetName().Version}"); DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenLoadNodeLibrary, 50)); InitializeNodeLibrary(); @@ -1012,7 +1012,7 @@ protected DynamoModel(IStartConfiguration config) //Disposed writer if it is in file system mode so that the index files can be used by other processes (potentially a second Dynamo session) if (LuceneUtility.startConfig.StorageType == LuceneSearchUtility.LuceneStorage.FILE_SYSTEM) { - LuceneUtility.DisposeWriter(); + LuceneUtility.DisposeWriter(); } @@ -1656,10 +1656,8 @@ private void InitializeNodeLibrary() // Initialize all nodes inside of this assembly. InitializeIncludedNodes(); - List modelTypes; - List migrationTypes; Loader.LoadNodeModelsAndMigrations(pathManager.NodeDirectories, - Context, out modelTypes, out migrationTypes); + Context, out var modelTypes, out var migrationTypes); LoadNodeModels(modelTypes, false); diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index e880fe2549c..a7b640453d3 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -248,7 +248,7 @@ private void TryLoadPackageIntoLibrary(Package package) // load custom nodes var packageInfo = new Graph.Workspaces.PackageInfo(package.Name, new Version(package.VersionName)); - // skip loding if the CustomNodeDirectory does not exist + // skip loading if the CustomNodeDirectory does not exist var customNodes = Directory.Exists(package.CustomNodeDirectory)? OnRequestLoadCustomNodeDirectory(package.CustomNodeDirectory, packageInfo) : []; package.LoadedCustomNodes.AddRange(customNodes); diff --git a/src/Engine/ProtoCore/DSASM/Executive.cs b/src/Engine/ProtoCore/DSASM/Executive.cs index ecc0a89a0f2..dc62db50b45 100644 --- a/src/Engine/ProtoCore/DSASM/Executive.cs +++ b/src/Engine/ProtoCore/DSASM/Executive.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -176,7 +176,10 @@ public StackValue BounceUsingExecutive( { rmem.PushFrameForLocals(locals); rmem.PushStackFrame(stackFrame); - runtimeCore.DebugProps.SetUpBounce(exec, stackFrame.FunctionCallerBlock, stackFrame.ReturnPC); + if (runtimeCore.Options.IDEDebugMode && runtimeCore.Options.RunMode != InterpreterMode.Expression) + { + runtimeCore.DebugProps.SetUpBounce(exec, stackFrame.FunctionCallerBlock, stackFrame.ReturnPC); + } } executive.Execute(exeblock, entry, breakpoints); return executive.RX; diff --git a/src/Engine/ProtoCore/Utils/CompilerUtils.cs b/src/Engine/ProtoCore/Utils/CompilerUtils.cs index 060a38b8fda..6058205d13b 100644 --- a/src/Engine/ProtoCore/Utils/CompilerUtils.cs +++ b/src/Engine/ProtoCore/Utils/CompilerUtils.cs @@ -202,9 +202,11 @@ public static ProtoCore.BuildStatus PreCompile(string code, Core core, CodeBlock try { //defining the global Assoc block that wraps the entire .ds source file - ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); - globalBlock.Language = ProtoCore.Language.Associative; - globalBlock.Code = code; + var globalBlock = new ProtoCore.LanguageCodeBlock + { + Language = ProtoCore.Language.Associative, + Code = code + }; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); @@ -246,18 +248,17 @@ internal static string ToLiteral(string input) } } - public static bool TryLoadAssemblyIntoCore(Core core, string assemblyPath) + public static bool TryLoadAssemblyIntoCore(Core core, string /*assemblyPath*/ code) { bool parsingPreloadFlag = core.IsParsingPreloadedAssembly; bool parsingCbnFlag = core.IsParsingCodeBlockNode; core.IsParsingPreloadedAssembly = true; core.IsParsingCodeBlockNode = false; - int blockId; - string importStatement = @"import (""" + ToLiteral(assemblyPath) + @""");"; + //string importStatement = @"import (""" + ToLiteral(assemblyPath) + @""");"; core.ResetForPrecompilation(); - var status = PreCompile(importStatement, core, null, out blockId); + var status = PreCompile(/*importStatement*/ code, core, null, out _); core.IsParsingPreloadedAssembly = parsingPreloadFlag; core.IsParsingCodeBlockNode = parsingCbnFlag; diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index 41b391401de..792695feacc 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -1637,7 +1637,6 @@ private void CompileAndExecuteForDeltaExecution(string code) System.Diagnostics.Debug.WriteLine("SyncInternal => " + code); } - ResetForDeltaExecution(); CompileAndExecute(code); PostExecution(); } @@ -1739,15 +1738,13 @@ private void SynchronizeInternal(string code) { runnerCore.Options.IsDeltaCompile = true; + ResetForDeltaExecution(); + if (string.IsNullOrEmpty(code)) { - ResetForDeltaExecution(); return; } - else - { - CompileAndExecuteForDeltaExecution(code); - } + CompileAndExecuteForDeltaExecution(code); } /// @@ -1791,21 +1788,24 @@ public void ResetVMAndResyncGraph(IEnumerable libraries) // Reset VM. This needs to be in mutex context as it turns DSExecutable null. ReInitializeLiveRunner(); - if (!libraries.Any()) + var enumerable = libraries.ToList(); + if (!enumerable.Any()) { return; } // generate import node for each library in input list - List importNodes = new List(); - foreach (string lib in libraries) + var importNodes = new List(); + foreach (string lib in enumerable) { - ProtoCore.AST.AssociativeAST.ImportNode importNode = new ProtoCore.AST.AssociativeAST.ImportNode(); - importNode.ModuleName = lib; + var importNode = new ImportNode + { + ModuleName = lib + }; importNodes.Add(importNode); } - ProtoCore.CodeGenDS codeGen = new ProtoCore.CodeGenDS(importNodes); + var codeGen = new CodeGenDS(importNodes); string code = codeGen.GenerateCode(); SynchronizeInternal(code); diff --git a/src/Engine/ProtoScript/Runners/ProtoScriptRunner.cs b/src/Engine/ProtoScript/Runners/ProtoScriptRunner.cs index 0bf4cc3a034..bdc816cf1f6 100644 --- a/src/Engine/ProtoScript/Runners/ProtoScriptRunner.cs +++ b/src/Engine/ProtoScript/Runners/ProtoScriptRunner.cs @@ -21,14 +21,15 @@ private bool Compile(string code, ProtoCore.Core core, ProtoCore.CompileTime.Con //String strSource = ProtoCore.Utils.LexerUtils.HashAngleReplace(code); //defining the global Assoc block that wraps the entire .ds source file - ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); - globalBlock.Language = ProtoCore.Language.Associative; - globalBlock.Code = code; + var globalBlock = new ProtoCore.LanguageCodeBlock + { + Language = ProtoCore.Language.Associative, + Code = code + }; //passing the global Assoc wrapper block to the compiler ProtoCore.Language id = globalBlock.Language; - int blockId = Constants.kInvalidIndex; - core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink); + core.Compilers[id].Compile(out _, null, globalBlock, context, EventSink); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; @@ -145,15 +146,13 @@ public ProtoCore.RuntimeCore ExecuteLive(ProtoCore.Core core, ProtoCore.RuntimeC { try { - Executable exe = runtimeCore.DSExecutable; - Validity.Assert(exe.CodeBlocks.Count == 1); + Validity.Assert(runtimeCore.DSExecutable.CodeBlocks.Count == 1); CodeBlock codeBlock = runtimeCore.DSExecutable.CodeBlocks[0]; - int codeBlockID = codeBlock.codeBlockId; // Comment Jun: // On first bounce, the stackframe depth is initialized to -1 in the Stackfame constructor. // Passing it to bounce() increments it so the first depth is always 0 - ProtoCore.DSASM.StackFrame stackFrame = new ProtoCore.DSASM.StackFrame(core.GlobOffset); + var stackFrame = new ProtoCore.DSASM.StackFrame(core.GlobOffset); stackFrame.FramePointer = runtimeCore.RuntimeMemory.FramePointer; // Comment Jun: Tell the new bounce stackframe that this is an implicit bounce @@ -165,7 +164,7 @@ public ProtoCore.RuntimeCore ExecuteLive(ProtoCore.Core core, ProtoCore.RuntimeC int locals = 0; // This is the global scope, there are no locals if (runtimeCore.CurrentExecutive.CurrentDSASMExec == null) { - ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore); + var interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore); runtimeCore.CurrentExecutive.CurrentDSASMExec = interpreter.runtime; } diff --git a/test/DynamoCoreTests/CodeBlockNodeTests.cs b/test/DynamoCoreTests/CodeBlockNodeTests.cs index 12674e18b1a..6b11399bbb7 100644 --- a/test/DynamoCoreTests/CodeBlockNodeTests.cs +++ b/test/DynamoCoreTests/CodeBlockNodeTests.cs @@ -1897,8 +1897,9 @@ public void Resolve_NamespaceConflict_LoadLibrary() // FFITarget.Dummy.Point, FFITarget.Dynamo.Point const string libraryPath = "FFITarget.dll"; + string importStatement = @"import (""" + CompilerUtils.ToLiteral(libraryPath) + @""");"; CompilerUtils.TryLoadAssemblyIntoCore( - CurrentDynamoModel.LibraryServices.LibraryManagementCore, libraryPath); + CurrentDynamoModel.LibraryServices.LibraryManagementCore, importStatement); code = "Point.ByCoordinates(0,0,0);"; UpdateCodeBlockNodeContent(cbn, code); @@ -2136,7 +2137,8 @@ public void Init() libraryServicesCore.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(libraryServicesCore)); libraryServicesCore.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(libraryServicesCore)); - CompilerUtils.TryLoadAssemblyIntoCore(libraryServicesCore, libraryPath); + var importStatement = @"import (""" + CompilerUtils.ToLiteral(libraryPath) + @""");"; + CompilerUtils.TryLoadAssemblyIntoCore(libraryServicesCore, importStatement); } [TearDown] @@ -2388,8 +2390,9 @@ public void TestMethodSignatureReturnTypeCompletion() public void TestBuiltInMethodSignatureCompletion() { const string libraryPath = "BuiltIn.ds"; + string importStatement = @"import (""" + CompilerUtils.ToLiteral(libraryPath) + @""");"; - CompilerUtils.TryLoadAssemblyIntoCore(libraryServicesCore, libraryPath); + CompilerUtils.TryLoadAssemblyIntoCore(libraryServicesCore, importStatement); var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); diff --git a/test/DynamoCoreTests/Engine/CodeCompletion/CodeCompletionServicesTest.cs b/test/DynamoCoreTests/Engine/CodeCompletion/CodeCompletionServicesTest.cs index a48efc3094d..06c0b6122a2 100644 --- a/test/DynamoCoreTests/Engine/CodeCompletion/CodeCompletionServicesTest.cs +++ b/test/DynamoCoreTests/Engine/CodeCompletion/CodeCompletionServicesTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using Dynamo.Engine.CodeCompletion; using NUnit.Framework; @@ -25,7 +25,8 @@ public void Init() libraryServicesCore.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(libraryServicesCore)); libraryServicesCore.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(libraryServicesCore)); - CompilerUtils.TryLoadAssemblyIntoCore(libraryServicesCore, libraryPath); + var importStmt = @"import (""" + CompilerUtils.ToLiteral(libraryPath) + @""");"; + CompilerUtils.TryLoadAssemblyIntoCore(libraryServicesCore, importStmt); }