Upsilon/Upsilon/ModuleHandler.cs

30 lines
899 B
C#

using System.Collections.Generic;
using Upsilon.Binder;
using Upsilon.Evaluator;
namespace Upsilon
{
public class ModuleHandler
{
private readonly Dictionary<string, BoundScript> _cachedModules = new Dictionary<string, BoundScript>();
public virtual BoundScript GetModule(Script script, string name)
{
if (_cachedModules.TryGetValue(name, out var module))
return module;
var moduleScript = script.Options.ScriptLoader.LoadModule(name);
if (moduleScript == null)
return null;
var parsed = Executor.ContinueWith(script, moduleScript, name);
module = parsed.Bind();
_cachedModules.Add(name, module);
return module;
}
public void ClearCachedModule(string name)
{
_cachedModules.Remove(name);
}
}
}