omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / om / compiler / osc_artifact.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note oscc artifact entry, in the text format consumed by the unit packager. |
| 3 | note bridge c-type entry OscArtifactEntry |
| 4 | om2 |
| 5 | layout entry 40 |
| 6 | field index uint at 0 little |
| 7 | field count uint at 4 little |
| 8 | field result uint at 8 little |
| 9 | field kind uint 6 at 12 little |
| 10 | field offset uint at 36 little |
| 11 | end |
| 12 | |
| 13 | fn decimal value uint dst edit uchar * pos ulong to ulong |
| 14 | digits = new uchar 10 0 |
| 15 | n = ulong 0 |
| 16 | while true |
| 17 | put digits n uchar add rem value 10 48 |
| 18 | n = add n 1 |
| 19 | value = div value 10 |
| 20 | if eq value 0 |
| 21 | break |
| 22 | end |
| 23 | end |
| 24 | if gt add pos n len dst |
| 25 | ret len dst |
| 26 | end |
| 27 | for i ulong n |
| 28 | put dst add pos i get digits sub sub n 1 i |
| 29 | end |
| 30 | ret add pos n |
| 31 | end |
| 32 | |
| 33 | note Negative results -1 through -6 name a refused parameter register. |
| 34 | note -7 means insufficient space or an arity outside the artifact format. |
| 35 | export fn osc_artifact_entry row view entry name view uchar * dst edit uchar * to long |
| 36 | count = ulong get row count |
| 37 | if gt count 6 |
| 38 | ret -7 |
| 39 | end |
| 40 | for i ulong count |
| 41 | kind = get row kind i |
| 42 | if or eq kind 0 or eq kind 10 gt kind 12 |
| 43 | ret sub long -1 long i |
| 44 | end |
| 45 | end |
| 46 | pos = decimal get row index dst 0 |
| 47 | for i ulong 9 |
| 48 | if ge pos len dst |
| 49 | ret -7 |
| 50 | end |
| 51 | put dst pos 32 |
| 52 | value = uint 0 |
| 53 | if eq i 0 |
| 54 | value = uint count |
| 55 | end |
| 56 | if eq i 1 |
| 57 | value = get row result |
| 58 | end |
| 59 | if and ge i 2 lt i add count 2 |
| 60 | value = get row kind sub i 2 |
| 61 | end |
| 62 | if eq i 8 |
| 63 | value = get row offset |
| 64 | end |
| 65 | pos = decimal value dst add pos 1 |
| 66 | end |
| 67 | if gt add add pos len name 2 len dst |
| 68 | ret -7 |
| 69 | end |
| 70 | put dst pos 32 |
| 71 | pos = add pos 1 |
| 72 | for i ulong len name |
| 73 | put dst add pos i get name i |
| 74 | end |
| 75 | pos = add pos len name |
| 76 | put dst pos 10 |
| 77 | ret long add pos 1 |
| 78 | end |
| 79 | |
| 80 | fn digit_hex nibble uchar to uchar |
| 81 | if lt nibble 10 |
| 82 | ret add nibble 48 |
| 83 | end |
| 84 | ret add nibble 87 |
| 85 | end |
| 86 | |
| 87 | export fn osc_artifact_hex digest view uchar 32 dst edit uchar 65 to void |
| 88 | for i ulong 32 |
| 89 | value = get digest i |
| 90 | put dst mul i 2 digit_hex shr value 4 |
| 91 | put dst add mul i 2 1 digit_hex and value 15 |
| 92 | end |
| 93 | put dst 64 0 |
| 94 | end |