next up previous
Next: Control Structure Up: User-level Constructs Previous: User-level Constructs

Program Structure

The executable portion of a program normally consists of a single defmain statement, and any number of defsub statements. These statements may appear in any order.



defmain

Define program's main routine.
Syntax:

 (defmain  progname

statement

statement ... )

Elements:
progname ---
A symbol naming the program. The name should be a sequence of letters and digits starting with a letter. It should be distinct from the names of all subroutines and static data items in the program.
statement, statement, ... ---
Statements to be executed in sequence as the main routine of the program.

Description:

The defmain statement is used to define the main routine of a program. It is intended to appear as a top-level form, but may actually appear anywhere a statement may appear. (If executed as a statement, it does nothing.) Currently there is no ``command line'' or other argument list available to the program; it must either be self-contained along with its data or explicitly read data from an input stream. Defmain generates information in the output file that tells the run-time environment where to begin executing. If there are zero or more than one defmain statements in a given program, then the result of attempting to run the program is undefined.

Defmain currently also has the side effect of causing the entire standard library to be included in the output program. Right now there is only one subroutine in the standard library (named smf), so this is not too burdensome.



defsub

Define subroutine.
Syntax:

 (defsub  subname ( arg arg ...)

statement

statement ... )

Elements:
subname ---
A symbol naming the subroutine. The name should be a sequence of letters and digits starting with a letter. It should be distinct from the names of the main routine, all other subroutines, and all static data items in the program.
arg, arg, ... ---
Formal argument names, with the same alphanumeric format. These names are not required to be distinct from any other names in the program. However a single subroutine cannot have two arguments with the same name. Currently, the compiler does not support subroutines taking more than 29 arguments on the Pendulum architecture.
statement, statement, ... ---
Statements to be executed in sequence as the body of the subroutine.

Description:

Defsub statements are used to define subroutines within a program. They are intended to appear only as top-level forms, but may actually appear anywhere that a statement may appear. (If executed as a statement, a defsub construct does nothing.) If there are two defsub statements with the same subname in a given program, then the result of attempting to execute that program is undefined.

The formal arguments may be accessed as read-write variables within the body of the subroutine. On entry to the subroutine, the values of these variables are bound to the values of the actual arguments that were passed in via the call statement in the caller. The call statement must pass exactly the number of arguments required by the subroutine or else the behavior of the subroutine is undefined. On exit, the values of the argument variables become the new values of the actual arguments (see the description of call).

Any subroutine may also be called in reverse; see rcall.



next up previous
Next: Control Structure Up: User-level Constructs Previous: User-level Constructs



Michael Frank
Mon Nov 3 16:33:38 EST 1997