Exemplo n.º 1
0
        protected static Expression CallNormal(CodeBlockExpression cbe, params Expression[] ppp)
        {
            bool       needscontext = NeedsContext(cbe); // true;
            int        pc           = ppp.Length;
            MethodInfo dc           = GetDirectCallable(needscontext, pc, cbe.Type);

            List <Variable> paruninit = new List <Variable>(cbe.Block.Parameters);

            for (int i = 0; i < ppp.Length; i++)
            {
                if (ppp[i].Type == typeof(Uninitialized))
                {
                    paruninit[i].SetUnInitialized();
                }
            }

            if (needscontext)
            {
                ppp = ArrayUtils.Insert <Expression>(Ast.CodeContext(), ppp);
            }

            var delegatetype = cbe.Type != typeof(Delegate) ? cbe.Type : CallTargets.GetTargetType(needscontext, pc, false);

            cbe = Ast.CodeBlockReference(cbe.Block, delegatetype);

            cbe.Block.Bind();

            var r = Ast.ComplexCallHelper(cbe, dc, ppp);

            if (SpanHint.IsValid)
            {
                r.SetLoc(SpanHint);
            }
            return(r);
        }
Exemplo n.º 2
0
 protected override void PostWalk(CodeBlockExpression node)
 {
     base.PostWalk(node);
     if (!blocks.ContainsKey(node.Block))
     {
         var c = Current;
         WalkNode(node.Block);
         Current = c;
     }
 }
Exemplo n.º 3
0
                static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, params Expression[] pp)
                {
                    // all var names are unique.
                    CodeBlock cb = cbe.Block;

                    List <Statement> assigns = new List <Statement>();
                    int i = 0;

                    cb.Inlined = true;

                    var parentvars = new List <Variable>(parent.Variables);

                    foreach (Variable p in cb.Parameters)
                    {
                        SymbolId origname = p.Name;

                        p.Name  = (SymbolId)Builtins.GenSym(p.Name);
                        p.Block = parent;
                        p.Kind  = Variable.VariableKind.Local;
                        parent.AddVariable(p);

                        assigns.Add(Ast.Write(p, pp[i]));

                        if (p.Lift)
                        {
                            parent.HasEnvironment = true;
                        }
                        i++;
                    }

                    foreach (Variable l in cb.Variables)
                    {
                        if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global)
                        {
                            l.Name = (SymbolId)Builtins.GenSym(l.Name);
                        }
                        l.Block = parent;
                        parent.AddVariable(l);

                        if (l.Lift)
                        {
                            parent.HasEnvironment = true;
                        }
                    }

                    assigns.Add(cb.Body);

                    return(Ast.Void(Ast.Block(assigns)));
                }
Exemplo n.º 4
0
        protected static Expression CallVarArgs(CodeBlockExpression cbe, Expression[] ppp)
        {
            bool needscontext = NeedsContext(cbe); //true;

            int pc = cbe.Block.ParameterCount;

            Expression[] tail = new Expression[ppp.Length - (pc - 1)];

            Array.Copy(ppp, ppp.Length - tail.Length, tail, 0, tail.Length);

            Expression[] nppp = new Expression[pc];

            Array.Copy(ppp, nppp, ppp.Length - tail.Length);

            if (tail.Length > 0)
            {
                nppp[nppp.Length - 1] = Ast.ComplexCallHelper(MakeList(tail, true), tail);
            }
            else
            {
                nppp[nppp.Length - 1] = Ast.Null();
            }

            ppp = nppp;

            MethodInfo dc = GetDirectCallable(needscontext, pc, cbe.Type);

            if (needscontext)
            {
                ppp = ArrayUtils.Insert <Expression>(Ast.CodeContext(), ppp);
            }

            cbe = Ast.CodeBlockReference(cbe.Block, CallTargets.GetTargetType(needscontext, pc, false));

            cbe.Block.Bind();

            var r = Ast.ComplexCallHelper(cbe, dc, ppp);

            if (SpanHint.IsValid)
            {
                r.SetLoc(SpanHint);
            }
            return(r);
        }
