| | @@ -1050,7 +1050,7 @@ |
| 1050 | 1050 | ## 10. Programs |
| 1051 | 1051 | |
| 1052 | 1052 | Any module may export a procedure `main`, declared `proc main*;` or |
| 1053 | | -`proc main*: I64;`. The program runs the bodies of all its modules |
| 1053 | +`proc main*: INT;`. The program runs the bodies of all its modules |
| 1054 | 1054 | (section 3), then the main module's `main`, if it has one, and ends |
| 1055 | 1055 | with status 0, or with the status `main` returns, by calling |
| 1056 | 1056 | `Rt.exit`. The `main` of an imported module is an ordinary procedure, |
| | @@ -1074,7 +1074,7 @@ |
| 1074 | 1074 | |
| 1075 | 1075 | ``` |
| 1076 | 1076 | proc atExit*(p: proc): ERROR; (* Rt.Full if 32 are registered *) |
| 1077 | | -proc exit*(status: I64); |
| 1077 | +proc exit*(status: INT); |
| 1078 | 1078 | ``` |
| 1079 | 1079 | |
| 1080 | 1080 | Only what can be reached from `main` and the module bodies goes into |
| | @@ -1169,6 +1169,11 @@ |
| 1169 | 1169 | | `Files` | an argument as a string, and a whole file read or written | |
| 1170 | 1170 | | `Opt` | a command line read through one table, by `getopt`'s rules with long options; its help and its mistakes | |
| 1171 | 1171 | |
| 1172 | +Lengths, counts, file descriptors, process ids and statuses are |
| 1173 | +`INT`s, and a character is an `I32`. What may pass an `INT` on a small |
| 1174 | +target is an `I64`: a file's size and position, a time in nanoseconds, |
| 1175 | +and a number read from text. |
| 1176 | + |
| 1172 | 1177 | ``` |
| 1173 | 1178 | module Mem; |
| 1174 | 1179 | type |
| | @@ -1200,7 +1205,7 @@ |
| 1200 | 1205 | Info* = record |
| 1201 | 1206 | size*: I64; (* in bytes *) |
| 1202 | 1207 | mtime*: I64; (* when its contents last changed, in nanoseconds since 1970 *) |
| 1203 | | - mode*: I64; (* its permission bits, as chmod takes them: 1EDH is rwxr-xr-x *) |
| 1208 | + mode*: INT; (* its permission bits, as chmod takes them: 1EDH is rwxr-xr-x *) |
| 1204 | 1209 | dir*: BOOL; (* a directory *) |
| 1205 | 1210 | file*: BOOL; (* a regular file: not a directory, device, pipe or socket *) |
| 1206 | 1211 | symlink*: BOOL; (* the path itself is a symbolic link *) |
| | @@ -1212,68 +1217,68 @@ |
| 1212 | 1217 | env*: [][]U8; (* NAME=value, each added to this program's environment *) |
| 1213 | 1218 | onlyEnv*: BOOL; (* env is its whole environment *) |
| 1214 | 1219 | dir*: []U8; (* its working directory; "" for this program's *) |
| 1215 | | - fds*: [3]I64; (* its standard input, output and error; 0 for this program's own *) |
| 1216 | | - group*: I64; (* the process group it joins: 0 for this program's, -1 a new one it leads *) |
| 1220 | + fds*: [3]INT; (* its standard input, output and error; 0 for this program's own *) |
| 1221 | + group*: INT; (* the process group it joins: 0 for this program's, -1 a new one it leads *) |
| 1217 | 1222 | foreground*: BOOL; (* its group takes the terminal on standard input *) |
| 1218 | | - tty*: I64; (* a pseudo-terminal's fd, to start a session on; 0 for none *) |
| 1223 | + tty*: INT; (* a pseudo-terminal's fd, to start a session on; 0 for none *) |
| 1219 | 1224 | end; |
| 1220 | 1225 | Status* = (running, exited, killed, stopped); |
| 1221 | 1226 | |
| 1222 | | -proc open*(path: []U8; how: Accesses): I64; (* its fd *) |
| 1223 | | -proc openRead*(path: []U8): I64; (* open(path, {reading}) *) |
| 1224 | | -proc create*(path: []U8): I64; (* open(path, {writing, creating, truncating}) *) |
| 1225 | | -proc seek*(fd, pos: I64; fromEnd: BOOL): I64; (* the new position *) |
| 1227 | +proc open*(path: []U8; how: Accesses): INT; (* its fd *) |
| 1228 | +proc openRead*(path: []U8): INT; (* open(path, {reading}) *) |
| 1229 | +proc create*(path: []U8): INT; (* open(path, {writing, creating, truncating}) *) |
| 1230 | +proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; (* the new position *) |
| 1226 | 1231 | |
| 1227 | | -proc rename*(old, new: []U8): I64; (* replaces what new names *) |
| 1228 | | -proc remove*(path: []U8): I64; (* a file, not a directory *) |
| 1229 | | -proc removeDir*(path: []U8): I64; (* an empty directory *) |
| 1230 | | -proc makeDir*(path: []U8): I64; (* readable by all, writable by its owner *) |
| 1231 | | -proc chmod*(path: []U8; mode: I64): I64; |
| 1232 | | -proc symlink*(target, path: []U8): I64; (* path made a link to target *) |
| 1233 | | -proc readLink*(path: []U8): ([]U8, I64); (* what the link names, good until the next call *) |
| 1234 | | -proc info*(path: []U8): (Info, I64); (* following a symbolic link *) |
| 1232 | +proc rename*(old, new: []U8): INT; (* replaces what new names *) |
| 1233 | +proc remove*(path: []U8): INT; (* a file, not a directory *) |
| 1234 | +proc removeDir*(path: []U8): INT; (* an empty directory *) |
| 1235 | +proc makeDir*(path: []U8): INT; (* readable by all, writable by its owner *) |
| 1236 | +proc chmod*(path: []U8; mode: INT): INT; |
| 1237 | +proc symlink*(target, path: []U8): INT; (* path made a link to target *) |
| 1238 | +proc readLink*(path: []U8): ([]U8, INT); (* what the link names, good until the next call *) |
| 1239 | +proc info*(path: []U8): (Info, INT); (* following a symbolic link *) |
| 1235 | 1240 | |
| 1236 | | -proc openDir*(d: ^Dir; path: []U8): I64; |
| 1241 | +proc openDir*(d: ^Dir; path: []U8): INT; |
| 1237 | 1242 | proc nextEntry*(d: ^Dir): ([]U8, BOOL); (* a name, good until the next call; false at the end *) |
| 1238 | 1243 | proc closeDir*(d: ^Dir); |
| 1239 | 1244 | |
| 1240 | | -proc rawMode*(fd: I64): BOOL; (* the terminal on fd: no echo, no lines, no signals *) |
| 1241 | | -proc restoreMode*(fd: I64); (* as rawMode found it *) |
| 1242 | | -proc termSize*(fd: I64): (I64, I64); (* columns and rows; 80 and 24 if unknown *) |
| 1243 | | -proc ready*(fd: I64; ms: I64): BOOL; (* something to read within ms, or ever if ms < 0 *) |
| 1244 | | -proc readyOf*(fds: []I64; ms: I64): I64; (* the first of fds with something to read within ms, or -1 *) |
| 1245 | +proc rawMode*(fd: INT): BOOL; (* the terminal on fd: no echo, no lines, no signals *) |
| 1246 | +proc restoreMode*(fd: INT); (* as rawMode found it *) |
| 1247 | +proc termSize*(fd: INT): (INT, INT); (* columns and rows; 80 and 24 if unknown *) |
| 1248 | +proc ready*(fd: INT; ms: INT): BOOL; (* something to read within ms, or ever if ms < 0 *) |
| 1249 | +proc readyOf*(fds: []INT; ms: INT): INT; (* the first of fds with something to read within ms, or -1 *) |
| 1245 | 1250 | |
| 1246 | 1251 | proc env*(name: []U8): []U8; (* the environment variable's value; "" if unset *) |
| 1247 | | -proc workDir*: ([]U8, I64); (* the working directory, good until the next call *) |
| 1248 | | -proc setWorkDir*(path: []U8): I64; |
| 1252 | +proc workDir*: ([]U8, INT); (* the working directory, good until the next call *) |
| 1253 | +proc setWorkDir*(path: []U8): INT; |
| 1249 | 1254 | |
| 1250 | | -proc pipe*: (I64, I64); (* the fd to read and the fd to write; or minus an errno and -1 *) |
| 1251 | | -proc openPty*: I64; (* a pseudo-terminal: the fd of its controlling side *) |
| 1252 | | -proc setTermSize*(fd, cols, rows: I64): I64; (* the size its programs are told of *) |
| 1253 | | -proc spawn*(p: Program): I64; (* a program started: its process id *) |
| 1254 | | -proc wait*(pid: I64; block: BOOL): (I64, Status, I64); (* which program, how, and its code *) |
| 1255 | | -proc kill*(pid, signal: I64): I64; |
| 1256 | | -proc pid*: I64; (* this program's process id *) |
| 1257 | | -proc setGroup*(pid, group: I64): I64; (* pid 0 is this program; group 0 a new one pid leads *) |
| 1258 | | -proc foreground*(fd, group: I64): I64; (* the terminal on fd gives its keys to group *) |
| 1259 | | -proc foregroundOf*(fd: I64): I64; (* the group the terminal on fd gives its keys to *) |
| 1255 | +proc pipe*: (INT, INT); (* the fd to read and the fd to write; or minus an errno and -1 *) |
| 1256 | +proc openPty*: INT; (* a pseudo-terminal: the fd of its controlling side *) |
| 1257 | +proc setTermSize*(fd, cols, rows: INT): INT; (* the size its programs are told of *) |
| 1258 | +proc spawn*(p: Program): INT; (* a program started: its process id *) |
| 1259 | +proc wait*(pid: INT; block: BOOL): (INT, Status, INT); (* which program, how, and its code *) |
| 1260 | +proc kill*(pid, signal: INT): INT; |
| 1261 | +proc pid*: INT; (* this program's process id *) |
| 1262 | +proc setGroup*(pid, group: INT): INT; (* pid 0 is this program; group 0 a new one pid leads *) |
| 1263 | +proc foreground*(fd, group: INT): INT; (* the terminal on fd gives its keys to group *) |
| 1264 | +proc foregroundOf*(fd: INT): INT; (* the group the terminal on fd gives its keys to *) |
| 1260 | 1265 | |
| 1261 | | -proc catch*(sigs: []I64): I64; (* sigs caught: an fd to wait on *) |
| 1262 | | -proc caught*(fd: I64): I64; (* the next signal caught, or 0 if none is waiting *) |
| 1263 | | -proc ignore*(sig: I64; yes: BOOL): I64; (* sig ignored; or, if not yes, back to what it does at first *) |
| 1266 | +proc catch*(sigs: []INT): INT; (* sigs caught: an fd to wait on *) |
| 1267 | +proc caught*(fd: INT): INT; (* the next signal caught, or 0 if none is waiting *) |
| 1268 | +proc ignore*(sig: INT; yes: BOOL): INT; (* sig ignored; or, if not yes, back to what it does at first *) |
| 1264 | 1269 | |
| 1265 | 1270 | proc clock*: I64; (* nanoseconds, on a clock that only goes forward *) |
| 1266 | 1271 | proc now*: I64; (* nanoseconds since 1970-01-01, UTC *) |
| 1267 | | -proc sleep*(ms: I64); |
| 1272 | +proc sleep*(ms: INT); |
| 1268 | 1273 | proc random*(b: []U8); (* b filled with random bytes *) |
| 1269 | 1274 | |
| 1270 | | -proc connect*(path: []U8): I64; (* a stream socket, connected to the Unix socket at path: its fd *) |
| 1271 | | -proc connectTcp*(addr: []U8; port: I64): I64; (* addr an IPv4 or IPv6 address, as numbers *) |
| 1272 | | -proc connectUdp*(addr: []U8; port: I64): I64; |
| 1273 | | -proc listen*(path: []U8): I64; (* a Unix socket made at path, taking connections *) |
| 1274 | | -proc listenTcp*(addr: []U8; port: I64): I64; |
| 1275 | | -proc accept*(fd: I64): I64; (* the next connection, waiting for one *) |
| 1276 | | -proc send*(fd: I64; s: []U8): I64; (* write, to a socket: -32 (EPIPE), not a signal, if it is closed *) |
| 1275 | +proc connect*(path: []U8): INT; (* a stream socket, connected to the Unix socket at path: its fd *) |
| 1276 | +proc connectTcp*(addr: []U8; port: INT): INT; (* addr an IPv4 or IPv6 address, as numbers *) |
| 1277 | +proc connectUdp*(addr: []U8; port: INT): INT; |
| 1278 | +proc listen*(path: []U8): INT; (* a Unix socket made at path, taking connections *) |
| 1279 | +proc listenTcp*(addr: []U8; port: INT): INT; |
| 1280 | +proc accept*(fd: INT): INT; (* the next connection, waiting for one *) |
| 1281 | +proc send*(fd: INT; s: []U8): INT; (* write, to a socket: -32 (EPIPE), not a signal, if it is closed *) |
| 1277 | 1282 | ``` |
| 1278 | 1283 | |
| 1279 | 1284 | `info` follows a symbolic link: `size`, `dir` and `file` are those of |
| | @@ -1395,8 +1400,8 @@ |
| 1395 | 1400 | |
| 1396 | 1401 | ``` |
| 1397 | 1402 | module Str; |
| 1398 | | -proc encode*(c: I64): ([4]U8, I64); (* c in UTF-8: its bytes, and how many *) |
| 1399 | | -proc decode*(s: []U8): (I64, I64); (* the character s starts with, and its length in bytes *) |
| 1403 | +proc encode*(c: I32): ([4]U8, INT); (* c in UTF-8: its bytes, and how many *) |
| 1404 | +proc decode*(s: []U8): (I32, INT); (* the character s starts with, and its length in bytes *) |
| 1400 | 1405 | proc toInt*(s: []U8): (I64, BOOL); (* s, in decimal; false if it isn't a number an I64 holds *) |
| 1401 | 1406 | proc le*(s: []U8): U64; (* s, at most 8 bytes, the first the lowest *) |
| 1402 | 1407 | proc be*(s: []U8): U64; (* s, at most 8 bytes, the first the highest *) |
| | @@ -1405,7 +1410,7 @@ |
| 1405 | 1410 | |
| 1406 | 1411 | module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL); |
| 1407 | 1412 | proc remove*(m: ^Map; k: K): BOOL; (* false if k wasn't there *) |
| 1408 | | -proc next*(m: ^Map; i: I64): (I64, K, V); (* the entry after i *) |
| 1413 | +proc next*(m: ^Map; i: INT): (INT, K, V); (* the entry after i *) |
| 1409 | 1414 | |
| 1410 | 1415 | module Sort(T; less: proc(a, b: T): BOOL); |
| 1411 | 1416 | proc sort*(s: []T); |
| | @@ -1421,7 +1426,7 @@ |
| 1421 | 1426 | proc ln*(x: F64): F64; |
| 1422 | 1427 | |
| 1423 | 1428 | module Fmt; |
| 1424 | | -type Arg* = variant ... real(r: F64; places: I64); end; |
| 1429 | +type Arg* = variant ... real(r: F64; places: INT); end; |
| 1425 | 1430 | ``` |
| 1426 | 1431 | |
| 1427 | 1432 | `Str` reads and writes UTF-8. `encode` writes a character, of at most |
| | @@ -1465,7 +1470,7 @@ |
| 1465 | 1470 | |
| 1466 | 1471 | ``` |
| 1467 | 1472 | module Files; |
| 1468 | | -proc arg*(i: I64): []U8; (* argument i; 0 is the program's name *) |
| 1473 | +proc arg*(i: INT): []U8; (* argument i; 0 is the program's name *) |
| 1469 | 1474 | proc read*(path: []U8; b: ^Buf.Buf): BOOL; (* the whole file added to b *) |
| 1470 | 1475 | proc write*(path, data: []U8): BOOL; (* the file made to hold data *) |
| 1471 | 1476 | |
| | @@ -1690,9 +1695,12 @@ |
| 1690 | 1695 | `INT`, `UINT` and pointers (6.8). An integer constant past an |
| 1691 | 1696 | extern's parameters goes as an `INT` (9). Modules compile on their |
| 1692 | 1697 | own, into object files, and instances are named so that one type |
| 1693 | | - gives one name (section 10; appendix A). The library of section 11 |
| 1694 | | - still says `I64` for its lengths, sizes, counts and descriptors; |
| 1695 | | - they become `INT` when it is revised for this version. |
| 1698 | + gives one name (section 10; appendix A). The library takes and gives |
| 1699 | + `INT` for lengths, counts, descriptors, process ids and statuses, |
| 1700 | + `main`'s and `Rt.exit`'s among them, and `I32` for a character; |
| 1701 | + `I64` stays for what may pass an `INT` on a small target: a file's |
| 1702 | + size and position, times, and numbers read from text (section |
| 1703 | + 11). |
| 1696 | 1704 | |
| 1697 | 1705 | ## Appendix A. What an implementation chooses |
| 1698 | 1706 | |