Ejemplo n.º 1
0
        StatementBlock TranslateInvoke(InvokeExpression e)
        {
            var function = Assert.IsType <TypeReference.FunctionTypeCase>(e.Function.Type()).Item;

            var args = e.Args.Select(TranslateExpression).ToArray();

            if (e.Function is Expression.ParameterCase variable && this.ActiveLocalFunctions.TryGetValue(variable.Item.Id, out var localFunction))
            {
                var call = CallLocalFunction(localFunction, args.Select(a => a.Instr()));
                return(StatementBlock.Concat(
                           args.Append(StatementBlock.Expression(localFunction.Method.ReturnType, call))
                           ));
            }
Ejemplo n.º 2
0
            /// <summary> Concatenates the effects of the specified <paramref name="blocks" />. The result values are returned separate. </summary>
            public static (StatementBlock effect, ImmutableArray <ILInstruction> results) CombineInstr(params StatementBlock[] blocks)
            {
                bool hasEmptyBody = true;

                foreach (var b in blocks)
                {
                    Assert.False(b.IsVoid);
                    hasEmptyBody &= b.Statements.IsEmpty;
                }
                if (hasEmptyBody)
                {
                    return(StatementBlock.Nop, blocks.EagerSelect(r => r.Instr()));
                }
                else
                {
                    var vars   = blocks.EagerSelect(b => new ILVariable(VariableKind.StackSlot, b.Type));
                    var result = StatementBlock.Concat(blocks.Zip(vars, (r, v) => r.WithOutputInto(v)));
                    return(result, vars.EagerSelect(v => (ILInstruction) new LdLoc(v)));
                }
            }