示例#1
0
 // A method for testing the other methods in the CompiledFunction class.
 public static bool UnitTest(bool verbose)
 {
     try {
         CompiledFunction cf = new CompiledFunction("test");
         cf.AddArgument("a");
         cf.AddArgument("b");
         cf.AddVariable("x");
         cf.AddVariable("y");
         cf.AddInstruction(OpCode.Load,1);
         int k = cf.AddInstruction(OpCode.Jump, 0);
         cf.AddInstruction(OpCode.Call, "getval", 0);
         int t = cf.getCodeOffset();
         cf.PatchInstruction(k, t);
         cf.AddInstruction(OpCode.Add);
     } catch( Exception e ) {
         Console.WriteLine("CompiledFunction: unit test failed; exception thrown:\n\t{0}",
             e.Message);
         return false;
     }
     Console.WriteLine("CompiledFunction: unit test succeeded");
     return true;
 }