Run ByteCode in VM

Parent Previous Next

Run ByteCode in VM.

Once the bytecode is compiled and stored in memory, we are ready to use the test bench to execute the code in a VM.

» Press the function key F5 or click the menu item Compile > Test Execution.

» Each of the Main function arguments x, y, z is initially zero  A .

» Set the values  to search the cells for row 1 and columns 1..2.

» Start execution by clicking the button  C .

The results are:

Class Main


 Public Function Main(Integer x, y, z) : Integer


   //Create our text variable.

   String text := "X=" + x.ToString() + " and Y=" + y.ToString();

   //Convert text to UTF8 bytes, rotated z bits left.

   Blob crypto := Encrypt(text, z);

   //Write to the public VM cells, which are readable to the host.

   //Each cell is assigned as @CellSetType(rowIdx, columnIdx, value).

   @CellSetString(1, 1, text);

   @CellSetBytes(1, 2, crypto);

   Return crypto.Length();


 Private Function Encrypt(String text; Integer rotateBitsLeft) : Blob


   //This is a very simple encryption which turns the text

   //into UTF8 bytes, and then rotates the bits to the left

   //(or alternatively to the right if rotateBitsLeft < 0).

   Integer cpUTF8 := 65001; //the utf8 codepage;

   Blob tmp := @EncodeStringToBytes(text, cpUTF8);

   Return tmp.Rotate(0, rotateBitsLeft);



Rotate Bits.

» Assign another value to the z-argument of the Main function  A .

This will cause a bit rotation of the returned blob. Please notice that z = -1 will give the same result as z = 87, because 11 characters * 8 bit = 88 for a full rotation.

Next: Debug Execution