Exemplo n.º 1
0
            private static ISeq sqExpandList(ISeq seq)
            {
                IPersistentVector ret = PersistentVector.EMPTY;

                for (; seq != null; seq = seq.next())
                {
                    Object item = seq.first();
                    //if (item is Unquote)
                    //    ret = ret.cons(RT.list(LIST, ((Unquote)item).Obj));
                    // REV 1184
                    if (isUnquote(item))
                    {
                        ret = ret.cons(RT.list(LIST, RT.second(item)));
                    }
                    else if (isUnquoteSplicing(item))
                    {
                        ret = ret.cons(RT.second(item));
                    }
                    else
                    {
                        ret = ret.cons(RT.list(LIST, syntaxQuote(item)));
                    }
                }
                return(ret.seq());
            }
Exemplo n.º 2
0
        internal static int GetMatchingParams(string methodName, List<ParameterInfo[]> parmlists, IPersistentVector argexprs, List<Type> rets)
        {
            // Assume matching lengths
            int matchIndex = -1;
            bool tied = false;
            bool foundExact = false;

            for (int i = 0; i < parmlists.Count; i++)
            {
                bool match = true;
                ISeq aseq = argexprs.seq();
                int exact = 0;
                for (int p = 0; match && p < argexprs.count() && aseq != null; ++p, aseq = aseq.next())
                {
                    Expr arg = (Expr)aseq.first();
                    Type atype = arg.HasClrType ? arg.ClrType : typeof(object);
                    Type ptype = parmlists[i][p].ParameterType;
                    if (arg.HasClrType && atype == ptype)
                        exact++;
                    else
                        match = Reflector.ParamArgTypeMatch(ptype, atype);
                }

                if (exact == argexprs.count())
                {
                    if ( !foundExact || matchIndex == -1 || rets[matchIndex].IsAssignableFrom(rets[i]))
                        matchIndex = i;
                    foundExact = true;
                }
                else if (match && !foundExact)
                {
                    if (matchIndex == -1)
                        matchIndex = i;
                    else
                    {
                        if (Reflector.Subsumes(parmlists[i], parmlists[matchIndex]))
                        {
                            matchIndex = i;
                            tied = false;
                        }
                        else if (Array.Equals(parmlists[i], parmlists[matchIndex]))
                            if (rets[matchIndex].IsAssignableFrom(rets[i]))
                                matchIndex = i;
                            else if (!Reflector.Subsumes(parmlists[matchIndex], parmlists[i]))
                                tied = true;
                    }
                }
            }

            if (tied)
                throw new ArgumentException("More than one matching method found: " + methodName);

            return matchIndex;
        }
Exemplo n.º 3
0
        internal object ParseFile()
        {
            IPersistentVector pv = PersistentVector.EMPTY;

            StringReader       sr = new StringReader(_text);
            PushbackTextReader pr = new PushbackTextReader(sr);

            pv = pv.cons(Compiler.DO);

            object eofVal = new object();
            object form;

            while ((form = LispReader.read(pr, false, eofVal, false)) != eofVal)
            {
                pv = pv.cons(form);
            }

            return(pv.seq());
        }
