Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
78 changes: 37 additions & 41 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,52 +813,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)
// 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;

// If a custom python template path was set in the config apply that template
if (!string.IsNullOrEmpty(templatePath) && File.Exists(templatePath))
{
var configurationSettings = (DefaultStartConfiguration)config;
var templatePath = configurationSettings.PythonTemplatePath;

// 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
{
SetDefaultPythonTemplate();
}
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 +929,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 +1010,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 +1654,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
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
Loading