Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pushed all remaining changes from CodePlex to GitHub.
- Loading branch information
1 parent
aff2f62
commit 5313216
Showing
169 changed files
with
14,606 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#region License | ||
/* ********************************************************************************** | ||
* Copyright (c) Roman Ivantsov | ||
* This source code is subject to terms and conditions of the MIT License | ||
* for Irony. A copy of the license can be found in the License.txt file | ||
* at the root of this distribution. | ||
* By using this source code in any fashion, you are agreeing to be bound by the terms of the | ||
* MIT License. | ||
* You must not remove this notice from this software. | ||
* **********************************************************************************/ | ||
// This file and all functionality of dynamic assembly reloading was contributed by Alexey Yakovlev (yallie) | ||
#endregion | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Reflection; | ||
using Irony.Parsing; | ||
using System.IO; | ||
using System.Threading; | ||
|
||
namespace Irony.GrammarExplorer { | ||
/// <summary> | ||
/// Maintains grammar assemblies, reloads updated files automatically. | ||
/// </summary> | ||
class GrammarLoader { | ||
private TimeSpan _autoRefreshDelay = TimeSpan.FromMilliseconds(500); | ||
private Dictionary<string, CachedAssembly> _cachedAssemblies = new Dictionary<string, CachedAssembly>(); | ||
|
||
class CachedAssembly { | ||
public long FileSize; | ||
public DateTime LastWriteTime; | ||
public FileSystemWatcher Watcher; | ||
public Assembly Assembly; | ||
} | ||
|
||
public event EventHandler AssemblyUpdated; | ||
|
||
public GrammarItem SelectedGrammar { get; set; } | ||
|
||
public Grammar CreateGrammar() { | ||
if (SelectedGrammar == null) | ||
return null; | ||
|
||
var type = SelectedGrammarAssembly.GetType(SelectedGrammar.TypeName, true, true); | ||
return Activator.CreateInstance(type) as Grammar; | ||
} | ||
|
||
Assembly SelectedGrammarAssembly { | ||
get { | ||
if (SelectedGrammar == null) | ||
return null; | ||
|
||
// create assembly cache entry as needed | ||
var location = SelectedGrammar.Location; | ||
if (!_cachedAssemblies.ContainsKey(location)) { | ||
var fileInfo = new FileInfo(location); | ||
_cachedAssemblies[location] = | ||
new CachedAssembly { | ||
LastWriteTime = fileInfo.LastWriteTime, | ||
FileSize = fileInfo.Length, | ||
Assembly = null | ||
}; | ||
|
||
// set up file system watcher | ||
_cachedAssemblies[location].Watcher = CreateFileWatcher(location); | ||
} | ||
|
||
// get loaded assembly from cache if possible | ||
var assembly = _cachedAssemblies[location].Assembly; | ||
if (assembly == null) { | ||
assembly = LoadAssembly(location); | ||
_cachedAssemblies[location].Assembly = assembly; | ||
} | ||
|
||
return assembly; | ||
} | ||
} | ||
|
||
private FileSystemWatcher CreateFileWatcher(string location) { | ||
var folder = Path.GetDirectoryName(location); | ||
var watcher = new FileSystemWatcher(folder); | ||
watcher.Filter = Path.GetFileName(location); | ||
|
||
watcher.Changed += (s, args) => { | ||
if (args.ChangeType != WatcherChangeTypes.Changed) | ||
return; | ||
// check if assembly was changed indeed to work around multiple FileSystemWatcher event firing | ||
var cacheEntry = _cachedAssemblies[location]; | ||
var fileInfo = new FileInfo(location); | ||
if (cacheEntry.LastWriteTime == fileInfo.LastWriteTime && cacheEntry.FileSize == fileInfo.Length) | ||
return; | ||
// clear cached assembly and save last file update time | ||
cacheEntry.LastWriteTime = fileInfo.LastWriteTime; | ||
cacheEntry.FileSize = fileInfo.Length; | ||
cacheEntry.Assembly = null; | ||
// delay auto-refresh for safety reasons | ||
ThreadPool.QueueUserWorkItem(_ => { | ||
Thread.Sleep(_autoRefreshDelay); | ||
OnAssemblyUpdated(location); | ||
}); | ||
}; | ||
|
||
watcher.EnableRaisingEvents = true; | ||
return watcher; | ||
} | ||
|
||
private void OnAssemblyUpdated(string location) { | ||
if (AssemblyUpdated == null || SelectedGrammar == null || SelectedGrammar.Location != location) | ||
return; | ||
AssemblyUpdated(this, EventArgs.Empty); | ||
} | ||
|
||
Assembly LoadAssembly(string fileName) { | ||
// 1. Assembly.Load doesn't block the file | ||
// 2. Assembly.Load doesn't check if the assembly is already loaded in the current AppDomain | ||
return Assembly.Load(File.ReadAllBytes(fileName)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{321A7F5D-00C2-4095-9970-075CDEE8C139}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Irony.Interpreter</RootNamespace> | ||
<AssemblyName>Irony.Interpreter</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SignAssembly>true</SignAssembly> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<AssemblyOriginatorKeyFile>irony.snk</AssemblyOriginatorKeyFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Numerics" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Ast\Base\BasicTypes.cs" /> | ||
<Compile Include="Ast\Base\AstInterfaces.cs" /> | ||
<Compile Include="Ast\Base\AstNode.cs" /> | ||
<Compile Include="Ast\Expressions\IndexedAccessNode.cs" /> | ||
<Compile Include="Ast\Expressions\MemberAccessNode.cs" /> | ||
<Compile Include="LanguageRuntime\SpecialFormsLibrary.cs" /> | ||
<Compile Include="Ast\Expressions\BinaryOperationNode.cs" /> | ||
<Compile Include="Ast\Expressions\ExpressionListNode.cs" /> | ||
<Compile Include="Ast\Expressions\IfNode.cs" /> | ||
<Compile Include="Ast\Expressions\IncDecNode.cs" /> | ||
<Compile Include="Ast\Expressions\UnaryOperationNode.cs" /> | ||
<Compile Include="Ast\Functions\Closure.cs" /> | ||
<Compile Include="Ast\Functions\FunctionCallNode.cs" /> | ||
<Compile Include="Ast\Functions\FunctionDefNode.cs" /> | ||
<Compile Include="Ast\Functions\ParamListNode.cs" /> | ||
<Compile Include="Ast\PrimitiveNodes\IdentifierNode.cs" /> | ||
<Compile Include="Ast\PrimitiveNodes\LiteralValueNode.cs" /> | ||
<Compile Include="Ast\PrimitiveNodes\StringTemplateNode.cs" /> | ||
<Compile Include="Ast\SpecialNodes\EmptyStatementNode.cs" /> | ||
<Compile Include="Ast\SpecialNodes\NotSupportedNode.cs" /> | ||
<Compile Include="Ast\SpecialNodes\NullNode.cs" /> | ||
<Compile Include="Ast\Statements\AssignmentNode.cs" /> | ||
<Compile Include="Ast\Statements\StatementListNode.cs" /> | ||
<Compile Include="Diagnostics\ScriptException.cs" /> | ||
<Compile Include="Diagnostics\ScriptStackTrace.cs" /> | ||
<Compile Include="Bindings\BindingTargetInfo.cs" /> | ||
<Compile Include="Bindings\IBindingSource.cs" /> | ||
<Compile Include="Utilities\Extensions.cs" /> | ||
<Compile Include="InterpretedLanguageGrammar.cs" /> | ||
<Compile Include="LanguageRuntime\LanguageRuntime.cs" /> | ||
<Compile Include="LanguageRuntime\LanguageRuntime_Binding.cs" /> | ||
<Compile Include="LanguageRuntime\LanguageRuntime_OpDispatch.cs" /> | ||
<Compile Include="LanguageRuntime\LanguageRuntime_OpDispatch_Init.cs" /> | ||
<Compile Include="LanguageRuntime\NoneClass.cs" /> | ||
<Compile Include="LanguageRuntime\OperatorImplementation.cs" /> | ||
<Compile Include="Bindings\BindingRequest.cs" /> | ||
<Compile Include="Bindings\BuiltInObjectBinding.cs" /> | ||
<Compile Include="Bindings\SpecialFormBinding.cs" /> | ||
<Compile Include="Bindings\ModuleExport.cs" /> | ||
<Compile Include="SriptApplication\ConsoleAdaptor.cs" /> | ||
<Compile Include="_Evaluator\ExpressionEvaluator.cs" /> | ||
<Compile Include="_Evaluator\ExpressionEvaluatorGrammar.cs" /> | ||
<Compile Include="_Evaluator\ExpressionEvaluatorRuntime.cs" /> | ||
<None Include="irony.snk" /> | ||
<None Include="Utilities\HotSwapDictionary.cs" /> | ||
<Compile Include="Bindings\Binding.cs" /> | ||
<Compile Include="Bindings\ClrInteropBindings.cs" /> | ||
<Compile Include="Bindings\SlotBinding.cs" /> | ||
<Compile Include="Scopes\Scope.cs" /> | ||
<Compile Include="Scopes\ScopeInfo.cs" /> | ||
<Compile Include="Scopes\ScopeValuesDictionary.cs" /> | ||
<Compile Include="Scopes\AppDataMap.cs" /> | ||
<Compile Include="Scopes\ModuleInfo.cs" /> | ||
<Compile Include="Scopes\SlotInfo.cs" /> | ||
<Compile Include="Scopes\ScopeBase.cs" /> | ||
<Compile Include="SriptApplication\CommandLine.cs" /> | ||
<Compile Include="SriptApplication\ScriptApp.cs" /> | ||
<Compile Include="SriptApplication\ScriptThread.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="Bindings\_about_bindings.txt" /> | ||
<Content Include="Scopes\_about_storage.txt" /> | ||
<Content Include="_about_Irony_Interpreter.txt" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Irony\010.Irony.2010.csproj"> | ||
<Project>{D81F5C91-D7DB-46E5-BC99-49488FB6814C}</Project> | ||
<Name>010.Irony.2010</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#region License | ||
/* ********************************************************************************** | ||
* Copyright (c) Roman Ivantsov | ||
* This source code is subject to terms and conditions of the MIT License | ||
* for Irony. A copy of the license can be found in the License.txt file | ||
* at the root of this distribution. | ||
* By using this source code in any fashion, you are agreeing to be bound by the terms of the | ||
* MIT License. | ||
* You must not remove this notice from this software. | ||
* **********************************************************************************/ | ||
#endregion | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Irony.Parsing; | ||
|
||
namespace Irony.Interpreter.Ast{ | ||
|
||
//This interface is expected by Irony's Gramamr Explorer. | ||
public interface ICallTarget { | ||
object Call(ScriptThread thread, object[] parameters); | ||
} | ||
|
||
//Simple visitor interface | ||
public interface IAstVisitor { | ||
void BeginVisit(IVisitableNode node); | ||
void EndVisit(IVisitableNode node); | ||
} | ||
|
||
public interface IVisitableNode { | ||
void AcceptVisitor(IAstVisitor visitor); | ||
} | ||
|
||
} |
Oops, something went wrong.