public override void Evaluate(IScriptContext context) { bool condBool; object result = RuntimeHost.NullValue; init.Evaluate(context); cond.Evaluate(context); condBool = context.Result == null ? true : (bool)context.Result; while (condBool) { statement.Evaluate(context); result = context.Result; if (context.IsBreak() || context.IsReturn()) { context.SetBreak(false); break; } if (context.IsContinue()) { context.SetContinue(false); } next.Evaluate(context); cond.Evaluate(context); condBool = context.Result == null ? true : (bool)context.Result; } context.Result = result; }
//TODO: reorganize switch public override void Evaluate(IScriptContext context) { switch (operation) { case "break": if (context.Result == null) { context.Result = RuntimeHost.NullValue; } context.SetBreak(true); break; case "continue": if (context.Result == null) { context.Result = RuntimeHost.NullValue; } context.SetContinue(true); break; case "return": expression.Evaluate(context); context.SetReturn(true); break; case "throw": expression.Evaluate(context); throw (Exception)context.Result; default: throw new ScriptException("This should never happen"); } }
public override void Evaluate(IScriptContext context) { name.Evaluate(context); context.CreateScope(RuntimeHost.ScopeFactory.Create(ScopeTypes.Using, context.Scope, context.Result)); statement.Evaluate(context); context.RemoveLocalScope(); }
public object Invoke(IScriptContext context, object[] args) { activeContext = context; object result = RuntimeHost.NullValue; INotifyingScope functionScope = (INotifyingScope)RuntimeHost.ScopeFactory.Create(ScopeTypes.Function, context.Scope, context); context.CreateScope(functionScope); try { if (Parameters != null) { context.Result = args; Parameters.Evaluate(context); } functionScope.BeforeSetItem += ScopeBeforeSetItem; if (Contract != null) { functionScope.AfterSetItem += CheckContractInvariant; Contract.CheckPre(context); Contract.CheckInv(context); } context.Result = RuntimeHost.NullValue; Body.Evaluate(context); result = context.Result; if (Contract != null) { functionScope.AfterSetItem -= CheckContractInvariant; Contract.CheckInv(context); Contract.CheckPost(context); } } finally { context.RemoveLocalScope(); context.SetBreak(false); context.SetContinue(false); context.SetReturn(false); context.Result = result; functionScope.BeforeSetItem -= ScopeBeforeSetItem; activeContext = null; } return(result); }
/// <summary> /// Evaluates script /// </summary> /// <param name="Context">ScriptContext</param> public virtual void Evaluate(IScriptContext context) { if (ChildNodes.Count > 0) { int index = 0; while (index < ChildNodes.Count) { ScriptAst node = ChildNodes[index] as ScriptAst; if (node != null) { node.Evaluate(context); } index++; } } }
//TODO: Implement Breaking, Returning, etc. here public override void Evaluate(IScriptContext context) { if (ChildNodes.Count == 0) { return; } int index = 0; while (index < ChildNodes.Count) { ScriptAst node = (ScriptAst)ChildNodes[index]; node.Evaluate(context); if (context.IsBreak() || context.IsReturn() || context.IsContinue()) { break; } index++; } }
protected static bool CheckCondition(ScriptAst cond, IScriptContext context) { cond.Evaluate(context); return((bool)context.Result); }
public object Invoke(IScriptContext context, object[] args) { metaProg.Evaluate(context); return(context.Result); }
protected static bool CheckCondition(ScriptAst cond, IScriptContext context) { cond.Evaluate(context); return (bool)context.Result; }