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; } }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; var check = (Object.LpObject)Expr.Evaluate(thread); Object.LpObject result = null; if ((bool)check.boolValue) { result = (Object.LpObject)Stmts.Evaluate(thread); } else if (ElsIfStmts != null) { result = (Object.LpObject)ElsIfStmts.Evaluate(thread); } if (result == null) { if (ElseStmt != null) { result = (Object.LpObject)ElseStmt.Evaluate(thread); } else { result = Object.LpNl.initialize(); } } thread.CurrentNode = Parent; return(result); }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; var state = Node.Evaluate(thread); thread.CurrentNode = Parent; return(state); }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; var obj = (Object.LpObject)Expr.Evaluate(thread); thread.CurrentNode = Parent; return(new object[] { Varname, obj.variables }); }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; // 単一式を評価して、整数を取得する int number = (int)exprNode.Evaluate(thread); thread.CurrentNode = Parent; return(number); }
protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread) { // PROLOG thread.CurrentNode = this; try { var appResult = new MtResult(); MtResult[] args = _args.Evaluate(thread) as MtResult[]; if (args == null) { throw new Exception("Args evaluated to null!"); } var subthreadF = _head.NewScriptThread(thread); var headResult = _head.Evaluate(subthreadF); if (headResult == null) { throw new Exception("Head can't evaluate to null!"); } MtFunctionObjectBase.ExtractAsFunction(headResult, (wrkFun) => { #if DEBUG && !SILVERLIGHT if (wrkFun is BuiltInCallTarget) { var builtin = wrkFun as BuiltInCallTarget; Debug.Print("Calling builtin: {0}", builtin.Name); } else { Debug.Print("Calling user function"); } #endif var resultFun = wrkFun.Call(thread, args) as MtResult; resultFun.GetValue((r3) => { appResult.SetValue(r3); }); }); return(appResult); } catch (Exception e) { throw new Exception("Exception on MtApplication.", e); } finally { // EPILOG //thread.CurrentNode = Parent; } }
protected override void DoEvaluate(EvaluationContext context) { try { Left.Evaluate(context); object arg1 = context.CurrentResult; Right.Evaluate(context); context.Arg2 = context.CurrentResult; context.Arg1 = arg1; _dispatcher.Evaluate(context); } catch (RuntimeException e) { e.Location = this.Location; throw; } }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; var expr = (Object.LpObject)Expr.Evaluate(thread); var whenStmts = (AstNode[][])WhenStmts.Evaluate(thread); var result = cond(thread, expr, whenStmts); if (result == null) { result = (ElseStmt != null) ? (Object.LpObject)ElseStmt.Evaluate(thread) : Object.LpNl.initialize(); } thread.CurrentNode = Parent; return(result); }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; var check = (Object.LpObject)Expr.Evaluate(thread); Object.LpObject result = null; if ((bool)check.boolValue) { result = (Object.LpObject)Stmts.Evaluate(thread); } thread.CurrentNode = Parent; return(result); }
protected override void DoEvaluate(EvaluationContext context) { foreach (CondClauseNode clause in Clauses) { clause.Test.Evaluate(context); if (context.Runtime.IsTrue(context.CurrentResult)) { clause.Expressions.Evaluate(context); return; } }//foreach if (ElseClause != null) { ElseClause.Evaluate(context); } }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; var value = (Object.LpObject)Value.Evaluate(thread); var reference = (object[])VarNode.Evaluate(thread); var Varname = (string)reference[0]; var dic = (IDictionary <string, object>)reference[1]; dic[Varname] = value; thread.CurrentNode = Parent; return(value); }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; Object.LpObject result = null; if(Stmts != null) { result = (Object.LpObject)Stmts.Evaluate(thread); } else { result = Object.LpNl.initialize(); } thread.CurrentNode = Parent; return result; }
private void Evaluate(Grammar grammar, string script, bool expectError, object result) { var compiler = new Compiler(grammar); var context = new CompilerContext(compiler); var source = new SourceStream(script, "source"); AstNode root = compiler.Parse(context, source); compiler.AnalyzeCode(root, context); if (!expectError && context.Errors.Count > 0) { Assert.Fail("Unexpected source error(s) found: " + context.Errors[0].Message); } var evalContext = new EvaluationContext(context.Runtime, root); root.Evaluate(evalContext); Assert.AreEqual(evalContext.CurrentResult, result, "Evaluation result is null, expected " + result); }
protected override void DoEvaluate(EvaluationContext context) { Test.Evaluate(context); if (context.Runtime.IsTrue(context.CurrentResult)) { if (IfTrue != null) { IfTrue.Evaluate(context); } } else { if (IfFalse != null) { IfFalse.Evaluate(context); } } }
protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread) { thread.CurrentNode = this; try { var myRes = new MtResult(); // Eval expression var subthread = _expression.NewScriptThread(thread); var res = _expression.Evaluate(subthread) as MtResult; res.GetValue((resExpr) => { AstNode toEval = null; if (resExpr.Value == MtObject.False.Value) { // Evaluate false branch toEval = _falseBranch; } else { // Evaluate true branch toEval = _trueBranch; } // Evaluate! var subsubthread = toEval.NewScriptThread(thread); var resBranch = toEval.Evaluate(subsubthread) as MtResult; resBranch.GetValue((_resBranch) => { myRes.SetValue(_resBranch); }); }); return(myRes); } catch (Exception e) { throw new Exception("Exception on If.DoEvaluate.", e); } finally { //thread.CurrentNode = Parent; } }
protected override object DoEvaluate(ScriptThread thread) { // PROLOG thread.CurrentNode = this; try { #if SILVERLIGHT var result = new MtResult(); // This is the best we can do in silverlight. There is no BeginInvoke! ThreadPool.QueueUserWorkItem(new WaitCallback(_ => { // synchronous eval :( var headResult = _head.Evaluate(thread); // Wrap it if necessary. if (headResult as ICallTarget != null) { headResult = MtResult.CreateAndWrap(headResult); } if (headResult as MtResult == null) { throw new Exception("Head of chain evaluated to null!"); } var subthread = _tail.NewScriptThread(thread); var accessor = subthread.Bind("_", BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew); accessor.SetValueRef(subthread, headResult); var _tailResult = _tail.Evaluate(subthread) as MtResult; if (_tailResult == null) { throw new Exception("tail of chain evaluated to null!"); } _tailResult.GetValue(o => { result.SetValue(o); }); })); return(result); #else // SILVERLIGHT #if ALL_SYNC // synchronous eval :( var headResult = _head.Evaluate(thread); // Wrap it if necessary. if (headResult as ICallTarget != null) { headResult = MtResult.CreateAndWrap(headResult); } if (headResult as MtResult == null) { throw new Exception("Head of chain evaluated to null!"); } var subthread = _tail.NewScriptThread(thread); var accessor = subthread.Bind("_", BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew); accessor.SetValueRef(subthread, headResult); var _tailResult = _tail.Evaluate(subthread) as MtResult; if (_tailResult == null) { throw new Exception("tail of chain evaluated to null!"); } return(_tailResult); #else // ALL_SYNC MtResult chainResult = new MtResult(); _head.Evaluate.BeginInvoke(thread, iar => { var headResult = _head.Evaluate.EndInvoke(iar); // Wrap if necessary. if (headResult as ICallTarget != null) { headResult = MtResult.CreateAndWrap(headResult); } if (headResult as MtResult == null) { throw new Exception("Head of chain evaluated to null!"); } var subthread = _tail.NewScriptThread(thread); var accessor = subthread.Bind("_", BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew); accessor.SetValueRef(subthread, headResult); var tailResult = _tail.Evaluate(subthread) as MtResult; if (tailResult == null) { throw new Exception("tail of chain evaluated to null!"); } tailResult.GetValue(o => { chainResult.SetValue(o); }); }, null); return(chainResult); #endif // ALL_SYNC #endif // SILVERLIGHT } catch (Exception e) { throw new Exception("Exception on MtChain.DoEvaluate.", e); } finally { // EPILOG //thread.CurrentNode = Parent; } }
protected override void DoEvaluate(EvaluationContext context) { Expression.Evaluate(context); Identifier.Evaluate(context); //writes the value into the slot }
private void EvaluatePlus(EvaluationContext context) { Arg.Evaluate(context); }
private int GetIndex(Irony.Interpreter.ScriptThread thread, AstNode astNode, IEnumerable<object> o, int defaultValue) { object ret = astNode.Evaluate(thread); int retIndex = 0; try { retIndex = Convert.ToInt32(ret); if (retIndex < 0) retIndex = o.Count() + retIndex; // -1 becomes the last; -2 next to last... } catch (Exception) { retIndex = defaultValue; } return retIndex; }
protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; try { var ret = new MtResult(); var emitterThread = _eventEmitter.NewScriptThread(thread); var emitter = _eventEmitter.Evaluate(emitterThread) as MtResult; var listThread = _listener.NewScriptThread(thread); var list = _listener.Evaluate(listThread) as MtResult; emitter.GetValue(o => { list.GetValue(l => { // set listener var wrkEmitter = o.Value as IEventEmitter; if (wrkEmitter == null) { #if DEBUG && !SILVERLIGHT Debug.Print("I dont throw events"); #endif } else { ICallTarget callable = null; var haveCallable = new ManualResetEvent(false); // Extract Callable (Compute it once) MtFunctionObjectBase.ExtractAsFunction( l, fun => { callable = fun; haveCallable.Set(); }); wrkEmitter.On(_eventName, args => { #if DEBUG && !SILVERLIGHT Debug.Print("EventEmitter Called {0}", _eventName); #endif var resArgs = new MtResult[args.Length]; for (var i = 0; i < args.Length; ++i) { resArgs[i] = MtResult.CreateAndWrap(args[i]); } haveCallable.WaitOne(); // Call it var result = callable.Call(thread, resArgs) as MtResult; }); } ret.SetValue(o); }); }); return(ret.WaitForValue()); //return ret; } catch (Exception e) { throw new Exception("Exception on listener statement evaluate", e); } finally { //thread.CurrentNode = Parent; } }