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/babel/blob/main/src/00-core.om # babel aien-dev/babel 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 `babel / src / 00-core.om` 250 lines ยท 3324 bytes Raw Blame History 1 note babel 00-core: arena builder, persistent pool, decimal and escaping. Program mode, OM-2. 2 note Ob is a scratch arena used as a stack (mark/reset); Pl is an append-only pool for strings that 3 note outlive one step (paths, names, reasons, vectors, oracle outputs). 4 global Ob uchar `8388608` 5 global Ol ulong 1 6 global Pl uchar `8388608` 7 global Pn ulong 1 8 global Fb uchar 524288 9 global Fn ulong 1 10 global Dn uchar 65536 11 global Sb uchar 256 12 global Ag uchar 8192 13 global Cap ulong 1 14 global Hash uchar 32 15 16 fn mark to ulong 17 ret get Ol 0 18 end 19 20 fn reset m ulong to void 21 put Ol 0 m 22 end 23 24 fn bc c uchar to void 25 o = get Ol 0 26 if ge o `8388000` 27 put Cap 0 1 28 ret 29 end 30 put Ob o c 31 put Ol 0 add o 1 32 end 33 34 fn bs s view uchar * to void 35 for i ulong len s 36 bc get s i 37 end 38 end 39 40 fn bob o ulong n ulong to void 41 for i ulong n 42 bc get Ob add o i 43 end 44 end 45 46 fn bpl o ulong n ulong to void 47 for i ulong n 48 bc get Pl add o i 49 end 50 end 51 52 fn bfb o ulong n ulong to void 53 for i ulong n 54 bc get Fb add o i 55 end 56 end 57 58 fn bu v ulong to void 59 d = new uchar 24 0 60 n = ulong 0 61 x = v 62 while true bound 30 63 put d n uchar add 48 rem x 10 64 n = add n 1 65 x = div x 10 66 if eq x 0 67 break 68 end 69 end 70 while gt n 0 bound 30 71 n = sub n 1 72 bc get d n 73 end 74 end 75 76 fn bl v long to void 77 if lt v 0 78 bc 45 79 bu ulong neg v 80 ret 81 end 82 bu ulong v 83 end 84 85 fn bsp n ulong to void 86 for i ulong n 87 bc 32 88 end 89 end 90 91 fn bhex v ulong to void 92 if lt v 10 93 bc uchar add v 48 94 ret 95 end 96 bc uchar add v 87 97 end 98 99 note copy Ob[o, o+n) into the pool; returns the pool offset 100 fn psave o ulong n ulong to ulong 101 p = get Pn 0 102 if gt add p n `8388000` 103 put Cap 0 1 104 ret p 105 end 106 for i ulong n 107 put Pl add p i get Ob add o i 108 end 109 put Pn 0 add p n 110 ret p 111 end 112 113 fn ptext s view uchar * to ulong 114 p = get Pn 0 115 for i ulong len s 116 put Pl add p i get s i 117 end 118 put Pn 0 add p len s 119 ret p 120 end 121 122 fn pleq a ulong an ulong b ulong bn ulong to bool 123 if ne an bn 124 ret false 125 end 126 for i ulong an 127 if ne get Pl add a i get Pl add b i 128 ret false 129 end 130 end 131 ret true 132 end 133 134 fn plteq o ulong n ulong s view uchar * to bool 135 if ne n len s 136 ret false 137 end 138 for i ulong n 139 if ne get Pl add o i get s i 140 ret false 141 end 142 end 143 ret true 144 end 145 146 note does Pl[o, o+n) start with text s 147 fn plpre o ulong n ulong s view uchar * to bool 148 if lt n len s 149 ret false 150 end 151 for i ulong len s 152 if ne get Pl add o i get s i 153 ret false 154 end 155 end 156 ret true 157 end 158 159 fn obteq o ulong n ulong s view uchar * to bool 160 if ne n len s 161 ret false 162 end 163 for i ulong n 164 if ne get Ob add o i get s i 165 ret false 166 end 167 end 168 ret true 169 end 170 171 note does Pl[o, o+n) end with text s 172 fn plsuf o ulong n ulong s view uchar * to bool 173 if lt n len s 174 ret false 175 end 176 b = add o sub n len s 177 for i ulong len s 178 if ne get Pl add b i get s i 179 ret false 180 end 181 end 182 ret true 183 end 184 185 note JSON string body of Pl[o, o+n) (no quotes) 186 fn bjs o ulong n ulong to void 187 for i ulong n 188 c = get Pl add o i 189 if eq c 34 190 bc 92 191 bc 34 192 continue 193 end 194 if eq c 92 195 bc 92 196 bc 92 197 continue 198 end 199 if eq c 10 200 bc 92 201 bc 110 202 continue 203 end 204 if lt c 32 205 bc 92 206 bc 117 207 bc 48 208 bc 48 209 bhex ulong shr c 4 210 bhex ulong and c 15 211 continue 212 end 213 bc c 214 end 215 end 216 217 fn bjq o ulong n ulong to void 218 bc 34 219 bjs o n 220 bc 34 221 end 222 223 note Markdown table cell of Pl[o, o+n): pipes escaped, newlines flattened 224 fn bmd o ulong n ulong to void 225 for i ulong n 226 c = get Pl add o i 227 if eq c 124 228 bc 92 229 bc 124 230 continue 231 end 232 if eq c 10 233 bc 32 234 continue 235 end 236 if eq c 96 237 bc 39 238 continue 239 end 240 bc c 241 end 242 end 243 244 fn bhash to void 245 for i ulong 32 246 c = get Hash i 247 bhex ulong shr c 4 248 bhex ulong and c 15 249 end 250 end