Annotated King Reference Manual/Types

This page is work in progress.

Type Declarations
Some general principles:


 * All scalar subtypes have a default value. For bounded numeric and enumeration subtypes, this is the 'First of the subtype, unless a different value is specified with the Default_Value aspect. For unbounded numeric subtypes, the Default_Value aspect must be specified. Note that an unbounded numeric type can have bounded subtypes.
 * The Predicate aspect may be specified for all subtypes.
 * All scalar types have the attributes 'Image, 'Value, 'Min, 'Max, 'Previous, and 'Next.
 * Integer and enumeration types have the attributes 'Position, 'Value (integer), 'Representation, and 'From_Representation. For integer types, 'Position and 'Representation both give the value of the parameter, and 'Value (integer) and 'From_Representation give the value of the type with the value of the parameter (if that exists); this is similar to 'Pos and "Val for integer types in Ada.
 * 'Image <=>, 'Value (string) are inverses of each other, as are 'Position <=> 'Value (integer)

Syntax
type_declaration ::= full_type_declaration | hidden_type_declaration full_type_declaration ::= type defining_identifier [known_discriminant_part] is type_definition [aspect_specification]; hidden_type_declaration ::= type defining_identifier [discriminant_part] is hidden [aspect_specification]; discriminant_part ::= unknown_discriminant_part | known_discriminant_part unknown_discriminant_part ::= (<>) known_discriminant_part ::= (discriminant_specification {; discriminant_specification}) discriminant_specification ::= defining_identifier : subtype_mark [<- default_expression] type_definition ::= enumeration_type_definition | integer_type_definition | real_type_definition | map_type_definition | sequence_type_definition | set_type_definition | record_type_definition | derived_type_definition | module_type_definition | task_type_definition

Rationale
-

Discussion
-

Syntax
enumeration_type_definition ::= (enumeration_literal_specification {, enumeration_literal_specification}) enumeration_literal_specification ::= defining_identifier | defining_character_literal

Rationale
-

Discussion
-

Syntax
integer_type_definition ::= bounded_integer_type_definition | unbounded_integer_type_definition bounded_integer_type_definition ::= range static_simple_expression .. static_simple_expression unbounded_integer_type_definition ::= range <>

Rationale
Bit-wise operations are available for the base type of all bounded integer types that fit in a single hardware integer.

Discussion
-

Syntax
real_type_definition ::= floating_point_definition | fixed_point_definition

Syntax
floating_point_definition ::= bounded_floating_point_definition | unbounded_floating_point_definition bounded_floating_point_definition ::= digits static_expression [real_range_specification] real_range_specification ::= range static_simple_expression .. static_simple_expression unbounded_floating_point_definition ::= digits <>

Rationale
-

Discussion
-

Syntax
fixed_point_definition ::= bounded_fixed_point_definition | unbounded_fixed_point_definition bounded_fixed_point_definition ::= delta static_expression real_range_specification unbounded_fixed_point_definition ::= delta static_expression range <>

Rationale
Shouldn't decimal types be available, in order to cover the corresponding available type of Ada?

A King fixed-point type with a delta that is a power of 10 is equivalent to an Ada decimal fixed-point type.

type Money is delta 0.01 digits 14;

The above would be equivalent to:

type Money is delta 0.01 range -999_999_999_999.99 .. 999_999_999_999.99;

Discussion
-

Syntax
map_type_definition := map key_subtype_mark => value_subtype_mark

Operators
"=" is only defined if it is defined for the value subtype.

Attributes
-

Aspects
-

Rationale
Maps may also be implemented by functions, so King uses a common notation for both.

Discussion
-

Syntax
sequence_type_definition := sequence of element_subtype_mark

Operators
"=" is only defined if it is defined for the value subtype.

Attributes
-

Aspects
-

Rationale
-

Discussion
-

Syntax
set_type_definition := set of element_subtype_mark

Attributes
-

Aspects
-

Component deference
-

Rationale
-

Discussion
-

Syntax
record_type_definition ::= record_definition record_definition ::= record component_list end record record_identifier component_list ::= component_item {component_item} | {component_item} variant_part | null; component_item ::= component_declaration component_declaration ::= defining_identifier : component_definition [<- default_expression] [aspect_specification]; component_definition ::= subtype_indication variant_part ::= case discriminant_direct_name is variant {variant} end case; variant ::= when discrete_choice_list => component_list discrete_choice_list ::= discrete_choice {| discrete_choice} discrete_choice ::= choice_expression | discrete_subtype_indication | range_specification | others

Attributes
-

Aspects
-

Rationale
-

Discussion
-

Syntax
derived_type_definition ::= new parent_subtype_indication

Operators
-

Attributes
-

Aspects
-

Rationale
The operations, attributes, and so on are based on the parent type.

Discussion
-

Syntax
module_type_definition ::= module subprogram_declaration {subprogram_declaration} end module module_identifier

Operators
-

Attributes
-

Aspects
-

Rationale
-

Discussion
-

Syntax
task_type_definition ::= task

Attributes
-

Aspects
-

Rationale
-

Discussion
-

Syntax
task_type_definition ::= task subprogram_declaration {subprogram_declaration} end task task_identifier

Attributes
-

Aspects
-

Rationale
Passive tasks are the only way that active tasks may communicate.

Discussion
-