Esempio n. 1
0
File: CPU.cs Progetto: CalebJ2/KOS
 public bool VariableIsRemovable(Variable variable)
 {
     return !(variable is BoundVariable);
 }
Esempio n. 2
0
File: CPU.cs Progetto: CalebJ2/KOS
 /// <summary>
 /// Try to make a new local variable at the localmost scoping level and
 /// give it a starting value.  It errors out of there is already one there
 /// by the same name.<br/>
 /// <br/>
 /// This does NOT scan up the scoping stack like SetValue() does.
 /// It operates at the local level only.<br/>
 /// <br/>
 /// This is the normal way to make a new local variable.  You cannot make a
 /// local variable without attempting to give it a value.
 /// </summary>
 /// <param name="identifier">variable name to attempt to store into</param>
 /// <param name="value">value to put into it</param>
 public void SetNewLocal(string identifier, object value)
 {
     Variable variable;
     VariableScope localDict = GetNestedDictionary(0);
     if (!localDict.Variables.TryGetValue(identifier, out variable))
     {
         variable = new Variable { Name = identifier };
         AddVariable(variable, identifier, true);
     }
     variable.Value = value;
 }
Esempio n. 3
0
File: CPU.cs Progetto: CalebJ2/KOS
 /// <summary>
 /// Make a new global variable at the localmost scoping level and
 /// give it a starting value, or overwrite an existing variable
 /// at the localmost level with a starting value.<br/>
 /// <br/>
 /// This does NOT scan up the scoping stack like SetValue() does.
 /// It operates at the global level only.<br/>
 /// </summary>
 /// <param name="identifier">variable name to attempt to store into</param>
 /// <param name="value">value to put into it</param>
 public void SetGlobal(string identifier, object value)
 {
     Variable variable;
     // Attempt to get it as a global.  Make a new one if it's not found.
     // This preserves the "bound-ness" of the variable if it's a
     // BoundVariable, whereas unconditionally making a new Variable wouldn't:
     if (!globalVariables.Variables.TryGetValue(identifier, out variable))
     {
         variable = new Variable { Name = identifier };
         AddVariable(variable, identifier, false, true);
     }
     variable.Value = value;
 }
Esempio n. 4
0
File: CPU.cs Progetto: CalebJ2/KOS
        /// <summary>
        /// Make a new variable at either the local depth or the
        /// global depth depending.
        /// throws exception if it already exists as a boundvariable at the desired
        /// scope level, unless overwrite = true.
        /// </summary>
        /// <param name="variable">variable to add</param>
        /// <param name="identifier">name of variable to add</param>
        /// <param name="local">true if you want to make it at local depth</param>
        /// <param name="overwrite">true if it's okay to overwrite an existing variable</param>
        public void AddVariable(Variable variable, string identifier, bool local, bool overwrite = false)
        {
            identifier = identifier.ToLower();

            if (!identifier.StartsWith("$"))
            {
                identifier = "$" + identifier;
            }

            VariableScope whichDict = local ? GetNestedDictionary(0) : globalVariables;
            if (whichDict.Variables.ContainsKey(identifier))
            {
                if (whichDict.Variables[identifier].Value is BoundVariable)
                    if (!overwrite)
                        throw new KOSIdentiferClashException(identifier);
                whichDict.Variables.Remove(identifier);
            }
            whichDict.Variables.Add(identifier, variable);
        }
Esempio n. 5
0
File: CPU.cs Progetto: CalebJ2/KOS
 /// <summary>
 /// Get the value of a variable or create it at global scope if not found.
 /// </summary>
 /// <param name="identifier"></param>
 /// <returns></returns>
 private Variable GetOrCreateVariable(string identifier)
 {
     Variable variable = GetVariable(identifier, false, true);
     if (variable == null)
     {
         variable = new Variable { Name = identifier };
         AddVariable(variable, identifier, false);
     }
     return variable;
 }
Esempio n. 6
0
 public void AddVariable(Variable variable, string identifier, bool local, bool overwrite = false)
 {
     throw new NotImplementedException();
 }