示例#1
0
        /// <summary>
        /// Convert environment to array of bindings
        /// </summary>
        /// <returns></returns>
        public AstBinding[] ToArray()
        {
            var array = new AstBinding[Bindings.Count];

            Bindings.Values.CopyTo(array, 0);
            return(array);
        }
示例#2
0
        /// <summary>
        /// Define new definition.
        /// </summary>
        /// <param name="name">identifier</param>
        /// <param name="binding">binding</param>
        public int Define(Symbol name, AstBinding binding)
        {
            var variable = LookupLocal(name);

            if (variable != null)
            {
                throw SchemeError.SyntaxError("define", "environment already have key", binding.Id);
            }

            binding.environment = this;
            binding.VarIdx      = Bindings.Count;
            Bindings[name]      = binding;
            return(binding.VarIdx);
        }
示例#3
0
文件: Inspector.cs 项目: hww/VARP
 private static string InspectInternal(AstBinding bind, InspectOptions options = InspectOptions.Default)
 {
     if (bind is UpBinding)
     {
         var upbind = bind as UpBinding;
         return(string.Format("[{0},{1}] {1}>", upbind.UpEnvIdx, upbind.UpVarIdx, bind.Identifier.Name));
     }
     else if (bind is PrimitiveBinding)
     {
         return(string.Format("#Prim {0}", bind.Identifier.Name));
     }
     else
     {
         return(string.Format(" {0}", bind.Identifier.Name));
     }
 }
示例#4
0
 /// <summary>
 /// Convert ast environment to the ast array
 /// </summary>
 /// <returns></returns>
 public AstBinding[] ToAstArray()
 {
     if (IsLexical)
     {
         var array = new AstBinding[Bindings.Count];
         foreach (var bind in Bindings)
         {
             if (bind.Value is AstBinding)
             {
                 var ast = bind.Value as AstBinding;
                 array[ast.VarIdx] = ast;
             }
             else
             {
                 throw new Exception();
             }
         }
         return(array);
     }
     else
     {
         throw new Exception("Excepted lexical array");
     }
 }
示例#5
0
 /// <summary>
 /// Define new definition.
 /// </summary>
 /// <param name="binding">binding</param>
 public int Define(AstBinding binding)
 {
     return(Define(binding.Identifier, binding));
 }