public void ImportScope(Scope scope) { foreach (var @var in scope.Locals) { CurScope.SetVar(@var.Key, @var.Value); } }
public override Expression Evaluate() { Expression res; for (int i = 0; i < Conditions.Count; i++) { res = Conditions[i].ReduceEvaluate(); if (CurScope.GetBool("debug")) { CurScope.SideEffects.Add(new DebugData("Debug if cond[" + i + "]: " + Conditions[i] + " = " + res)); } if (res is Error) { return(res); } if (res is Boolean) { // If true if (res as Boolean) { res = Expressions[i].ReduceEvaluate(); if (CurScope.GetBool("debug")) { CurScope.SideEffects.Add(new DebugData("Debug if expr[" + i + "]: " + Expressions[i] + " = " + res)); } return(res); } } else { return(new Error(this, "Condition " + i + ": " + Conditions[i] + " does not evaluate to bool")); } } if (Expressions.Count > Conditions.Count) { res = Expressions[Expressions.Count - 1].Evaluate(); if (CurScope.GetBool("debug")) { CurScope.SideEffects.Add(new DebugData("Debug if[" + (Expressions.Count - 1) + "]: " + Expressions[Expressions.Count - 1] + " = " + res)); } return(res); } return(Constant.Null); }