You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
4.7 KiB
Plaintext

[[concepts]]
== Concepts
[[concept-scripts]]
=== Scripts
A _script_ is a unit of execution which contains its own program counter, local variables and compare flag.
A _program_ is a collection of scripts running concurrently in a cooperative fashion.
A _variable_ is a named storage location. This location holds a value of specific type.
There are global and local variables. _Global variables_ are stored in a way they are accessible from any script. _Local variables_ pertain to its particular script and is only accessible from it.
The lifetime of a global variable is the same as of the execution of all scripts. The lifetime of a local variable is the same as its script and lexical scope.
A _command_ is an operation to be performed by a script. Commands produce side effects which are described by their command description.
A possible side effect of executing a command is the updating of the compare flag. The _compare flag_ of a command is the boolean result it produces. The _compare flag of a script_ is the compare flag of its last executed command.
The _program counter_ of a script indicates its currently executing command. Unless one of the side effects of a command is to change the program counter, the counter goes from the current command to the next sequentially. An explicit change in the program counter is said to be a change in the flow of control.
A command is said to perform a _jump_ if it changes the flow of control irreversibly.
A command is said to call a _subroutine_ if it changes the flow of control but saves the current program counter in a stack to be restored later.
A command is said to _terminate_ a script if it halts and reclaims storage of such a script.
[[concept-script-files]]
=== Script Files
A _script file_ is a source file containing a sequence of commands.
The _multi-file_ is a collection of script files. Hereafter being the collection of script files being translated.
The _main script file_ is the entry script file. This is where the first script (called the _main script_) starts execution.
Other script files are _required_ to become part of the multi-file by the means of require statements within the main script file or main extension files. The main script file itself is required from the translation environment.
A _main extension file_ (or _foreign gosub file_) is a script file required by the means of a GOSUB_FILE statement.
A _subscript file_ is a script file required by the means of a LAUNCH_MISSION statement. A _subscript_ is a script started by the same statement.
A _mission script file_ is a script file required by the means of a LOAD_AND_LAUNCH_MISSION statement. A _mission script_ is a script started by the same statement.
An implementation may contain special features regarding the way subscripts and mission scripts are executed.
The main script file is found in an unspecified manner. The other script files are found by recursively searching a directory with the same filename (excluding extension) as the main script file. This directory is in the same path as the main script file. The search for the script files shall be case-insensitive. All script files must have a `.sc` extension. If multiple script files with the same name are found, which script file is chosen is unspecified.
A script type is said to come before another script type under the following total order:
. Main script.
. Main extension script.
. Subscript.
. Mission script.
A script file _A_ (first required from _X_) is said to come before a script file _B_ (first required from _Y_) under the following total order:
. If _A_'s script type is not the same as _B_'s, then _A_ comes before _B_ if and only if _A_'s script type comes before _B_'s script type.
. Otherwise, if _X_ is not the same as _Y_, _A_ comes before _B_ if and only if _X_ comes before _Y_.
. Otherwise, _A_ comes before _B_ if and only if the line on which _A_ is first required from (in _X_) comes before the line on which _B_ is first required from.
A line of code _A_ in a script file _X_ is said to come before a line _B_ in a script file _Y_ different from _X_ if and only if _X_ comes before _Y_.
[[concept-types]]
=== Types
An _integer_ is a binary signed two's-complement integral number. It represents 32 bits of data and the range of values `-2147483648` through `2147483647`.
A _floating-point_ is a representation of a real number. Its exact representation, precision and range of values is implementation-defined.
A _label_ is a name specifying the location of a command.
A _text label_ is a name whose value is only known in the execution environment.
A _string_ is a sequence of zero or more characters.
An _array_ is a collection of one or more elements of the same type. Each element is indexed by an integer key.