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:
@@ -1100,13 +1100,13 @@ static const struct row rows[] = {
|
||||
" let m: mode = mode.R | mode.W;\n"
|
||||
" return m as i32;\n"
|
||||
"};", 3 },
|
||||
/* enum: pkg-qualified access — `os.whence.CUR` resolves through
|
||||
/* enum: pkg-qualified access — `pkg.dir.SOUTH` resolves through
|
||||
* SK_USE and folds to the member literal. */
|
||||
{ "// MODULE: os\n"
|
||||
"type whence = enum { SET, CUR, END };\n"
|
||||
{ "// MODULE: pkg\n"
|
||||
"type dir = enum { NORTH, SOUTH, EAST, WEST };\n"
|
||||
"// MODULE: main\n"
|
||||
"use os;\n"
|
||||
"fn main() i32 = { return os.whence.CUR as i32; };", 1 },
|
||||
"use pkg;\n"
|
||||
"fn main() i32 = { return pkg.dir.SOUTH as i32; };", 1 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user