S3 (programming language): Difference between revisions

Content deleted Content added
Removed syntax highlighting; this language is too different from algol68 to get good quality
fix formatting
Line 32:
The program starts with a module identification, and comments which we quote by way of acknowledgment to the authors:
 
MODULE KMT_MAIN_MODULE; @ Version 1.01 @
<source>
MODULE KMT_MAIN_MODULE; @ Version 1.01 @
@------------------------------------------------------------------------------@
@ @
@ @
@ ----- S W U R C C V M E K E R M I T ----- @
@ @
@ @
@ ---------------------------------------------------------------- @
@ @
@ @
@ Version 1.00 (February 1986) @
@ @
@ Written by : Richard Andrews and David Lord, @
@ South West Universities Regional Computer Centre, @
@ Claverton Down, Bath BA2 7AY, U.K. @
@ @
@ @
@ ---------------------------------------------------------------- @
@ @
@ @
@ Version 1.01 (October 1986) @
@ @
@ Fixes by : Dave Allum and David Lord, SWURCC. @
@ ---------------------------------------------------------------- @
</source>
 
Next follow a number of "mode declarations". Mode is the Algol 68 term for a type.
 
MODE KMT_BUFFER IS (96)BYTE;
<source>
MODE KMT_BUFFERKMT_STRING IS REF(96)BYTE;
MODE KMT_STRINGKMT_WORD IS REF()BYTE;
MODE KMT_WORD IS REF()BYTE;
MODE KMT_MTM_VALUES IS ANY
(LONG WORD LW_VALUE,
MODE KMT_MTM_VALUES IS ANY
( LONG WORDINT LW_VALUELI_VALUE,
LONG INTREF WORD LI_VALUE RW_VALUE,
REF WORDINT RW_VALUERI_VALUE,
REF INT LONG WORD RI_VALUERLW_VALUE,
REF LONG WORDINT RLW_VALUERLI_VALUE,
REF()BYTE LONG INT RLI_VALUERVB_VALUE,
REF()REF()BYTE RVB_VALUE,RVRVB_VALUE);
REF()REF()BYTE RVRVB_VALUE);
MODE KMT_PP_PACKET_STATISTICS_S IS STRUCT
(INT INPUT_TOTAL,
MODE KMT_PP_PACKET_STATISTICS_S IS STRUCT
OUTPUT_TOTAL);
(INT INPUT_TOTAL,
OUTPUT_TOTAL);
</source>
 
The first type is an array of 96 bytes; the next two are references (pointers) to arrays of bytes. KMT_MTM_VALUES is a union type allowing a variety of different types to appear. Note that WORD is a 32-bit unsigned integer, INT is a 32-bit signed integer; LONG makes it 64 bits. The last option in the union is marked REF()REF()BYTE, which means it is a pointer to an array whose members are pointers to arrays of bytes.
Line 88 ⟶ 84:
The program continues by declaring external procedures on which the module depends. RESPONSE indicates a return value containing error information:
 
EXT PROC (RESPONSE) KMT_UI;
<source>
EXT PROC (RESPONSE) KMT_UI;
EXT PROC (REF INT,INT,RESPONSE) KMT_PH;
EXT PROC (REF INT,REF INT,RESPONSE) KMT_PP_GET_PACKET,
PROC (INT,INT,BOOL,RESPONSE) KMT_PP_SEND_PACKET,
PROC (REF()BYTE,RESPONSE) KMT_PP_BUILD_STRING_PACKET_DATA;
EXT PROC (REF INT,INT,RESPONSE) KMT_PH;
EXT PROC (REF INT,REF INT,RESPONSE) KMT_PP_GET_PACKET,
PROC (INT,INT,BOOL,RESPONSE) KMT_PP_SEND_PACKET,
PROC (REF()BYTE,RESPONSE) KMT_PP_BUILD_STRING_PACKET_DATA;
</source>
 
and also some external variables:
 
EXT REF () BYTE KMT_VERSION;
<source>
EXT REF () BYTE KMT_VERSION;
EXT REF BOOL ASG_ROUTE;
EXT REF()KMT_MTM_VALUES KMT_MTM_AREA;
EXT REF()BYTE MTM_TEXT;
EXT REF INT MTM_TEXT_LEN;
EXT REF ()REF ()BYTE MTM_RECALL_DATA;
EXT REF BOOL ASG_ROUTE;
EXT REF()KMT_MTM_VALUES KMT_MTM_AREA;
EXT REF()BYTE MTM_TEXT;
EXT REF INT MTM_TEXT_LEN;
EXT REF ()REF ()BYTE MTM_RECALL_DATA;
</source>
 
The rest of the program consists of a number of procedure definitions. One of these, which actually defines the entry point to the program, is reproduced here:
 
