Converting from TopSpeed Modula-2

    TopSpeed Modula-2 mostly followed the old Wirth Modula-2 dialect. Stony Brook Modula-2 follows the ISO Standard Modula-2 dialect.

    TopSpeed was very loose with its interpretation of Wirth Modula-2. The ISO standard is very strict and leaves no room for interpretation. This is very good since it maximizes portability.

Runtime library

Wirth Modula-2 did not define much in the way of library modules and as such most Wirth Modula-2 compilers have incompatible library modules. ISO Modula-2 attempts to deal with this for modules that are portable from machine to machine. This means the ISO Modula-2 standard library will not have everything you may desire.

Currently we have a few TopSpeed compatible RTL modules available to simplify porting an application. Most of the modules are implemented by calling equivalent modules in the Stony Brook Modula-2 RTL thus incurring a slight additional overhead of an extra procedure call and parameter pass.

These modules were implemented from the descriptions in the printed documentation of the TopSpeed compiler. Thus any discrepancy between their documentation and their implementation will be implemented in our versions unless and until we are notified of a discrepancy. We do not have any TopSpeed RTL source code to consult.

To build the TopSpeed compatible library run the tslib batch file in the installation directory.

tslib win32 <= to build the library for Win32
tslib x32 <= to build the library for 32-bit DOS extended
tslib win16 <= to build the library for Win16
tslib dos <= to build the library for 16-bit DOS

Concerning any other TopSpeed RTL your application may be using you can...

  1. Implement you own copies of the Topspeed modules you use. You now have source code for these modules and are thus portable and self sufficient.
  2. Convert to use ISO Modula-2 standard modules when an ISO equivalent exists.
  3. Convert to use library modules from our RTL that are not ISO Modula-2 standard. You have source code for these modules and are thus portable and self sufficient.
  4. If ISO Modula-2 nor Stony Brook has an equivalent to a Topspeed module you will have to implement the module yourself.

Strict type checking

You may find that our compiler is more type strict than the Topspeed compiler was. This is a good thing and is generally a primary reason for choosing Modula-2 as a development language over other languages.

Type Transfers.

In Wirth Modula-2 type transfers, or type casts, used the following syntax.

TypeName(expression)

In ISO Modula-2 the syntax goes like

CAST(TypeName, expression)

where CAST is imported from the SYSTEM module.

This is a very easy conversion except that Topspeed changed the meaning of the type transfer syntax in some instances of its usage but not all. If the destination and source types are of an ordinal or numeric type then Topspeed performed a type conversion and not a type cast. Ordinal and numeric types are INTEGER, CARDINAL, enumeration, REAL and LONGREAL.

Because of this you cannot just replace all type transfers with the ISO CAST function. You must examine the circumstance and use either the CAST or VAL function.

Type casts are a possibly non portable source syntax and this is the reason CAST is imported from SYSTEM. The CAST function is easy to detect in source code where the Wirth M2 type cast syntax looked just like a normal procedure call making it more difficult to detect.

FOR loops

You should never depend on the value of the loop control variable after the completion of the FOR loop.

The ISO Modula-2 standard places many restrictions on how a loop control variable can be used. The reasons for this are to insure the integrity of the loop control variable. You will get compilation errors when a control variable is used in an invalid manner.

CASE statements

ISO Modula-2 defines that if no case selections are executed and the CASE selections do not handle all possible values in the CASE expression and there is no ELSE clause in the statement then an exception is raised. Wirth M2 did not define what should happen in this situation and most compilers like Topspeed simply let execution continue beyond the CASE statement with none of the code in the CASE statement having executed. To get this behavior in an ISO M2 compiler you simply need to place an empty ELSE clause in your CASE statement. The compiler will generate a warning when a CASE statement does not have an ELSE and the selectors do not handle all possible values.

Conditional compilation

Unfortunately ISO Modula-2 did not define a standard for this. Thus you will have to convert from the Topspeed mechanism to one of the two machanism's support by the Stony Brook compiler.

Embedded source code compiler directives

ISO Modula-2 defined the syntax for a embedded directive, but did not define the syntax of the contents of the directive.

Predefined TYPEs

ISO Modula-2 only defines INTEGER and CARDINAL as did Wirth Modula-2. We have extended this with SHORTCARD, SHORTINT, LONGINT and LONGCARD. These definitions are compatible with the TopSpeed extended definitions.

The Topspeed >> and  << operators

ISO Modula-2 does not have an equal to these operators, but we have extended operators that are the same.

SHR is the same as >>
SHL is the same as <<

BITSET constants

In Wirth Modula-2 BITSET constants did not have a type name preceding the {, but in ISO M2 all set constants must have the type name preceding the {. example BITSET{5, 7}