Beispiel #1
0
        static void Main(string[] args)
        {
            Neo.VM.ScriptBuilder builder = new Neo.VM.ScriptBuilder();

            builder.Emit(Neo.VM.OpCode.NOP);
            builder.EmitPush(1);
            builder.EmitPush(2);
            builder.Emit(Neo.VM.OpCode.ADD);
            builder.Emit(Neo.VM.OpCode.RET);

            var machinecode = builder.ToArray();
            var hexstr      = "0x";

            foreach (var m in machinecode)
            {
                hexstr += m.ToString("X02");
            }
            Console.WriteLine("machinecode=" + hexstr);

            //run machinecode with neovm
            var engine = new Neo.VM.ExecutionEngine();

            engine.LoadScript(machinecode);
            engine.Execute();

            //show result
            var calcstack = engine.ResultStack;

            var v = calcstack.Peek();

            Console.WriteLine("retvalue=" + v.GetBigInteger());

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            string srccode = @"
static class Program
{
    static int Main()
    {
        int a=1;
        int b=2;
        return a+b;
    }
}
";

            //step01 get a  c# dll;

            byte[] dll = GetILDLL(srccode);
            DumpILDLL(dll);

            //step02 compile AST->ASMLProject
            Neo.ASML.Node.ASMProject proj = Compiler.Compile(dll);
            proj.Dump((str) => Console.WriteLine(str));


            //step03 link ASML->machinecode
            var module = Neo.ASML.Linker.Linker.CreateModule(proj);

            module.Dump((str) => Console.WriteLine(str));
            var machinecode = Neo.ASML.Linker.Linker.Link(module);

            DumpAVM(machinecode);


            //run machinecode with neovm
            var engine = new Neo.VM.ExecutionEngine();

            engine.LoadScript(machinecode);
            engine.Execute();

            //show result
            var calcstack = engine.ResultStack;

            var v = calcstack.Peek();

            Console.WriteLine("retvalue=" + v.GetBigInteger());
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            string srccode = @"
class Program
{
    static void Main()
    {
        int a=1;
        int b=2;
        return a+b;
    }
}
";
            //step01 srccode -> AST
            var ast  = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(srccode);
            var root = ast.GetRoot();

            DumpAst(root);

            //step02 compile AST->ASMLProject
            Neo.ASML.Node.ASMProject proj = Compiler.Compile(root);

            //step03 link ASML->machinecode
            var module = Neo.ASML.Linker.Linker.CreateModule(proj);

            module.Dump((str) => Console.WriteLine(str));
            var machinecode = Neo.ASML.Linker.Linker.Link(module);

            DumpAVM(machinecode);



            //run machinecode with neovm
            var engine = new Neo.VM.ExecutionEngine();

            engine.LoadScript(machinecode);
            engine.Execute();

            //show result
            var calcstack = engine.ResultStack;

            var v = calcstack.Peek();

            Console.WriteLine("retvalue=" + v.GetBigInteger());
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var srccode = " 1 + 2 + 4 + 5";
            var ast     = ParseSyntaxNode(srccode);

            DumpAST(ast);


            Neo.VM.ScriptBuilder builder = new Neo.VM.ScriptBuilder();
            EmitCode(builder, ast);
            builder.Emit(Neo.VM.OpCode.RET);

            var machinecode = builder.ToArray();
            var hexstr      = "0x";

            foreach (var m in machinecode)
            {
                hexstr += m.ToString("X02");
            }
            Console.WriteLine("machinecode=" + hexstr);

            //run machinecode with neovm
            var engine = new Neo.VM.ExecutionEngine();

            engine.LoadScript(machinecode);
            engine.Execute();

            //show result
            var calcstack = engine.ResultStack;

            var v = calcstack.Peek();

            Console.WriteLine("retvalue=" + v.GetBigInteger());

            Console.ReadLine();
        }
 /// <summary>
 /// Invoke of NeoVM
 /// </summary>
 /// <param name="method">Method</param>
 /// <param name="engine">Engine</param>
 /// <returns>Return true if works</returns>
 public bool Invoke(byte[] method, Neo.VM.ExecutionEngine engine)
 {
     return(_service.Invoke(method, _engine));
 }