os: graduate O_*, SEEK_* defs to flag and whence enums
Mirrors Hare's `fs::flag` and `io::whence`:
export type flag = enum i32 {
RDONLY = 0,
WRONLY = 1,
RDWR = 2,
CREATE = 64, // 0o100
TRUNC = 512, // 0o1000
};
export type whence = enum i32 { SET = 0, CUR = 1, END = 2 };
open/tryopen/lseek signatures take the enum types (`flags: flag`,
`w: whence`) so callers get type-checked: `os.open(p, os.flag.RDONLY,
0)` is the correct shape, and `os.flag.WRONLY | os.flag.CREATE |
os.flag.TRUNC` typechecks as a `flag` via the same-named-type rule.
Callers in selfhost/cmd/{ww,w6c,w6a,w6l,wwdump} updated from
`os.O_RDONLY` etc. to `os.flag.RDONLY`. SYS_* syscall numbers kept
as `def` for now (internal-only, ABI surface, no Hare analogue in
this scope).
selfhost/test/smoke.ww keeps its standalone-compile property by
using a numeric literal (`0`, RDONLY's value) for the open flags
arg — probe 6 in 990_selfhost compiles smoke.ww with no `use`
expansion, so cross-module type refs like `os.flag.RDONLY` can't
resolve there. Untyped 0 → flag via type_isnum.
This commit is contained in:
@@ -99,7 +99,7 @@ fn buildpathv(dst: *u8, dir: *u8, name: *u8, v: u64) u64 = {
|
||||
|
||||
// islinkable: read first 8 bytes; require !<arch>\n or \x7fELF.
|
||||
fn islinkable(path: *u8) bool = {
|
||||
let fd: i32 = os.open(path, os.O_RDONLY, 0i32);
|
||||
let fd: i32 = os.open(path, os.flag.RDONLY, 0i32);
|
||||
if (fd < 0) { return false; };
|
||||
let mp: *u8 = os.alloc(8u64): *u8;
|
||||
let n: i64 = os.read(fd, mp, 8u64);
|
||||
@@ -168,7 +168,7 @@ fn resolvelib(a: *arena, name: *u8, libdirs: **u8, nlibdirs: i32) *u8 = {
|
||||
|
||||
// Read first 20 bytes; return 1 for ET_DYN .so, 0 for ar/.o.
|
||||
fn isso(path: *u8) i32 = {
|
||||
let fd: i32 = os.open(path, os.O_RDONLY, 0i32);
|
||||
let fd: i32 = os.open(path, os.flag.RDONLY, 0i32);
|
||||
if (fd < 0) { return 0; };
|
||||
let mp: *u8 = os.alloc(20u64): *u8;
|
||||
let n: i64 = os.read(fd, mp, 20u64);
|
||||
@@ -312,7 +312,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
return 1;
|
||||
};
|
||||
|
||||
let flags: i32 = os.O_WRONLY | os.O_CREAT | os.O_TRUNC;
|
||||
let flags: os.flag = os.flag.WRONLY | os.flag.CREATE | os.flag.TRUNC;
|
||||
let fd: i32 = os.open(outpath, flags, 493i32); // 0o755
|
||||
if (fd < 0) {
|
||||
os.write(2, "w6l: cannot open output\n".ptr, 23u64);
|
||||
|
||||
Reference in New Issue
Block a user