@V7 54 2 -5
@L4 CIUK1247
80
@L5 HIUK1047
0
85  85  85  85  85  85  85  85
85  85  85  85  85  85  85  85
85  85  85  85  85  85  85  85
85  85  85  85  85  85  85  85
85  58  78  85  85  127 90  60
85  85  90  85  85  85  85  85
85  85  85  85  85  85  85  85
85  85  85  85  85  85  85  85
100 91  99  107 109 93  90  109
111 50  82  93  78  127 112 109
90  109 100 89  90  115 95  127
86  83  87  55  72  55  80  91
60  84  87  82  87  84  50  87
83  46  46  74  46  125 83  85
87  87  61  76  45  83  65  100
63  65  65  55  50  55  85  127
@L2 GREE1247
80
@L3 COUK1247
80
@V9 0
@YCHAPTER 27 - MUSS USER MANUAL
@G@RCHAPTER 27 - MUSS C COMPILER@G
@V10 1 9 373
@T% 10
@S227.1 INTRODUCTION
@BThe MUSS C compiler implements the C language as described in
"The C Programming Language" by B. Kernighan and D. Ritchie (Prentice-Hall)
except for the restrictions and extensions outlined below, which apply to the fi
rst release of C in MUSS Issue 11.  The compiler generates
code through calls on the MUTL (Target Language) procedures and the code
generated is intended to run in the MUSS environment.  The set of files
making up a C program can be considered in this context to be analogous
to the set of modules constituting a MUSL program, and most of the
information about the overall compiling scheme for MUSL is also
relevent to this compiler.
@S227.2 RESTRICTIONS AND EXTENSIONS
@
@
  1)@IIn the issue 11 MUSS C compiler,
external declarations can only be made at the outermost
(external definition) level of any file which is a component of a program.@
@
  2)@IThe statement following the @5switch@0 statement must be a block.@
@
  3)@I@5Enum@0erated types are not implemented.@
@
  4)@IAggregate types (@5struct@0ures and @5unions@0) may be copied,
compared, passed as parameters or returned as the results of functions.@
@
  5)@I@5Struct@0ures (not @5auto@0) containing fields may be initialised
by giving a list of values for named members or fields, any unnamed fields
will be set to zero.@
@
  6)@I@5Struct@0ures may not contain unnamed trailing fields for
padding purposes.@
@
  7)@IArrays of characters (@5extern@0 or @5static@0), can be initialised by
