-
Notifications
You must be signed in to change notification settings - Fork 2
Language Specification : Terms of Reference
Note: This page may be out of sync with the authoritative PDF.
The allocation size of a type T, denoted as tsize T is the size of the memory required to allocate an instance of T. It is measured in units of 8 bits called octets.
The capacity of a collection c is the maximal number of values that can be stored in c. Its value is determined by the type of of c. Its definition is
- capacity c = tlimit T where T is the type of c.
The capacity of a pass-by-value open array parameter pval is equivalent to the cardinality or value count of the collection passed to pval. Its definition is
- capacity pval = count c where c is the collection passed to pval.
The capacity of a pass-by-reference open array parameter pref is equivalent to the capacity of the collection passed to pref. Its definition is
- capacity pref = capacity c where c is the collection passed to pref.
The capacity limit of a collection type T, denoted as tlimit T is the maximum number of items that an instance of T can store. A capacity limit of zero indicates that the collection type does not impose any hard limit.
In mathematics, the cardinality of a set A, denoted as |A| or card A is a measure of the number of elements in A. In this specification, the definition is extended to include collections, open array parameters and variadic argument lists.
- the cardinality of a collection c is the number of components stored in c
- the cardinality of an open array parameter p is that of of the collection passed in p
- the cardinality of a variadic argument list v is the number of arguments passed in v
Compatibility is a property that determines whether one entity may be assigned to, copied to, passed to or used in an expression with another entity.
- a literal is fully compatible with type T if it is assignment, copy, by‑value and by‑reference passing compatible to and expression compatible with type T
- type T1 is fully compatible with type T2 if it is assignment, copy, by‑value and by‑reference passing compatible to and expression compatible with type T2
Assignment compatibility is a property that determines whether one entity may be assigned to another entity.
- a literal is assignment compatible to type T if it may be assigned to a value of type T
- type T1 is assignment compatible to type T2 if an R‑value of type T1 may be assigned to an L‑value of type T2
Copy compatibility is a property that determines whether one entity may be copied to another entity.
- a literal is copy compatible to type T if it may be copied to a value of type T
- type T1 is copy compatible to type T2 if an R‑value of type T1 may be copied to an L‑value of type T2
Parameter passing compatibility is a property that determines whether an entity may be passed to a formal parameter.
- a literal is by-value passing compatible to type T if it may be passed to a formal by‑value parameter of type T
- a literal is by-reference passing compatible to type T if it may be passed to a formal
CONST
parameter of type T - type T1 is by-value passing compatible to type T2 if a value of type T1 may be passed to a formal by‑value parameter of type T2
- type T1 is by-reference passing compatible to type T2 if a value of type T1 may be passed to a formal by‑reference parameter of type T2
Expression compatibility is a property that determines whether an entity may be used together with another entity as operands in a binary expression.
- a literal is expression compatible to type T in respect of operation M if it may be used together with a value of type T as the operands in a binary expression with any operator representing operation M
- types T1 and T2 are expression compatible in respect of operation M if a value of type T1 and a value of type T2 may be used together as the operands in a binary expression with any operator representing operation M
A constant expression is an expression that is computable at compile time. A constant expression does not reference any variables nor invoke any library functions.
The fractional part of a real number x is the value that represents the digits of x after the decimal point if x was to be written out in decimal notation without an exponent.
Its definition is
- frac x = x - int x
The integral part of a real number x is the value that represents the digits of x before the decimal point if x was to be written out in decimal notation without an exponent.
Its definition is
- int x = sgn x · entier abs x
The entier value of a real number x is the largest integer less than x. Its definition is
- entier x = max i for i ∈ { ℤ | i < x }
The length of a character string s is the number of characters stored in s excluding its NUL terminator. Its definition is
- length s = min n for n ∈ { ℕ | sn = ASCII.NUL }
The length of an octet sequence s is the allocation size of the actual parameter p passed in to a formal parameter of type octet sequence. Its definition is
- length s = tsize p where p passed-to s
In this specification abstract number sets are defined as follows:
- the set of the abstract natural numbers ℕ = { 0, 1, 2, 3, ... ∞ }
- the set of the abstract ordinal numbers 𝕆 = { 0, 1, 2, 3, ..., ω, ω+1, ω+2, ... }
- the set of the abstract whole numbers ℤ = { -∞ ... -3, -2, -1, 0, 1, 2, 3, ... +∞ }
The odd value of a whole number i indicates whether i is odd. Its definition is
- odd i = true for i ∈ { ℤ | abs i mod 2 = 1 }
- odd i = false for i ∈ { ℤ | abs i mod 2 = 0 }
The signum or sgn value of a signed number x indicates the sign of x. Its definition is
- sgn x = 1 for x ∈ { ℝ | x > 0 }
- sgn x = 0 for x ∈ { ℝ | x = 0 }
- sgn x = -1 for x ∈ { ℝ | x < 0 }
A type is a classification of storage units defined by a set of three properties: storage representation, value range and semantics.
The set of all types is denoted Tany.
A builtin type is a type that is built into the language, that is, either a predefined type or a type provided by builtin module UNSAFE
.
The set of all builtin types is denoted Tbuiltin.
A countable type is a type that represents a set of values with a 1:1 correspondence to the first m ordinal numbers 𝕆 where m ∈ 𝕆.
- countable T if ∃ f : T → 𝕆;
The set of all countable types is denoted Tcountable.
- ∀ countable T, T ∈ Tcountable
An enumerated type is a type that represents a finite ordered set of identifiers.
- enumerated T if ∀ e ∈ { T | identifier e } ∧ ∃ f : T → ℕ
The set of all enumerated types is denoted Tenum.
- ∀ enumerated T, T ∈ Tenum
A machine type is a type that represents storage units that precisely match the storage units of the target architecture and have modular arithmetic semantics.
The set of all machine types is denoted Tmachine.
A signed type is a numeric type that represents both positive and negative scalar numeric values..
- signed T if ∃ x, y ∈ { T | x < 0 ∧ y > 0 }
The set of all signed types is denoted Tsigned.
- ∀ signed T, T ∈ Tsigned
An unsigned type is a numeric type that represents non-negative scalar numeric values.
- unsigned T if ∀ x ∈ { T | x ≥ 0 }
The set of all unsigned types is denoted Tunsigned.
- ∀ unsigned T, T ∈ Tunsigned
A whole number type is a numeric type that represents a subset of the set of integers ℤ.
- whole T if ∀ n ∈ { T | n ∈ ℤ }
The set of all whole number types is denoted Twhole.
- ∀ whole T, T ∈ Twhole
A real number type is a numeric type that represents a subset of the set of real numbers ℝ.
- real T if ∀ r ∈ { T | r ∈ ℝ }
The set of all real number types is denoted Treal.
- ∀ real T, T ∈ Treal
A cardinal type is a numeric type that represents a subset of the unsigned whole numbers ℤ⁺.
- cardinal T if unsigned T ∧ whole T
The set of all cardinal types is denoted Tcardinal.
- ∀ cardinal T, T ∈ Tcardinal
An integer type is a numeric type that represents a subset of the signed whole numbers ℤ.
- integer T if signed T ∧ whole T
The set of all integer types is denoted Tinteger.
- ∀ integer T, T ∈ Tinteger
A scalar type is a numeric type that represents scalar values.
The set of all scalar types is denoted Tscalar.
A collection type represents n-tuples of an arbitrary component type, where n is bounded by its capacity.
The set of all collection types is denoted Tcollection.
An array type is an ordered collection type whose components are mapped to the set of the first m ordinal numbers 𝕆 where m is the capacity limit of the array type.
The set of all array types is denoted Tarray.
An string type is an array type whose components are characters.
The set of all string types is denoted Tstring.
The set of all record types is denoted Trecord.
The set of all extensible record types is denoted Textrec.
The set of all extensible record pointer types is denoted Trecptr.
- Trecptr = { T ∈ Tpointer ∖ Topaque | target-type T ∈ Textrec }
The set of all opaque types is denoted Topaque.
An open array type is a formal array type whose capacity is indeterminate at compile time.
The set of all open array types is denoted Topenarray.
A variadic parameter list is a formal collection type whose cardinality is indeterminate at compile time.
The set of all variadic parameter lists is denoted Targlist.
The value count of an entity e is synonym with the cardinality of e. Its definition is
- count e ≡ card e, where card e is the cardinality of entity e
A Wirthian macro is a built-in syntactic entity whose occurrence is replaced with an appropriate library call, possibly filling in omitted arguments. The macro may be a statement or a built-in procedure or function. The mapped-to library must be explicitly imported.
Wirthian macros allow more convenient syntax than ordinary library calls and make a facility such as memory management or I/O appear to be built into the language even though it is actually provided by a library. Classic examples of Wirthian macros are procedures NEW
and DISPOSE
in earlier versions of Modula-2.
Copyright © 2015-2018 Modula-2 Software Foundation