Local() public method

public Local ( ) : ContextualOperand
return ContextualOperand
Ejemplo n.º 1
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");
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 3
0
        public void Generate(ParseTree parseTree) {
            if (parseTree == null) return;
            GeneratedOK = true;
            defaultClass = ag.Public.Class("Default");
            typeTable.Add("Default", defaultClass);
            mainMethod = defaultClass.Public.Static.Method(typeof(void), "Main");

            //generator stack
            typeStack.Push(defaultClass);
            funcStack.Push(mainMethod);

            //InitIO();
            InitRequiredType();
            PushScope();
            var ioOperand = mainMethod.Local(exp.New(typeTable["IO"]));

            ParseNode(parseTree.Root);
            
            if (GeneratedOK) {
                ag.Save();
                AppDomain.CurrentDomain.ExecuteAssembly(name + ".exe");
            }
        }