Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omnet/blob/main/om/quantity/mutate.om # omnet aien-dev/omnet Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omnet / om / quantity / mutate.om` 95 lines ยท 1699 bytes Raw Blame History 1 note Test-only source transformer. stdin quantity.om, argument a or m; stdout one guard removed. 2 note Requires exactly one exact guard occurrence, bounded input, complete writes. Never production code. 3 global src uchar 16384 4 text aguard "if gt get b val sub get a cap get a val\nret int 3\nend\n" 5 text mguard "if ne get a val ulong 0\nif gt get b val div get a cap get a val\nret int 3\nend\nend\n" 6 7 fn match at ulong kind uchar to bool 8 if eq kind uchar 97 9 for i ulong len aguard 10 if ne get src add at i get aguard i 11 ret bool 0 12 end 13 end 14 else 15 for i ulong len mguard 16 if ne get src add at i get mguard i 17 ret bool 0 18 end 19 end 20 end 21 ret bool 1 22 end 23 24 fn emit at ulong size ulong to bool 25 pos = ulong 0 26 while lt pos size bound 16384 27 n = write int 1 src add at pos sub size pos 28 if le n long 0 29 ret bool 0 30 end 31 pos = add pos ulong n 32 end 33 ret bool 1 34 end 35 36 fn load to long 37 size = ulong 0 38 while lt size len src bound 16384 39 n = read int 0 src size sub len src size 40 if lt n long 0 41 ret long -1 42 end 43 if eq n long 0 44 ret long size 45 end 46 size = add size ulong n 47 end 48 ret long -1 49 end 50 51 fn main to int 52 arg = new uchar 1 uchar 0 53 if ne argcnt long 2 54 ret int 2 55 end 56 n = argread ulong 1 arg ulong 0 ulong 1 57 if ne n long 1 58 ret int 2 59 end 60 kind = get arg 0 61 if and ne kind uchar 97 ne kind uchar 109 62 ret int 2 63 end 64 n = load 65 if lt n long 0 66 ret int 3 67 end 68 size = ulong n 69 width = len aguard 70 if eq kind uchar 109 71 width = len mguard 72 end 73 if lt size width 74 ret int 4 75 end 76 hits = ulong 0 77 found = ulong 0 78 for i ulong add sub size width ulong 1 79 if match i kind 80 hits = add hits ulong 1 81 found = i 82 end 83 end 84 if ne hits ulong 1 85 ret int 4 86 end 87 if not emit ulong 0 found 88 ret int 5 89 end 90 found = add found width 91 if not emit found sub size found 92 ret int 5 93 end 94 ret int 0 95 end