% from 20.3.1989 hk, version 0.03
% revised 5.11.1989 hk, version 0.30
% corrections by haible 25.9.90

% rest pragmas, lisp, m2, etc.

\chapter{System Commands} %-------------------------

In this chapter we summarize display commands, pragmas, 
how to access the operating system and command line parameters. 

\section{Information Display} %----------

The first important system commads are concerned with 
displaying information on the system configuration and 
what is going on during computations.
There are tree groups of commands: 
1) for configuration display,
2) for specification display and 
3) for environment display.

Configuration display commands show which 
external functions or predefined functions are available. 
Specification display commands show 
defined units, sorts, variables, signatures and generic items.
Environment display commands show 
storage usage, stream usage, symbol table contents, 
and top level variable bindings.
A summary of this commands follows:

\begin{deflist}{GENERICS}
\item[HELP\index{HELP}] lists all information available on 
      defined and accessible functions.
      That is all compiled procedures and functions,  
      all interpreter procedures and functions   
      and all signature\index{signature definition} definitions.
\item[EXTPROCS\index{EXTPROCS}] lists all accessible external 
      compiled functions and procedures.
\item[SIGS\index{SIGS}] lists all 
      signature definitions\index{signature definition} 
      of functions.
\item[GENERICS\index{GENERICS}] lists all generic\index{generic} 
      function definitions.
\item[VARS\index{VARS}] lists all defined variables\index{variable}
      together with the type information. 
\item[SORTS\index{SORTS}] lists all defined 
      sorts names\index{sort name}. 
\item[UNITS\index{UNITS}] lists all defined 
      unit names\index{unit name}. 

\item[BIOS\index{BIOS}] displays information on stream I/O usage, 
\item[GCM\index{GCM}] displays information on the 
      storage\index{storage} usage, 
\item[SYMTB\index{SYMTB}] displays the LISP symbol\index{symbol} 
      table including properties, 
\item[DUMPENV\index{DUMPENV}] lists all variable bindings, 
      that is all variables\index{variable} in the top level 
      environment together
      with their current value. The output is in LISP syntax:
\begin{verbatim}
       (SETQ var value)
\end{verbatim}
      so it should be possible to dump the variables to a disk
      file, and later read them in again.  
      Declarations are lost.
\item[LISTENV\index{LISTENV}] same as DUMPENV except output is in 
      Modula--2 like syntax. 
      Note that probably some constructs can not be read in again.
\item[PRAGMA(SHOW)\index{PRAGMA}\index{SHOW}] 
      displays the actual pragma settings.
\end{deflist}

Note that all display information can be 
printed to a file using output stream setting. 


\section{Pragmas} %---------

\label{prag.sec}
Besides displaying information the MAS system provides 
commands to modify the state of the running MAS program. 
These settings are organized by the \verb/PRAGMA/ command. 
The pragmas come in two groups, 
one for the selection of the actual parser and 
one for debuging purposes. 
\index{PRAGMA}

The general syntax of the pragma command is as follows:
\begin{verbatim}
       PRAGMA(subcommand).
\end{verbatim}
Where \verb/subcommand/ is one of the commands discussed in
the sequel. If an unknown subcommand is entered, then 
a list of all available pragmas is displayed. 
A list of the actual pragma settings is available with the 
\verb/SHOW/ subcommand.

The subcommands which modify and select the parser 
are as follows:

\begin{deflist}{MODULA}
\item[MODULA\index{MODULA}] input / output is in Modula--2 like 
      syntax\index{syntax}, 
      that means the MAS parser for the MAS language is used. 
