public int GetVariable(VariableIdent ident) { if (variables.ContainsKey(ident)) { return variables[ident]; } return -1; }
public void InitVariable(string variable) { VariableIdent ident = new VariableIdent() { FrameId = frameStack.Peek().Id, VariableName = variable }; if (!variables.ContainsKey(ident)) { variables[ident] = new ObjectVariable(new Undefined()); } }
public void AddVariable(VariableIdent ident, int id) { variables.Add(ident, id); }
public void SetVariableValue(string variable, Variable value) { Variable var = FindVariable(variable); if (var != null) { var.SetValue(value.Value); } else { VariableIdent ident = new VariableIdent() { FrameId = frameStack.Peek().Id, VariableName = variable }; variables.Add(ident, value); } }
private Variable FindVariable(string variableName) { Frame currentFrame = frameStack.Peek(); VariableIdent variableIdent = new VariableIdent() { FrameId = currentFrame.Id, VariableName = variableName }; while (!(variables.ContainsKey(variableIdent)) && (currentFrame.Parent != null)) { currentFrame = currentFrame.Parent; variableIdent.FrameId = currentFrame.Id; } if (variables.ContainsKey(variableIdent)) { return variables[variableIdent]; } return null; }