Annotated King Reference Manual/Bodies
Appearance
This page is work in progress.
Body declarations
[edit | edit source]Exemples
[edit | edit source]-
Syntax
[edit | edit source]body ::= proper_body | body_stub proper_body ::= subprogram_body | module_body | active_task_body | passive_task_body body_stub ::= subprogram_body_stub | module_body_stub | active_task_body_stub | passive_task_body_stub
Rationale
[edit | edit source]-
Discussions
[edit | edit source]-
Subprogram Body Declarations
[edit | edit source]Examples
[edit | edit source]Put : procedure (ID : in Philosopher_ID) body is
null; -- Declarative region must have a declarative item
Put : begin
Stick (ID) <- False;
Stick (Wrap.Next (ID) ) <- False;
Owner (ID) <- False;
Put : when E =>
E.Raise;
Put : end procedure;
Random : function (State : in out State) return Result body is
null; -- Declarative region must have a declarative item
Random : begin
State.Seed <- State.Seed + 1;
return State.Seed;
Random : when E =>
E.Raise;
Random : end function;
Syntax
[edit | edit source]subprogram_body ::= subprogram_specification body is declarative_part designator : begin sequence_of_statements designator : when identifier => sequence_of_statements designator : end procedure | function; designator ::= [parent_unit_name . ] identifier | operator_symbol
Rationale
[edit | edit source]-
Discussions
[edit | edit source]-
Module Body Declarations
[edit | edit source]Examples
[edit | edit source]Bad_Random : module body is
type State is record
Seed : Result is Result'Last;
end record State;
-- ...
Bad_Random : begin
null;
Bad_Random : when E =>
E.Raise;
Bad_Random : end module;
Syntax
[edit | edit source]module_body ::= defining_program_unit_name : module body is declarative_part defining_program_unit_name : begin sequence_of_statements defining_program_unit_name : when identifier => sequence_of_statements defining_program_unit_name : end module;
Rationale
[edit | edit source]-
Discussions
[edit | edit source]-
Active Task Body Declarations
[edit | edit source]Examples
[edit | edit source]Philosopher : task body is
Thinking = 10.0; -- Times in seconds
Talking = Thinking;
Eating = Thinking;
Philosopher : begin
All_Rounds : for Round in Integer range 1 .. 10 loop
-- ...
Message_Queue.Put (Item => ID'Image & " eating for " &
Eating'Image (Before => 0, After => 1, Exponent => 0));
wait of Eating;
end loop All_Rounds;
Philosopher : when Error =>
Message_Queue.Put (Item => ID'Image & " ended by " & Error.Information);
Philosopher : end task;
Syntax
[edit | edit source]active_task_body ::= defining_identifier : task body is declarative_part task_identifier : begin sequence_of_statements task_identifier : when identifier => sequence_of_statements task_identifier : end task;
Rationale
[edit | edit source]-
Discussions
[edit | edit source]-
Passive Task Body Declarations
[edit | edit source]Examples
[edit | edit source]Chopstick_Control : task body is
type State_Map is map Philosopher_ID => Boolean;
Stick : State_Map is State_Map'(others => False);
Owner : State_Map is State_Map'(others => False);
Has_Sticks : function (ID : in Philosopher_ID) return Boolean when True is (Owner (ID));
Picked : function (ID : in Philosopher_ID) return Boolean when True body is
Success : constant Boolean is not Stick (ID) and not Stick (Wrap.Next (ID) );
Picked : begin
-- ...
return Success;
Picked : when E =>
E.Raise;
Picked : end function;
Put : procedure (ID : in Philosopher_ID) when True body is
null;
Put : begin
-- ...
Put : when E =>
E.Raise;
Put : end procedure;
Chopstick_Control : end task;
Syntax
[edit | edit source]passive_task_body ::= defining_identifier : task body is {basic_declaration} barrier_body {{basic_declaration} barrier_body} task_identifier : end task; barrier_body ::= barrier_subprogram_body | barrier_statement_procedure_declaration | barrier_declare_statement_procedure_declaration | barrier_expression_function_declaration barrier_subprogram_body ::= subprogram_specification when condition body is declarative_part designator : begin sequence_of_statements designator : when identifier => sequence_of_statements designator : end procedure | function; barrier_statement_procedure_declaration ::= procedure_specification [aspect_specification] when condition is (simple_statement); barrier_declare_statement_procedure_declaration ::= procedure_specification [aspect_specification] when condition is (declare declare_declaration {declare_declaration} begin simple_statement); barrier_expression_function_declaration ::= function_specification [aspect_specification] when condition is (expression);
Rationale
[edit | edit source]-
Discussions
[edit | edit source]-
Body Stub Declarations
[edit | edit source]Examples
[edit | edit source]-
Syntax
[edit | edit source]subprogram_body_stub ::= subprogram_specification body is separate; module_body_stub ::= defining_identifier : module body is separate; active_task_body_stub ::= defining_identifier : task body is separate; passive_task_body_stub ::= active_task_body_stub
Rationale
[edit | edit source]-
Discussions
[edit | edit source]-