本文整理汇总了C#中Irony.Interpreter.ScriptThread类的典型用法代码示例。如果您正苦于以下问题:C# ScriptThread类的具体用法?C# ScriptThread怎么用?C# ScriptThread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptThread类属于Irony.Interpreter命名空间,在下文中一共展示了ScriptThread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvaluateSpecialForm
// Evaluation for special forms
private object EvaluateSpecialForm(ScriptThread thread)
{
thread.CurrentNode = this; //standard prolog
var result = _specialForm(thread, _specialFormArgs);
thread.CurrentNode = Parent; //standard epilog
return result;
}
示例2: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
thread.CurrentNode = this; //standard prolog
var pi = thread.GetPageInfo();
var test = globalNode.AsString.ToLower();
if (test.Contains(":")) {
Console.WriteLine("");
}
if ( test == "pagenumber") {
return pi.PageNumber;
} else if (test == "pages") {
return pi.TotalPages;
} else if (test == "reportname") {
return pi.ReportName;
} else if (test == "reportfolder") {
return pi.ReportFolder;
} else if (test == "reportfilename") {
return pi.ReportFileName;
}
else {
return String.Format(CultureInfo.CurrentCulture,"Syntaxerror in Globals <{0}>",globalNode.AsString);
}
}
示例3: ExtractLibraryFunctions
public static LibraryFunction[] ExtractLibraryFunctions(ScriptThread thread, object instance)
{
if (instance == null)
return new LibraryFunction[0];
var list = new List<LibraryFunction>();
var languageCaseSensitive = thread.App.Language.Grammar.CaseSensitive;
MethodInfo[] methods = instance.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
foreach (MethodInfo method in methods)
{
var fun = method.CreateDelegate<LibraryDelegate>(instance, false);
if (fun != null)
{
var fname = method.GetCustomAttribute<FunctionNamesAttribute>();
var names = (fname == null) ? new string[] { method.Name } : fname.Names;
foreach (var strName in names)
{
string name = languageCaseSensitive ? strName : strName.ToLowerInvariant();
list.Add(new LibraryFunction(name, fun));
}
}
}
return list.ToArray();
}
示例4: Sum
public static object Sum(ScriptThread thread, AstNode[] childNodes) {
double sum = 0;
var fieldName = childNodes[0].Evaluate(thread).ToString();
var dataSource = thread.GetDataSource();
var grouped = ImportAggregateHelper.IsGrouped(dataSource);
if (grouped != null) {
foreach (var element in grouped) {
var s = element.Sum(o => {
var v = ReadValueFromObject(fieldName, o);
return TypeNormalizer.EnsureType<double>(v);
});
sum = sum + s;
}
} else {
if (ImportAggregateHelper.FieldExist(dataSource.FirstOrDefault(),fieldName)) {
sum = dataSource.Sum(o => {
var v = ReadValueFromObject(fieldName, o);
return TypeNormalizer.EnsureType<double>(v);
});
}
}
return sum.ToString();
}
示例5: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
// standard prolog
thread.CurrentNode = this;
if (EntryPoint == null)
{
thread.ThrowScriptError("No entry point defined (entry point is a function named «Go»)");
return null;
}
// define built-in runtime library functions
var libraryFunctions = LibraryFunction.ExtractLibraryFunctions(thread, new RefalLibrary(thread));
foreach (var libFun in libraryFunctions)
{
var binding = thread.Bind(libFun.Name, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
binding.SetValueRef(thread, libFun);
}
// define functions declared in the compiled program
foreach (var fun in FunctionList)
{
fun.Evaluate(thread);
}
// call entry point with an empty expression
EntryPoint.Call(thread, new object[] { PassiveExpression.Build() });
// standard epilog
thread.CurrentNode = Parent;
return null;
}
示例6: Iif
public static object Iif(ScriptThread thread, AstNode[] childNodes)
{
var testValue = childNodes[0].Evaluate(thread);
object result = thread.Runtime.IsTrue(testValue) ? childNodes[1].Evaluate(thread) : childNodes[2].Evaluate(thread);
return result;
}
示例7: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
thread.CurrentNode = this; //standard prolog
//assign implementation method
switch (Op) {
case ExpressionType.AndAlso:
this.Evaluate = EvaluateAndAlso;
break;
case ExpressionType.OrElse:
this.Evaluate = EvaluateOrElse;
break;
default:
this.Evaluate = DefaultEvaluateImplementation;
break;
}
// actually evaluate and get the result.
var result = Evaluate(thread);
// Check if result is constant - if yes, save the value and switch to method that directly returns the result.
if (IsConstant()) {
_constValue = result;
AsString = Op + "(operator) Const=" + _constValue;
this.Evaluate = EvaluateConst;
}
thread.CurrentNode = Parent; //standard epilog
return result;
}
示例8: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
thread.CurrentNode = this;
try
{
var result = new MtResult();
var targetThread = _target.NewScriptThread(thread);
var rTarget = _target.Evaluate(targetThread) as MtResult;
var sourceThread = _source.NewScriptThread(thread);
var rSource = _source.Evaluate(sourceThread) as MtResult;
rTarget.GetValue(target =>
{
rSource.GetValue(source =>
{
MtStream.ReadFromWriteTo(
source.Value as MtStream, target.Value as MtStream, () => {
result.SetValue(MtObject.True);
});
});
});
return result;
}
catch (Exception e)
{
throw new Exception("Exception on MtFlowRightToLeft.DoEvaluate", e);
}
finally
{
//thread.CurrentNode = Parent;
}
}
示例9: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
// standard prolog
thread.CurrentNode = this;
object result = null;
// is this variable a part of a pattern?
if (UseType == NodeUseType.Name)
{
// don't evaluate it
result = CreateVariable();
}
else
{
// get last recognized pattern
var pattern = thread.GetLastPattern();
if (pattern == null)
{
thread.ThrowScriptError("No pattern recognized!");
return null;
}
// read variable from the last recognized pattern
result = pattern.GetVariable(Index);
}
// standard epilog
thread.CurrentNode = Parent;
return result;
}
示例10: ReallyDoEvaluate
protected override object ReallyDoEvaluate(ScriptThread thread)
{
Context.CurrentAct = actnumber;
thread.rs().Action.At(Span).Label(actnumber);
return base.ReallyDoEvaluate(thread);
}
示例11: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
// standard prolog
thread.CurrentNode = this;
var binding = thread.Bind(FunctionName, BindingRequestFlags.Read);
var result = binding.GetValueRef(thread);
if (result == null)
{
thread.ThrowScriptError("Unknown identifier: {0}", FunctionName);
return null;
}
CallTarget = result as ICallTarget;
if (CallTarget == null)
{
thread.ThrowScriptError("This identifier cannot be called: {0}", FunctionName);
return null;
}
// set Evaluate pointer
Evaluate = DoCall;
// standard epilog is done by DoCall
return DoCall(thread);
}
示例12: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
thread.CurrentNode = this; //standard prolog
var arg = Argument.Evaluate(thread);
var result = thread.Runtime.ExecuteUnaryOperator(base.ExpressionType, arg, ref _lastUsed);
thread.CurrentNode = Parent; //standard epilog
return result;
}
示例13: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
thread.CurrentNode = this; //standard prolog
SetupEvaluateMethod(thread);
var result = Evaluate(thread);
thread.CurrentNode = Parent; //standard epilog
return result;
}
示例14: RefalLibrary
public RefalLibrary(ScriptThread thread)
{
ScriptThread = thread;
OpenFiles = new Dictionary<string, object>();
BuriedKeys = new Dictionary<string, PassiveExpression>();
BuriedValues = new Dictionary<string, PassiveExpression>();
CommandLineArguments = null;
}
示例15: DoEvaluate
protected override object DoEvaluate(ScriptThread thread)
{
thread.CurrentNode = this;
try
{
var programResult = new MtResult();
// do NOT use this for anything else other than counting the number of to-finish-threads
var count = _chains.Count;
var waitForAllToEnd = new ManualResetEvent(false);
// TODO THIS NEEDS TO BE FIXED!
// The rest of the program only cares about the result of the last expression
// which doesn't depend of the result of the previous expressions;
// however, the program shouldn't end.
// SOLUTION: Keep a global counter of all awaiting MtResults?
for (int i = 0; i < _chains.Count; ++i)
{
// This is here because of issues with closures using the for variable
var safe_i = i + 0;
var ch = _chains[i];
var subthread = ch.NewScriptThread(thread);
var chResult = ch.Evaluate(subthread) as MtResult;
// Lookout:
// do not capture anything loop related inside here
chResult.GetValue(delegate(MtObject x)
{
if (Interlocked.Decrement(ref count) == 0)
{
waitForAllToEnd.Set();
}
// Wait for the last chain to end.
// Last refers in the order of the chain in the code,
// not the order of execution!!!
if (safe_i == _chains.Count - 1)
{
// Wait for the end of *all* the chains before returning ...
waitForAllToEnd.WaitOne();
programResult.SetValue(x);
}
});
}
// Return value does not matter. This is asynchronous, remember?
return programResult;
}
catch (Exception e)
{
throw new Exception("Exception on MtProgram.", e);
}
finally
{
//thread.CurrentNode = Parent;
}
}