\item[LISP\index{LISP}] input / output is in LISP syntax. 
\item[ALDES\index{ALDES}] input is in ALDES--2 syntax, 
      that means the ALDES parser is used to read 
      the next input until the ALDES end of file mark `\verb/||/'  
      is encountered.   
\item[GENPARSE\index{GENPARSE}] for the artihmetical operators 
      the generic names or LISP names are generated. The 
      correspondence is as shown in figure \ref{gen.fig}.
\end{deflist}
\begin{figure}[thbp] %-----------------------------
\begin{center}
\begin{tabular}{|c|l|l|} 
      \hline
      operator &  LISP name  & generic name \\
      \hline
      \verb/+/ &  \verb/ADD/  & \verb/SUM/ \\
      \verb/-/ &  \verb/SUB/  & \verb/DIF/ \\
      \verb/-/ &  \verb/SUB/  & \verb/NEG/ \\
      \verb/*/ &  \verb/MUL/  & \verb/PROD/ \\
      \verb./. &  \verb/QUOT/ & \verb/Q/ \\
      \verb.%. &  \verb/REM/  & \verb/REMAIN/ \\
               &              & \verb/REZIP/ \\
      \verb.^. &  \verb/POW/  & \verb/EXP/ \\
      \hline
\end{tabular}
\end{center}
\caption{Generic Operators and Functions}
\label{gen.fig}\index{generic operators}\index{operator overloading}
\end{figure} %---------------------------

The following subcommands turn {\bf flags} ON and OFF:

\begin{deflist}{SLOPPY}
\item[TIME\index{TIME}] if ON the times for 
     parsing, evaluation and printing are shown 
     (initial OFF), 
\item[TRACE\index{TRACE}] if ON the arguments of the evaluator 
      are displayed, may produce messy output 
     (initial OFF),  
\item[DEBUG\index{DEBUG}] if ON prints the result produced 
      by the actual parser\index{parser} 
     (initial OFF)
\item[FUSSY\index{FUSSY}] switches to strong(er) 
      type checking as usual.
\item[SLOPPY\index{SLOPPY}] switches to weak(er) 
      type checking.
\end{deflist}

The actual setting of these flags can be displayed with the 
\verb/SHOW/ subcommand. 


\section{Operating System}

With \verb/EXIT/ it is possible to leave the MAS main program 
and return to the operating system.
On some computers the MAS system further provides
access to the operating system during a running MAS session. 
Most important is the possibility to call an editor
from within MAS. 
The commands are summarized as follows:
\begin{deflist}{EDIT()}
\item[EXIT\index{EXIT}] Leaves the MAS system. 
\item[DOS(\verb*/"prog parms"/)\index{DOS}]  Calls the program 
      `\verb/prog/' with the parameters `\verb/parms/'. 
      The meaning of the string depends on the operating system.
\item[EDIT(\verb*/"data set name"/)\index{EDIT}] Edits 
      the specified data set. 
      The editor\index{editor} is expected to be 
      `EDITOR.PRG' on the current directory\index{directory}. 
      The editor on disk is `microEMACS 3.9'. 
      The data set name string is prefixed by the
      string \verb*/" @MAS.RC "/ which specifies the startup file
      for EMACS to be `MAS.RC'.  
      \index{EMACS}\index{MAS.RC}
\item[USEEMS\index{USEEMS}] Activates the usage of the EMS storage 
      on IBM PC's if available. 
      \index{IBM PC}\index{EMS}
\end{deflist}


\section{Input / Output}

The MAS input / output is organized in so called streams. 
A discussion of streams and their usage is conatined 
in the chapter on the MAS language \ref{lang.chap}.
In this section we give only a summary of the functions.

The stream switching functions are:
\begin{deflist}{SHUT()}
\item[IN(\verb/"stream"/)\index{IN}] the current input stream 
      is switched to the stream `stream',
\item[OUT(\verb/"stream"/)\index{OUT}] the current output stream 
      is switched to the stream `stream',
\item[SHUT(\verb/"stream"/)\index{SHUT}] the specified stream 
      is closed. 
\end{deflist}

The `stream' name may be prefixed by a `device name' to specify
non--disk data sets:
\begin{description}
\item[CON:] is the terminal
\item[WIN:] is a window (not yet implemented)
\item[RAM:] is an internal memory stream, 
            `RAM--disk'
\item[GRA:] is a graphic\index{graphic} window (not yet implemented)
\item[NUL:] is a dummy stream to suppress output\index{output}, 
            always empty on input, never full on output,
\end{description}
\index{WIN}\index{CON}\index{RAM}\index{GRA}\index{NUL}

Other `device names' are passed to the 
operating system\index{operating system} and
are usually interpreted as disk data sets.   


\section{Command Line Parameters}

The executable MAS program accepts several 
command line parameters to configure the 
running system. 
\index{command line}

The parameters available on all systems are: 
\begin{enumerate}
\item \verb/-m number-of-KB/ \\
      The memory option `\verb/-m/' gives the number of Kilo-Byte
      storage, requested from the operating system. This
      number includes the space reserved for the editor and
      other system calls. The number should be larger than
      about 250-300 on an Atari ST with microEMACS.
      \index{\verb/-m/}
\item \verb/-f data-set-name/ \\
      The file name option `\verb/-f/' can be used to overwrite the
      default file name `MAS.INI' during startup. With this
      option MAS can be run in batch mode if the EXIT
      statement is contained in the data set.
      \index{\verb/-f/}\index{MAS.INI}
\end{enumerate}
The parameters may appear in any order.
On multiple occurrences of parameters, the last
occurrence is used.

An additional parameter available on IBM PC Topspeed Modula--2
version is: 
\begin{enumerate}
\item \verb/-t data-set-name/ \\
      This parameter defines an temporary data set name 
      used for storing MAS memory during external command 
      invocation. The default for data-set-name is 
      `CELLMEM.TMP'. i.e the temporary data set is created in 
      the actual directory. If you have a RAM-Disk installed, 
      say on drive `R', then with `\verb/MAS -t R:\temp.tmp/'   
      MAS will use the RAM-Disk for the temorary data set.
      \index{\verb/-t/}