the elements of a string.  If the initializer concerned is enclosed in
@X {|}`
'{' '}', further elements can be given, (seperated by ','), otherwise if the
size of the array is known the remaining elements will be cleared to zero.@
@
@Ie.g.@
@I  char a[10] = "abc";@
@I  char b[20 = {4,"abc",5,"defy"};@
@Iare permitted@
@I  char c[10] = 4,"abc",5,6,7;@
@Iis not.@
@
  8)@IForward references to structure types are permitted but only
where they are used in a context that does not require information
about the actual storage size of the type.  Generally speaking, this
means that only instances of pointers to such types are acceptable.@
@
  9)@IIdentifiers may contain up to 64 characters and all of these have
significance in distinguishing between identifiers, not merely the first
eight.@
@
 10)@IFunctions which are called with a variable number of arguments
must give a declaration at
external definition level which specifies the maximum number of arguments with
which the function will be called, (and its result type if required).
The syntax of this is almost identical in form to that for external
definitions or declarations except that
within the '(' and ')' specifying the identifier
to be a function there appears an integer constant giving the maximum
number of arguments.@
@
@Ie.g.@
@I  extern char * sstrprnt(9);@
@I  char (*x1(4))[];@
@
@IFor all functions declared implicitly by use in a function call
context the maximum/formal number of arguments for the implicit declarations wil
l be
defined by the number of actual arguments at this first call of the function.@
@
 11)@IThe compiler contains no integral source preprocessor.  Any
source submitted to the compiler must have been already 'preprocessed'.
However the following compiler control lines are permitted@
@Q 6
@
@I  @2#@0line <CONST.EXPR> <NAME>@
@
@ICurrently has no effect).@
@
@I  @2#@0inform <CONST.EXPR>@
@
@IThis directive is introduced to control the printing of different
kinds of information during compiling, (some information is mainly
relevent to compiler debugging).  The integer constant is bit encoded
as follows:@
@T% 10 20
@
%Bit@IFunction@
% 0@IPrint the encoded itemised line is hexadecimal@
% 1@IPrint the source characters as read@
% 3@IPrint analysis record to expressions at end of
syntactic recognition@
% 4@IPrint analysis record for expressions at end of
semantic checking@
% 5@IInhibit compiler generated compile map@
%8-15@IUsed to control MUTL output i.e. they are passed
as bits 0-7 of the parameter of TL.PRINT
(described elsewhere), but the most usual bits to
set in this directive are bit 10 (MUTL prints a
procedure address map) and bit 13 (MUTL prints a
data mapping information).@
@T% 10
@
@Ie.g.@
@Ito print MUTL procedure map and MUTL data mapping information
and to inhibit compiler generated compile map@
@
@I  @2#@0inform 0x2420@
@
@I  @2#@0end@
@
@IThis directive may be used to indicate the end of the source
to the compiler, it is required if the source is not a file or is a
file containing information following the program source.@
@
 12)@IIn addition to the above, if a statement commences with the
sequence '@2#@0**' then a call on any MUSS library procedure may be
forced from the compiler using the line following the
 '@2#@0**' as a command to be processed by MUSS.  This may typically
be used to control the selection of different streams of input or
to make direct calls on the MUTL procedures in order to control the
environment of a compilation.  For example to include a file at any
point in compilation by using the MUSS 'IN' command@
@
@I@2#@0**IN FILENAME@
@
 13)@IWhere a name in a function call context has no current
declaration and matches a MUSS library name in a currently open
library then the function call will be to this MUSS library
procedure and the actual arguments must match the number and
types of the formal parameters of the procedure concerned.
Thus if any
ambiguity of function identifier could occur a declaration may need
to be made for functions declared later in the file.
Alternatively the automatic linking into the MUSS library structure
may be completely inhibited by setting a compiler mode list (Section 2.5.2).
@S227.3 GENERAL COMPILER OPERATION
@BThe MUSS C compiler operates in a similar manner to the MUSL compiler
and it would be useful to the user to have read about the compiling
scheme of MUSL as described in the opening paragraphs of the section
describing the MUSL language in this Manual.  The compiler has the
standard MUSS compiler format as described in section 2.5.2.
@BThe compiler operates on a statement by statement basis, but some
statements may be broken down into smaller lexical units in order to
avoid excessive sizes for various compiler lists.  Thus if a
line is echoed by the compiler the actual output may only be a part
of the physical line presented to the compiler.
@BWhere errors are detected the compiler will print the line number
where the fault occurred, a message telling what the fault was and the
source line causing the fault with the symbols '<?' inserted to show
the point in the line at which the error was detected,@
@
@Me.g. 3.174 >>>>*SYNTAX? i=int<?i;@
@
(If the fault is a warning rather than a 'fatal' error a
'?' symbol will be inserted after the >>>>* message).
@BIn addition the compiler will generate error messages when
identifiers for labels, structures or functions are found to be
undefined at the end of function bodies or of files.
@BIn the initial release of C, all programs must be compiled to be a library by
setting the
compiler mode bit appropriately.  When this mode is set all functions at
external definition level are put into the library interface.  To run the
program the library must be opened and the function @5main@0 called
explicitly, (obviously any other function could also be called).  Thus a
simple compile job might look like:-@
@X %|
@U 7
@
C 0 LIBNAME %5
main () {     /*this source could be a file */
CAPTION ("simple program");    /*calls on MUSS library procedures*/
NEWLINES(1);
}
@2#@0end    /*required if source not on a file*/
@
@
and to run this program the command sequence would be@
@U 3
@
     LIB LIBNAME@
     main@
@
To compile a program consisting of three files and using a library
STDIO to the library "a.out"@
@U 5
@
     LIB STDIO
     C file1.c a.out %405
     C file2.c 0 %C05
     C file3.c 0 %805
@
The library could then be used by@
@U 4
@
     LIB STDIO
     LIB a.out
     main
@0
@
(Any parameters to @5main@0 might need to be supplied to calling
it from another (possibly MUSL) program).
@X %%
@S227.4 STORAGE CONTROL
@BAt compiler initialisation time segments are created for the code of the
program and for the @5external@0 and @5static@0 variables of the program.
For the majority of programs it is assumed that these default actions will
suffice.  (it should be noted that initialisation of @5extern@0 and
@5static@0 variables is performed at compile time and therefore conceptually onl
y
occurs as the library comprising a program is opened.  Thus if the @5main@0
procedure of an opened MUSS C program library were to be called twice the
correct initialisation values would not be set).
@BIf explicit storage control is required then the procedures TLSEG,
TLLOAD and TLCODEAREA should be used (via the @2#@0** mechanism).  The
compiler used MUTL data area number 2 for @5extern@0 and @5static@0
variables, this is mapped to MUTL segment 1 which may
be redefined to be of a different size if the default of a segment
is not suitable.
@S227.5 IMPLEMENTATION AND MACHINE DEPENDENT INFORMATION
@BFor specific implementation information the MUSS C Implementation
Manual must be read, some more general information is given here.
@
@
 1)@IThe keyword @5register@0 has no effect@
@
 2)@I@5char@0s are considered to be signed quantities (@5unsigned@0
@5char@0 may be used).@
@
 3)@IParameters of MUSS C functions will occupy a size not necessarily
consistent with the size of the type of the formal parameters and may not
appear within the address space in the order in which they are
formally declared.  (Generally speaking parameters all occupy 8 bytes).
Thus before accessing consecutive parameters using pointers a thorough understan
ding
of the stack layout would be required.@
@
 4)@IActual parameters are evaluated left to right.@
@
 5)@IActual parameters which are of aggregate types
are passed as pointers to the aggregate and copied
to a local aggregate at function entry time.@
@
 6)@IFields are allocated from the least significant end of the integer
sized quantities within which they are packed and are considered to be
unsigned quantities.@
@
 7)@IThe sizes of various types of variable are as follows for
particular machines.@
@
@I@4char@0, @4unsigned char@0   @38 bits (all machines)@0@
@I@4short@0, @4unsigned@0 @4short@0 @316 bits (all machines)@0@
@I@4int@0, @4unsigned@0         @316 bits (MC68000)@0@
@I                     @332 bits (VAX11, MU6G)@0@
@I@4long@0, @4unsigned@0 @4long@0   @332 bits (all machines)@0@
@I@4float@0                @332 bits (all machines)@0@
@I@4double@0               @364 bits (all machines).@0
@S227.6 INTERFACING MUSS C PROGRAMS AND MUSS LIBRARIES
@BCalls of C functions in C programs may have a
variable number of arguments and the types of the arguments may vary
and need not match that of the formal arguments.
@BFor these reasons the arguments of C procedures are treated
as being of MUTL type Logical64 (Section 23.3), this size of argument being
sufficient to contain any of the 'basic' or pointer types.
The compiler does no type checking on these types of arguments
(although expressions of type @5char@0 or @5short@0 are
converted to @5int@0 and those of type @5float@0 to @5double@0).
The compiler also permits the
usage of MUSS library procedures as described earlier.
In this case some of the formal arguments may be of explicit type
and this is checked by the
compiler, (casts can be used to convert unsuitably typed
expressions), and the above conversions are not applied.
@BOne restriction imposed by the MUSS C compiler is that pointers
to ordinary MUTL procedures cannot be generated.  It is assumed within
the compiler that all pointers to functions are of the variable and
fixed size argument type.  If a pointer to a MUSS procedure is
required it will be necessary to use an intermediary MUSS C function.@
@U 6
@
     e.g.
          my.sin(x)
          double x; {
          return SIN((float)x);    /*MUSS SIN*/
          }
@BAlso, it should be noted that parameters of aggregate types are
passed to 'C' type procedures as pointers rather than the actual value.
@F
