Beispiel #1
0
        private void From(Exp variable, CodeExpression collection, List <CodeQueryClause> queryClauses)
        {
            switch (variable)
            {
            case Identifier id:
            {
                var f = m.From(id.Accept(this), collection);
                queryClauses.Add(f);
                break;
            }

            case ExpList expList:
            {
                var vars = expList.Expressions.Select(v => v.Accept(this)).ToArray();
                var type = MakeTupleType(expList.Expressions);
                var it   = gensym.GenSymAutomatic("_tup_", type, false);
                var f    = m.From(it, m.ApplyMethod(collection, "Chop",
                                                    m.Lambda(vars,
                                                             MakeTupleCreate(vars))));
                queryClauses.Add(f);
                for (int i = 0; i < vars.Length; ++i)
                {
                    var l = m.Let(vars[i], m.Access(it, $"Item{i + 1}"));
                    queryClauses.Add(l);
                }
                break;
            }

            case PyTuple tuple:
            {
                var vars = tuple.values.Select(v => v.Accept(this)).ToArray();
                var type = MakeTupleType(tuple.values);
                var it   = gensym.GenSymAutomatic("_tup_", type, false);
                var f    = m.From(it, m.ApplyMethod(collection, "Chop",
                                                    m.Lambda(vars,
                                                             MakeTupleCreate(vars))));
                queryClauses.Add(f);
                for (int i = 0; i < vars.Length; ++i)
                {
                    var l = m.Let(vars[i], m.Access(it, $"Item{i + 1}"));
                    queryClauses.Add(l);
                }
                break;
            }

            default:
                throw new NotImplementedException(variable.GetType().Name);
            }
        }
 public CodeVariableReferenceExpression GenSymParameter(string prefix, CodeTypeReference type)
 {
     return(gensym.GenSymAutomatic(prefix, type, true));
 }