\end{enumerate}
For the IBM PC version at least 512 KB memory is required,
but it is recomended to have at least 640 KB.
In case of problems starting MAS you should remove any
additional device drivers from CONFIG.SYS and AUTOEXEC.BAT
or any other program that needs memory.
\index{IBM PC}\index{RAM--disk}
        
The MAS version compiled with the Topspeed Modula-2 Compiler
uses EMS if present. Memory from EMS will be activated 
after 10 Garbage Collections or by the MAS function USEEMS(). 
\index{EMS}


\chapter{The LISP Interpreter} %--------------------------------

This chapter describes some issues of the LISP interpreter
which are not covered elsewhere. It is usually not required 
for the use of the MAS system. LISP whizzards may find some
background information regarding the MAS LISP implementation.

The idea of combining an ALGOL\index{ALGOL} like 
programming language\index{language} with LISP\index{LISP} 
is borrowed from A.C. Hearn's RLISP\index{RLISP}, which is part of the 
Reduce\index{Reduce} computer algebra system
\cite{Hearn 87}.
Our LISP interpreter is also influenced by SLISP\index{SLISP} 
(Standard LISP)
\cite{Marti 78}.
The actual implementation\index{implementation} of the 
interpreter
followed the book `LISP' of H. Stoyan and G. Goerz
\cite{Stoyan 84}.
A similar approach, implementing LISP in BCPL\index{BCPL}, 
was persuaded by Fitch and Norman
\cite{Fitch 77}.

Since in LISP everything is a function and there is no 
special syntax beyond the S--expression syntax we 
describe the MAS LISP by the functions.  
In the second section we will discuss some 
implementation dependend issues.


\section{Functions and Variables}

The semantics of the functions is as expected 
from other LISP systems.
The list of all available 
LISP\index{LISP} functions is as follows: 

\begin{description}
\item[List Processing:] \mbox{ }
      \\
      CAR\index{CAR}, CDR\index{CDR}, CONS\index{CONS}, 
      REVERSE\index{REVERSE}, JOIN\index{JOIN}, NIL\index{NIL} 
      (LISP\index{LISP} like versions)
      \\
      FIRST\index{FIRST}, RED\index{RED}, COMP\index{COMP}, 
      INV\index{INV}, CONC\index{CONC}, ADV\index{ADV} 
      (SAC--2 like versions).
\end{description}

For convenience both the LISP names and the ALDES /SAC--2 names
are available. The names are in corresponding order. 
NIL is the empty list. The ALDES constant `()' is not parsed, so
NIL must be used. 

The next functions correspond to the operators 
\verb. +, -, *, /, %. in the MAS language\index{language}.

\begin{description}
\item[Arithmetic:] \mbox{ }
      \\
      ADD\index{ADD}, SUB\index{SUB}, MUL\index{MUL}, 
      QUOT\index{QUOT}, REM\index{REM}.
\end{description}

\begin{description}
\item[Relations:] \mbox{ }
     \\
     EQ\index{EQ}, NE\index{NE}, LE, LT\index{LT}, GE, GT, 
     NOT\index{NOT}, AND\index{AND}, OR\index{OR}.
\end{description}

These functions are generated from the MAS relations  
\verb. =, #, <=, <, >=, >..

The following is a complete list of the intrinsic LISP
functions. The functions with Standard LISP names 
have the same meaning as in SLISP. Others are described 
elsewhere.

\begin{description}
\item[Functions:] \mbox{ }
     \\
     DE\index{DE}, DF\index{DF}, DM, DG\index{DG}, 
     LAMBDA\index{LAMBDA}, FLAMBDA\index{FLAMBDA}, 
     MLAMBDA\index{MLAMBDA}, GLAMBDA\index{GLAMBDA}, 
     \\
     VAR\index{VAR}, SORT\index{SORT}, 
     SIG\index{SIG}, MAP\index{MAP}, RULE\index{RULE},
     \\
     UNIT\index{UNIT}, SPEC\index{SPEC}, IMPL\index{IMPL}, 
     MODEL\index{MODEL}, AXIOMS\index{AXIOMS}, 
     \\
     SETQ\index{SETQ}, ASSIGN\index{ASSIGN}, 
     QUOTE\index{QUOTE}, COND\index{COND}, 
     \\
     PROGN\index{PROGN}, LIST\index{LIST}, 
     IF\index{IF}, WHILE\index{WHILE}, REPEAT\index{REPEAT}, 
     \\
     PROGA\index{PROGA}, GOTO\index{GOTO},
     ARRAY\index{ARRAY}, LABEL\index{LABEL},
