Skip to content

Instantly share code, notes, and snippets.

@Julio-Guerra
Created May 23, 2012 09:34
Show Gist options
  • Save Julio-Guerra/2774238 to your computer and use it in GitHub Desktop.
Save Julio-Guerra/2774238 to your computer and use it in GitHub Desktop.
Static pipeline in Ada
-- Usage example
with Ada.Text_IO; use Ada.Text_IO;
with Pipeline;
procedure Main is
-- Pipeline functions
procedure Step1 is
begin
Put("1");
end Step1;
procedure Step2 is
begin
Put("2");
end Step2;
procedure Step3 is
begin
Put("3");
end Step3;
-- Pipeline Steps using linked list representation (Step, Next_Pipeline_Step)
procedure PStep3 is new Pipeline.Step(Step3);
procedure PStep2 is new Pipeline.Step(Step2, PStep3);
procedure PStep1 is new Pipeline.Step(Step1, PStep2);
begin
-- Execute the pipeline
PStep1;
-- Make sure to compile with optimization options to unroll the pipeline & inline its steps.
-- The result here would be :
-- Step1;
-- Step2;
-- Step3;
-- Otherwise, the stack increases in each step (PStep(N) calls PStep(N+1)), which is a behavior to avoid.
end Main;
package body Pipeline is
procedure Step is
begin
F;
Next_Step;
end;
procedure Null_Step is
begin
null;
end Null_Step;
end Pipeline;
package Pipeline is
-- Do nothing.
procedure Null_Step;
generic
-- Function to be executed by the step.
with procedure F;
-- Next step to execute after F's, doing nothing by default.
with procedure Next_Step is Null_Step;
procedure Step;
end Pipeline;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment