This commit is contained in:
Yannick Reiß 2025-06-22 21:41:12 +02:00
commit e1edc387da
7 changed files with 118 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/obj/
/bin/
/alire/
/config/

12
alire.toml Normal file
View File

@ -0,0 +1,12 @@
name = "spark_mode"
description = ""
version = "0.1.0-dev"
authors = ["Nicki"]
maintainers = ["Nicki <yannick.reiss@nickr.eu>"]
maintainers-logins = ["yannickreiss"]
licenses = "MIT OR Apache-2.0 WITH LLVM-exception"
website = ""
tags = []
executables = ["spark_mode"]

1
spark.adc Normal file
View File

@ -0,0 +1 @@
pragma SPARK_Mode (On);

23
spark_mode.gpr Normal file
View File

@ -0,0 +1,23 @@
with "config/spark_mode_config.gpr";
project Spark_Mode is
for Source_Dirs use ("src/", "config/");
for Object_Dir use "obj/" & Spark_Mode_Config.Build_Profile;
for Create_Missing_Dirs use "True";
for Exec_Dir use "bin";
for Main use ("spark_mode.adb");
package Compiler is
for Default_Switches ("Ada") use Spark_Mode_Config.Ada_Compiler_Switches;
for Local_Configuration_Pragmas use "spark.adc";
end Compiler;
package Binder is
for Switches ("Ada") use ("-Es"); -- Symbolic traceback
end Binder;
package Install is
for Artifacts (".") use ("share");
end Install;
end Spark_Mode;

44
src/logic.adb Normal file
View File

@ -0,0 +1,44 @@
package body Logic is
-- @name Step
-- @return
-- @parameter N:Natural
-- @parameter O:Natural
-- @description Do one calculation step and safe the result to O.
procedure Step (N : Natural; O : out Natural) is
begin
if N mod 2 = 0 then
O := N / 2;
else
O := 3 * N + 1;
end if;
end Step;
-- @name Row
-- @return
-- @parameter N:Natural,Final
-- @description Calculate full row for design.
procedure Row (N : Natural; Final : out Natural) is
Old : Natural := N;
Update : Natural;
begin
while (Old < (Natural'Last / 3)) and (not (Old = 1)) loop
Step (Old, Update);
Old := Update;
end loop;
if not (Old = 1) then
Old := 1;
end if;
Final := Old;
end Row;
end Logic;

19
src/logic.ads Normal file
View File

@ -0,0 +1,19 @@
package Logic is
-- @name Step
-- @return
-- @parameter N:Natural
-- @parameter O:Natural
-- @description Do one calculation step and safe the result to O.
procedure Step (N : Natural; O : out Natural) with
Depends => (O => N), Pre => (N < (Natural'Last / 3));
-- @name Row
-- @return
-- @parameter N:Natural,Final
-- @description Calculate full row for design.
procedure Row (N : Natural; Final : out Natural) with
Depends => (Final => N), Pre => (N < (Natural'Last / 3)),
Post => (Final = 1);
end Logic;

15
src/spark_mode.adb Normal file
View File

@ -0,0 +1,15 @@
with Logic; use Logic;
with Ada.Text_IO; use Ada.Text_IO;
procedure Spark_Mode is
A, B : Natural;
begin
A := 8_400;
Row (A, B);
Put_Line (B'Image);
end Spark_Mode;