std: restructure — std/ modules, namespace tail, std/xml.sx
allocators/fs/process/socket/log/trace/test move under modules/std/ (allocators.sx becomes std/mem.sx; the Allocator protocol moves into the std.sx prelude, impls stay in mem.sx). New std/xml.sx holds xml_escape as xml.escape. std.sx gains the carried namespace tail — flat-importing std.sx now also provides mem./xml./log. — with the remaining modules (fs/process/socket/json/cli/hash/test) deferred from the tail until the global last-wins maps are fully own-wins (pulling them into every closure collides bare names corpus-wide; they stay direct imports: modules/std/fs.sx etc.). log.sx's internal emit renamed log_emit (it clobbered consumer fns named emit program-wide). bundle.sx uses xml.escape via the carried alias. Consumer import paths swept mechanically; .ir snapshots recaptured for the larger std closure. m3te + game build unchanged.
This commit is contained in:
33
library/modules/std/socket.sx
Normal file
33
library/modules/std/socket.sx
Normal file
@@ -0,0 +1,33 @@
|
||||
// POSIX socket module (macOS only)
|
||||
// sockaddr_in layout and constants are platform-specific.
|
||||
|
||||
libc :: #library "c";
|
||||
|
||||
// POSIX socket API
|
||||
socket :: (domain: s32, kind: s32, protocol: s32) -> s32 #foreign libc;
|
||||
setsockopt :: (fd: s32, level: s32, optname: s32, optval: *s32, optlen: u32) -> s32 #foreign libc;
|
||||
bind :: (fd: s32, addr: *SockAddr, addrlen: u32) -> s32 #foreign libc;
|
||||
listen :: (fd: s32, backlog: s32) -> s32 #foreign libc;
|
||||
accept :: (fd: s32, addr: *SockAddr, addrlen: *u32) -> s32 #foreign libc;
|
||||
read :: (fd: s32, buf: [*]u8, count: usize) -> isize #foreign libc;
|
||||
write :: (fd: s32, buf: [*]u8, count: usize) -> isize #foreign libc;
|
||||
close :: (fd: s32) -> s32 #foreign libc;
|
||||
|
||||
// Constants (macOS)
|
||||
AF_INET :s32: 2;
|
||||
SOCK_STREAM :s32: 1;
|
||||
SOL_SOCKET :s32: 0xFFFF;
|
||||
SO_REUSEADDR :s32: 0x4;
|
||||
|
||||
// macOS sockaddr_in (16 bytes, has sin_len field)
|
||||
SockAddr :: struct {
|
||||
sin_len: u8;
|
||||
sin_family: u8;
|
||||
sin_port: u16;
|
||||
sin_addr: u32 = 0;
|
||||
sin_zero: u64 = 0;
|
||||
}
|
||||
|
||||
htons :: (port: s64) -> u16 {
|
||||
cast(u16) (((port & 0xFF) << 8) | ((port >> 8) & 0xFF))
|
||||
}
|
||||
Reference in New Issue
Block a user