progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
59
AspClassic.VBScript/hosting/VBScriptCode.cs
Normal file
59
AspClassic.VBScript/hosting/VBScriptCode.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using AspClassic.Scripting.Runtime;
|
||||
|
||||
using System.Dynamic;
|
||||
#if USE35
|
||||
// Needed for type language implementers need to support DLR Hosting, such as
|
||||
// ScriptCode.
|
||||
using AspClassic.Scripting.Ast;
|
||||
using AspClassic.Scripting.Utils;
|
||||
#else
|
||||
using System.Linq.Expressions;
|
||||
#endif
|
||||
using AspClassic.Scripting;
|
||||
using Dlrsoft.VBScript.Runtime;
|
||||
|
||||
namespace Dlrsoft.VBScript.Hosting
|
||||
{
|
||||
class VBScriptCode : ScriptCode
|
||||
{
|
||||
//private readonly Expression<Action<VBScript, IDynamicMetaObjectProvider>> _lambda;
|
||||
private readonly VBScript _vbscript;
|
||||
private AspClassic.Scripting.Utils.Action<VBScript, IDynamicMetaObjectProvider> _compiledLambda;
|
||||
|
||||
public VBScriptCode(
|
||||
VBScript vbscript,
|
||||
AspClassic.Scripting.Utils.Action<VBScript, IDynamicMetaObjectProvider> lambda,
|
||||
SourceUnit sourceUnit)
|
||||
: base(sourceUnit) {
|
||||
_compiledLambda = lambda;
|
||||
_vbscript = vbscript;
|
||||
}
|
||||
|
||||
public override object Run() {
|
||||
return Run(new Scope());
|
||||
}
|
||||
|
||||
public override object Run(Scope scope) {
|
||||
//if (_compiledLambda == null) {
|
||||
// _compiledLambda = _lambda.Compile();
|
||||
//}
|
||||
//LC Load the system by default
|
||||
//RuntimeHelpers.VBScriptImport(_vbscript, module, new string[] { "System" }, new string[] { }, new string[] { });
|
||||
//RuntimeHelpers.VBScriptImport(_vbscript, module, new string[] { "VBScript", "Runtime" }, new string[] { "BuiltInFunctions" }, new string[] { "BuiltIn" });
|
||||
|
||||
//if (this.SourceUnit.Kind == SourceCodeKind.File)
|
||||
//{
|
||||
// // Simple way to convey script rundir for RuntimeHelpers.SymplImport
|
||||
// // to load .sympl files relative to the current script file.
|
||||
// DynamicObjectHelpers.SetMember(module, "__file__",
|
||||
// Path.GetFullPath(this.SourceUnit.Path));
|
||||
//}
|
||||
_compiledLambda(_vbscript, scope);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
93
AspClassic.VBScript/hosting/VBScriptContext.cs
Normal file
93
AspClassic.VBScript/hosting/VBScriptContext.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AspClassic.Scripting.Runtime;
|
||||
|
||||
using System.Dynamic;
|
||||
#if USE35
|
||||
// Needed for type language implementers need to support DLR Hosting, such as
|
||||
// ScriptCode.
|
||||
using AspClassic.Scripting.Ast;
|
||||
#else
|
||||
using System.Linq.Expressions;
|
||||
#endif
|
||||
using AspClassic.Scripting;
|
||||
using Dlrsoft.VBScript.Runtime;
|
||||
using Dlrsoft.VBScript.Compiler;
|
||||
using AspClassic.Scripting.Utils;
|
||||
|
||||
namespace Dlrsoft.VBScript.Hosting
|
||||
{
|
||||
public class VBScriptContext : LanguageContext
|
||||
{
|
||||
private readonly VBScript _vbscript;
|
||||
|
||||
public VBScriptContext(ScriptDomainManager manager,
|
||||
IDictionary<string, object> options)
|
||||
: base(manager) {
|
||||
// TODO: parse options
|
||||
// TODO: register event manager.AssemblyLoaded
|
||||
_vbscript = new VBScript(manager.GetLoadedAssemblyList(), manager.Globals);
|
||||
|
||||
if (options.ContainsKey("Trace") && options["Trace"].Equals(true))
|
||||
{
|
||||
_vbscript.Trace = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
|
||||
{
|
||||
using (var reader = sourceUnit.GetReader()) {
|
||||
try
|
||||
{
|
||||
switch (sourceUnit.Kind)
|
||||
{
|
||||
case SourceCodeKind.SingleStatement:
|
||||
case SourceCodeKind.Expression:
|
||||
case SourceCodeKind.AutoDetect:
|
||||
case SourceCodeKind.InteractiveCode:
|
||||
return new VBScriptCode(
|
||||
_vbscript, _vbscript.ParseExprToLambda(reader),
|
||||
sourceUnit);
|
||||
case SourceCodeKind.Statements:
|
||||
case SourceCodeKind.File:
|
||||
return new VBScriptCode(
|
||||
_vbscript,
|
||||
_vbscript.ParseFileToLambda(sourceUnit.Path, reader),
|
||||
sourceUnit);
|
||||
default:
|
||||
throw Assert.Unreachable;
|
||||
}
|
||||
}
|
||||
catch (VBScriptCompilerException ex)
|
||||
{
|
||||
VBScriptSourceCodeReader vbscriptReader = reader as VBScriptSourceCodeReader;
|
||||
if (vbscriptReader != null)
|
||||
{
|
||||
ISourceMapper mapper = vbscriptReader.SourceMapper;
|
||||
if (mapper != null)
|
||||
{
|
||||
foreach (VBScriptSyntaxError error in ex.SyntaxErrors)
|
||||
{
|
||||
DocSpan docSpan = mapper.Map(error.Span);
|
||||
error.FileName = docSpan.Uri;
|
||||
error.Span = docSpan.Span;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Real language implementation would have a specific type
|
||||
// of exception. Also, they would pass errorSink down into
|
||||
// the parser and add messages while doing tighter error
|
||||
// recovery and continuing to parse.
|
||||
errorSink.Add(sourceUnit, e.Message, SourceSpan.None, 0,
|
||||
Severity.FatalError);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue