Exemplo n.º 1
0
        protected override void DoExpand(MacroContext context)
        {
            if (context.Invocation.Arguments.Count < 1)
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(Resources.Pack_Usage_obj_missing, Alias),
                        context.Invocation.Position, MessageClasses.PackUsage));
                return;
            }

            context.EstablishMacroContext();

            // [| context.StoreForTransport(boxed($arg0)) |]

            var getContext = context.CreateIndirectCall(context.CreateCall(
                EntityRef.Variable.Local.Create(MacroAliases.ContextAlias)));
            var boxedArg0 = context.CreateCall(EntityRef.Command.Create(Engine.BoxedAlias),PCall.Get,
                                               context.Invocation.Arguments[0]);
            context.Block.Expression = context.CreateGetSetMember(getContext, PCall.Get, "StoreForTransport", boxedArg0);
        }
Exemplo n.º 2
0
        protected override void DoExpand(MacroContext context)
        {
            if (context.Invocation.Arguments.Count < 1)
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(
                            "{0} requires at least one argument, the id of the object to unpack.", Alias),
                        context.Invocation.Position, MessageClasses.UnpackUsage));
                return;
            }

            context.EstablishMacroContext();

            // [| macro\unpack\impl(context, $arg0) |]

            var getContext =
                context.CreateIndirectCall(context.CreateCall(EntityRef.Variable.Local.Create(MacroAliases.ContextAlias)));

            context.Block.Expression = context.CreateCall(EntityRef.Command.Create(Impl.Alias),
                                                          PCall.Get, getContext, context.Invocation.Arguments[0]);
        }
Exemplo n.º 3
0
        protected override void DoExpand(MacroContext context)
        {
            if (context.Invocation.Arguments.Count == 0)
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(Resources.CallSubInterpret_OneArgument, Alias), context.Invocation.Position,
                        MessageClasses.SubUsage));
                return;
            }

            if (context.CurrentLoopBlock != null && !context.IsJustEffect)
            {
                context.ReportMessage(
                    Message.Error(
                        string.Format(
                            Resources.CallSubInterpret_asExpressionInLoop, CallSub.Alias, Alias),
                        context.Invocation.Position, MessageClasses.SubAsExpressionInLoop));
                return;
            }

            //Store result of call
            var resultV = context.AllocateTemporaryVariable();
            _storeResult(context, resultV);

            //Extract return variant as int into retVarV
            var retVarV = context.AllocateTemporaryVariable();
            _extractReturnVariant(context, resultV, retVarV);

            Func<AstGetSet> retVar = () => context.CreateCall(EntityRef.Variable.Local.Create(retVarV));

            //Extract return value into retValueV (which happens to be the same as resultV)
            var retValueV = resultV;
            _extractReturnValue(context, resultV, retValueV);

// ReSharper disable ImplicitlyCapturedClosure // perfectly safe as neither lambda survives the method
            Func<AstGetSet> retValue = () => context.CreateCall(EntityRef.Variable.Local.Create(retValueV));
// ReSharper restore ImplicitlyCapturedClosure

            //Break and Continue behave differently outside loop blocks
            AstNode contStmt, breakStmt;
            _determineActions(context, retValue, out contStmt, out breakStmt);

            //Generate check for continue
            _genChecks(context, retVar, contStmt, breakStmt);

            context.Block.Expression = retValue();

            context.FreeTemporaryVariable(retVarV);
            context.FreeTemporaryVariable(resultV);
        }
Exemplo n.º 4
0
 private static void _storeResult(MacroContext context, string resultV)
 {
     var computeKvp = context.Invocation.Arguments[0];
     var setResult = context.CreateCall(EntityRef.Variable.Local.Create(resultV), PCall.Set, computeKvp);
     context.Block.Add(setResult);
 }
Exemplo n.º 5
0
 private static void _extractReturnVariant(MacroContext context, string resultV,
     string retVarV)
 {
     var inv = context.Invocation;
     var intT = new AstConstantTypeExpression(inv.File, inv.Line, inv.Column,
         IntPType.Literal);
     var getRetVar =
         context.CreateGetSetMember(context.CreateCall(EntityRef.Variable.Local.Create(resultV)), PCall.Get,
                                    "Key");
     var asInt = new AstTypecast(inv.File, inv.Line, inv.Column, getRetVar, intT);
     var setRetVar = context.CreateCall(EntityRef.Variable.Local.Create(retVarV), PCall.Set, asInt);
     context.Block.Add(setRetVar);
 }
Exemplo n.º 6
0
 private static void _extractReturnValue(MacroContext context, string resultV,
     string retValueV)
 {
     var getRetValue =
         context.CreateGetSetMember(
             context.CreateCall(EntityRef.Variable.Local.Create(resultV)), PCall.Get, "Value");
     var setRetValue = context.CreateCall(EntityRef.Variable.Local.Create(retValueV), PCall.Set, getRetValue);
     context.Block.Add(setRetValue);
 }