The Main Entry Point

Parent Previous Next

The Main Entry Point.

Compiled bytecode is constructed to have a single point of entry defined by the public Main function in a Main class like this:


Class Main

{

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

 {

   //Here execution starts and ends

 }

}


This is the bare minimum source code requirement. The bytecode must always have an entry point at which execution begins.


It is recommended to encapsulate execution by using a Try - Catch control statement like this:


Class Main

{

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

 {

   Try

   {

     //Here execution starts

   }

   Catch

   {

     //Catch any errors

   }

 }

}


Execution of Main.

Once the bytecode has been loaded by the VM, it can be triggered from the outside to start execution by calling the @VMExecute library function which has this definition:


 @VMExecute(integer vm, x, y, z) : integer


The involved elements are


The term "from the outside" here means it can be triggered by a call from the host to the DLL - or from one VM to another. The origin is not important - from the VM point of view the job is the same: Start execution of the Main function.


Security Considerations.

It may seem like a limitation to only have the Main function as a single point of entry into the bytecode. After all it is very likely that the bytecode has different kinds of functionality bundled together, which should be easy accessible in different scenarios.


However, it would compromise security, if the bytecode could have multiple entry functions. It would provide too much valuable information for a cracker.


By only providing a single point of entry, it forces the programmer to "branch out" to other functions internally in the bytecode which is much harder to detect by a cracker.


And due to the flexibility of VM cells - which you can use for the public storage and transport of thousands of values - it is entirely up to the programmer to decide how to interpret the input and output of the Main function.