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(); } }
/// <summary> /// Adds a field. FieldDefn must not already exist. /// </summary> /// <param name="name"></param> /// <param name="val"></param> public void AddField(VarDesc v, HeronValue val) { AssureFieldDoesntExist(v.name); fields.Add(v, val); }