Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  Entry point
Entry point

In the programming language, The place where a program start executing is called the entry point.

It is important to understand the entry point when writing a program. That is because it is an understanding of the execution procedure.


The entry point, which is the starting point for executing, the exit point, which is the ending point for executing, and the main class, which is a user-defined class that includes them, are important elements in the actual operation of the script.


Table of contents:


Entry point

Exit point

main class

Entry point

The format of entry points varies. For example, the function named main is the entry point in the C lungage. Since BASIC is executed from the beginning of the source code, the beginning of the file is the entry point.

The entry point for the Rice language depends on the application. All open methods of the main class can be the entry point.

Language components such as the "main class" and "open method" will be discussed later.

Let's take Cooker as an example to explain the entry point of the Rice language.

Cooker, instructed to run the program, reads the source file and creates a virtual machine. Then the virtual machine calls the start() method of the main class.

This calling of the start() method is the entry point in the Cooker.


Definition of the main class and start() method is mandatory in the Cooker. A script cannot execute if they are not defined.

1:

class main

2:

open method void start()

3:

endmethod

4:

endclass

The above is an example of the definition of the main class in Cooker. You can create an executable Rice script in Cooker by adding code to the start() method.


The start() method is the entry point in Cooker because Cooker is implemented that way.

As mentioned earlier, all open methods of the main class can be entry point. Which method is the entry point depends on the implementation of the application.

Exit point

The start point of program execution is called the entry point, while the end point is called the exit point. The exit point can be important for some applications.

Like the entry point, all open methods of the main class can be exit point. Which method is the exit point depends on the implementation of the application.


Let's take Cooker as an example to explain the exit point.

The exit point of Cooker program execution is when the script is switched and when the application is closed.

Cooker can switch scripts. Since only one script is being executed at a time, when executing a new script file, it may be necessary to post-process the script that was executed before that.

The same is true when Cooker is closed. You may need to post-process the script that is running before you exit the application.


Whether or not the script needs post-processing depends on the content of the script, and the application cannot determine it.

Cooker attempts to call the end() method of the main class at the exit point instead of determining if post-processing is needed. Call the end() method if it exists. If it doesn't exist, it doesn't do anything.


That is, the definition of the end() method is optional. You should define the end() method only when post-processing is required.

1:

class main

2:

open method void start()

3:

endmethod

4:

open method void end()

5:

endmethod

6:

endclass

Added the end() method to the definition of the main class. You can add code to this end() method to define the behavior of the script at the exit point.


The end() method is the exit point in Cooker because Cooker is implemented that way.

As mentioned earlier, all open methods of the main class can be exit point. Which method is the exit point depends on the implementation of the application.

main class

As mentioned above, the main class is an important class that has start() and end() methods as members. The Rice language is implemented assuming that the main class acts as an interface to your application.


There are other important features of the main class as well. That is, the instance of the main class is a singleton.


Now suppose you have a fictitious user-defined class "someclass".

1:

someclass newInstance = new someclass();

Such a statement is called a definition statement. In this case, we are defining the variable "newInstance".

When this statement is executed, the variable "newInstance" and the data for the someclass class will be reserved on memory. The data of someclass class on memory is called an instance.

Then, the memory address of the instance of someclass class is written to the memory area of newInstance.


User-defined class other than the main class is allocated different instance, when it is created. If there are ten definition statements of someclass class, individual data will be allocated to ten memory areas.

On the other hand, the main class is not allocated a separate memory area. Even if there are ten definition statements of the main class, the same instance is assigned to all of them.

Such an instance is called a singleton instance.


There are many advantages to having the main class as a singleton instance.

Next
Previous
Copyright © Rice All rights reserved.