Aztec Script Startup
But whichever way I go...
I come back to the place you are.
- Peter Gabriel
There are three separate ways to specify the starting point of execution for an Aztec Script/Application. The Compiler and Virtual Machine search for the starting (entry) point in the following order:
♦ If a class named 'Main' is defined and it is derived from the 'Thread' class, the system automatically creates an instance of the Main class.
♦ The Virtual Machine invokes the Main constructor, and then invokes the Main.Run() method, which overrides the abstract Thread.Run() method.
♦ Main.Run() becomes the main execution thread of the Script. When that Run() method ends, the Script automatically shuts down.
♦ If a single ‘shared’ method named “Main” is defined within a class (with no args), the system starts the main thread of execution with the 'Main' method.
♦ When the shared "Main" method ends, the Script shuts down.
♦ Finally, if a global method named 'Main' exists (with no args), the system starts the main thread of execution with the 'Main' method.
♦ When the global "Main" method ends, the Script shuts down.
The Aztec Engine supports a “-main” command line option to change the name of the 'Main' class or method.
♦ If “-main Aztec” is entered on the command line, the Compiler and VM go through the above logic using the name 'Aztec' instead of 'Main'.
♦ This option also provides the ability to create multiple entry points into the Script, which is great for troubleshooting, unit tests, or other backdoor access to the script/application.
The logic described above is used when compiling and when executing an Aztec script.
♦ When executing an Aztec source file, the above logic is used to determine the script entry point, and it is immediately passed to the Virtual Machine for execution.
♦ When compiling a source file, the script entry point is determined using the above logic, and it is then written into the Aztec bytecode file.
♦ When executing an Aztec bytecode file, the VM uses the entry point that was written into the bytecode file as the default. However, the "-main" option can also be used on the command line for the Virtual Machine to override the "default" entry point from the bytecode. The VM then goes through the same logic as above to determine the new entry point.