Exemplo n.º 5
0
 protected internal virtual void PostWalk(CodeBlockExpression node) { }
Exemplo n.º 6
0
 // CodeBlockExpression
 protected internal virtual bool Walk(CodeBlockExpression node) { return true; }
Exemplo n.º 7
0
 protected internal override bool Walk(CodeBlockExpression node)
 {
     // Do not recurse into nested code block expression
     return(false);
 }
Exemplo n.º 8
0
 protected override bool Walk(CodeBlockExpression node)
 {
     return(!blocks.ContainsKey(node.Block) && base.Walk(node));
 }
Exemplo n.º 9
0
                bool IsHoistable(MethodCallExpression mce, out CodeBlockExpression cbe, out Variable var)
                {
                    cbe = null;
                    var = null;

                    // Am I needed?
                    //if (!mce.TailCall) return false;
                    if (mce.Instance == null)
                    {
                        return(false);
                    }
                    var i = Unwrap(mce.Instance);

                    if (!typeof(Callable).IsAssignableFrom(i.Type))
                    {
                        return(false);
                    }
                    var be = i as BoundExpression;

                    if (be == null)
                    {
                        return(false);
                    }
                    var = be.Variable;

                    int x;

                    if (!refmap.TryGetValue(var, out x))
                    {
                        return(false);
                    }
                    else
                    {
                        if (x != 1)
                        {
                            return(false);
                        }
                    }

                    if (!callsites.TryGetValue(var, out x))
                    {
                        return(false);
                    }
                    else
                    {
                        if (x != 1)
                        {
                            return(false);
                        }
                    }

                    if (var.Lift || !typeof(Callable).IsAssignableFrom(var.Type) || var.ReAssigned)
                    {
                        return(false);
                    }
                    if (!(mce.Method.Name == "Call" || mce.Method.Name == "Invoke"))
                    {
                        return(false);
                    }
                    if (mce.Arguments.Count > 0 && mce.Arguments[0].Type == typeof(object[]))
                    {
                        return(false);
                    }
                    if (mce.Arguments.Count > 8)
                    {
                        return(false);
                    }

                    var av = var.AssumedValue as MethodCallExpression;

                    while (av == null && be.Variable.AssumedValue is BoundExpression)
                    {
                        be = be.Variable.AssumedValue as BoundExpression;
                        av = be.Variable.AssumedValue as MethodCallExpression;
                    }

                    if (av == null && be.Variable.AssumedValue is NewExpression)
                    {
                        var ne = be.Variable.AssumedValue as NewExpression;
                        if (!typeof(Callable).IsAssignableFrom(ne.Type))
                        {
                            return(false);
                        }
                        cbe = ne.Arguments[0] as CodeBlockExpression;
                        if (cbe == null || cbe.Block.Parent != Current)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (av == null || !typeof(Callable).IsAssignableFrom(av.Type) || av.Method.Name != "Create")
                        {
                            return(false);
                        }
                        cbe = av.Arguments[0] as CodeBlockExpression;
                        if (cbe == null || cbe.Block.Parent != Current)
                        {
                            return(false);
                        }
                    }

                    //if (av == null || av.Type != typeof(Callable) || av.Method.Name != "Create") return false;
                    //cbe = av.Arguments[0] as CodeBlockExpression;
                    //if (cbe == null || cbe.Block.Parent != Current) return false;
                    //if (mce.Arguments.Count > 8) return false;

                    return(true);
                }
