private void GetFreeVars(VM vm, Statement st, Stack<string> boundVars, Scope result) { // InternalCount and store the names defined by this statement int nNewVars = 0; foreach (string name in st.GetDefinedNames()) { ++nNewVars; boundVars.Push(name); } // Iterate over all names used by expressions in the statement foreach (string name in st.GetUsedNames()) { // Is this not a boundVar, and not already marked as a free var if (!boundVars.Contains(name) && !result.HasName(name)) { // Throws an exception if the name is not found HeronValue v = vm.LookupName(name); result.Add(new VarDesc(name), v); } } // Recurse over all sub statements, getting the free vars foreach (Statement child in st.GetSubStatements()) GetFreeVars(vm, child, boundVars, result); // Pop all variables added by this variable for (int i = 0; i < nNewVars; ++i) boundVars.Pop(); }
private void GetFreeVars(VM vm, Statement st, Stack <string> boundVars, Scope result) { // InternalCount and store the names defined by this statement int nNewVars = 0; foreach (string name in st.GetDefinedNames()) { ++nNewVars; boundVars.Push(name); } // Iterate over all names used by expressions in the statement foreach (string name in st.GetUsedNames()) { // Is this not a boundVar, and not already marked as a free var if (!boundVars.Contains(name) && !result.HasName(name)) { // Throws an exception if the name is not found HeronValue v = vm.LookupName(name); result.Add(new VarDesc(name), v); } } // Recurse over all sub statements, getting the free vars foreach (Statement child in st.GetSubStatements()) { GetFreeVars(vm, child, boundVars, result); } // Pop all variables added by this variable for (int i = 0; i < nNewVars; ++i) { boundVars.Pop(); } }
public override HeronValue Eval(VM vm) { using (vm.CreateScope()) { vm.AddVar(new VarDesc(acc), vm.Eval(init)); vm.AddVar(new VarDesc(each), HeronValue.Null); foreach (HeronValue x in vm.EvalListAsDotNet(list)) { vm.SetVar(each, x); vm.SetVar(acc, vm.Eval(expr)); } return(vm.LookupName(acc)); } }
public override HeronValue Eval(VM vm) { return(vm.LookupName(name)); }