Esempio n. 1
0
        public void SetValue(Symbol key, SchemeObject value, bool isDefinition)
        {
            SchemeEnvironment env = this;
            if (!isDefinition)
            {
                for (; env != null; env = env.parent)
                    if (env.dictionary.ContainsKey(key))
                        break;

                if (env == null)
                    throw new InvalidSyntaxException();
            }
            env.dictionary[key] = value;
        }
Esempio n. 2
0
        private static Datum BuildRestArgument(SchemeObject[] arguments, int index)
        {
            if (index == arguments.Length)
                return SchemeNull.Instance;

            Pair current = new Pair(SchemeNull.Instance, SchemeNull.Instance);
            Pair list = current;
            for (; index < arguments.Length - 1; index++)
            {
                current.Car = arguments[index];
                current.Cdr = new Pair(SchemeNull.Instance, SchemeNull.Instance);
                current = (Pair)current.Cdr;
            }

            current.Car = arguments[index];
            return list;
        }
Esempio n. 3
0
        private static SchemeEnvironment BuildCallEnvironment(SchemeObject[] arguments, Closure closure)
        {
            ReadOnlyCollection<Variable> parameters = closure.Parameters;
            Variable restParameter = closure.RestParameter;

            if (arguments.Length != parameters.Count && restParameter == null)
                throw InvalidSyntaxException.Format(Strings.IncorrectArgumentCount, parameters.Count, arguments.Length);

            if (arguments.Length < parameters.Count)
                throw InvalidSyntaxException.Format(Strings.TooFewArguments, parameters.Count, arguments.Length);

            SchemeEnvironment result = new SchemeEnvironment(closure.Environment);
            int index = 0;
            for (; index < parameters.Count; index++)
                result.Add(parameters[index], arguments[index]);

            if (restParameter != null)
            {
                Datum restArgument = BuildRestArgument(arguments, index);
                result.Add(closure.RestParameter, restArgument);
            }

            return result;
        }
Esempio n. 4
0
 public void Add(Symbol key, SchemeObject value)
 {
     this.dictionary[key] = value;
 }
Esempio n. 5
0
 public void Add(Variable key, SchemeObject value)
 {
     Add(key.Symbol, value);
 }