Exemplo n.º 10
0
        protected internal static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, bool istailpostion, params Expression[] pp)
        {
            // all var names are unique.
            CodeBlock cb = cbe.Block;

            if (parent.IsGlobal)
            {
                return(CallNormal(cbe, pp));
            }

            List <Statement> assigns = new List <Statement>();
            int i = 0;

            cb.Inlined = true;

            if (parent.Filename == null && cb.Filename != null)
            {
                parent.Filename = cb.Filename;
            }

            var parentvars = new List <Variable>(parent.Variables);

            foreach (Variable p in cb.Parameters)
            {
                SymbolId origname = p.Name;

                p.Name  = (SymbolId)Builtins.GenSym(p.Name);
                p.Block = parent;
                p.Kind  = Variable.VariableKind.Local;
                parent.AddVariable(p);

                Expression val = Unwrap(pp[i]);
                if (val.Type != typeof(SymbolId) && !Generator.assigns.ContainsKey(origname))
                {
                    if (p.Type == typeof(object))
                    {
                        p.Type = val.Type;
                        assigns.Add(Ast.Write(p, val));
                    }
                    else
                    {
                        assigns.Add(Ast.Write(p, Ast.ConvertHelper(val, p.Type)));
                    }
                }
                else
                {
                    if (p.Type == typeof(object))
                    {
                        assigns.Add(Ast.Write(p, pp[i]));
                    }
                    else
                    {
                        assigns.Add(Ast.Write(p, Ast.ConvertHelper(pp[i], p.Type)));
                    }
                }

                if (p.Lift)
                {
                    parent.HasEnvironment = true;
                }
                i++;
            }

            foreach (Variable l in cb.Variables)
            {
                if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global)
                {
                    l.Name = (SymbolId)Builtins.GenSym(l.Name);
                }
                l.Block = parent;
                parent.AddVariable(l);

                if (l.Lift)
                {
                    parent.HasEnvironment = true;
                }
            }

            Expression body = RewriteReturn(cb.Body);

            if (assigns.Count > 0)
            {
                return(Ast.Comma(Ast.Void(Ast.Block(assigns)), body));
            }
            else
            {
                return(body);
            }
        }
Exemplo n.º 11
0
 protected static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, params Expression[] pp)
 {
     return(InlineCall(parent, cbe, false, pp));
 }