GLOBAL STATIC (<STATUS 5;PSPACE 10001; TEMPLATE>) PROC KERMIT_THE_FROG IS
<source>
((<LIT "COMMAND">) REF()BYTE OPTION,
GLOBAL STATIC (<STATUS 5;PSPACE 10001; TEMPLATE>) PROC KERMIT_THE_FROG IS
( (<LIT "COMMAND" >) REF()BYTE OPTIONVME_FILE,
(<LIT "" >) REF()BYTE VME_FILEREM_FILE,
(<KEY RESPONSE;DEF N'RESULT>) RESPONSE RESULT):
(<LIT "" >) REF()BYTE REM_FILE,
(<KEY RESPONSE;DEF N'RESULT>) RESPONSE RESULT):
BEGIN
BEGIN
()BYTE JSV_NAME := "ASG"; @ obtain value for ASG_ROUTE bool @
CTM_JS_READ(JSV_NAME,NIL,NIL,ASG_ROUTE,RC_IGNORED);
()BYTE JSV_NAME := "ASG"; @ obtain value for ASG_ROUTE bool @
IF RC_IGNORED NE 0 THEN ASG_ROUTE := FALSE FI;
CTM_JS_READ(JSV_NAME,NIL,NIL,ASG_ROUTE,RC_IGNORED);
IF RC_IGNORED NE 0 THEN ASG_ROUTE := FALSE FI;
@ verify parameter references (parameter values validated later): @
@ OPTION must be of mode REF () BYTE, may not be ZLR or NIL @
@ verify parameter references (parameter values validated later): @
@ OPTION VME_FILE must be of mode REF () BYTE, may not be ZLR, or NIL must not be NIL @
@ VME_FILEREM_FILE must be of mode REF () BYTE, may be ZLR, must not be NIL @
@ REM_FILE must be of mode REF () BYTE, may be ZLR, must not be NIL @
UNLESS (VERIFY OPTION AND VALIDR OPTION)
UNLESS AND (VERIFY OPTIONVME_FILE AND (VALIDR OPTIONVME_FILE OR NOT(VME_FILE IS NIL)))
AND (VERIFY VME_FILEREM_FILE AND (VALIDR VME_FILEREM_FILE OR NOT(VME_FILEREM_FILE IS NIL)))
THEN @ invalid parameter reference @
AND (VERIFY REM_FILE AND (VALIDR REM_FILE OR NOT(REM_FILE IS NIL)))
RESULT := 10002 @ ARCH_INACCESSIBLE_PARAMETER @
THEN @ invalid parameter reference @
RESULT := 10002 @ ARCH_INACCESSIBLE_PARAMETER @
ELSF @ create resource block @
CTM_JS_BEGIN(RESULT);
ELSF @ create resource block @
CTM_JS_BEGIN( RESULT); <= 0
THEN @ resource block created @
RESULT <= 0
LONG LONG WORD KERMIT_RESULT;
THEN @ resource block created @
LONG ANY((3)LONG WORD KERMIT_RESULTAS_LW,(6) WORD AS_W) PARAMS;
PARAMS.AS_LW := (BDESC OPTION,BDESC VME_FILE,BDESC REM_FILE);
ANY((3)LONG WORD AS_LW,(6) WORD AS_W) PARAMS;
PARAMS.AS_LW := (BDESC OPTION,BDESC VME_FILE,BDESC REM_FILE);
@ set up program error handler @
IF KMT_EH_INFORM_PE_CONTINGENCY(RESULT);
@ set up program error handler @
IF KMT_EH_INFORM_PE_CONTINGENCY( RESULT); > 0
THEN @ failed to set error handler @
RESULT > 0
SKIP
THEN @ failed to set error handler @
ELSF CTM_JS_CALL(NIL,PDESC KERMIT_SUPPORT,PARAMS.AS_W,KERMIT_RESULT,
SKIP
RESULT); @ create firewall @
ELSF CTM_JS_CALL(NIL,PDESC KERMIT_SUPPORT,PARAMS.AS_W,KERMIT_RESULT,
RESULT); @ create firewall<= @0
THEN @ either exited normally or via CTM_STOP @
RESULT <= 0
RESULT := IF (S'S'KERMIT_RESULT) <= 0
THEN @ either exited normally or via CTM_STOP @
THEN 0 @ ignore warnings @
RESULT := IF (S'S'KERMIT_RESULT) <= 0
THEN 0ELSE 52000 @ error return common @ ignore warningsresultcode @
ELSE 52000 @ error return common resultcode @FI
FI;
FI;
CTM_JS_END(RC_IGNORED) @ end resource block @
FI
CTM_JS_END(RC_IGNORED) @ end resource block @

FIEND
END
</source>
 
Features to note here include: