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 / train / omega-llm / tools / contrast / mix.om
| 1 | om2 |
| 2 | note Shuffle complete NUL-prefixed records from the two source files. |
| 3 | text old "old.om" |
| 4 | text newpath "contrast.om" |
| 5 | text target "mixed.om" |
| 6 | global corpus uchar * |
| 7 | global starts ulong * |
| 8 | global ids ulong * |
| 9 | fn append path view uchar * to void |
| 10 | fd = int fopen path 0 len path 0 0 |
| 11 | if lt fd 0 |
| 12 | exit 70 |
| 13 | end |
| 14 | size = fseek fd 0 2 |
| 15 | if le size 0 |
| 16 | exit 72 |
| 17 | end |
| 18 | if ne fseek fd 0 0 0 |
| 19 | exit 70 |
| 20 | end |
| 21 | base = len corpus |
| 22 | stop = add base ulong size |
| 23 | if le stop base |
| 24 | exit 70 |
| 25 | end |
| 26 | rc = enlarge corpus stop |
| 27 | if lt rc 0 |
| 28 | exit 70 |
| 29 | end |
| 30 | off = base |
| 31 | for attempt ulong ulong size bound 9223372036854775807 |
| 32 | n = read fd corpus off sub stop off |
| 33 | if le n 0 |
| 34 | exit 70 |
| 35 | end |
| 36 | off = add off ulong n |
| 37 | if eq off stop |
| 38 | break |
| 39 | end |
| 40 | end |
| 41 | if ne fclose fd 0 |
| 42 | exit 70 |
| 43 | end |
| 44 | if ne get corpus base 0 |
| 45 | exit 72 |
| 46 | end |
| 47 | end |
| 48 | fn makeindex to ulong |
| 49 | count = ulong 0 |
| 50 | for i ulong len corpus bound 9223372036854775807 |
| 51 | if eq get corpus i 0 |
| 52 | count = add count 1 |
| 53 | end |
| 54 | end |
| 55 | rc = enlarge starts add count 1 |
| 56 | if lt rc 0 |
| 57 | exit 70 |
| 58 | end |
| 59 | rc = enlarge ids count |
| 60 | if lt rc 0 |
| 61 | exit 70 |
| 62 | end |
| 63 | k = ulong 0 |
| 64 | for i ulong len corpus bound 9223372036854775807 |
| 65 | if eq get corpus i 0 |
| 66 | put starts k i |
| 67 | put ids k k |
| 68 | k = add k 1 |
| 69 | end |
| 70 | end |
| 71 | put starts count len corpus |
| 72 | ret count |
| 73 | end |
| 74 | fn putrecord fd int k ulong to void |
| 75 | off = get starts k |
| 76 | stop = get starts add k 1 |
| 77 | for attempt ulong sub stop off bound 9223372036854775807 |
| 78 | r = write fd corpus off sub stop off |
| 79 | if le r 0 |
| 80 | exit 70 |
| 81 | end |
| 82 | off = add off ulong r |
| 83 | if eq off stop |
| 84 | ret |
| 85 | end |
| 86 | end |
| 87 | end |
| 88 | fn main to int |
| 89 | append old |
| 90 | append newpath |
| 91 | n = makeindex |
| 92 | seed = ulong 123456789 |
| 93 | for i ulong sub n 1 bound 9223372036854775807 |
| 94 | last = sub sub n i 1 |
| 95 | seed = add mul seed 6364136223846793005 1442695040888963407 |
| 96 | j = rem shr seed 16 add last 1 |
| 97 | tmp = get ids last |
| 98 | put ids last get ids j |
| 99 | put ids j tmp |
| 100 | end |
| 101 | fd = int fopen target 0 len target 193 384 |
| 102 | if lt fd 0 |
| 103 | ret 70 |
| 104 | end |
| 105 | for i ulong n bound 9223372036854775807 |
| 106 | putrecord fd get ids i |
| 107 | end |
| 108 | ret int fclose fd |
| 109 | end |