Category:Types

From Mesham
Revision as of 15:44, 15 April 2019 by Polas (talk | contribs) (7 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Overview

A type can follow a number of different syntactic forms. The abstract syntax of a type is detailed in the table below. Where elementtype is defined in the type library, varname represents the current type of a variable and type :: type represents type combination to coerce into a new supertype.

type =   elementtype
	| compoundtype
	| type :: type 
	| varname

All element types start with a capitalised first letter and there must be at least one element type per type chain. Compound types start with a small case and contain a number of different subcategories of type

compoundtype =   attribute
		| allocation
		| collection 
		| primitive communication
		| communication mode
		| partition
		| distribution
		| composition

Types may be referred to with or without arguments, it is therefore optional to specify square braces, [] after a type with or without data in.

Declarations

Syntax

var name:type;

Where type, as explained, is an elementtype, a compoundtype, variable name or type :: type. The operator : sets the type and :: is type combination (coercion).

Semantics

This will declare a variable to be a specific type. Type combination is subject to a number of semantic rules. If no type information is given, then the type will be found via inference where possible.

Examples

function void main() {
   var i:Int :: allocated[multiple[]];
};

Here the variable i is declared to be integer, allocated to all processes. There are three types included in this declaration, the element type Int and the compound types allocated and multiple. The type multiple is provided as an argument to the allocation type allocated, which is then combined with the Int type.

function void main() {
   var m:String;
};

In this example, variable m is declared to be of type String. For programmer convenience, by default, the language will automatically assume to combine this with allocated[multiple] if such allocation type is missing.

Statements

Syntax

name:type;

Semantics

Will modify the type of an already declared variable via the : operator. Note, allocation information (via the allocation type) may not be changed. Type modification such as this binds to the current block, the type is reverted back to its previous value once that block has been left.

Examples

function void main() {
   var i:Int :: allocated[multiple[]];
   i:=23;
   i:i :: const[];
};

Here the variable i is declared to be integer, allocated to all processes and its value is set to 23. Later on in the code the type is modified to set it also to be constant (so from this point on the programmer may not change the variable's value.) In this third line i:i :: const[]; sets the type of i to be that of i combined with the const type.\twolines{}

Important Rule - Changing the type will not have any runtime code generation in itself, although the modified semantics will affect how the variable behaves from that point on.

Expressions

Syntax

name::type

Semantics

When used as an expression, a variable's current type can be coerced with additional types just for that expression.

Example

function void main() {
   var i:Int :: allocated[multiple[]];
   (i :: channel[1,2]):=82;
   i:=12;
};

This code will declare i to be an integer, allocated on all processes. On line 2 i :: channel[1,2] will combine the channel type (primitive communication) just for that assignment and then on line 3 the assignment happens as a normal integer. This is because on line 2 we have not set the type of i, just modified it for that assignment.

Pages in category ‘Types’

The following 3 pages are in this category, out of 3 total.