Exemplo n.º 4
0
            static object syntaxQuote(object form)
            {
                object ret;

                if (Compiler.isSpecial(form))
                {
                    ret = RT.list(Compiler.QUOTE, form);
                }
                else if (form is Symbol)
                {
                    Symbol sym = (Symbol)form;
                    if (sym.Namespace == null && sym.Name.EndsWith("#"))
                    {
                        IPersistentMap gmap = (IPersistentMap)GENSYM_ENV.deref();
                        if (gmap == null)
                        {
                            throw new InvalidDataException("Gensym literal not in syntax-quote");
                        }
                        Symbol gs = (Symbol)gmap.valAt(sym);
                        if (gs == null)
                        {
                            GENSYM_ENV.set(gmap.assoc(sym, gs = Symbol.intern(null,
                                                                              sym.Name.Substring(0, sym.Name.Length - 1)
                                                                              + "__" + RT.nextID() + "__auto__")));
                        }
                        sym = gs;
                    }
                    else if (sym.Namespace == null && sym.Name.EndsWith("."))
                    {
                        Symbol csym = Symbol.intern(null, sym.Name.Substring(0, sym.Name.Length - 1));
                        csym = Compiler.resolveSymbol(csym);
                        sym  = Symbol.intern(null, csym.Name + ".");
                    }
                    else if (sym.Namespace == null && sym.Name.StartsWith("."))
                    {
                        // simply quote method names
                    }
                    else
                    {
                        sym = Compiler.resolveSymbol(sym);
                    }
                    ret = RT.list(Compiler.QUOTE, sym);
                }
                //else if (form is Unquote)
                //    return ((Unquote)form).Obj;
                // Rev 1184
                else if (isUnquote(form))
                {
                    return(RT.second(form));
                }
                else if (isUnquoteSplicing(form))
                {
                    throw new ArgumentException("splice not in list");
                }
                else if (form is IPersistentCollection)
                {
                    if (form is IPersistentMap)
                    {
                        IPersistentVector keyvals = flattenMap(form);
                        ret = RT.list(APPLY, HASHMAP, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(keyvals.seq()))));
                    }
                    else if (form is IPersistentVector)
                    {
                        ret = RT.list(APPLY, VECTOR, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(((IPersistentVector)form).seq()))));
                    }
                    else if (form is IPersistentSet)
                    {
                        ret = RT.list(APPLY, HASHSET, RT.list(SEQ, RT.cons(CONCAT, sqExpandList(((IPersistentSet)form).seq()))));
                    }
                    else if (form is ISeq || form is IPersistentList)
                    {
                        ISeq seq = RT.seq(form);
                        if (seq == null)
                        {
                            ret = RT.cons(LIST, null);
                        }
                        else
                        {
                            ret = RT.list(SEQ, RT.cons(CONCAT, sqExpandList(seq)));
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("Unknown Collection type");
                    }
                }
                else if (form is Keyword ||
                         Util.IsNumeric(form) ||
                         form is Char ||
                         form is String)
                {
                    ret = form;
                }
                else
                {
                    ret = RT.list(Compiler.QUOTE, form);
                }

                if (form is IObj && RT.meta(form) != null)
                {
                    //filter line numbers
                    IPersistentMap newMeta = ((IObj)form).meta().without(RT.LINE_KEY);
                    if (newMeta.count() > 0)
                    {
                        return(RT.list(WITH_META, ret, syntaxQuote(((IObj)form).meta())));
                    }
                }
                return(ret);
            }
Exemplo n.º 5
0
        internal static int GetMatchingParams(string methodName, List <ParameterInfo[]> parmlists, IPersistentVector argexprs, List <Type> rets)
        {
            // Assume matching lengths
            int  matchIndex = -1;
            bool tied       = false;
            bool foundExact = false;

            for (int i = 0; i < parmlists.Count; i++)
            {
                bool match = true;
                ISeq aseq  = argexprs.seq();
                int  exact = 0;
                for (int p = 0; match && p < argexprs.count() && aseq != null; ++p, aseq = aseq.next())
                {
                    Expr arg   = (Expr)aseq.first();
                    Type atype = arg.HasClrType ? arg.ClrType : typeof(object);
                    Type ptype = parmlists[i][p].ParameterType;
                    if (arg.HasClrType && atype == ptype)
                    {
                        exact++;
                    }
                    else
                    {
                        match = Reflector.ParamArgTypeMatch(ptype, atype);
                    }
                }

                if (exact == argexprs.count())
                {
                    if (!foundExact || matchIndex == -1 || rets[matchIndex].IsAssignableFrom(rets[i]))
                    {
                        matchIndex = i;
                    }
                    foundExact = true;
                }
                else if (match && !foundExact)
                {
                    if (matchIndex == -1)
                    {
                        matchIndex = i;
                    }
                    else
                    {
                        if (Reflector.Subsumes(parmlists[i], parmlists[matchIndex]))
                        {
                            matchIndex = i;
                            tied       = false;
                        }
                        else if (Array.Equals(parmlists[i], parmlists[matchIndex]))
                        {
                            if (rets[matchIndex].IsAssignableFrom(rets[i]))
                            {
                                matchIndex = i;
                            }
                            else if (!Reflector.Subsumes(parmlists[matchIndex], parmlists[i]))
                            {
                                tied = true;
                            }
                        }
                    }
                }
            }

            if (tied)
            {
                throw new ArgumentException("More than one matching method found: " + methodName);
            }

            return(matchIndex);
        }