\end{description}

The VAR, SIG, MAP, RULE, UNIT, SPEC, IMPL, MODEL and AXIOMS
functions are used by the specification component.
The PROGA, GOTO, LABEL and ARRAY functions are used for the 
interpretation of ALDES algorithms.


\subsection{What is Not Contained}

Several functions which are normally available from 
LISP interpreters are not accessible in MAS LISP, but they are 
normally available (probably with different name) 
at the Modula--2 programming level:

\begin{quote}
CATCH\index{CATCH}, THROW\index{THROW}, 
ASSOC\index{ASSOC}, PUT\index{PUT}, GET\index{GET}, 
EXPLODE\index{EXPLODE}, IMPLODE\index{IMPLODE}, 
GENSYM\index{GENSYM}, SUBLIS\index{SUBLIS}.
\end{quote}

Definitely not available are:

\begin{quote}
DO--loops or FOR--loops, a LISP compiler\index{compiler}. 
\end{quote}
Of course a FOR--loop construct can be defined as macro\index{macro}, 
if one accepts an ugly syntax.
GOTO\index{GOTO} is only available 
in PROGA for ALDES sequential statements.

Probably available in future releases will be:
\begin{quote}
LOOP\index{LOOP}--EXIT\index{EXIT}--END, 
CASE\index{CASE}, graphics\index{graphic}, \ldots 
\end{quote}
A CASE construct is available in ALDES, it is simulated using 
the COND function.

Not contained as primitive but definable are 
\begin{quote}
APPLY\index{APPLY}, MAP\index{MAP}, EVAL\index{EVAL}.  
\end{quote}
Here MAP means the LISP MAP function family and not the 
specification component MAP function. 
The MAP\index{MAP} function family can be defined as 
procedures, as explained in the section `Talking LISP'.
\index{mapcar}


\section{Implementation Issues}

The current implementation\index{implementation} uses the 
MAS storage\index{storage} management and
input\index{input} /output\index{output} management which have 
their origin in the
ALDES /SAC--2 Basic and List Processing System by 
G.E. Collins and R. Loos \cite{Collins 82}, \cite{Loos 76}. 

The symbol\index{symbol} handling was first done by the 
ALDES / SAC--2 Symbol System,
which uses an unbalanced tree for the symbol table.
In the present version ($\geq 0.6$) we use 
a hash table with balanced symbol tree entries.
Therefore the generation of alphabetical lists 
(as in the HELP command) needs some more time as 
in the previous system.
Without the specification component
there are typically less than 100 -- 200 symbols defined,
since sub--procedures in compiled code\index{compiled code} 
which are not accessible from the interpreter do not count.
With the specifications of algebraic structures loaded 
about 700 -- 1000 symbols are defined.
In contrast in a running Reduce system about 4000 symbols and
2000 functions are defined.

The variable binding mechanism is the so called `deep access' binding
using a linear list  for the symbols and values 
(ALIST\index{ALIST}).  
At the moment there are typically less than 50 values bound to symbols,
since variables in compiled code are not stored in the ALIST.
The MAS parser performs static scope anlysis and declares 
textualy local variables, but at LISP level 
dynamic scope is implemented.

The minimal MAS executable module is about 90 KB code. 
This includes storage management, input / output, symbol handling,
LISP interpreter, specification component and the parser. 
Not included are the 
arithmetic\index{arithmetic} routines.
In contrast XLISP is about 76 KB,
microEMACS 3.8 is about 80KB,
muSIMP-86 is about 57 KB, 
the muLISP\index{muLISP}-87 kernel is about 50 KB 
and SLISP\index{SLISP}/370 is about 50 KB of code. 

A full fledged MAS including arbitrary precision arithmetic,
a polynomial system, two Gr\"obner bases packages, a 
numerical\index{numeric} 
differential equation solver is about 176 KB.
In contrast Derive\index{Derive} is about 209 KB, the
Reduce\index{Reduce} savefile is about 610 KB 
( + 213 KB for PSL\index{PSL})
and the bare Reduce (without factorizer and integrator)
is reported to be about 459 KB.


\chapter{Internal Structure of MAS} %-------------------------------------

