|
|
|
|
|
13. PRIMITIVE ACTIONS
Not all functions can be described by calling other functions of the same language. For this reason and for performance reasons several functions are defined using a mechanism called action. For example the while statement can easy be defined using recursion. But this would hurt performance and use a huge amount of memory for the runtime stack. In practise an implementation of the while statement can use a goto instead of a subroutine call. Since we have no goto-statement the primitive action PRC_WHILE can be used. The declaration of the while statement follows:
const proc: while (in func boolean param) do
(in proc param) end while is action "PRC_WHILE";
This declaration shows the types and the position of the parameters of the while-statement. This gives you enough information to use this statement. But it is not possible to change the position or the type of the parameters because they are hard coded in the interpreter. Currently there are several hundred primitive actions predefined in the interpreter. They all have names in upper case characters which have the form:
TYPE_ACTION
Which means that for example all 'integer' actions start with INT_ and all assignment actions end with _CPY . For the following types exist primitive actions (which are grouped together in the *lib.c files mentioned):
ACT_ actlib.c ACTION operations
ARR_ arrlib.c array operations
BIG_ biglib.c bigInteger operations
BLN_ blnlib.c boolean operations
CHR_ chrlib.c char operations
CMD_ cmdlib.c Various directory, file and other commands
DCL_ dcllib.c Declaration operations
DRW_ drwlib.c Drawing operations
ENU_ enulib.c Enumeration operations
FIL_ fillib.c external_file operations
FLT_ fltlib.c float operations
HSH_ hshlib.c hash operations
INT_ intlib.c integer operations
KBD_ kbdlib.c Keyboard operations
LST_ lstlib.c List operations
PRC_ prclib.c proc operations and statements
PRG_ prglib.c Program operations
REF_ reflib.c reference operations
RFL_ rfllib.c ref_list operations
SCR_ scrlib.c Screen operations
SCT_ sctlib.c struct operations
SET_ setlib.c set operations
STR_ strlib.c string operations
TIM_ timlib.c time and duration operations
TYP_ typlib.c type operations
UT8_ ut8lib.c utf8_file operations
The C functions in the *lib.c files have lowercase names. Therefore the 'PRC_WHILE' action is implemented as the C function 'prc_while' in the file 'prclib.c'. The prototype for all C primitiv action functions is identical. The 'prc_while' function has the following prototype:
objecttype prc_while (listtype);
All the *lib.c files containing primitive actions are grouped together in the Seed7 runtime library (Licensed under LGPL). Every *lib.c file has a corresonding *lib.h file. The following list shows actions which are used with more than one type:
_ABS Absolute value
_ADD Addition
_CAT Concatenation
_CMP Compare
_CPY Copy (Assignment)
_CREATE Initialize (Construct)
_DESTR Destroy (Destruct)
_DECR Decrement
_DIV Division
_EQ Equal
_GE Greater equal
_GT Greater than
_HEAD Head of ref_list, array, string
_IDX Index (Element) of ref_list, array, string
_INCR Increment
_LE Less equal
_LNG Length
_LOWER Convert to lower case
_LT Less than
_MINUS Change sign
_MULT Multiply
_NE Not equal
_PLUS Positive sign (noop)
_POW Power
_PRED Predecessor
_RAND Random value
_RANGE Range of ref_list, array, string
_SBTR Subtract
_SCAN Convert from string to another type
_SQRT Square root
_STR Convert to string
_SUCC Successor
_TAIL Tail of ref_list, array, string
_UPPER Convert to upper case
If you are interested in the primitive actions just look into the file seed7_05.s7i . |
|