/// <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); }
/// <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); }
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)); } }
/// <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"); } }
/// <summary> /// Define new definition. /// </summary> /// <param name="binding">binding</param> public int Define(AstBinding binding) { return(Define(binding.Identifier, binding)); }