In this chapter we will provide some background 
on the internal structure of MAS. 
First we discuss the components of MAS, then 
the program layout, the configuration and available 
libraries.


\section{System Components}

\begin{figure}[thbp] %-----------------------------
\begin{center}
\setlength{\unitlength}{1mm}
\begin{picture}(120,100)
\put(75.3,33){\framebox(33,34.7){}}
\put(19.3,81){\oval(26,9.3)}
\put(42,77){\framebox(25.7,11.3){}}
\put(45,80.7){\makebox(18.3,4)[b]{Editor}}
\put(7.3,79){\makebox(22,5.7)[b]{MAS input}}
\put(77,45.3){\makebox(25,8.7)[b]{compiler}}
\thicklines
\put(90,67.7){\line(0,1){11}}
\put(75,82.7){\line(-1,0){7}}
\put(41.7,82.3){\line(-1,0){9.3}}
\put(75.3,40.3){\vector(-1,0){20.3}}
\put(30.7,26.7){\vector(1,0){44.7}}
\thinlines
\put(8,56.7){\framebox(22.7,8.3){}}
\put(8,45.7){\framebox(22.7,8.3){}}
\put(5,12){\framebox(49.7,58){}}
\put(8,34.7){\framebox(22.7,8.3){}}
\put(8,13.7){\framebox(22.7,8.3){}}
\put(7.7,24.3){\framebox(22.7,8.3){}}
\put(9.3,58.3){\makebox(19,5){Parse}}
\put(10.3,35.7){\makebox(18,5.7){Lisp}}
\put(10,25.7){\makebox(18.3,5.3){Call}}
\put(10.7,15.3){\makebox(17.3,4.7){Print}}
\put(37.3,49){\makebox(11.7,5){Decla-}}
\put(35.3,43.3){\makebox(15.7,5){rations}}
\put(21,5.7){\oval(34,8)}
\put(6.7,3){\makebox(29,5.3){MAS output}}
\thicklines
\put(30.7,52.3){\vector(1,0){4}}
\put(34.3,47){\vector(-1,0){4}}
\put(14.3,76){\vector(0,-1){11.3}}
\put(13.3,13.7){\vector(0,-1){4.7}}
\thinlines
\put(13,48){\vector(0,-1){7}}
\put(12.7,26){\vector(0,-1){5.7}}
\put(49.7,56.3){\line(3,2){33.7}}
\put(42,42){\line(5,-2){34.3}}
\put(35.7,13.3){\makebox(17,7){MAS}}
\put(91.3,21.7){\oval(32.7,17.3)}
\put(91.7,83){\oval(33.3,9.3)}
\put(44,49.3){\oval(18.7,14)}
\thicklines
\put(90,33){\line(0,-1){2.7}}
\put(9.3,47.3){\makebox(20.3,4.7){Specification}}
\put(77,51.3){\makebox(25.7,6.7){Modula--2}}
\put(77.3,17.7){\makebox(28.7,8.3){M--2 libraries}}
\put(76,80){\makebox(31.3,6.3){M--2 source}}
\thinlines
\put(12.7,58.3){\vector(0,-1){7.7}}
\put(12.7,37.7){\vector(0,-1){8.3}}
\end{picture}
\end{center}
\caption{System Components}
\label{figSCo}\index{system components}
\end{figure} %---------------------------

The MAS system components are identified in 
figure \ref{figSCo}.
Active components (programs) are enclosed in square boxes
and passive components (data) are enclosed in oval boxes. 
Arrows indicate flow of data and lines between 
boxes show that the components are related in some way.

As allready mentioned MAS itself is a 
Modula--2 program. Thus the MAS program can be recompiled 
and linked together with other symbolic and 
numberical libraries by a suitable Modula--2 compiler.
This is shown as an arrow from the compiler box on the right 
to the enclosing MAS box on the left.

On the top line the editor box both acts on the 
Modula--2 source code (on the right) 
and the MAS input data (on the left). 
The input is processed by the following internal components: 
\begin{enumerate}
\item The parser for the MAS language (Parse box):
      character strings in concrete syntax are transformed 
      into abstract syntax trees. Static syntax check together 
      with variable scope analysis is performed.
\item The specification processor (Specification box) 
      with an attached data base of declarations 
      (Declarations box): 
      declarations are extracted from the parse tree and 
      stored in the declaration base, 
      information is retrieved during interpretation.
      The declarations reflect the Modula--2 source code 
      and the library structure.
\item The LISP interpreter (LISP box): 
      according to the type or the function name of an
      S--expression inner most (that is eager) evaluation 
      is performed. 
