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

Verification Of Operator Bindings

=== This page is now out of date ===

Semantic Superset Types

For a library defined type to define bindings to operators and pervasive functions it must be declared as a subset of one of six semantic superset types:

  • the A-Type, semantic superset of all dynamic array and set types
  • the S-Type, semantic superset of all dynamic character string types
  • the Z-Type, semantic superset of all integer number types
  • the R-Type, semantic superset of all real number types
  • the C-Type, semantic superset of all complex number types
  • the V-Type, semantic superset of all vector and ordered tuple types

The syntax is defined as:

recordType :
    RECORD ( '(' semanticType | baseType ')' )? fieldListSequence? END ;

opaquePointerType :
    OPAQUE ( '(' semanticType ')' )?;

semanticType : string ;
// "A-Type" and "S-Type" for opaque pointers
// "Z-Type", "R-Type", "C-Type", "V-Type" for records

The verification of operator bindings depends on the semantic type that a library type is declared a subset of. It is a compile time error to declare a binding for an operator or pervasive function that is not permitted by the type's semantic superset type.

The bindings permitted for each semantic type are listed below:

A-Type Bindings

The following bindings are permitted:

  • [NIL] null key value
  • [NEW] constructor
  • [DISPOSE] destructor
  • [COUNT] number of entries
  • [FOR] iterator
  • [IN] membership test
  • [.] entry accessor
  • [!] entry mutator
  • [-] entry removal

Example: SampleCollection

S-Type Bindings

The following bindings are permitted:

  • [NEW] constructor
  • [DISPOSE] destructor
  • [LENGTH] length
  • [:=] literal assignment
  • [::] type conversion
  • [+] concatenation
  • [=] equality
  • [<] lower in collating sequence
  • [>] higher in collating sequence

Example: STRING

Z-Type Bindings

The following bindings are permitted:

  • [TMIN] minimum value
  • [TMAX] maximum value
  • [ABS] absolute value
  • [NEG] sign reversal
  • [ODD] odd or even
  • [:=] literal assignment
  • [::] type conversion
  • [+] addition
  • [-] subtraction
  • [*] multiplication
  • [DIV] division
  • [MOD] modulo
  • [=] equality
  • [<] less than
  • [>] greater than
  • [TO] scalar conversion primitive
  • [FROM] scalar conversion primitive

Examples: SampleUINT and SampleINT

R-Type Bindings

The following bindings are permitted:

  • [TMIN] minimum value
  • [TMAX] maximum value
  • [ABS] absolute value
  • [NEG] sign reversal
  • [:=] literal assignment
  • [::] type conversion
  • [+] addition
  • [-] subtraction
  • [*] multiplication
  • [/] division
  • [=] equality
  • [<] less than
  • [>] greater than
  • [TO] scalar conversion primitive
  • [FROM] scalar conversion primitive

Example: BCD

C-Type Bindings

The following bindings are permitted:

  • [ABS] absolute value
  • [NEG] sign reversal
  • [::] type conversion
  • [+] addition
  • [-] subtraction
  • [*] multiplication
  • [/] division
  • [=] equality

Example: COMPLEX

V-Type Bindings

The following bindings are permitted:

  • [HIGH] highest component index
  • [ABS] absolute value
  • [NEG] sign reversal
  • [.] component accessor
  • [!] component mutator
  • [::] type conversion
  • [+] addition
  • [-] subtraction
  • [=] equality

Example: SampleVector and SampleTuple

Common constraints

The following constraints are common to all semantic types:

  • a module can only define bindings for a type that is declared in the module and has the same identifier as the module.
  • multiple type conversion bindings may be declared but only if each binding has a different conversion target type.
  • any other bindings can only be declared once.

Summary

 S-TypeZ-TypeR-TypeC-TypeV-TypeCollection
  TMINyesyes
  TMAXyesyes
  HIGHyes
  LENGTHyes
  COUNTyes
  ABSyesyesyesyes
  NEGyesyesyesyes
  ODDyes
  DIVyes
  MODyes
  NILyes
  NEWyes
  DISPOSEyes
  FORyes
  INyes
  TOyesyes
  FROMyesyes
  ::yesyesyesyes
  :=yesyesyes
  .yesyes
  !yesyes
  +yesyesyesyesyes
  -yesyesyesyesyes
  *yesyesyes
  /yesyes
  =yesyesyesyesyes
  <yesyesyes
  >yesyesyes