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); } }
public void Evaluate(EvaluationContext context) { context.PushFrame(MethodName, Node, ParentFrame); try { BindingInfo.Evaluate(context); } finally { context.PopFrame(); }//finally }
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); }
/* public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Binding: _dispatcher = args.Context.Runtime.GetDispatcher(Op); if (_dispatcher == null) args.Context.ReportError(this.Location, "Operator " + Op + " not defined."); break; }//switch base.OnCodeAnalysis(args); } */ 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 void DoEvaluate(EvaluationContext context) { foreach(AstNode node in ChildNodes) { node.Evaluate(context); /* switch (context.Jump) { case JumpType.Goto: //TODO: implement GOTO break; case JumpType.Break: case JumpType.Continue: case JumpType.Return: return; case JumpType.None: continue; //nothing to do, just continue }//switch */ }//foreach }
protected void EvaluateDoNothing(EvaluationContext context) { }
protected void EvaluateWriteParent(EvaluationContext context) { context.CurrentFrame.Parent.Locals[Slot.Index] = context.CurrentResult; }
protected void EvaluateWrite(EvaluationContext context) { context.CurrentFrame.SetValue(Slot, context.CurrentResult); }
protected void EvaluateReadParent(EvaluationContext context) { try { context.CurrentResult = context.CurrentFrame.Parent.Locals[Slot.Index]; } catch (RuntimeException rex) { rex.Location = this.Location; throw; } }
private void EvaluateArgs(EvaluationContext context, FunctionBindingInfo targetInfo) { object[] values = context.CreateCallArgs(this.Arguments.Count); //Just for perfomance, we implement two cases separately if (targetInfo.IsSet(FunctionFlags.HasParamArray)) { //with params array for (int i = 0; i < targetInfo.ParamCount-1; i++) { Arguments[i].Evaluate(context); values[i] = context.CurrentResult; } //Now combine all remaining arguments into one array and put it into the last element int startIndex = targetInfo.ParamCount - 1; int arrayLen = Arguments.Count - startIndex; object[] arrayArgs = new object[arrayLen]; for (int i = 0; i < arrayLen; i++) { Arguments[startIndex + i].Evaluate(context); arrayArgs[i] = context.CurrentResult; } values[startIndex] = arrayArgs; } else { //No params array for (int i = 0; i < Arguments.Count; i++) { Arguments[i].Evaluate(context); values[i] = context.CurrentResult; } } context.CallArgs = values; }
protected void EvaluateOnDefine(EvaluationContext context) { context.CurrentResult = new Closure(context.CurrentFrame, this, BindingInfo); // Body.Evaluate); }
protected override void DoEvaluate(EvaluationContext context) { Expressions.Evaluate(context); }
private void EvaluatePlus(EvaluationContext context) { Arg.Evaluate(context); }
private void EvaluateOther(EvaluationContext context) { Arg.Evaluate(context); context.Arg1 = context.CurrentResult; _dispatcher.Evaluate(context); }
/* public override void OnCodeAnalysis(CodeAnalysisArgs args) { //process child nodes first, so that NameRef is processed base.OnCodeAnalysis(args); switch (args.Phase) { case CodeAnalysisPhase.Binding: if (NameRef.Slot != null) { NameRef.Slot.Flags |= SlotFlags.UsedAsCallTarget; } else { // Slot does not exist so it is not locally-defined method. Let's try global/library function // TODO: implement support for library references at scope level, so that all "import.." statements are checked // before checking global methods FixedTargetInfo = args.Context.Runtime.GetFunctionBindingInfo(NameRef.Name, Arguments); if (FixedTargetInfo == null) { args.Context.ReportError(this.Location, "Method not found: {0}", NameRef.Name); return; } }//else break; case CodeAnalysisPhase.MarkTailCalls: _isTail = IsSet(AstNodeFlags.IsTail) && this.Scope.Level > 0; break; case CodeAnalysisPhase.Optimization: if (this.FixedTargetInfo != null) this.Evaluate = InvokeFixed; else this.Evaluate = InvokeDynamic; break; }//switch }//method */ protected void InvokeDynamic(EvaluationContext context) { NameRef.Evaluate(context); Closure target; try { target = (Closure)context.CurrentResult; if (target.MethodName == null) target.MethodName = NameRef.Name; } catch (InvalidCastException castExc) { throw new RuntimeException("Method [" + NameRef.Name + "] not found or method reference is not set.", castExc, NameRef.Location); } catch (NullReferenceException) { throw new RuntimeException("Method reference is not set in variable " + NameRef.Name, null, NameRef.Location); } EvaluateArgs(context, target.BindingInfo); if (_isTail) { context.Tail = target; return; } //execute non-tail call target.Evaluate(context); if (context.Tail == null) return; //check returning tail while (context.Tail != null) { Closure tail = context.Tail; context.Tail = null; tail.Evaluate(context); } context.CallArgs = null; }
protected override void DoEvaluate(EvaluationContext context) { Expression.Evaluate(context); Identifier.Evaluate(context); //writes the value into the slot }
protected void EvaluateRead(EvaluationContext context) { try { context.CurrentResult = context.CurrentFrame.GetValue(Slot); } catch (RuntimeException rex) { rex.Location = this.Location; throw; } }
protected void InvokeFixed(EvaluationContext context) { EvaluateArgs(context, FixedTargetInfo); FixedTargetInfo.Evaluate(context); //check returning tail if (context.Tail == null) return; while (context.Tail != null) { Closure tail = context.Tail; context.Tail = null; tail.Evaluate(context); } context.CallArgs = null; }