\item The interface to the compiled library procedures (Call box): 
      if external functions are encountered 
      then compiled procedures are restored and 
      called with the appropriate parameters. 
\item Finally the results are displayed by the 
      (pretty) printing part (Print box).  
\end{enumerate}


\section{Module Layout of MAS}

In this section we will discuss the
internal structure of MAS as a Modula--2 program.
The principal module structure shown in figure \ref{figMSt}.

\begin{figure}[thbp] %-----------------------------
\begin{center}
       \framebox[6cm]{Interpreter} \\ 
       \framebox[6cm]{MAS Language} \\ 
       \framebox[6cm]{LISP Evaluator} \\ 
       \framebox[12.3cm]{Modula-2 Subroutine Libraries} \\ 
       \framebox[4cm]{SAC--2 Libraries} 
       \framebox[4cm]{MAS Libraries}
       \framebox[4cm]{Others} \\ 
       \framebox[4cm]{Integer} 
       \framebox[4cm]{Floating Point} 
        \makebox[4cm]{ } \\ 
       \framebox[4cm]{Rational Number} 
       \framebox[4cm]{Others} 
        \makebox[4cm]{ } \\ 
       \framebox[4cm]{Others} 
        \makebox[4cm]{ }
        \makebox[4cm]{ } \\ 
       \framebox[10.1cm]{MAS Kernel} 
        \makebox[2.1cm]{ } \\ 
\end{center}
\caption{Module Structure}
\label{figMSt}\index{module structure}
\end{figure} %---------------------------

The MAS interpreter main program uses the parser module
`MAS Language' and the LISP evaluator module. 
Various library modules can then be connected to 
the LISP interpreter.
All list processing modules use the MAS kernel 
with its storage management system and basic input/output system.

MAS is an open system. Beside the ALDES /SAC--2 and the MAS
libraries other libraries can be connected to the interpreter.
In a first test we used a numerical\index{numeric} 
library\index{library} developed
at the Technische Hochschule Aachen by 
Prof. G. Engeln-M\"ullges and   
Prof. F. Reutter \cite{Engeln 88}. 
It was not only possible to call numerical
programs from MAS, but moreover it was also possible to call
MAS routines from the numerical programs. 

In a differential equation solver we called the 
LISP evaluator from within the function which computes the 
right hand side of the differential equation.    
This might not be the fastest way to do it but it was possible to 
define different right hand sides interactively\index{interactive} 
as MAS procedures and then integrate them numerically. 

The design\index{design} of the 
garbage collector allows arbitrary 
mixtures of list  processing programs with 
numerical\index{numeric} or other
programs. It also allows mixtures with other Modula--2 
data types\index{data type} 
such as real numbers, vectors, arrays or records. 
However it only collects garbage produced by the MAS list processing
system, not any other dynamically allocated data 
structures\index{structure}.
The collector uses a mark and sweep technique and 
is not compacting despite of the open system design\index{design}.

{\bf Restriction:} 
{\em MAS list pointers may not be part of other 
{\bf dynamically allocated} data structures, 
since then the garbage collector 
can not get information about them.} 

This restriction can be overcome in the following way:
Dynamically allocated data structures must be linked together
in some way, so use the MAS list processing for the links and
put pointers to the dynamically allocated data in the FIRST fields 
of the MAS lists. 
If no list pointers are stored in other dynamically allocated
data structures, then no restrictions exist.


\section{Program Dependencies}

A simplified list  of the dependencies\index{dependencies} 
of the program modules
is contained in the following list. 
Modules with smaller numbers depend on those with higher numbers.
 
\begin{enumerate}
\item MAS.MOD \\
      main program.
\item SACSYM, MASSPEC, MASLISP, MASPARSE, MASLOAD, \\
      (.DEF and .MOD), \\
      symbol\index{symbol} system, interpreter and parser\index{parser}.
\item SACD, SACI, SACM, SACRN, SACPRIM, MASAPF, \\ 
      MASF (.DEF and .MOD), \\
      arithmetic\index{arithmetic} system, or various other 
      programs which are connected 
      to the interpreter.
\item SACBIOS\index{BIOS}, SACLIST (.DEF and .MOD), \\
      rest of ALDES /SAC-2 basic system.  
\item MASELEM, MASSTOR, MASBIOS (.DEF and .MOD), \\
      basic system adapted for Modula--2 compiler\index{compiler} 
      and Atari computer,
      containing a garbage collector and file handling.
\end{enumerate}

Modules under 3 and 4 belong to the MAS kernel, 
modules under 1 and 2 constitute the MAS interpreter and parser.
Under 3 only an example configuration is given.
The MAS configuration\index{configuration}
set up is discussed in the next section.


\section{LISP to Modula--2 Interface}

The interface between LISP and the compiled code\index{compiled code} 
is realized with
the Modula--2 procedure types\index{procedure type}\index{type}. 
The procedure code pointers are stored in the property list
of a symbol together with some signature information. 
Upon application of such a function symbol, the procedure 
is restored, the actual parameters are supplied and the
procedure is called. 

A simplified example of this mechanism is explained by
the following Modula--2 code piece:   

\begin{verbatim}
       TYPE procf1 = PROCEDURE(LIST): LIST;
       PROCEDURE name(a: LIST): LIST; 
                 BEGIN  ... RETURN(x) END;
       VAR   f: procf1;
             a: ADDRESS;
             l: LIST;
       BEGIN a:=ADDRESS(name); ...
             f:=procf1(a);
             l:=f(2); ...
\end{verbatim}

With \verb/a:=ADDRESS(name)/ the code pointer of the 
function `name'
is saved in a, and can further be stored in the property 
list  of a symbol. 
Later an executable function can be restored with
\verb/f:=procf1(a)/ and can then be executed like any other 
function: \verb/l:=f(2)/.

