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/aienos.com/blob/main/om/omega-reference/vendor/examples/tmp_files.om # aienos.com Source of www.aienos.com, served from my own hardware 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 `aienos.com / om / omega-reference / vendor / examples / tmp_files.om` 81 lines ยท 1844 bytes Raw Blame History 1 note tmp_files: make a directory and a file relative to the current directory, read it back, clean up 2 note run it in an empty scratch directory. Linux AArch64 values: O_WRONLY|O_CREAT|O_EXCL = 193, 3 note mode 0600 = 384, 0700 = 448, st_size at byte 48 of the 128-byte stat structure 4 note ---- output helpers: a function works on a global by naming it (a global is never an argument) 5 global ob uchar 32 6 note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 7 note bound: every pass writes at least one byte and n <= 32, so at most 32 passes 8 fn outb off ulong n ulong to void 9 e = add off n 10 p = off 11 while lt p e bound 32 12 k = write 1 ob p sub e p 13 if le k 0 14 exit 90 15 end 16 p = add p ulong k 17 end 18 end 19 note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes 20 fn putu v ulong to void 21 i = ulong 31 22 put ob 31 10 23 n = v 24 while true bound 20 25 i = sub i 1 26 put ob i uchar add rem n 10 48 27 n = div n 10 28 if eq n 0 29 break 30 end 31 end 32 outb i sub 32 i 33 end 34 note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 35 fn putl v long to void 36 if lt v 0 37 put ob 0 45 38 outb 0 1 39 putu add ulong neg add v 1 1 40 ret 41 end 42 putu ulong v 43 end 44 text dname "scratch" 45 text fname "scratch/f.txt" 46 text body "omega\n" 47 global rb uchar 16 48 global sb uchar 128 49 fn main to int 50 r = makedir dname 0 len dname 448 51 putl r 52 fd = fopen fname 0 len fname 193 384 53 if lt fd 0 54 exit 93 55 end 56 w = write int fd body 0 len body 57 putl w 58 c = fclose int fd 59 putl c 60 fd2 = fopen fname 0 len fname 0 0 61 if lt fd2 0 62 exit 94 63 end 64 k = read int fd2 rb 0 16 65 putl k 66 c2 = fclose int fd2 67 s = stat fname 0 len fname sb 0 128 68 putl s 69 sz = or uint get sb 48 shl uint get sb 49 8 70 putu ulong sz 71 if gt k 0 72 x = write 1 rb 0 ulong k 73 end 74 u = unlink fname 0 len fname 75 putl u 76 d = rmdir dname 0 len dname 77 putl d 78 gone = fopen fname 0 len fname 0 0 79 putl gone 80 ret 0 81 end