public override BasicNode Eval(BasicEnvironment env) { env.InstructionCount++; if (For.own1 == null || For.own2 == null) { return(env.RuntimeError(ERuntimeErrors.JumpIntoForLoop)); } env.InstructionCount++; var v = Var.GetValue(env) as NumericConstantNode; if (v == null) { return(env.RuntimeError()); } var val = v.Value; val += For.own2.Value; var valNode = new NumericConstantNode(val); Var.SetValue(env, valNode); if (For.LoopStep(env, valNode)) { env.GotoPc(For.Pc + 1); } return(this); }
internal override NumericConstantNode ToNumericConstant() { double val; if (!NumericConstantNode.TryParse(Text, out val)) { return(null); } return(new NumericConstantNode(val)); }
internal bool LoopStep(BasicEnvironment env, NumericConstantNode v) { var cmp = v.Value.CompareTo(own1.Value); if (cmp * Math.Sign(own2.Value) > 0) { env.GotoPc(nextNode.Pc + 1); // jump out of loop own1 = own2 = null; return(false); } return(true); }
private void WriteNumericConstant(NumericConstantNode nu) { var value = nu.Value; if (double.IsNaN(value) || double.IsInfinity(value)) { WriteString(nu.ToString()); return; } if (Math.Sign(value) >= 0) { WriteString(" "); } WriteString(nu.ToString()); WriteString(" "); }
public override BasicNode Eval(BasicEnvironment env) { env.InstructionCount++; own1 = to.Eval(env) as NumericConstantNode; own2 = step.Eval(env) as NumericConstantNode; if (own1 == null || own2 == null) { return(env.RuntimeError()); } //if (own2.Value.IsZero) // return env.RuntimeError(ERuntimeErrors.ZeroStep); var initVal = from.Eval(env); var setRes = Var.SetValue(env, initVal); if (env.HasEnded) { return(this); } LoopStep(env, initVal as NumericConstantNode); return(this); }