In this example the user himself is responsible for
using the correct type conversion \verb/procf1/. 
For execution it is absolutely necessary that the number and 
types\index{type} of 
the actual and formal arguments are identical.  
For this MAS exports type dependent functions for the 
declaration of compiled code\index{compiled code} 
for interactive\index{interactive} usage.

Such a declaration looks like
\begin{verbatim}
       FROM MASLISPU IMPORT Compiledf1;
       FROM MASSTOR IMPORT FIRST; 
       Compiledf1(FIRST,"CAR");
\end{verbatim}
here the compiled function FIRST\index{FIRST} 
(with 1 input parameter)
is made available as LISP function CAR\index{CAR}.
And provisions are made to prevent CAR from being
called with the wrong number of arguments.
The Modula--2 compiler itself checks that the type of the 
function FIRST matches the type of the first parameter
of `Compiledf1'.
So the procedure types are an incredibly 
helpful feature of Modula--2. 


\section{Configuration Management}

Despite of the large amount of available procedures
it seems necessary to provide some mechanisms
to select only the ones which one is actually interested in.
The Modula--2 procedure types together with 
the MAS interpreter design allow for a transparent 
configuration management.
\index{configuration}\index{procedure type}\index{interpreter}

The association of a compiled procedure with 
a function symbol of the MAS language is accomplished
in a way described in the section on LISP implementation.
\index{compiled procedure}\index{language}

In this section we will first discuss some 
key aspects of the MAS configuration management and then
we will give a sample listing of a `load module'.

In the MAS main program a procedure named 
\verb/InitExternals/ is called, which in turn activates
several other \verb*/InitExternals / procedures.
The name externals indicates code that is not required to run
the LISP kernel. 
\index{kernel}\index{InitExternals}

With the InitExternals procedures any desired configuration 
of the MAS system can be achieved. For example
if no arithmetic routines are required 
their declaration can be left out from the InitExternals.
Or if only Gr\"obner bases are to be studied, one 
can include declarations of the respective procedures.

Four points should be observed:

{\em first}, the complete {\bf type checking mechanism} of Modula--2
\index{type checking}
is in effect. The compiler will detect discrepancies
between the declaration of the procedures and their usage.
Consider the procedure \verb/IWRITE/. 
In the import list it is specified from which 
module IWRITE is to be taken, here \verb/SACI/.  
Then it is used as input to the 
\verb/Compiledp1/ procedure. If accidentally some other
procedure is used (p.e. \verb/Compiledp2/) then the 
compiler will complain about a type mismatch error. 

{\em second}, the linker will take care that all 
\index{linker}
subroutines used in the IWRITE procedure are 
collected together for the executable program. 
\index{executable program}
So if only a top level procedure is made accessible to
LISP, the linker looks for all {\bf lower level routines}
required to execute the top level routine.
\index{lower level routine}

{\em third}, the configuration of the MAS system can be done
using a {\bf familiar program development system}.
It is not necessary to learn about a special configuration
manager. Simply specify all required routines in 
the InitExternals and re--link the MAS main program and you have
a fitting MAS system.
\index{relink}

{\em fourth}, only the 
{\bf minimal number} of procedures is packed together.
On other LISP systems or LISP based computer 
algebra systems the whole packages (or modules) 
are put together, since it is not distinguished between
used (accessible) and unused (not accessible) procedures.   
\index{optimized linking}\index{package}

A listing of part of the arithmetic 
InitExternals is shown:

