Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

System Types

The following scenarios are relevant to determining the definition of system types ...

8-bit byte hardware and multiple-of-8-bit byte software:

Before architectures will move to multiple-of-8-bit bytes, it is likely that prior to such change there would have been a shift in a number of programming languages using larger "virtual" bytes and the common use of the term "byte" itself might have changed to mean a larger unit than 8 bits. At that point there would be 8-bit machine-bytes and multiple-of-8-bit software bytes.

Multiple-of-8-bit byte hardware bytes and 8-bit byte software

If and when architectures will move to multiple-of-8-bit bytes, it is likely that even after such change there would still remain architectures and languages using 8-bit bytes. At that point there would be a need for a backwards compatible 8-bit byte in languages that mandate a de-facto 8-bit byte and languages that have a large code base that depends on de-facto 8-bit bytes, e.g. C and C++.

Wider than 8-bit but not multiples of 8-bit byte hardware

Legacy computer systems with 18 and 36-bit words are still in use, although their significance and numbers are in decline and they will eventually disappear. When compilers for languages that mandate 8-bit bytes or de-facto 8-bit bytes are targeted at architectures that use bytes wider than eight bits but not multiple's of eight bits, a common technique is to ignore the extra bits and use mappings whereby the number of wasted bits is minimal. This approach does not usually incur any significant performance penalty.

Smaller than 8-bit byte hardware

Embedded micro-controllers with 4-bit wide bytes continue to be developed, manufactured and used in large numbers. When compilers for languages that mandate 8-bit bytes or de-facto 8-bit bytes are targeted at architectures that use bytes with significantly less than eight bits, there are two possible approaches. One approach is to simulate an 8-bit architecture by combining multiple smaller-than-8-bit bytes into a single 8-bit byte. This approach is extremely inefficient and generally unsuitable for embedded micro-controller development. The other approach is to add an additional non-standard machine byte that matches the size of the actual architecture. This approach is efficient but it renders the source code non-standard.

Covering all four scenarios

Type OCTET

A new type OCTET shall be introduced

  • it shall have a fixed size of eight bits
  • it shall replace types BYTE and LOC in all occurrences of the standard library

It remains to be determined whether OCTET should be

  • a pervasive type, or
  • provided by module SYSTEM

Type BYTE

Type BYTE shall remain

  • it shall have an implementation defined size of one or more octets
  • a constant OctetsPerByte shall define the number of bytes per word
  • both constant and type shall be provided by module SYSTEM

Type WORD

Type WORD shall remain

  • it shall have an implementation defined size of one or more bytes
  • a constant BytesPerWord shall define the number of bytes per word
  • both constant and type shall be provided by module SYSTEM

Type MACHINEBYTE

A new type MACHINEBYTE shall be introduced

  • it shall be identical to the machine byte of the target architecture
  • a constant BitsPerMachineByte shall define the number of bits per machine byte
  • both constant and type shall be provided by module SYSTEM
  • IO formats for values of type MACHINEBYTE shall be implementation defined

For 8-bit byte target architectures, BitsPerMachineByte shall have a value of 8 and type MACHINEBYTE shall be an alias for OCTET. For non-8-bit targets, implementors shall be at liberty to implement the target by emulating an 8-bit byte architecture and if they do so, BitsPerMachineByte shall have a value of 8 and type MACHINEBYTE shall be an alias for OCTET.

Type MACHINEWORD

A new type MACHINEWORD shall be introduced

  • it shall be identical to the machine word of the target architecture
  • a constant MachineBytesPerMachineWord shall define the number of machine bytes per machine word
  • both constant and type shall be provided by module SYSTEM
  • IO formats for values of type MACHINEWORD shall be implementation defined

For 8-bit byte target architectures, MachineBytesPerMachineWord shall have a value identical to BytesPerWord and type MACHINEWORD shall be an alias for WORD. For non-8-bit targets, implementors shall be at liberty to implement the target by emulating an 8-bit byte architecture and if they do so, MachineBytesPerMachineWord shall have a value identical to BytesPerWord and type MACHINEWORD shall be an alias for WORD.

Type ADDRESS

Type ADDRESS shall remain

  • it shall be identical to the machine address of the target architecture
  • a constant OctetsPerAddress shall define the number of octets required to store an address
  • a constant MachineBytesPerAddress shall define the number of machine bytes per address
  • both constants and the type shall be provided by module SYSTEM