Exemplo n.º 12
0
        protected internal static Expression GetAst(object args, CodeBlock cb, bool istailposition)
        {
            if (args is Annotation)
            {
                args = ((Annotation)args).stripped;
            }
            Cons c = args as Cons;

            if (c != null)
            {
                if (c.car is SymbolId)
                {
                    SymbolId f = (SymbolId)c.car;

                    Variable var = cb.Lookup(f);

                    if (var != null && !assigns.ContainsKey(f))
                    {
                        var = null;
                    }

                    object m;

#if OPTIMIZATIONS
#if !BLAH
                    CodeBlockExpression cbe;

                    //// needs to do the same for overloads...
                    if (SimpleGenerator.libraryglobals.TryGetValue(f, out cbe))
                    {
                        Expression[] ppp = GetAstListNoCast(c.cdr as Cons, cb);

                        if (cbe.Block.ParameterCount < 9 && cbe.Block.ParameterCount == ppp.Length)
                        {
                            //inline here? we could for simple bodies, but we need to copy the entire structure
                            if (!(cbe.Block.HasEnvironment || cbe.Block.IsClosure))
                            {
                                if (cbe.Block.Body is ReturnStatement)
                                {
                                    ReturnStatement rs = (ReturnStatement)cbe.Block.Body;

                                    if (!ScriptDomainManager.Options.DebugMode &&
                                        !ScriptDomainManager.Options.LightweightDebugging &&
                                        !cb.IsGlobal && IsSimpleExpression(rs.Expression))
                                    {
                                        return(InlineCall(cb, Ast.CodeBlockExpression(RewriteBody(cbe.Block), false, cbe.IsStronglyTyped), ppp));
                                    }
                                }
                            }
                            if (cbe.Block != cb.Parent && cbe.Block != cb) // do TCE later
                            {
                                return(CallNormal(cbe, ppp));
                            }
                        }
                    }

                    // varargs
                    if (SimpleGenerator.libraryglobalsX.TryGetValue(f, out cbe))
                    {
                        Expression[] ppp = GetAstListNoCast(c.cdr as Cons, cb);

                        if (cbe.Block.ParameterCount < 9 && cbe.Block.ParameterCount - 1 <= ppp.Length)
                        {
                            //inline here?
                            return(CallVarArgs(cbe, ppp));
                        }
                    }

                    // overloads
                    CodeBlockDescriptor[] cbd;
                    if (SimpleGenerator.libraryglobalsN.TryGetValue(f, out cbd))
                    {
                        Expression[] ppp = GetAstListNoCast(c.cdr as Cons, cb);

                        foreach (CodeBlockDescriptor d in cbd)
                        {
                            if (d.codeblock.Block.ParameterCount < 9)
                            {
                                if (ppp.Length == d.arity || (d.varargs && ppp.Length > d.arity))
                                {
                                    if (d.varargs)
                                    {
                                        //inline here?
                                        return(CallVarArgs(d.codeblock, ppp));
                                    }
                                    else
                                    {
                                        //inline here?
                                        //if (d.codeblock.Block != cb.Parent && d.codeblock.Block != cb) // do TCE later, not yet
                                        {
                                            return(CallNormal(d.codeblock, ppp));
                                        }
                                    }
                                }
                            }
                        }
                    }
#endif

                    //if (!ScriptDomainManager.Options.DebugMode)
                    {
                        if (f == SymbolTable.StringToId("call-with-values"))
                        {
                            Expression[] ppp = GetAstListNoCast(c.cdr as Cons, cb);
                            if (ppp.Length == 2 && ppp[1] is MethodCallExpression)
                            {
                                MethodCallExpression consumer = ppp[1] as MethodCallExpression;

                                if (ppp[0] is MethodCallExpression)
                                {
                                    MethodCallExpression producer = ppp[0] as MethodCallExpression;
                                    if (consumer.Method == Closure_Make && producer.Method == Closure_Make)
                                    {
                                        CodeBlockExpression ccbe = consumer.Arguments[0] as CodeBlockExpression;
                                        CodeBlockExpression pcbe = producer.Arguments[0] as CodeBlockExpression;

                                        pcbe.Block.Bind();
                                        ccbe.Block.Bind();

                                        if (ccbe.Block.ParameterCount == 0)
                                        {
                                            return(InlineCall(cb, ccbe));
                                        }
                                        else if (ccbe.Block.ParameterCount == 1)
                                        {
                                            return(InlineCall(cb, ccbe, Ast.SimpleCallHelper(typeof(Helpers).GetMethod("UnwrapValue"), InlineCall(cb, pcbe))));
                                        }
                                        else
                                        {
                                            Variable values = cb.CreateTemporaryVariable((SymbolId)Builtins.GenSym("values"), typeof(object[]));

                                            Expression valuesarr = Ast.Read(values);

                                            Expression[] pppp = new Expression[ccbe.Block.ParameterCount];

                                            for (int i = 0; i < pppp.Length; i++)
                                            {
                                                pppp[i] = Ast.ArrayIndex(valuesarr, Ast.Constant(i));
                                            }

                                            return(Ast.Comma(
                                                       Ast.Void(
                                                           Ast.Write(
                                                               values,
                                                               Ast.ComplexCallHelper(
                                                                   Ast.SimpleCallHelper(typeof(Helpers).GetMethod("WrapValue"), InlineCall(cb, pcbe)),
                                                                   typeof(MultipleValues).GetMethod("ToArray", new Type[] { typeof(int) }),
                                                                   Ast.Constant(pppp.Length)))),
                                                       InlineCall(cb, ccbe, pppp)));
                                        }
                                    }
                                }
                                if (consumer.Method == Closure_Make)
                                {
                                    CodeBlockExpression ccbe = consumer.Arguments[0] as CodeBlockExpression;
                                    ccbe.Block.Bind();

                                    Expression producer = ppp[0];

                                    Expression exx = Ast.ConvertHelper(producer, typeof(Callable));

                                    MethodInfo callx = GetCallable(0);

                                    if (ccbe.Block.ParameterCount == 0)
                                    {
                                        return(InlineCall(cb, ccbe));
                                    }
                                    else if (ccbe.Block.ParameterCount == 1)
                                    {
                                        return(InlineCall(cb, ccbe, Ast.SimpleCallHelper(typeof(Helpers).GetMethod("UnwrapValue"), Ast.Call(exx, callx))));
                                    }
                                    else
                                    {
                                        Variable values = cb.CreateTemporaryVariable((SymbolId)Builtins.GenSym("values"), typeof(object[]));

                                        Expression valuesarr = Ast.Read(values);

                                        Expression[] pppp = new Expression[ccbe.Block.ParameterCount];

                                        for (int i = 0; i < pppp.Length; i++)
                                        {
                                            pppp[i] = Ast.ArrayIndex(valuesarr, Ast.Constant(i));
                                        }

                                        return(Ast.Comma(
                                                   Ast.Void(
                                                       Ast.Write(
                                                           values,
                                                           Ast.ComplexCallHelper(
                                                               Ast.SimpleCallHelper(typeof(Helpers).GetMethod("WrapValue"),
                                                                                    Ast.Call(exx, callx)),
                                                               typeof(MultipleValues).GetMethod("ToArray", new Type[] { typeof(int) }),
                                                               Ast.Constant(pppp.Length)))),
                                                   InlineCall(cb, ccbe, pppp)));
                                    }
                                }
                            }
                            else
                            {
                                ;
                            }
                        }
                    }
#endif
                    // this can be enabled once builtins are auto CPS'd.
                    // ok I tried, but there are issues still, not sure what
#if OPTIMIZATIONS
                    // check for inline emitter
                    InlineEmitter ie;
                    if (TryGetInlineEmitter(f, out ie))
                    {
                        Expression result = ie(GetAstList(c.cdr as Cons, cb));
                        // if null is returned, the method cannot be inlined
                        if (result != null)
                        {
                            if (spanhint.IsValid)
                            {
                                result.SetLoc(spanhint);
                            }
                            return(result);
                        }
                    }
#endif

                    if (Context.Scope.TryLookupName(f, out m))
                    {
                        if (var == null)
                        {
                            IGenerator gh = m as IGenerator;
                            if (gh != null)
                            {
                                return(gh.Generate(c.cdr, cb));
                            }

                            BuiltinMethod bf = m as BuiltinMethod;
                            if (bf != null)
                            {
                                MethodBinder mb   = bf.Binder;
                                Expression[] pars = Array.ConvertAll(GetAstList(c.cdr as Cons, cb), e => Unwrap(e));

                                if (bf.AllowConstantFold && !ScriptDomainManager.Options.DebugMode)
                                {
                                    bool constant = Array.TrueForAll(pars, e => e is ConstantExpression && e.Type != typeof(BigInteger));

                                    if (constant)
                                    {
                                        object[]    cargs = Array.ConvertAll(pars, e => GetRuntimeConstant((ConstantExpression)e));
                                        CallTarget0 disp  = delegate
                                        {
                                            return(bf.Call(cargs));
                                        };
                                        CallTarget1 handler = delegate(object e)
                                        {
                                            throw new CompileTimeEvaluationException();
                                        };

                                        try
                                        {
                                            object result = Runtime.R6RS.Exceptions.WithExceptionHandler(
                                                Closure.Create(handler),
                                                Closure.Create(disp));
                                            var rrrr = GetCons(result, cb);
                                            if (spanhint.IsValid)
                                            {
                                                rrrr.SetLoc(spanhint);
                                            }
                                            return(rrrr);
                                        }
                                        catch (CompileTimeEvaluationException)
                                        {
                                        }
                                    }
                                }

                                Type[]          types = GetExpressionTypes(pars);
                                MethodCandidate mc    = mb.MakeBindingTarget(CallType.None, types);
                                if (mc != null)
                                {
                                    if (mc.Target.NeedsContext)
                                    {
                                        pars = ArrayUtils.Insert <Expression>(Ast.CodeContext(), pars);
                                    }
                                    MethodBase meth = mc.Target.Method;

                                    var rrrr = Ast.ComplexCallHelper(meth as MethodInfo, pars);
                                    if (spanhint.IsValid)
                                    {
                                        rrrr.SetLoc(spanhint);
                                    }
                                    return(rrrr);
                                }
                            }

                            Closure clos = m as Closure;
                            if (clos != null && !SetGenerator.IsAssigned(f))
                            {
                                // no provision for varargs
                                MethodInfo[] mis = clos.Targets;
                                if (mis.Length > 0)
                                {
                                    MethodBinder mb = MethodBinder.MakeBinder(binder, SymbolTable.IdToString(f), mis, BinderType.Normal);

                                    Expression[] pars = Array.ConvertAll(GetAstList(c.cdr as Cons, cb), e => Unwrap(e));

                                    if (clos.AllowConstantFold && !ScriptDomainManager.Options.DebugMode)
                                    {
                                        bool constant = Array.TrueForAll(pars, e => e is ConstantExpression && e.Type != typeof(BigInteger));

                                        if (constant)
                                        {
                                            object[] cargs = Array.ConvertAll(pars, e => GetRuntimeConstant((ConstantExpression)e));

                                            CallTarget0 disp = delegate
                                            {
                                                var rrrr = clos.Call(cargs);
                                                return(rrrr);
                                            };

                                            CallTarget1 handler = delegate(object e)
                                            {
                                                throw new CompileTimeEvaluationException();
                                            };

                                            try
                                            {
                                                object result = Runtime.R6RS.Exceptions.WithExceptionHandler(
                                                    Closure.Create(handler),
                                                    Closure.Create(disp));
                                                var rrrr = GetCons(result, cb);
                                                if (spanhint.IsValid)
                                                {
                                                    rrrr.SetLoc(spanhint);
                                                }
                                                return(rrrr);
                                            }
                                            catch (CompileTimeEvaluationException)
                                            {
                                            }
                                        }
                                    }

                                    // exclude transient members if needed
                                    if (!AllowTransientBinding)
                                    {
                                        mis = Array.FindAll(mis, x => !IsTransient(x.Module));
                                    }

                                    if (mis.Length > 0)
                                    {
                                        Type[]          types = GetExpressionTypes(pars);
                                        MethodCandidate mc    = mb.MakeBindingTarget(CallType.None, types);
                                        if (mc != null)
                                        {
                                            if (mc.Target.NeedsContext)
                                            {
                                                pars = ArrayUtils.Insert <Expression>(Ast.CodeContext(), pars);
                                            }
                                            MethodBase meth = mc.Target.Method;

                                            var rrrr = Ast.ComplexCallHelper(meth as MethodInfo, pars);
                                            if (spanhint.IsValid)
                                            {
                                                rrrr.SetLoc(spanhint);
                                            }
                                            return(rrrr);
                                        }
                                    }
                                }
                                // check for overload thing
                            }
                        }
                    }
                }


                Expression ex = Unwrap(GetAst(c.car, cb));

                // a 'let'
                if (ex is MethodCallExpression)
                {
                    var ppp = GetAstList(c.cdr as Cons, cb);
                    MethodCallExpression mcexpr = (MethodCallExpression)ex;
                    if (mcexpr.Method == Closure_Make)
                    {
                        CodeBlockExpression cbe = mcexpr.Arguments[0] as CodeBlockExpression;

                        if (ppp.Length < 9 && cbe.Block.ParameterCount == ppp.Length)
                        {
                            return(InlineCall(cb, cbe, istailposition, ppp));
                        }
                    }

                    // cater for varargs more efficiently, this does not seem to hit, probably needed somewhere else
                    if (mcexpr.Method == Closure_MakeVarArgsX)
                    {
                        CodeBlockExpression cbe = mcexpr.Arguments[0] as CodeBlockExpression;

                        if (ppp.Length < 9 && cbe.Block.ParameterCount <= ppp.Length)
                        {
                            return(CallVarArgs(cbe, ppp));
                        }
                    }
                }

                if (ex is NewExpression && typeof(ITypedCallable).IsAssignableFrom(ex.Type))
                {
                    NewExpression       mcexpr = ex as NewExpression;
                    CodeBlockExpression cbe    = mcexpr.Arguments[0] as CodeBlockExpression;
                    if (cbe == null && mcexpr.Arguments[0].Type == typeof(CodeContext) && mcexpr.Arguments[0] is ConstantExpression) // implies null
                    {
                        cbe = mcexpr.Arguments[1] as CodeBlockExpression;
                    }
                    if (cbe != null)
                    {
                        var ppp = GetAstListNoCast(c.cdr as Cons, cb);

                        if (ppp.Length < 9 && cbe.Block.ParameterCount == ppp.Length)
                        {
                            return(InlineCall(cb, cbe, istailposition, ppp));
                        }
                    }
                }

                if (ex is ConstantExpression)
                {
                    Builtins.SyntaxError(SymbolTable.StringToObject("generator"), "expecting a procedure", c.car, c);
                }

                Expression r = null;

                if (ex.Type.Name.Contains("TypedClosure"))
                {
                    Expression[] pp = GetAstListNoCast(c.cdr as Cons, cb);

                    var m = ex.Type.GetMethod("Invoke");
                    r = Ast.SimpleCallHelper(ex, m, pp);
                }
                else
                {
                    Expression[] pp = GetAstList(c.cdr as Cons, cb);

                    if (ex.Type != typeof(Callable))
                    {
                        ex = Ast.ConvertHelper(ex, typeof(Callable));
                    }

                    MethodInfo call = GetCallable(pp.Length);

                    r = pp.Length > 8 ?
                        Ast.Call(ex, call, Ast.NewArray(typeof(object[]), pp)) :
                        Ast.Call(ex, call, pp);
                }

                if (spanhint.IsValid)
                {
                    r.SetLoc(spanhint);
                }

                return(r);
            }

            object[] v = args as object[];

            if (v != null)
            {
                return(GetConsVector(v, cb));
            }
            else if (args is byte[])
            {
                Expression[] ba = Array.ConvertAll(args as byte[], b => Ast.Constant(b));
                return(Ast.NewArray(typeof(byte[]), ba));
            }
            else
            {
                if (args is SymbolId)
                {
                    SymbolId sym = (SymbolId)args;
                    if (sym == SymbolTable.StringToId("uninitialized"))
                    {
                        return(Ast.ReadField(null, typeof(Uninitialized), "Instance"));
                    }
                    else
                    {
                        return(Read(sym, cb, typeof(object)));
                    }
                }
                if (args == Builtins.Unspecified)
                {
                    return(Ast.ReadField(null, Unspecified));
                }
                if (args is Fraction)
                {
                    Fraction f = (Fraction)args;
                    return(Ast.Constant(new FractionConstant(f)));
                }
                if (args is ComplexFraction)
                {
                    ComplexFraction f = (ComplexFraction)args;
                    return(Ast.Constant(new ComplexFractionConstant(f)));
                }
                if (args != null && args.GetType().Name == "stx")
                {
                    args = new SerializedConstant(args);
                }
                return(Ast.Constant(args));
            }
        }
Exemplo n.º 13
0
 static bool NeedsContext(CodeBlockExpression cbe)
 {
     return(cbe.Block.IsClosure ||
            cbe.Block.ExplicitCodeContextExpression == null &&
            (cbe.Block.Parent != null && !cbe.Block.Parent.IsGlobal));
 }
Exemplo n.º 14
0
 protected internal override bool Walk(CodeBlockExpression node)
 {
     // Do not recurse into nested code block expression
     return false;
 }
Exemplo n.º 15
0
 // CodeBlockExpression
 protected internal virtual bool Walk(CodeBlockExpression node)
 {
     return(true);
 }
Exemplo n.º 16
0
 protected internal virtual void PostWalk(CodeBlockExpression node)
 {
 }