sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / harness / examples / om2_tour.om
| 1 | note om2_tour: layout, abstract/holds/seal/open, fresh, unroll (after omega-mv examples/om2-tour.om) |
| 2 | om2 |
| 3 | layout blk 8 |
| 4 | field lo uint at 0 little |
| 5 | field hi uint at 4 big |
| 6 | end |
| 7 | abstract v32 ulong |
| 8 | holds v32 dup32 |
| 9 | note the erasing constructor: the body is exactly this line |
| 10 | fn v32mk x uint to v32 |
| 11 | ret seal v32 or shl ulong x 32 ulong x |
| 12 | end |
| 13 | note fresh: every element is written before it is read (error 27 otherwise) |
| 14 | fn seed s edit uint 8 fresh to uint |
| 15 | for i uint 8 unroll |
| 16 | put s i mul i 3 |
| 17 | end |
| 18 | ret get s 7 |
| 19 | end |
| 20 | fn stamp c edit blk to void |
| 21 | put c lo 0x01020304 |
| 22 | put c hi 0x05060708 |
| 23 | end |
| 24 | fn main to int |
| 25 | s = new uint 8 0 |
| 26 | v = seed s |
| 27 | if ne v 21 |
| 28 | ret 1 |
| 29 | end |
| 30 | c = new uchar 8 0 |
| 31 | stamp c |
| 32 | if ne get c 0 0x04 |
| 33 | ret 2 |
| 34 | end |
| 35 | if ne get c 4 0x05 |
| 36 | ret 3 |
| 37 | end |
| 38 | u = open v32mk 7 |
| 39 | if ne u 0x0000000700000007 |
| 40 | ret 4 |
| 41 | end |
| 42 | ret 0 |
| 43 | end |