Exemple #1
0
 public void RevertContextualsIn(FrameScope fs, CodeGen cg)
 {
     foreach (var varname in MangledContextuals.Values)
     {
         if (fs.AssignedContextuals.Contains(varname))
         {
             if (cg.This().Type.Name != "TopLevelFrame")
             {
                 cg.If(cg.This().Field("_assigned_" + fs.ID + "_" + varname) > 0);
                 {
                     cg.Assign(cg.This().Field("TopLevelFrame").Field("_ctxl_" + varname), cg.This().Field("TopLevelFrame").Field("_stack_" + varname).Invoke("Pop"));
                     cg.Assign(cg.This().Field("_assigned_" + fs.ID + "_" + varname), 0);
                 }
                 cg.End();
             }
             else
             {
                 cg.If(cg.This().Field("_assigned_" + fs.ID + "_" + varname) > 0);
                 {
                     cg.Assign(cg.This().Field("_ctxl_" + varname), cg.This().Field("_stack_" + varname).Invoke("Pop"));
                     cg.Assign(cg.This().Field("_assigned_" + fs.ID + "_" + varname), 0);
                 }
                 cg.End();
             }
         }
     }
 }
Exemple #2
0
        static void DynamicMethodExamples()
        {
            DynamicMethodGen dmg = DynamicMethodGen.Static <Program>().Void().Parameter <string>("name");
            CodeGen          g   = dmg.GetCode();

            g.Try();
            {
                Operand name = g.Local <string>(g.Arg("name"));
                g.WriteLine("Hello {0}!", name);
            }
            g.CatchAll();
            {
                g.WriteLine("Error");
            }
            g.End();

            DynamicMethod dm = dmg.GetCompletedDynamicMethod(true);

            // reflection-style invocation
            dm.Invoke(null, new object[] { "Dynamic Method" });

            // delegate invocation
            var hello = dm.CreateDelegate <Action <string> >();

            hello("Delegate");
        }
Exemple #3
0
        static void DynamicMethodExamples()
        {
            DynamicMethodGen dmg = DynamicMethodGen.Static(typeof(Program)).Method(typeof(void)).Parameter(typeof(string), "name");
            CodeGen          g   = dmg.GetCode();

            g.Try();
            {
                Operand name = g.Local(typeof(string), g.Arg("name"));
                g.WriteLine("Hello {0}!", name);
            }
            g.CatchAll();
            {
                g.WriteLine("Error");
            }
            g.End();

            DynamicMethod dm = dmg.GetCompletedDynamicMethod(true);

            // reflection-style invocation
            dm.Invoke(null, new object[] { "Dynamic Method" });

            // delegate invocation
            Action <string> hello = (Action <string>)dm.CreateDelegate(typeof(Action <string>));

            hello("Delegate");
        }