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/cortex/blob/main/tests/json/t_io.om # cortex aien-dev/cortex 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 `cortex / tests / json / t_io.om` 132 lines ยท 2138 bytes Raw Blame History 1 note tests/json/t_io.om - test-only buffered stdin records (u32 LE length + bytes) and stdout records. 2 note Not part of the product build. Globals prefixed t. 3 global tib uchar `16777216` 4 global tibl ulong 1 5 global tibp ulong 1 6 global tibe uchar 1 7 global tob uchar `16777216` 8 global tobl ulong 1 9 note make at least n bytes available at tibp (compacting and reading); false at end of input 10 fn t_need n ulong to bool 11 if le n sub get tibl 0 get tibp 0 12 ret true 13 end 14 p = get tibp 0 15 l = get tibl 0 16 k = sub l p 17 t_mv p k 18 put tibp 0 0 19 put tibl 0 k 20 for it ulong 100000 21 if le n get tibl 0 22 ret true 23 end 24 if eq get tibe 0 1 25 ret false 26 end 27 l = get tibl 0 28 r = read 0 tib l sub `16777216` l 29 if le r 0 30 put tibe 0 1 31 else 32 put tibl 0 add l ulong r 33 end 34 end 35 ret false 36 end 37 fn t_u32 to ulong 38 p = get tibp 0 39 v = ulong get tib p 40 v = or v shl ulong get tib add p 1 8 41 v = or v shl ulong get tib add p 2 16 42 v = or v shl ulong get tib add p 3 24 43 put tibp 0 add p 4 44 ret v 45 end 46 note next record into jin/jinl; false at end 47 fn t_rec to bool 48 if not t_need 4 49 ret false 50 end 51 n = t_u32 52 if not t_need n 53 trap 9 54 end 55 p = get tibp 0 56 t_cpin p n 57 put tibp 0 add p n 58 put jinl 0 n 59 ret true 60 end 61 fn t_flush to void 62 n = get tobl 0 63 o = ulong 0 64 for it ulong 100000 65 if ge o n 66 put tobl 0 0 67 ret 68 end 69 w = write 1 tob o sub n o 70 if le w 0 71 trap 8 72 end 73 o = add o ulong w 74 end 75 end 76 fn t_ob c uchar to void 77 n = get tobl 0 78 if ge n `16777216` 79 t_flush 80 n = 0 81 end 82 put tob n c 83 put tobl 0 add n 1 84 end 85 note emit job[0 .. jobl) as one output record 86 fn t_emitjob to void 87 n = get jobl 0 88 if gt add n 4 sub `16777216` get tobl 0 89 t_flush 90 end 91 t_ob uchar and n 255 92 t_ob uchar and shr n 8 255 93 t_ob uchar and shr n 16 255 94 t_ob uchar and shr n 24 255 95 i = ulong 0 96 for b ulong 4000 97 for c ulong 4000 98 if ge i n 99 ret 100 end 101 t_ob get job i 102 i = add i 1 103 end 104 end 105 end 106 note tib[p .. p+k) -> tib[0 ..] (overlap safe: forward copy to a lower index) 107 fn t_mv p ulong k ulong to void 108 i = ulong 0 109 for b ulong 4000 110 for c ulong 4000 111 if ge i k 112 ret 113 end 114 x = get tib add p i 115 put tib i x 116 i = add i 1 117 end 118 end 119 end 120 fn t_cpin p ulong n ulong to void 121 i = ulong 0 122 for b ulong 4000 123 for c ulong 4000 124 if ge i n 125 ret 126 end 127 x = get tib add p i 128 put jin i x 129 i = add i 1 130 end 131 end 132 end