我目前正在大学实时编程语言课程中学习 Ada,并且有一个关于 SPARK 的问题。
我正在从事一个项目,其任务是监控离网电源。这项任务对机器安全至关重要,因此应尽可能避免错误,例如用 SPARK 证明。
我收到了这个奇怪的错误,我无法找到解决方法11:14 tasking in SPARK requires sequential elaboration (SPARK RM 9(2)) violation of pragma SPARK_Mode
原始代码有点长,但我能够通过一个最小的示例得到相同的错误。
规格:
pragma Profile (Ravenscar);
pragma SPARK_Mode;
with System;
package simple_monitoring is
function sign (val : in Float) return Float
with Pre => val >= 10.0;
task type myTask is
end myTask;
end simple_monitoring;
实施:
pragma Profile (Ravenscar);
pragma SPARK_Mode;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Text_IO; use Ada.Text_IO;
package body simple_monitoring is
function sign (val : in Float) return Float is
res : Float;
begin
pragma Assert (val >= 10.0);
res := 100.0 / val;
return res;
end sign;
task body myTask is
TASK_PERIOD : constant Time_Span := Milliseconds (100);
next_time : Time := Clock;
myVar : Float;
begin
loop
Put_Line ("Running task");
myVar := sign (20.0);
next_time := next_time + TASK_PERIOD;
delay until next_time;
end loop;
end myTask;
end simple_monitoring;
任何帮助表示赞赏:-)