跳转到内容

注释版 King 参考手册/主体

来自维基教科书,开放世界中的开放书籍

此页面正在开发中。

主体声明

[编辑 | 编辑源代码]

-

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

基本原理

[编辑 | 编辑源代码]

-

-

子程序主体声明

[编辑 | 编辑源代码]
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;
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

基本原理

[编辑 | 编辑源代码]

-

-

模块主体声明

[编辑 | 编辑源代码]
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;
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;

基本原理

[编辑 | 编辑源代码]

-

-

主动任务主体声明

[编辑 | 编辑源代码]
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;
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;

基本原理

[编辑 | 编辑源代码]

-

-

被动任务体声明

[编辑 | 编辑源代码]
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;
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);

基本原理

[编辑 | 编辑源代码]

-

-

体存根声明

[编辑 | 编辑源代码]

-

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

基本原理

[编辑 | 编辑源代码]

-

-

华夏公益教科书