{\small
\begin{verbatim}
      IMPLEMENTATION MODULE MASLOADA;

      FROM MASLISPU IMPORT Compiledp1, ...

      FROM SACI IMPORT IWRITE, IREAD, INEG, IPROD, ISUM, IDIF,  
                       IQ, IREM, IQR, ISIGNF, IABSF, IEXP, 
                       ICOMP, IGCD, ILCM, IRAND, ILWRIT;
 
      FROM SACRN IMPORT RNWRIT, RNDWR, RNREAD, RNSIGN, RNCOMP, 
                        RNNEG, RNABS, RNINT, RNRED, 
                        RNSUM, RNDIF, RNPROD, RNQ;

      PROCEDURE InitExternalsA;
      (*Tell Modula about external compiled procedures. *)
      BEGIN 
      (*1*) (*from SACI. *)
            Compiledp1(IWRITE,"IWRITE");
            Compiledp1(ILWRIT,"ILWRIT");
            Compiledf0(IREAD,"IREAD");
            Compiledf1(ISIGNF,"ISIGN");
            Compiledf2(ICOMP,"ICOMP");
            Compiledf1(INEG,"INEG");
            ... 
            Compiledf2(IGCD,"IGCD");
            Compiledf2(ILCM,"ILCM");
            Compiledf1(IRAND,"IRAND");
      (*2*) (*from SACRN. *)
            Compiledp2(RNDWR,"RNDWR");
            Compiledp1(RNWRIT,"RNWRIT");
            Compiledf0(RNREAD,"RNREAD");
            Compiledf2(RNRED,"RNRED");
            ...
            Compiledf1(RNSIGN,"RNSIGN");
            Compiledf2(RNDIF,"RNDIF");
            Compiledf2(RNPROD,"RNPROD");
            Compiledf2(RNQ,"RNQ");
      (*3*) (*from MASAPF. *) ...
      (*4*) (*from SACPRIM. *) ...
      (*5*) (*from MASF. *) ...
      (*9*) END InitExternalsA;

      END MASLOADA.
\end{verbatim}
}
\index{integer}\index{rational number}\index{floating point}
\index{integer factorization}\index{numeric}


\section{Libraries}

Currently available libraries are:
\index{library}

Kernel and interpreter:
\index{kernel}\index{interpreter}
\begin{quote}
\begin{obeylines} 
  MAS          Storage Management System
  MAS          Basic Input/Output System 
  MAS          LISP Interpreter System
  MAS          SPEC Specification Component
  MAS          Parser System 
  ALDES        Parser System 
  ALDES/SAC--2 List Processing System
  ALDES/SAC--2 Symbol System
\end{obeylines}
\index{storage management}\index{input}\index{output}
\index{interpreter}\index{parser}\index{list processing}
\index{symbol handling}

\end{quote}

Basic arithmetic:
\index{basic arithmetic}\index{arithmetic}
\begin{quote}
\begin{obeylines} 
  ALDES/SAC--2 Digit Arithmetic System,
  ALDES/SAC--2 Integer Arithmetic System,
  ALDES/SAC--2 Rational Number System,
  ALDES/SAC--2 Modular Integer Arithmetic System, 
  ALDES/SAC--2 Integer Factorization System, 
  ALDES/SAC--2 Set of Integers System, 
  ALDES/SAC--2 Combinatorical System, 
  MAS          Arbitrary Precision Floating Point System, 
\end{obeylines}
\index{digit}\index{modular integer}
\index{integer}\index{rational number}
\index{integer factorization}\index{set of integer}
\index{floating point}
\end{quote}

Polynomial arithmetic, ring theory, algebraic geometry:
\begin{quote}
\begin{obeylines}
  ALDES/SAC--2 Polynomial System,
  ALDES/SAC--2 GCD and Resultant System,
  ALDES/SAC--2 Polynomial Factorization System,
  ALDES/SAC--2 Algebraic Number System,
  ALDES/SAC--2 Real Root Isolation System,
  DIP          Distributive Polynomial System,
  DIP          Buchberger Algorithm and Groebner Base System,
  DIP          Ideal Real Root Isolation System,
  DIP          Ideal Decomposition System,
\end{obeylines}
\index{recursive polynomial}\index{greatest common divisor}
\index{resultant}
\index{algebraic number}\index{real root isolation}
\index{distributive polynomial}
\index{Buchberger algorithm}\index{polynomial ideals}
\index{ideal decomposition}\index{roots of ideals}
\index{systems of equations}
\end{quote}

and further algorithms for Computer Algebra.

Also any other Modula--2 program libraries can be interfaced 
to the MAS system.

