tlang-runtime-compiler/TLang.VM/DefaultDependencyPool.cs

53 lines
1.7 KiB
C#
Raw Permalink Normal View History

2023-07-29 00:11:09 +00:00
using System.Collections;
using System.Collections.Generic;
using System.IO;
2023-07-30 07:55:10 +00:00
using System.Linq;
2023-07-29 00:11:09 +00:00
using TLang.Common;
namespace TLang.VM
{
public class DefaultDependencyPool : IDependencyPool
{
List<(TLangDependency Dependency,TVMFile File)> items = new List<(TLangDependency Dependency, TVMFile File)>();
2023-07-30 07:55:10 +00:00
public bool AddDependency(TLangDependency dependency,RootEnvironment env)
2023-07-29 00:11:09 +00:00
{
string fileName = $"{dependency.Name}-{dependency.Version}.tvm";
if(File.Exists(fileName))
{
using(var f = File.OpenRead(fileName))
{
2023-07-30 07:55:10 +00:00
TVMFile file = new TVMFile(f,env);
2023-07-29 00:11:09 +00:00
items.Add((dependency,file));
return file.LoadDependencies(this);
}
}
return false;
}
private static TLangDependencyResponse DefaultDependencyCheck(TLangDependency dep)
{
string fileName = $"{dep.Name}-{dep.Version}.tvm";
if(File.Exists(fileName))
{
return new TLangDependencyResponse(){Stream = File.OpenRead(fileName)};
}
return new TLangDependencyResponse(){Found = false};
}
public bool DependencyExists(TLangDependency dependency)
{
2023-07-30 07:55:10 +00:00
return items.Any(e=>
e.Dependency.Equals(dependency)
);
2023-07-29 00:11:09 +00:00
}
public IEnumerator<(TLangDependency Dependency, TVMFile File)> GetEnumerator()
{
2023-07-30 07:55:10 +00:00
return items.GetEnumerator();
2023-07-29 00:11:09 +00:00
}
IEnumerator IEnumerable.GetEnumerator()
{
2023-07-30 07:55:10 +00:00
return this.GetEnumerator();
2023-07-29 00:11:09 +00:00
}
}
}