public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.AssignScopes: // for all child nodes we define a new scope OwnerScope = base.Scope; base.Scope = new Scope(this, OwnerScope); Scope.ParamCount = Parameters.ChildNodes.Count; break; case CodeAnalysisPhase.MarkTailCalls: Body.Flags |= AstNodeFlags.IsTail; //unconditionally set body's tail flag break; }//switch //process child nodes base.OnCodeAnalysis(args); //The following actions should be performed AFTER we process child nodes switch (args.Phase) { case CodeAnalysisPhase.Binding: BindingInfo.LocalCount = Scope.Slots.Count; //there may be two different evaluation cases: // 1. Evaluation of function definition - this is when Evaluate function of this node is called. Normally this method should // set the variable associated with function name to point to the evaluation method. The value is a reference to the actual // evaluation method; it is either Evaluate method of new closure (if this function needs closure), or simply reference // to static evaluation method; for definition, we need to do what is needed in this.Evaluate method. this.Evaluate = EvaluateOnDefine; // 2. Actual function call and evaluation of the body. // All functions are closures, so the caller finds a closure in the function name's slot. // The caller invokes then closure.Evaluate, which in turn pushes a frame // into framestack and invokes BindingInfo.Evaluate. The BindingInfo.Evaluate points to // Body.Evaluate - we provide this method as implementation to the BindingInfo constructor - // (see the constructor of AnonFunctionNode(this) class). break; }//switch }
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 }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Allocate: if (IsSet(AstNodeFlags.AllocateSlot) && !Scope.SlotDefined(Name)) { Slot = Scope.CreateSlot(Name); } break; case CodeAnalysisPhase.Binding: Slot = Scope.FindSlot(Name); if (Slot == null && !IsSet(AstNodeFlags.SuppressNotDefined)) { args.Context.ReportError(this.Location, "Variable " + Name + " is not declared"); } if (Slot != null) { //unless suppressed, mark this ID use as RValue if (!IsSet(AstNodeFlags.NotRValue)) { Slot.Flags |= SlotFlags.UsedAsRValue; } if (IsSet(AstNodeFlags.IsLValue)) { Slot.Flags |= SlotFlags.ExplicitlyAssigned; } } SetupEvaluateMethod(); break; }//switch base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.MarkTailCalls: if (IsSet(AstNodeFlags.IsTail)) Expressions.Flags |= AstNodeFlags.IsTail; break; } base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.MarkTailCalls: if (IsSet(AstNodeFlags.IsTail) && ChildNodes.Count > 0) ChildNodes[ChildNodes.Count - 1].Flags |= AstNodeFlags.IsTail; break; } base.OnCodeAnalysis(args); }
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); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.MarkTailCalls: if (IsSet(AstNodeFlags.IsTail)) { foreach (CondClauseNode clause in Clauses) clause.Flags |= AstNodeFlags.IsTail; ElseClause.Flags |= AstNodeFlags.IsTail; } break; } base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Binding: if (Op == "+U") Evaluate = EvaluatePlus; else { _dispatcher = args.Context.Runtime.GetDispatcher(Op); Evaluate = EvaluateOther; } break; }//switch base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.MarkTailCalls: if (IsSet(AstNodeFlags.IsTail)) { Expressions.Flags |= AstNodeFlags.IsTail; } break; } base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.MarkTailCalls: if (IsSet(AstNodeFlags.IsTail)) { if (IfTrue != null) IfTrue.Flags |= AstNodeFlags.IsTail; if (IfFalse != null) IfFalse.Flags |= AstNodeFlags.IsTail; } break; } base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.MarkTailCalls: if (IsSet(AstNodeFlags.IsTail) && ChildNodes.Count > 0) { ChildNodes[ChildNodes.Count - 1].Flags |= AstNodeFlags.IsTail; } break; } base.OnCodeAnalysis(args); }
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); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.MarkTailCalls: if (IsSet(AstNodeFlags.IsTail)) { foreach (CondClauseNode clause in Clauses) { clause.Flags |= AstNodeFlags.IsTail; } ElseClause.Flags |= AstNodeFlags.IsTail; } break; } base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Binding: if (Op == "+U") { Evaluate = EvaluatePlus; } else { _dispatcher = args.Context.Runtime.GetDispatcher(Op); Evaluate = EvaluateOther; } break; }//switch base.OnCodeAnalysis(args); }
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.MarkTailCalls: if (IsSet(AstNodeFlags.IsTail)) { if (IfTrue != null) { IfTrue.Flags |= AstNodeFlags.IsTail; } if (IfFalse != null) { IfFalse.Flags |= AstNodeFlags.IsTail; } } break; } base.OnCodeAnalysis(args); }
}//constructor 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
public override void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Allocate: if (IsSet(AstNodeFlags.AllocateSlot) && !Scope.SlotDefined(Name)) Slot = Scope.CreateSlot(Name); break; case CodeAnalysisPhase.Binding: Slot = Scope.FindSlot(Name); if (Slot == null && !IsSet(AstNodeFlags.SuppressNotDefined)) args.Context.ReportError(this.Location, "Variable " + Name + " is not declared"); if (Slot != null) { //unless suppressed, mark this ID use as RValue if (!IsSet(AstNodeFlags.NotRValue)) Slot.Flags |= SlotFlags.UsedAsRValue; if (IsSet(AstNodeFlags.IsLValue)) Slot.Flags |= SlotFlags.ExplicitlyAssigned; } SetupEvaluateMethod(); break; }//switch base.OnCodeAnalysis(args); }
public virtual void OnCodeAnalysis(CodeAnalysisArgs args) { switch (args.Phase) { case CodeAnalysisPhase.Init: foreach (AstNode child in ChildNodes) { child.Parent = this; child.Scope = null; } break; case CodeAnalysisPhase.AssignScopes: foreach (AstNode child in ChildNodes) { if (child.Scope == null) //don't override if it already exists { child.Scope = this.Scope; } } break; case CodeAnalysisPhase.MarkTailCalls: //if (!IsSet(AstNodeFlags.IsTail)) args.SkipChildren = true; break; }//switch if (ChildNodes.Count > 0 && !args.SkipChildren) { foreach (AstNode child in ChildNodes) { child.OnCodeAnalysis(args); } } args.SkipChildren = false; }//method