From aa6ed8eb0ca78c5173417d0ddb93f6c8687cd4d8 Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 28 Mar 2019 01:32:15 +0100 Subject: [PATCH] mimic typed enums --- std/assembly/bindings/wasi_unstable.ts | 605 ++++++++++++------------- tests/compiler/wasi.optimized.wat | 8 +- tests/compiler/wasi.ts | 6 +- tests/compiler/wasi.untouched.wat | 3 + 4 files changed, 317 insertions(+), 305 deletions(-) diff --git a/std/assembly/bindings/wasi_unstable.ts b/std/assembly/bindings/wasi_unstable.ts index ef02aa05..5313f3b0 100644 --- a/std/assembly/bindings/wasi_unstable.ts +++ b/std/assembly/bindings/wasi_unstable.ts @@ -2,87 +2,90 @@ /* tslint:disable:max-line-length */ +type uintptr = usize; +type size = usize; + /** Read command-line argument data. */ -export declare function args_get(argv: uintptr_t, argv_buf: uintptr_t): errno; +export declare function args_get(argv: uintptr, argv_buf: uintptr): errno; /** Return command-line argument data sizes. */ -export declare function args_sizes_get(argc: uintptr_t, argv_buf_size_ptr: uintptr_t): errno; +export declare function args_sizes_get(argc: uintptr, argv_buf_size_ptr: uintptr): errno; /** Return the resolution of a clock. */ -export declare function clock_res_get(clock: clockid, resolution: uintptr_t): errno; +export declare function clock_res_get(clock: clockid, resolution: uintptr): errno; /** Return the time value of a clock. */ -export declare function clock_time_get(clock: clockid, precision: timestamp_t, time: uintptr_t): errno; +export declare function clock_time_get(clock: clockid, precision: timestamp, time: uintptr): errno; /** Read environment variable data. */ -export declare function environ_get(environ: uintptr_t, environ_buf: uintptr_t): errno; +export declare function environ_get(environ: uintptr, environ_buf: uintptr): errno; /** Return command-line argument data sizes. */ -export declare function environ_sizes_get(environ_count: uintptr_t, environ_buf_size: uintptr_t): errno; +export declare function environ_sizes_get(environ_count: uintptr, environ_buf_size: uintptr): errno; /** Provide file advisory information on a file descriptor. */ -export declare function fd_advise(fd: fd_t, offset: filesize_t, len: filesize_t, advice: advice): errno; +export declare function fd_advise(fd: fd, offset: filesize, len: filesize, advice: advice): errno; /** Provide file advisory information on a file descriptor. */ -export declare function fd_allocate(fd: fd_t, offset: filesize_t, len: filesize_t): errno; +export declare function fd_allocate(fd: fd, offset: filesize, len: filesize): errno; /** Close a file descriptor. */ -export declare function fd_close(fd: fd_t): errno; +export declare function fd_close(fd: fd): errno; /** Synchronize the data of a file to disk. */ -export declare function fd_datasync(fd: fd_t): errno; +export declare function fd_datasync(fd: fd): errno; /** Get the attributes of a file descriptor. */ -export declare function fd_fdstat_get(fd: fd_t, buf: uintptr_t): errno; +export declare function fd_fdstat_get(fd: fd, buf: uintptr): errno; /** Adjust the flags associated with a file descriptor. */ -export declare function fd_fdstat_set_flags(fd: fd_t, flags: fdflags): errno; +export declare function fd_fdstat_set_flags(fd: fd, flags: fdflags): errno; /** Adjust the rights associated with a file descriptor. */ -export declare function fd_fdstat_set_rights(fd: fd_t, fs_rights_base: rights, fs_rights_inheriting: rights): errno; +export declare function fd_fdstat_set_rights(fd: fd, fs_rights_base: rights, fs_rights_inheriting: rights): errno; /** Return the attributes of an open file. */ -export declare function fd_filestat_get(fd: fd_t, buf: uintptr_t): errno; +export declare function fd_filestat_get(fd: fd, buf: uintptr): errno; /** Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. */ -export declare function fd_filestat_set_size(fd: fd_t, size: filesize_t): errno; +export declare function fd_filestat_set_size(fd: fd, size: filesize): errno; /** Adjust the timestamps of an open file or directory. */ -export declare function fd_filestat_set_times(fd: fd_t, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags): errno; +export declare function fd_filestat_set_times(fd: fd, st_atim: timestamp, st_mtim: timestamp, fstflags: fstflags): errno; /** Read from a file descriptor, without using and updating the file descriptor's offset. */ -export declare function fd_pread(fd: fd_t, iovs: uintptr_t, iovs_len: size_t, offset: filesize_t, nread: uintptr_t): errno; +export declare function fd_pread(fd: fd, iovs: uintptr, iovs_len: size, offset: filesize, nread: uintptr): errno; /** Return a description of the given preopened file descriptor. */ -export declare function fd_prestat_get(fd: fd_t, buf: uintptr_t): errno; +export declare function fd_prestat_get(fd: fd, buf: uintptr): errno; /** Return a description of the given preopened file descriptor. */ -export declare function fd_prestat_dir_name(fd: fd_t, path: uintptr_t, path_len: size_t): errno; +export declare function fd_prestat_dir_name(fd: fd, path: uintptr, path_len: size): errno; /** Write to a file descriptor, without using and updating the file descriptor's offset. */ -export declare function fd_pwrite(fd: fd_t, iovs: uintptr_t, iovs_len: size_t, offset: filesize_t, nwritten: uintptr_t): errno; +export declare function fd_pwrite(fd: fd, iovs: uintptr, iovs_len: size, offset: filesize, nwritten: uintptr): errno; /** Read from a file descriptor. */ -export declare function fd_read(fd: fd_t, iovs: uintptr_t, iovs_len: size_t, nread: uintptr_t): errno; +export declare function fd_read(fd: fd, iovs: uintptr, iovs_len: size, nread: uintptr): errno; /** Read directory entries from a directory. */ -export declare function fd_readdir(fd: fd_t, buf: uintptr_t, buf_len: size_t, cookie: dircookie_t, buf_used: uintptr_t): errno; +export declare function fd_readdir(fd: fd, buf: uintptr, buf_len: size, cookie: dircookie, buf_used: uintptr): errno; /** Atomically replace a file descriptor by renumbering another file descriptor. */ -export declare function fd_renumber(from: fd_t, to: fd_t): errno; +export declare function fd_renumber(from: fd, to: fd): errno; /** Move the offset of a file descriptor. */ -export declare function fd_seek(fd: fd_t, offset: filedelta_t, whence: whence, newoffset: uintptr_t): errno; +export declare function fd_seek(fd: fd, offset: filedelta, whence: whence, newoffset: uintptr): errno; /** Synchronize the data and metadata of a file to disk. */ -export declare function fd_sync(fd: fd_t): errno; +export declare function fd_sync(fd: fd): errno; /** Return the current offset of a file descriptor. */ -export declare function fd_tell(fd: fd_t, newoffset: uintptr_t): errno; +export declare function fd_tell(fd: fd, newoffset: uintptr): errno; /** Write to a file descriptor. */ -export declare function fd_write(fd: fd_t, iovs: uintptr_t, iovs_len: size_t, nwritten: uintptr_t): errno; +export declare function fd_write(fd: fd, iovs: uintptr, iovs_len: size, nwritten: uintptr): errno; /* Create a directory. */ -export declare function path_create_directory(fd: fd_t, path: uintptr_t, path_len: size_t): errno; +export declare function path_create_directory(fd: fd, path: uintptr, path_len: size): errno; /** Return the attributes of a file or directory. */ -export declare function path_filestat_get(fd: fd_t, flags: lookupflags, path: uintptr_t, path_len: size_t, buf: uintptr_t): errno; +export declare function path_filestat_get(fd: fd, flags: lookupflags, path: uintptr, path_len: size, buf: uintptr): errno; /** Adjust the timestamps of a file or directory. */ -export declare function path_filestat_set_times(fd: fd_t, flags: lookupflags, path: uintptr_t, path_len: size_t, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags): errno; +export declare function path_filestat_set_times(fd: fd, flags: lookupflags, path: uintptr, path_len: size, st_atim: timestamp, st_mtim: timestamp, fstflags: fstflags): errno; /** Create a hard link. */ -export declare function path_link(fd0: fd_t, flags0: lookupflags, path0: uintptr_t, path_len0: size_t, fd1: fd_t, path1: uintptr_t, path_len: size_t): errno; +export declare function path_link(fd0: fd, flags0: lookupflags, path0: uintptr, path_len0: size, fd1: fd, path1: uintptr, path_len: size): errno; /** Open a file or directory. */ -export declare function path_open(dirfd: fd_t, dirflags: lookupflags, path: uintptr_t, path_len: size_t, oflags: oflags, fs_rights_base: rights, fs_rights_inheriting: rights, fs_flags: fdflags, fd: fd_t): errno; +export declare function path_open(dirfd: fd, dirflags: lookupflags, path: uintptr, path_len: size, oflags: oflags, fs_rights_base: rights, fs_rights_inheriting: rights, fs_flags: fdflags, fd: fd): errno; /** Read the contents of a symbolic link. */ -export declare function path_readlink(fd: fd_t, path: uintptr_t, path_len: size_t, buf: uintptr_t, buf_len: size_t, buf_used: uintptr_t): errno; +export declare function path_readlink(fd: fd, path: uintptr, path_len: size, buf: uintptr, buf_len: size, buf_used: uintptr): errno; /** Remove a directory. */ -export declare function path_remove_directory(fd: fd_t, path: uintptr_t, path_len: size_t): errno; +export declare function path_remove_directory(fd: fd, path: uintptr, path_len: size): errno; /** Rename a file or directory. */ -export declare function path_rename(fd0: fd_t, path0: uintptr_t, path_len0: size_t, fd1: fd_t, path1: uintptr_t, path_len1: size_t): errno; +export declare function path_rename(fd0: fd, path0: uintptr, path_len0: size, fd1: fd, path1: uintptr, path_len1: size): errno; /** Create a symbolic link. */ -export declare function path_symlink(path0: uintptr_t, path_len0: size_t, fd: fd_t, path1: uintptr_t, path_len1: size_t): errno; +export declare function path_symlink(path0: uintptr, path_len0: size, fd: fd, path1: uintptr, path_len1: size): errno; /** Unlink a file. */ -export declare function path_unlink_file(fd: fd_t, path: uintptr_t, path_len: size_t): errno; +export declare function path_unlink_file(fd: fd, path: uintptr, path_len: size): errno; /** Concurrently poll for the occurrence of a set of events. */ -export declare function poll_oneoff(in_: uintptr_t, out: uintptr_t, nsubscriptions: size_t, nevents: uintptr_t): errno; +export declare function poll_oneoff(in_: uintptr, out: uintptr, nsubscriptions: size, nevents: uintptr): errno; /** Terminate the process normally. An exit code of 0 indicates successful termination of the program. The meanings of other values is dependent on the environment. */ export declare function proc_exit(rval: u32): void; @@ -90,602 +93,598 @@ export declare function proc_exit(rval: u32): void; export declare function proc_raise(sig: signal): errno; /** Write high-quality random data into a buffer. */ -export declare function random_get(buf: uintptr_t, buf_len: size_t): errno; +export declare function random_get(buf: uintptr, buf_len: size): errno; /** Temporarily yield execution of the calling thread. */ export declare function sched_yield(): errno; /** Receive a message from a socket. */ -export declare function sock_recv(sock: fd_t, ri_data: uintptr_t, ri_data_len: size_t, ri_flags: riflags, ro_datalen: uintptr_t, ro_flags: roflags): errno; +export declare function sock_recv(sock: fd, ri_data: uintptr, ri_data_len: size, ri_flags: riflags, ro_datalen: uintptr, ro_flags: roflags): errno; /** Send a message on a socket. */ -export declare function sock_send(sock: fd_t, si_data: uintptr_t, si_data_len: size_t, si_flags: siflags, so_datalen: uintptr_t): errno; +export declare function sock_send(sock: fd, si_data: uintptr, si_data_len: size, si_flags: siflags, so_datalen: uintptr): errno; /** Shut down socket send and receive channels. */ -export declare function sock_shutdown(sock: fd_t, how: sdflags): errno; +export declare function sock_shutdown(sock: fd, how: sdflags): errno; // === Types ====================================================================================== /** File or memory access pattern advisory information. */ -export const enum advice { +export namespace advice { /** The application has no advice to give on its behavior with respect to the specified data. */ - NORMAL = 0, + @inline export const NORMAL: advice = 0; /** The application expects to access the specified data sequentially from lower offsets to higher offsets. */ - SEQUENTIAL = 1, + @inline export const SEQUENTIAL : advice = 1; /** The application expects to access the specified data in a random order. */ - RANDOM = 2, + @inline export const RANDOM: advice = 2; /** The application expects to access the specified data in the near future. */ - WILLNEED = 3, + @inline export const WILLNEED: advice = 3; /** The application expects that it will not access the specified data in the near future. */ - DONTNEED = 4, + @inline export const DONTNEED: advice = 4; /** The application expects to access the specified data once and then not reuse it thereafter. */ - NOREUSE = 5 + @inline export const NOREUSE: advice = 5; } -export type advice_t = u8; +export type advice = u8; /** Identifiers for clocks. */ -export const enum clockid { +export namespace clockid { /** The clock measuring real time. Time value zero corresponds with 1970-01-01T00:00:00Z. */ - REALTIME = 0, + @inline export const REALTIME: clockid = 0; /** The store-wide monotonic clock. Absolute value has no meaning. */ - MONOTONIC = 1, + @inline export const MONOTONIC: clockid = 1; /** The CPU-time clock associated with the current process. */ - PROCESS_CPUTIME_ID = 2, + @inline export const PROCESS_CPUTIME_ID: clockid = 2; /** The CPU-time clock associated with the current thread. */ - THREAD_CPUTIME_ID = 3 + @inline export const THREAD_CPUTIME_ID: clockid = 3; } -export type clockid_t = u32; +export type clockid = u32; /** Identifier for a device containing a file system. Can be used in combination with `inode` to uniquely identify a file or directory in the filesystem. */ -export type device_t = u64; +export type device = u64; /** A reference to the offset of a directory entry. */ -export type dircookie_t = u64; +export type dircookie = u64; /** A directory entry. */ @unmanaged export class dirent { /** The offset of the next directory entry stored in this directory. */ - next: dircookie_t; + next: dircookie; /** The serial number of the file referred to by this directory entry. */ - ino: inode_t; + ino: inode; /** The length of the name of the directory entry. */ namlen: u32; /** The type of the file referred to by this directory entry. */ - type: filetype_t; + type: filetype; private __padding0: u16; } /** Error codes returned by functions. */ -export const enum errno { +export namespace errno { /** No error occurred. System call completed successfully. */ - SUCCESS = 0, + @inline export const SUCCESS: errno = 0; /** Argument list too long. */ - TOOBIG = 1, + @inline export const TOOBIG: errno = 1; /** Permission denied. */ - ACCES = 2, + @inline export const ACCES: errno = 2; /** Address in use. */ - ADDRINUSE = 3, + @inline export const ADDRINUSE: errno = 3; /** Address not available. */ - ADDRNOTAVAIL = 4, + @inline export const ADDRNOTAVAIL: errno = 4; /** Address family not supported. */ - AFNOSUPPORT = 5, + @inline export const AFNOSUPPORT: errno = 5; /** Resource unavailable, or operation would block. */ - AGAIN = 6, + @inline export const AGAIN: errno = 6; /** Connection already in progress. */ - ALREADY = 7, + @inline export const ALREADY: errno = 7; /** Bad file descriptor. */ - BADF = 8, + @inline export const BADF: errno = 8; /** Bad message. */ - BADMSG = 9, + @inline export const BADMSG: errno = 9; /** Device or resource busy. */ - BUSY = 10, + @inline export const BUSY: errno = 10; /** Operation canceled. */ - CANCELED = 11, + @inline export const CANCELED: errno = 11; /** No child processes. */ - CHILD = 12, + @inline export const CHILD: errno = 12; /** Connection aborted. */ - CONNABORTED = 13, + @inline export const CONNABORTED: errno = 13; /** Connection refused. */ - CONNREFUSED = 14, + @inline export const CONNREFUSED: errno = 14; /** Connection reset. */ - CONNRESET = 15, + @inline export const CONNRESET: errno = 15; /** Resource deadlock would occur. */ - DEADLK = 16, + @inline export const DEADLK: errno = 16; /** Destination address required. */ - DESTADDRREQ = 17, + @inline export const DESTADDRREQ: errno = 17; /** Mathematics argument out of domain of function. */ - DOM = 18, + @inline export const DOM: errno = 18; /** Reserved. */ - DQUOT = 19, + @inline export const DQUOT: errno = 19; /** File exists. */ - EXIST = 20, + @inline export const EXIST: errno = 20; /** Bad address. */ - FAULT = 21, + @inline export const FAULT: errno = 21; /** File too large. */ - FBIG = 22, + @inline export const FBIG: errno = 22; /** Host is unreachable. */ - HOSTUNREACH = 23, + @inline export const HOSTUNREACH: errno = 23; /** Identifier removed. */ - IDRM = 24, + @inline export const IDRM: errno = 24; /** Illegal byte sequence. */ - ILSEQ = 25, + @inline export const ILSEQ: errno = 25; /** Operation in progress. */ - INPROGRESS = 26, + @inline export const INPROGRESS: errno = 26; /** Interrupted function. */ - INTR = 27, + @inline export const INTR: errno = 27; /** Invalid argument. */ - INVAL = 28, + @inline export const INVAL: errno = 28; /** I/O error. */ - IO = 29, + @inline export const IO: errno = 29; /** Socket is connected. */ - ISCONN = 30, + @inline export const ISCONN: errno = 30; /** Is a directory. */ - ISDIR = 31, + @inline export const ISDIR: errno = 31; /** Too many levels of symbolic links. */ - LOOP = 32, + @inline export const LOOP: errno = 32; /** File descriptor value too large. */ - MFILE = 33, + @inline export const MFILE: errno = 33; /** Too many links. */ - MLINK = 34, + @inline export const MLINK: errno = 34; /** Message too large. */ - MSGSIZE = 35, + @inline export const MSGSIZE: errno = 35; /** Reserved. */ - MULTIHOP = 36, + @inline export const MULTIHOP: errno = 36; /** Filename too long. */ - NAMETOOLONG = 37, + @inline export const NAMETOOLONG: errno = 37; /** Network is down. */ - NETDOWN = 38, + @inline export const NETDOWN: errno = 38; /** Connection aborted by network. */ - NETRESET = 39, + @inline export const NETRESET: errno = 39; /** Network unreachable. */ - NETUNREACH = 40, + @inline export const NETUNREACH: errno = 40; /** Too many files open in system. */ - NFILE = 41, + @inline export const NFILE: errno = 41; /** No buffer space available. */ - NOBUFS = 42, + @inline export const NOBUFS: errno = 42; /** No such device. */ - NODEV = 43, + @inline export const NODEV: errno = 43; /** No such file or directory. */ - NOENT = 44, + @inline export const NOENT: errno = 44; /** Executable file format error. */ - NOEXEC = 45, + @inline export const NOEXEC: errno = 45; /** No locks available. */ - NOLCK = 46, + @inline export const NOLCK: errno = 46; /** Reserved. */ - NOLINK = 47, + @inline export const NOLINK: errno = 47; /** Not enough space. */ - NOMEM = 48, + @inline export const NOMEM: errno = 48; /** No message of the desired type. */ - NOMSG = 49, + @inline export const NOMSG: errno = 49; /** Protocol not available. */ - NOPROTOOPT = 50, + @inline export const NOPROTOOPT: errno = 50; /** No space left on device. */ - NOSPC = 51, + @inline export const NOSPC: errno = 51; /** Function not supported. */ - NOSYS = 52, + @inline export const NOSYS: errno = 52; /** The socket is not connected. */ - NOTCONN = 53, + @inline export const NOTCONN: errno = 53; /** Not a directory or a symbolic link to a directory. */ - NOTDIR = 54, + @inline export const NOTDIR: errno = 54; /** Directory not empty. */ - NOTEMPTY = 55, + @inline export const NOTEMPTY: errno = 55; /** State not recoverable. */ - NOTRECOVERABLE = 56, + @inline export const NOTRECOVERABLE: errno = 56; /** Not a socket. */ - NOTSOCK = 57, + @inline export const NOTSOCK: errno = 57; /** Not supported, or operation not supported on socket. */ - NOTSUP = 58, + @inline export const NOTSUP: errno = 58; /** Inappropriate I/O control operation. */ - NOTTY = 59, + @inline export const NOTTY: errno = 59; /** No such device or address. */ - NXIO = 60, + @inline export const NXIO: errno = 60; /** Value too large to be stored in data type. */ - OVERFLOW = 61, + @inline export const OVERFLOW: errno = 61; /** Previous owner died. */ - OWNERDEAD = 62, + @inline export const OWNERDEAD: errno = 62; /** Operation not permitted. */ - PERM = 63, + @inline export const PERM: errno = 63; /** Broken pipe. */ - PIPE = 64, + @inline export const PIPE: errno = 64; /** Protocol error. */ - PROTO = 65, + @inline export const PROTO: errno = 65; /** Protocol not supported. */ - PROTONOSUPPORT = 66, + @inline export const PROTONOSUPPORT: errno = 66; /** Protocol wrong type for socket. */ - PROTOTYPE = 67, + @inline export const PROTOTYPE: errno = 67; /** Result too large. */ - RANGE = 68, + @inline export const RANGE: errno = 68; /** Read-only file system. */ - ROFS = 69, + @inline export const ROFS: errno = 69; /** Invalid seek. */ - SPIPE = 70, + @inline export const SPIPE: errno = 70; /** No such process. */ - SRCH = 71, + @inline export const SRCH: errno = 71; /** Reserved. */ - STALE = 72, + @inline export const STALE: errno = 72; /** Connection timed out. */ - TIMEDOUT = 73, + @inline export const TIMEDOUT: errno = 73; /** Text file busy. */ - TXTBSY = 74, + @inline export const TXTBSY: errno = 74; /** Cross-device link. */ - XDEV = 75, + @inline export const XDEV: errno = 75; /** Extension: Capabilities insufficient. */ - NOTCAPABLE = 76 + @inline export const NOTCAPABLE: errno = 76; } -export type errno_t = u16; +export type errno = u16; /** An event that occurred. */ @unmanaged export abstract class event { /** User-provided value that got attached to `subscription#userdata`. */ - userdata: userdata_t; + userdata: userdata; /** If non-zero, an error that occurred while processing the subscription request. */ - error: errno_t; + error: errno; /* The type of the event that occurred. */ - type: eventtype_t; + type: eventtype; private __padding0: u16; } /** An event that occurred when type is `eventtype.FD_READ` or `eventtype.FD_WRITE`. */ @unmanaged export class rwevent extends event { /* The number of bytes available for reading or writing. */ - nbytes: filesize_t; + nbytes: filesize; /* The state of the file descriptor. */ - flags: eventrwflags_t; + flags: eventrwflags; private __padding1: u32; } /** The state of the file descriptor subscribed to with `eventtype.FD_READ` or `eventtype.FD_WRITE`. */ -export const enum eventrwflags { +export namespace eventrwflags { /** The peer of this socket has closed or disconnected. */ - HANGUP = 1 + @inline export const HANGUP: eventrwflags = 1; } -export type eventrwflags_t = u16; +export type eventrwflags = u16; /** Type of a subscription to an event or its occurrence. */ -export const enum eventtype { +export namespace eventtype { /** The time value of clock has reached the timestamp. */ - CLOCK = 0, + @inline export const CLOCK: eventtype = 0; /** File descriptor has data available for reading. */ - FD_READ = 1, + @inline export const FD_READ: eventtype = 1; /** File descriptor has capacity available for writing */ - FD_WRITE = 2 + @inline export const FD_WRITE: eventtype = 2; } -export type eventtype_t = u8; +export type eventtype = u8; /** Exit code generated by a process when exiting. */ -export type exitcode_t = u32; +export type exitcode = u32; /** A file descriptor number. */ -export type fd_t = u32; +export type fd = u32; /** File descriptor flags. */ -export const enum fdflags { +export namespace fdflags { /** Append mode: Data written to the file is always appended to the file's end. */ - APPEND = 1, + @inline export const APPEND: fdflags = 1; /** Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. */ - DSYNC = 2, + @inline export const DSYNC: fdflags = 2; /** Non-blocking mode. */ - NONBLOCK = 4, + @inline export const NONBLOCK: fdflags = 4; /** Synchronized read I/O operations. */ - RSYNC = 8, + @inline export const RSYNC: fdflags = 8; /** Write according to synchronized I/O file integrity completion. */ - SYNC = 16 + @inline export const SYNC: fdflags = 16; } -export type fdflags_t = u16; +export type fdflags = u16; /** File descriptor attributes. */ @unmanaged export class fdstat { /** File type. */ - filetype: filetype_t; + filetype: filetype; /** File descriptor flags. */ - flags: fdflags_t; + flags: fdflags; /** Rights that apply to this file descriptor. */ - rights_base: rights_t; + rights_base: rights; /** Maximum set of rights that may be installed on new file descriptors that are created through this file descriptor, e.g., through `path_open`. */ - rights_inheriting: rights_t; + rights_inheriting: rights; } /** Relative offset within a file. */ -export type filedelta_t = i64; +export type filedelta = i64; /** Non-negative file size or length of a region within a file. */ -export type filesize_t = u64; +export type filesize = u64; /** File attributes. */ @unmanaged export class filestat { /** Device ID of device containing the file. */ - dev: device_t; + dev: device; /** File serial number. */ - ino: inode_t; + ino: inode; /** File type. */ - filetype: filetype_t; + filetype: filetype; /** Number of hard links to the file. */ - nlink: linkcount_t; + nlink: linkcount; /** For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. */ - size: filesize_t; + size: filesize; /** Last data access timestamp. */ - atim: timestamp_t; + atim: timestamp; /** Last data modification timestamp. */ - mtim: timestamp_t; + mtim: timestamp; /** Last file status change timestamp. */ - ctim: timestamp_t; + ctim: timestamp; } /** The type of a file descriptor or file. */ -export const enum filetype { +export namespace filetype { /** The type of the file descriptor or file is unknown or is different from any of the other types specified. */ - UNKNOWN = 0, + @inline export const UNKNOWN: filetype = 0; /** The file descriptor or file refers to a block device inode. */ - BLOCK_DEVICE = 1, + @inline export const BLOCK_DEVICE: filetype = 1; /** The file descriptor or file refers to a character device inode. */ - CHARACTER_DEVICE = 2, + @inline export const CHARACTER_DEVICE: filetype = 2; /** The file descriptor or file refers to a directory inode. */ - DIRECTORY = 3, + @inline export const DIRECTORY: filetype = 3; /** The file descriptor or file refers to a regular file inode. */ - REGULAR_FILE = 4, + @inline export const REGULAR_FILE: filetype = 4; /** The file descriptor or file refers to a datagram socket. */ - SOCKET_DGRAM = 5, + @inline export const SOCKET_DGRAM: filetype = 5; /** The file descriptor or file refers to a byte-stream socket. */ - SOCKET_STREAM = 6, + @inline export const SOCKET_STREAM: filetype = 6; /** The file refers to a symbolic link inode. */ - SYMBOLIC_LINK = 7 + @inline export const SYMBOLIC_LINK: filetype = 7; } -export type filetype_t = u8; +export type filetype = u8; /** Which file time attributes to adjust. */ -export const enum fstflags { +export namespace fstflags { /** Adjust the last data access timestamp to the value stored in `filestat#st_atim`. */ - SET_ATIM = 1, + @inline export const SET_ATIM = 1; /** Adjust the last data access timestamp to the time of clock `clockid.REALTIME`. */ - SET_ATIM_NOW = 2, + @inline export const SET_ATIM_NOW = 2; /** Adjust the last data modification timestamp to the value stored in `filestat#st_mtim`. */ - SET_MTIM = 4, + @inline export const SET_MTIM = 4; /** Adjust the last data modification timestamp to the time of clock `clockid.REALTIME`. */ - SET_MTIM_NOW = 8 + @inline export const SET_MTIM_NOW = 8; } -export type fstflags_t = u16; +export type fstflags = u16; /** File serial number that is unique within its file system. */ -export type inode_t = u64; +export type inode = u64; /** A region of memory for scatter/gather reads. */ @unmanaged export class iovec { /** The address of the buffer to be filled. */ - buf: uintptr_t; + buf: uintptr; /** The length of the buffer to be filled. */ - buf_len: size_t; + buf_len: size; } /** Number of hard links to an inode. */ -export type linkcount_t = u32; +export type linkcount = u32; /** Flags determining the method of how paths are resolved. */ -export const enum lookupflags { +export namespace lookupflags { /** As long as the resolved path corresponds to a symbolic link, it is expanded. */ - SYMLINK_FOLLOW = 1 + @inline export const SYMLINK_FOLLOW: lookupflags = 1; } -export type lookupflags_t = u32; +export type lookupflags = u32; /** Open flags. */ -export const enum oflags { +export namespace oflags { /** Create file if it does not exist. */ - CREAT = 1, + @inline export const CREAT: oflags = 1; /** Fail if not a directory. */ - DIRECTORY = 2, + @inline export const DIRECTORY: oflags = 2; /** Fail if file already exists. */ - EXCL = 4, + @inline export const EXCL: oflags = 4; /** Truncate file to size 0. */ - TRUNC = 8 + @inline export const TRUNC: oflags = 8; } -export type oflags_t = u16; +export type oflags = u16; /** Flags provided to `sock_recv`. */ -export const enum riflags { +export namespace riflags { /** Returns the message without removing it from the socket's receive queue. */ - PEEK = 1, + @inline export const PEEK: riflags = 1; /** On byte-stream sockets, block until the full amount of data can be returned. */ - WAITALL = 2 + @inline export const WAITALL: riflags = 2; } -export type riflags_t = u16; +export type riflags = u16; /** File descriptor rights, determining which actions may be performed. */ -export const enum rights { +export namespace rights { /** The right to invoke `fd_datasync`. */ - FD_DATASYNC = 1, + @inline export const FD_DATASYNC: rights = 1; /** The right to invoke `fd_read` and `sock_recv`. */ - FD_READ = 2, + @inline export const FD_READ: rights = 2; /** The right to invoke `fd_seek`. This flag implies `rights.FD_TELL`. */ - FD_SEEK = 4, + @inline export const FD_SEEK: rights = 4; /** The right to invoke `fd_fdstat_set_flags`. */ - FD_FDSTAT_SET_FLAGS = 8, + @inline export const FD_FDSTAT_SET_FLAGS: rights = 8; /** The right to invoke `fd_sync`. */ - FD_SYNC = 16, + @inline export const FD_SYNC: rights = 16; /** The right to invoke `fd_seek` in such a way that the file offset remains unaltered (i.e., `whence.CUR` with offset zero), or to invoke `fd_tell`). */ - FD_TELL = 32, + @inline export const FD_TELL: rights = 32; /** The right to invoke `fd_write` and `sock_send`. If `rights.FD_SEEK` is set, includes the right to invoke `fd_pwrite`. */ - FD_WRITE = 64, + @inline export const FD_WRITE: rights = 64; /** The right to invoke `fd_advise`. */ - FD_ADVISE = 128, + @inline export const FD_ADVISE: rights = 128; /** The right to invoke `fd_allocate`. */ - FD_ALLOCATE = 256, + @inline export const FD_ALLOCATE: rights = 256; /** The right to invoke `path_create_directory`. */ - PATH_CREATE_DIRECTORY = 512, + @inline export const PATH_CREATE_DIRECTORY: rights = 512; /** If `rights.PATH_OPEN` is set, the right to invoke `path_open` with `oflags.CREAT`. */ - PATH_CREATE_FILE = 1024, + @inline export const PATH_CREATE_FILE: rights = 1024; /** The right to invoke `path_link` with the file descriptor as the source directory. */ - PATH_LINK_SOURCE = 2048, + @inline export const PATH_LINK_SOURCE: rights = 2048; /** The right to invoke `path_link` with the file descriptor as the target directory. */ - PATH_LINK_TARGET = 4096, + @inline export const PATH_LINK_TARGET: rights = 4096; /** The right to invoke `path_open`. */ - PATH_OPEN = 8192, + @inline export const PATH_OPEN: rights = 8192; /** The right to invoke `fd_readdir`. */ - FD_READDIR = 16384, + @inline export const FD_READDIR: rights = 16384; /** The right to invoke `path_readlink`. */ - PATH_READLINK = 32768, + @inline export const PATH_READLINK: rights = 32768; /** The right to invoke `path_rename` with the file descriptor as the source directory. */ - PATH_RENAME_SOURCE = 65536, + @inline export const PATH_RENAME_SOURCE: rights = 65536; /** The right to invoke `path_rename` with the file descriptor as the target directory. */ - PATH_RENAME_TARGET = 131072, + @inline export const PATH_RENAME_TARGET: rights = 131072; /** The right to invoke `path_filestat_get`. */ - PATH_FILESTAT_GET = 262144, + @inline export const PATH_FILESTAT_GET: rights = 262144; /** The right to change a file's size (there is no `path_filestat_set_size`). If `rights.PATH_OPEN` is set, includes the right to invoke `path_open` with `oflags.TRUNC`. */ - PATH_FILESTAT_SET_SIZE = 524288, + @inline export const PATH_FILESTAT_SET_SIZE: rights = 524288; /** The right to invoke `path_filestat_set_times`. */ - PATH_FILESTAT_SET_TIMES = 1048576, + @inline export const PATH_FILESTAT_SET_TIMES: rights = 1048576; /** The right to invoke `fd_filestat_get`. */ - FD_FILESTAT_GET = 2097152, + @inline export const FD_FILESTAT_GET: rights = 2097152; /** The right to invoke `fd_filestat_set_size`. */ - FD_FILESTAT_SET_SIZE = 4194304, + @inline export const FD_FILESTAT_SET_SIZE: rights = 4194304; /** The right to invoke `fd_filestat_set_times`. */ - FD_FILESTAT_SET_TIMES = 8388608, + @inline export const FD_FILESTAT_SET_TIMES: rights = 8388608; /** The right to invoke `path_symlink`. */ - RIGHT_PATH_SYMLINK = 16777216, + @inline export const RIGHT_PATH_SYMLINK: rights = 16777216; /** The right to invoke `path_remove_directory`. */ - PATH_REMOVE_DIRECTORY = 33554432, + @inline export const PATH_REMOVE_DIRECTORY: rights = 33554432; /** The right to invoke `path_unlink_file`. */ - PATH_UNLINK_FILE = 67108864, + @inline export const PATH_UNLINK_FILE: rights = 67108864; /** If `rights.FD_READ` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype.FD_READ`. If `rights.FD_WRITE` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype.FD_WRITE`. */ - POLL_FD_READWRITE = 134217728, + @inline export const POLL_FD_READWRITE: rights = 134217728; /** The right to invoke `sock_shutdown`. */ - SOCK_SHUTDOWN = 268435456 + @inline export const SOCK_SHUTDOWN: rights = 268435456; } -export type rights_t = u64; +export type rights = u64; /** Flags returned by `sock_recv`. */ -export const enum roflags { +export namespace roflags { /** Message data has been truncated. */ - DATA_TRUNCATED = 1 + @inline export const DATA_TRUNCATED: roflags = 1; } -export type roflags_t = u16; +export type roflags = u16; /** Which channels on a socket to shut down. */ -export const enum sdflags { +export namespace sdflags { /** Disables further receive operations. */ - RD = 1, + @inline export const RD: sdflags = 1; /** Disables further send operations. */ - WR = 2 + @inline export const WR: sdflags = 2; } -export type sdflags_t = u8; +export type sdflags = u8; /** Flags provided to `sock_send`. */ -export const enum siflags { +export namespace siflags { // As there are currently no flags defined, it must be set to zero. } -export type siflags_t = u16; +export type siflags = u16; /** Signal condition. */ -export const enum signal { +export namespace signal { /** Hangup. */ - HUP = 1, + @inline export const HUP: signal = 1; /** Terminate interrupt signal. */ - INT = 2, + @inline export const INT: signal = 2; /** Terminal quit signal. */ - QUIT = 3, + @inline export const QUIT: signal = 3; /** Illegal instruction. */ - ILL = 4, + @inline export const ILL: signal = 4; /** Trace/breakpoint trap. */ - TRAP = 5, + @inline export const TRAP: signal = 5; /** Process abort signal. */ - ABRT = 6, + @inline export const ABRT: signal = 6; /** Access to an undefined portion of a memory object. */ - BUS = 7, + @inline export const BUS: signal = 7; /** Erroneous arithmetic operation. */ - FPE = 8, + @inline export const FPE: signal = 8; /** Kill. */ - KILL = 9, + @inline export const KILL: signal = 9; /** User-defined signal 1. */ - USR1 = 10, + @inline export const USR1: signal = 10; /** Invalid memory reference. */ - SEGV = 11, + @inline export const SEGV: signal = 11; /** User-defined signal 2. */ - USR2 = 12, + @inline export const USR2: signal = 12; /** Write on a pipe with no one to read it. */ - PIPE = 13, + @inline export const PIPE: signal = 13; /** Alarm clock. */ - ALRM = 14, + @inline export const ALRM: signal = 14; /** Termination signal. */ - TERM = 15, + @inline export const TERM: signal = 15; /** Child process terminated, stopped, or continued. */ - CHLD = 16, + @inline export const CHLD: signal = 16; /** Continue executing, if stopped. */ - CONT = 17, + @inline export const CONT: signal = 17; /** Stop executing. */ - STOP = 18, + @inline export const STOP: signal = 18; /** Terminal stop signal. */ - TSTP = 19, + @inline export const TSTP: signal = 19; /** Background process attempting read. */ - TTIN = 20, + @inline export const TTIN: signal = 20; /** Background process attempting write. */ - TTOU = 21, + @inline export const TTOU: signal = 21; /** High bandwidth data is available at a socket. */ - URG = 22, + @inline export const URG: signal = 22; /** CPU time limit exceeded. */ - XCPU = 23, + @inline export const XCPU: signal = 23; /** File size limit exceeded. */ - XFSZ = 24, + @inline export const XFSZ: signal = 24; /** Virtual timer expired. */ - VTALRM = 25, - PROF = 26, - WINCH = 27, - POLL = 28, - PWR = 29, + @inline export const VTALRM: signal = 25; + @inline export const PROF: signal = 26; + @inline export const WINCH: signal = 27; + @inline export const POLL: signal = 28; + @inline export const PWR: signal = 29; /** Bad system call. */ - SYS = 30 + @inline export const SYS: signal = 30; } -export type signal_t = u8; +export type signal = u8; /** Flags determining how to interpret the timestamp provided in `subscription_t::u.clock.timeout. */ -export const enum subclockflags { +export namespace subclockflags { /** If set, treat the timestamp provided in `clocksubscription` as an absolute timestamp. */ - ABSTIME = 1 + @inline export const ABSTIME: subclockflags = 1; } -export type subclockflags_t = u16; +export type subclockflags = u16; /** Subscription to an event. */ @unmanaged export abstract class subscription { /** User-provided value that is attached to the subscription. */ - userdata: userdata_t; + userdata: userdata; /** The type of the event to which to subscribe. */ - type: eventtype_t; + type: eventtype; private __padding0: u32; } /* Subscription to an event of type `eventtype.CLOCK`.**/ @unmanaged export class clocksubscription extends subscription { /** The user-defined unique identifier of the clock. */ - identifier: userdata_t; + identifier: userdata; /** The clock against which to compare the timestamp. */ - clock_id: clockid_t; + clock_id: clockid; /** The absolute or relative timestamp. */ - timeout: timestamp_t; + timeout: timestamp; /** The amount of time that the implementation may wait additionally to coalesce with other events. */ - precision: timestamp_t; + precision: timestamp; /** Flags specifying whether the timeout is absolute or relative. */ - flags: subclockflags_t; + flags: subclockflags; private __padding1: u32; } /* Subscription to an event of type `eventtype.FD_READ` or `eventtype.FD_WRITE`.**/ @unmanaged export class fdsubscription extends subscription { /** The file descriptor on which to wait for it to become ready for reading or writing. */ - fd: fd_t; + fd: fd; } /** Timestamp in nanoseconds. */ -export type timestamp_t = u64; +export type timestamp = u64; /** User-provided value that may be attached to objects that is retained when extracted from the implementation. */ -export type userdata_t = u64; +export type userdata = u64; /** The position relative to which to set the offset of the file descriptor. */ -export const enum whence { +export namespace whence { /** Seek relative to current position. */ - CUR = 0, + @inline export const CUR: whence = 0; /** Seek relative to end-of-file. */ - END = 1, + @inline export const END: whence = 1; /** Seek relative to start-of-file. */ - SET = 2 + @inline export const SET: whence = 2; } -export type whence_t = u8; - -// glue -export type uintptr_t = usize; -export type size_t = usize; +export type whence = u8; diff --git a/tests/compiler/wasi.optimized.wat b/tests/compiler/wasi.optimized.wat index d478ff33..e04375f3 100644 --- a/tests/compiler/wasi.optimized.wat +++ b/tests/compiler/wasi.optimized.wat @@ -3,10 +3,16 @@ (memory $0 1) (data (i32.const 8) "\07\00\00\00w\00a\00s\00i\00.\00t\00s") (table $0 1 funcref) - (elem (i32.const 0) $start) + (elem (i32.const 0) $null) + (global $wasi/sig (mut i32) (i32.const 1)) (export "memory" (memory $0)) (export "table" (table $0)) + (start $start) (func $start (; 0 ;) (type $FUNCSIG$v) + i32.const 9 + global.set $wasi/sig + ) + (func $null (; 1 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/wasi.ts b/tests/compiler/wasi.ts index fbcb0e96..618f1e2d 100644 --- a/tests/compiler/wasi.ts +++ b/tests/compiler/wasi.ts @@ -1,4 +1,4 @@ -import { dirent, rwevent, fdstat, filestat, iovec, clocksubscription, fdsubscription } from "bindings/wasi"; +import { dirent, rwevent, fdstat, filestat, iovec, clocksubscription, fdsubscription, signal } from "bindings/wasi"; // TODO: WASM64 @@ -48,3 +48,7 @@ assert(offsetof("userdata") == 0); assert(offsetof("type") == 8); assert(offsetof("fd") == 16); assert(offsetof() == 20); + +// check assignability of mimicked typed enums +var sig: signal = signal.HUP; +sig = signal.KILL; diff --git a/tests/compiler/wasi.untouched.wat b/tests/compiler/wasi.untouched.wat index 0f81081e..9bb03b94 100644 --- a/tests/compiler/wasi.untouched.wat +++ b/tests/compiler/wasi.untouched.wat @@ -6,6 +6,7 @@ (data (i32.const 8) "\07\00\00\00w\00a\00s\00i\00.\00t\00s\00") (table $0 1 funcref) (elem (i32.const 0) $null) + (global $wasi/sig (mut i32) (i32.const 1)) (global $~lib/memory/HEAP_BASE i32 (i32.const 28)) (export "memory" (memory $0)) (export "table" (table $0)) @@ -491,6 +492,8 @@ call $~lib/env/abort unreachable end + i32.const 9 + global.set $wasi/sig ) (func $start (; 2 ;) (type $FUNCSIG$v) call $start:wasi