raw
cryostat_genesis.kv     1 ------------------------------------------------------------------------------
cryostat_genesis.kv 2 ------------------------------------------------------------------------------
cryostat_genesis.kv 3 -- This file is part of 'CryoDemo', a tutorial example for 'Cryostat'. --
cryostat_genesis.kv 4 -- --
cryostat_genesis.kv 5 -- (C) 2020 Stanislav Datskovskiy ( www.loper-os.org ) --
cryostat_genesis.kv 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
cryostat_genesis.kv 7 -- --
cryostat_genesis.kv 8 -- You do not have, nor can you ever acquire the right to use, copy or --
cryostat_genesis.kv 9 -- distribute this software ; Should you use this software for any purpose, --
cryostat_genesis.kv 10 -- or copy and distribute it to anyone or in any manner, you are breaking --
cryostat_genesis.kv 11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
cryostat_genesis.kv 12 -- continue doing so for the indefinite future. In any case, please --
cryostat_genesis.kv 13 -- always : read and understand any software ; verify any PGP signatures --
cryostat_genesis.kv 14 -- that you use - for any purpose. --
cryostat_genesis.kv 15 ------------------------------------------------------------------------------
cryostat_genesis.kv 16 ------------------------------------------------------------------------------
cryostat_genesis.kv 17
cryostat_genesis.kv 18 with Interfaces; use Interfaces;
cryostat_genesis.kv 19 with ada.text_io; use ada.text_io;
cryostat_genesis.kv 20
cryostat_genesis.kv 21 with Cryostat;
cryostat_genesis.kv 22
cryostat_genesis.kv 23
cryostat_genesis.kv 24 procedure CryoDemo is
cryostat_genesis.kv 25
cryostat_genesis.kv 26 -- Path on disk for the example Cryostat backing file :
cryostat_genesis.kv 27 File_Path : constant String := "cryotest.bin";
cryostat_genesis.kv 28
cryostat_genesis.kv 29 -- Now, let's define an example data structure to place in a Cryostat :
cryostat_genesis.kv 30
cryostat_genesis.kv 31 -- Example payload array's element type: byte.
cryostat_genesis.kv 32 subtype ADatum is Unsigned_8;
cryostat_genesis.kv 33
cryostat_genesis.kv 34 -- Let's make it 512MB - far bigger than a typical stack, to demonstrate
cryostat_genesis.kv 35 -- that it will in fact reside in the Cryostat, rather than on the stack :
cryostat_genesis.kv 36 A_MBytes : constant Unsigned_32 := 512;
cryostat_genesis.kv 37
cryostat_genesis.kv 38 -- Example payload: an array.
cryostat_genesis.kv 39 subtype ARange is Unsigned_32 range 0 .. (A_MBytes * 1024 * 1024) - 1;
cryostat_genesis.kv 40
cryostat_genesis.kv 41 -- Complete the definition of the payload data structure :
cryostat_genesis.kv 42 type TestArray is array(ARange) of ADatum;
cryostat_genesis.kv 43
cryostat_genesis.kv 44 -- Declare a Cryostat which stores a TestArray :
cryostat_genesis.kv 45 package Cryo is new Cryostat(Form => TestArray,
cryostat_genesis.kv 46 Path => File_Path,
cryostat_genesis.kv 47 Writable => True, -- Permit writing
cryostat_genesis.kv 48 Create => True); -- Create file if not exists
cryostat_genesis.kv 49
cryostat_genesis.kv 50 -- Handy reference to the payload; no pointerisms needed !
cryostat_genesis.kv 51 T : TestArray renames Cryo.Item;
cryostat_genesis.kv 52
cryostat_genesis.kv 53 -- T can now be treated as if it lived on the stack :
cryostat_genesis.kv 54
cryostat_genesis.kv 55 begin
cryostat_genesis.kv 56
cryostat_genesis.kv 57 Put_Line("T(0) before : " & ADatum'Image(T(0)));
cryostat_genesis.kv 58 Put_Line("T(Last) before : " & ADatum'Image(T(T'Last)));
cryostat_genesis.kv 59
cryostat_genesis.kv 60 -- Increment each of the elements of T :
cryostat_genesis.kv 61 for i in T'Range loop
cryostat_genesis.kv 62 T(i) := T(i) + 1;
cryostat_genesis.kv 63 end loop;
cryostat_genesis.kv 64
cryostat_genesis.kv 65 Put_Line("T(0) after : " & ADatum'Image(T(0)));
cryostat_genesis.kv 66 Put_Line("T(Last) after : " & ADatum'Image(T(T'Last)));
cryostat_genesis.kv 67
cryostat_genesis.kv 68 --- Optional, finalizer always syncs in this example
cryostat_genesis.kv 69 -- Cryo.Sync;
cryostat_genesis.kv 70
cryostat_genesis.kv 71 --- Test of Zap -- uncomment and get zeroized payload every time :
cryostat_genesis.kv 72 -- Cryo.Zap;
cryostat_genesis.kv 73
cryostat_genesis.kv 74 Put_Line("OK.");
cryostat_genesis.kv 75
cryostat_genesis.kv 76 end CryoDemo;