Chapter 14: Standard interfaces
14.1 : The machine interface
We provide here a detailed list of the exports from the ``Machine'' package. This package provides the basic machine-level types and operations on them to Aldor
These are the types provided by ``Machine''. They are described in section 13.15.
These are special values of the various types: ``min'' and ``max'' are the smallest (most negative) and largest (most positive) values belonging to the finite arithmetic types; ``epsilon'' is the smallest number E such that 1 + E is distinguishable from 1 in floating point arithmetic.
These operations provide various tests to inquire about values.
The ``single?'' function tests whether a BInt
value
can be represented as a member of SInt
.
These functions provide tests for equality, inequality and order.
These operations manipulate character data. The ``upper'' and ``lower'' operations change the case of letters, and leave characters which are not letters unchanged. The ``ord'' and ``char'' are inverse operations mapping between character and integer values.
These are the arithmetic operations of addition, subtraction, multiplicaiton, division and exponentiation.
These are ``multiply-add'' operations:
_*_+(a,b,c)
is mathematically equivalent to a*b + c
but may be faster or have less rounding error.
These are operations related to integer division. The ``divide'' operations return a quotient-remainder pair.
These operations perform arithmetic modulo their third arguments. The ``mod_*inv'' operation is equivalent to ``mod_*'' but expects an accurate floating point approximation to the inverse of the modulus as its last argument.
These are bit-wise logical operations.
These functions provide access to the bits in the base-2 representation of integers.
These functions provide next and previous values of the given type.
For example, ``next 1'' is 2 for SInt
and BInt
values,
but might be approximately 1.0000000000000002220446
for DFlo
,
depending on the platform.
These are the basic operations underpinning multi-word arithmetic. The first two functions provide double word integer multiply and divide operations. The double word multiply instruction returns its results as a pair. The double word division accepts the dividend as a pair, passed as the first two arguments, the divisor as the third argument, and returns the quotient and remainder. The ``plusStep'' operation adds two values and a carry to produce a result and a carry. The ``timesStep'' operation computes the product of its first two arguments, adds in the other two, and represents the result as a word pair. This may be summarized as:
double_* : (rH, rL) = divide(a * b, wordsize) plusStep : (kout, r) = divide(a + b + kin, wordsize) timesStep : (rHout, rL) = divide(a * b + c + rHin, wordsize)
These operations allow manipulation of the sign s = ± 1, exponent e, and significand x of floating point numbers, f = s x x x 2e.
These provide rounded floating point arithmetic.
The third argument
of the round_
op functions is a rounding mode, as supplied
by nearest
,
zero
(toward zero),
up
(toward plus infinity),
down
(toward minus infinity),
or any
(doesn't matter).
These functions convert values between the various Machine
types.
Most of the operations may be accomplished by simply padding or narrowing
the internal representation of values.
Others such as the integer to floating point conversion are more complex.
These operations allow the conversion of numeric data to and from a textual form.
These operations allow the implementation of array types.
Calling one of these operations indicates that the storage for the argument will no longer be used. On some platforms this makes the storage available for immediate re-use, while on others it does not become available until after the next garbage collection. If a program does not make calls to ``dispose!'', then the storage is reclaimed by garbage collection.
These operations allow programs to inquire about the platform on which they are running.
The ``RTE'' operation indicates the run time environment. This is sometimes useful in selecting between alternative foreign imports. The following values may be returned:
0 | The environment cannot be determined. |
1 | The program is linked as a C-based application. |
2 | The program is running on top of a Common Lisp system. |
OS() quo 1000 | Operating system |
0 | Cannot be determined. |
1 | A Unix derivative. |
2 | IBM VM/CMS. |
3 | OS/2. |
4 | DOS for IBM PC compatibles. |
5 | Microsoft Windows. |
6 | DEC VMS. |
7 | Macintosh System 7 |
Finally, this operation terminates the execution of a program.
On platforms which support it, the integer argument is returned
to the calling environment.
14.2 : Standard Libraries
Programs will normally use more than just the language-defined types. The programs in this guide make use of two libraries: the base Aldor library and the AXIOM library.
The base Aldor library provides a set of basic types for numbers, data structures, objects, input, output and so on, and is described in chapter 25 and chapter26. This library should be used when developing stand-alone programs, or programs to link with C- or Fortran-based applications. Most of the programs presented in this guide make use of this library.
The simplest way to make the base Aldor library available within an Aldor program is to use a line of the form
#include "aldor"
This incorporates the text of the standard header file ``aldor.as'' into the program being compiled. As well as making the library visible, this include file also defines a few standard macros and imports a few basic operations from types in the library. So, for example, after including this file, ``print'' and some ``<<'' operations have meanings.
This header file uses a #library command to make the library archive ``libaldor.al'' available as a package called ``Aldor'' within the program. Normally it is not necessary to use the name ``Aldor'' at all, but if you are using other libraries which introduce colliding exports, you can disambiguate the collisions by referring to the base library entities with a $-qualification, such as ``Integer$Aldor'' or ``+$Integer$Aldor''.
The AXIOM library is most useful when writing programs for use with the AXIOM system. This library is described in the book AXIOM: the scientific computation system by Jenks and Sutor, published by Springer Verlag. Examples of using the AXIOM library with Aldor are given in chapter 18 and section 23.21.
The simplest way to make the AXIOM library available within an Aldor program is to use the following line
#include "axiom"This associates the AXIOM library archive with the name AxiomLib in the program. Similar comments apply to disambiguating using
$
-qualification as applied for Aldor.
The AXIOM library is quite large, and the types it provides are very interdependent (the base clique has 125 mutually recursive interfaces) so compiling files against this library is quite a bit slower and takes much more space than compiling files against the base Aldor library.