Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/DynamoCore/Library/LibraryServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,24 @@ private void PreloadLibraries(IEnumerable<string> 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<AssociativeNode>();
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)
Expand Down Expand Up @@ -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)
{
Expand Down
80 changes: 39 additions & 41 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<string> { BuiltInPackagesToken, pathManager.UserDataDirectory };
}

if (!PreferenceSettings.CustomPackageFolders.Contains(BuiltInPackagesToken))
{
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -1656,10 +1656,8 @@ private void InitializeNodeLibrary()
// Initialize all nodes inside of this assembly.
InitializeIncludedNodes();

List<TypeLoadData> modelTypes;
List<TypeLoadData> migrationTypes;
Loader.LoadNodeModelsAndMigrations(pathManager.NodeDirectories,
Context, out modelTypes, out migrationTypes);
Context, out var modelTypes, out var migrationTypes);

LoadNodeModels(modelTypes, false);

Expand Down
2 changes: 1 addition & 1 deletion src/DynamoPackages/PackageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions src/Engine/ProtoCore/DSASM/Executive.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions src/Engine/ProtoCore/Utils/CompilerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions src/Engine/ProtoScript/Runners/LiveRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,6 @@ private void CompileAndExecuteForDeltaExecution(string code)
System.Diagnostics.Debug.WriteLine("SyncInternal => " + code);
}

ResetForDeltaExecution();
CompileAndExecute(code);
PostExecution();
}
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -1791,21 +1788,24 @@ public void ResetVMAndResyncGraph(IEnumerable<string> 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<AssociativeNode> importNodes = new List<AssociativeNode>();
foreach (string lib in libraries)
var importNodes = new List<AssociativeNode>();
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);
Expand Down
19 changes: 9 additions & 10 deletions src/Engine/ProtoScript/Runners/ProtoScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
9 changes: 6 additions & 3 deletions test/DynamoCoreTests/CodeBlockNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Dynamo.Engine.CodeCompletion;
using NUnit.Framework;
Expand All @@ -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);
}


Expand Down
Loading