|
|
This is a fascimile of the documentation for the Algol Genie prototype posted in this repository.
PACT - Portable Algol68 subset to C Translator
J.M. van der Veer
1993-1994
Introduction
PACT translates an Algol68 subset to ANSI C. PACT offers low level modular programming through the use of preludes (much like the ENVIRONs offered by the Algol68C compilers).
Differences with Algol68 and Algol68C
With Algol68
• There is no straightening in transput. Standard procedures as put and print are defined only for the modes lengethy bits, bool, char, [] char, lengethy compl, lengethy int, proc (ref file) void and lengethy real (or references to these modes in the case of get and read). Formatted transput is not implemented.
• There is no support for the parallel-clause. This clause is elaborated as a strong-void-collateral-clause.
• Garbage collection of the heap is not implemented. Programs with many heap generators or many local arrays should be designed carefully since they may require a lot of memory.
• The symbols [ and ] cannot be replaced by ( and ).
• Pragments are allowed in length options.
• Priorities are integral denotations.
With Algol68C
• PACT implements FLEX names.
• PACT implements STRING as FLEX [] CHAR, all standard prelude declarations for operations on STRING are supplied.
• PACT does not restrict the set of symbols for operators.
• All widenings are implemented.
Usage
pact filename.a68 [options]
The compiler writes (by default) the object code in filename.c, the listing file to filename.l and the prelude information to filename.p. These defaults can be superseded by using appropriate options.
Options
Options can also be passed to the compiler as PRAGMAT items.
-bl; -big-listing
Produces an extensive listing, containing source code, syntax tree, generated code, cross reference (also of the standard - and user preludes) and compilation statistics.
-co; -check-only
Syntax check only, do not generate object code.
-ctty; -code-to-tty
Copies the generated object code to stdout (an object file is also generated).
-cc; -commented-code
Produces generated object code in the listing file, which is annotated with source lines.
-cc++; -comments-c++
Generates c++ type comments in the code whenever commented object code is required.
-cr; -cross-reference
Produces a cross reference in the listing file.
-ev; -explicit-voidening
Lets the code generator produce explicit casting to void where appropriate.
-gc; -generated-code
Produces the generated code in the listing file.
-l; -listing
Produces a listing file, containing source code, syntax tree, generated code, cross reference and compilation statistics.
-ln a1; -listing-name a1
The name of the listing file will be a1.
-mp; -make-prelude
The compiler will build a prelude from the source file.
-O1; -optimise
Perform optimisations.
-on a1; -object-name a1
The name of the object file will be a1.
-pr a1, .. an; -pragma a1, .. an
The arguments a1, .. will be included in a #pragma directive in the generated code. Arguments are processed until an argument starts with a - or no arguments are left. Hence arguments cannot start with -, but if they have to, \- can be used.
-proff; -pragmats-off
Lets the compiler skip further options until -pragmats-on is encountered.
-pron; -pragmats-on
Resumes option handling after -pragmats-off.
-p a1, .. an; -prelude a1, .., an
The arguments a1, .. will be included as preludes. The arguments are treated as filenames. Arguments are processed until an argument starts with a - or no arguments are left. Hence arguments cannot start with -, but if they have to, \- can be used.
-pn a1; -prelude-name a1
The name of the prelude file will be a1.
-rp; -refinement-preprocessor
Invokes the refinement preprocessor.
-sl; -source-listing
Produces a source listing in the listing file.
-spl; -standard-prelude-listing
Produces a cross reference of the standard prelude in the listing file.
-s; -statistics
Produces compilation statistics in the listing file.
-upl; -user-prelude-listing
Produces a cross reference of included preludes (except the standard prelude) in the listing file.
-ve; -vax-errors
Produces VAX-style error messages.
-v; -verbose
Prints (on stdout) information during the translation.
-V; -version-number
Lets the translator state its version number on stdout.
Modular programs
Programs can be split into preludes which contain declarations and a particular program that includes preludes. When a source must be a prelude the option -mp must be issued upon translation. In this case:
• All declarations in the outermost level will be exported. All variables that will be referenced externally must be allocated on the heap.
• The "particular program" will be executed at the start of the execution of the particular program that includes the prelude.
Preludes can be imported using the -p option.
The refinement preprocessor
The compiler is equipped with a refinement preprocessor which facilitates top down program construction. The superimposed syntax reads
NOTION sequence:
NOTION; NOTION, NOTION sequence.
program with refinements:
token sequence, point symbol,
refinement definition sequence.
refinement definition:
refinement identifier tag, colon symbol,
token sequence, point symbol.
Where token is any Algol68 symbol except a point symbol. A refinement identifier tag is an Algol68 identifier tag. For example:
begin
add two numbers
end.
add two numbers:
read two numbers; write their sum.
read two numbers:
int i = read int, j = read int.
write their sum:
write(i + j).
Comments on jumps
PACT does not restrict the use of jumps and labels. However, whether certain jumps are safe depends on the reliability of the back end C compiler. In general
• Jumps in the outermost level and jumps to labels in the same routine-text are safe.
• Jumps to other labels and jumps involving coercion to proc void may be unsafe. PACT then uses the setjmp/longjmp routines which should be safe since local variables are declared volatile. Unfortunately, some ANSI C implementations do not guarantee that variables are not corrupted when using longjmp.
See Also
[MC] D. Grune. The Revised MC Algol 68 Test Set. IW 122/79, Mathematisch Centrum Amsterdam (1979).
[RR] A. van Wijngaarden et al. Revised Report on the Algorithmic Language Algol 68. Springer Verlag (1976).