hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 5c7cd7750ee823382acb8c47248cf6b4549be626
parent 985854be35bd787ff3790827d3fc3171a191362f
Author: Alexey Yerin <yyp@disroot.org>
Date:   Fri, 15 Oct 2021 16:01:32 +0300

all: add 0 value to enums used as flags

It indicates to the type system that none of flags can be active.
Which also allows types::strflag to work correctly on those types.

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Mfnmatch/fnmatch.ha | 2++
Mformat/elf/types.ha | 4++++
Mhare/lex/lex.ha | 3++-
Mlinux/io_uring/cqe.ha | 4++--
Mlinux/io_uring/queue.ha | 2+-
Mlinux/io_uring/uring.ha | 12++++++++++++
Mrt/types.ha | 1+
7 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/fnmatch/fnmatch.ha b/fnmatch/fnmatch.ha @@ -5,6 +5,8 @@ use sort; // A set of flags that alter the matching behavior of [[fnmatch::fnmatch]] export type flags = enum uint { + NONE = 0, + // If this flag is set, slashes in the string will only be matched by // literal slashes in the pattern PATHNAME = 1u << 0, diff --git a/format/elf/types.ha b/format/elf/types.ha @@ -552,6 +552,8 @@ export type sht = enum u32 { // Section flags export type shf = enum u32 { + // Section contains no data + NONE = 0, // Section contains writable data WRITE = 0x1, // Section is allocated in memory image of program @@ -718,6 +720,8 @@ export type pt = enum u32 { // Segment attributes export type pf = enum u32 { + // No permission + NONE = 0, // Execute permission X = 0x1, // Write permission diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -24,6 +24,7 @@ export type lexer = struct { // Flags which apply to this lexer export type flags = enum uint { + NONE = 0, // Enables lexing comments COMMENTS = 1 << 0, }; @@ -48,7 +49,7 @@ export fn strerror(err: error) const str = { // Initializes a new lexer for the given input stream. The path is borrowed. export fn init(in: *io::stream, path: str, flags: flags...) lexer = { - let f: flags = 0: flags; + let f = flags::NONE; for (let i = 0z; i < len(flags); i += 1) { f |= flags[i]; }; diff --git a/linux/io_uring/cqe.ha b/linux/io_uring/cqe.ha @@ -28,7 +28,7 @@ export fn wait(ring: *io_uring) (*cqe | error) = { export fn peek(ring: *io_uring) (nullable *cqe | error) = get_cqe(ring, 0, 0); // Returns the result of a [[cqe]], or an error if unsuccessful. -export fn result(cqe: *cqe) (int | error) = +export fn result(cqe: *cqe) (int | error) = if (cqe.res < 0) errors::errno(rt::wrap_errno(-cqe.res)) else cqe.res; @@ -56,7 +56,7 @@ fn get_cqe( let cq: nullable *cqe = null; for (cq == null) { let enter = false, overflow = false; - let flags: enter_flags = 0; + let flags = enter_flags::NONE; // TODO: tuple destructuring let tup = peek_cqe(ring); diff --git a/linux/io_uring/queue.ha b/linux/io_uring/queue.ha @@ -81,7 +81,7 @@ fn do_submit( submitted: uint, wait: uint, ) (uint | error) = { - let flags: enter_flags = enter_flags::GETEVENTS; + let flags = enter_flags::GETEVENTS; if (needs_enter(ring, &flags) || wait != 0) { match (rt::io_uring_enter(ring.fd, submitted, wait, flags, null)) { diff --git a/linux/io_uring/uring.ha b/linux/io_uring/uring.ha @@ -56,6 +56,7 @@ export type op = enum u8 { // Flags for an [[sqe]]. export type flags = enum u8 { + NONE = 0, // Use fixed fileset FIXED_FILE = 1 << 0, // Issue after inflight IO @@ -72,11 +73,13 @@ export type flags = enum u8 { // Flags for an fsync operation. export type fsync_flags = enum u32 { + NONE = 0, DATASYNC = 1 << 0, }; // Flags for a timeout operation. export type timeout_flags = enum u32 { + NONE = 0, // If set, the timeout will be "absolute", waiting until CLOCK_MONOTONIC // reaches the time defined by the timespec. If unset, it will be // interpted as a duration relative to the I/O submission. @@ -88,11 +91,13 @@ export type timeout_flags = enum u32 { // Flags for a splice operation. export type splice_flags = enum u32 { + NONE = 0, F_FD_IN_FIXED = 1 << 31, }; // Flags for a [[cqe]]. export type cqe_flags = enum u32 { + NONE = 0, F_BUFFER = 1 << 0, }; @@ -162,6 +167,7 @@ export type sqring_offsets = struct { // Flags for the sq ring. export type sqring_flags = enum u32 { + NONE = 0, // Needs io_uring_enter wakeup NEED_WAKEUP = 1 << 0, // CQ ring is overflown @@ -183,11 +189,13 @@ export type cqring_offsets = struct { // Flags for the cq ring. export type cqring_flags = enum u32 { + NONE = 0, EVENTFD_DISABLED = 1 << 0, }; // Flags for [[setup]]. export type setup_flags = enum u32 { + NONE = 0, // io_context is polled IOPOLL = 1 << 0, // SQ poll thread @@ -220,6 +228,7 @@ export type params = struct { // Features supported by the kernel. export type features = enum u32 { + NONE = 0, SINGLE_MMAP = 1 << 0, NODROP = 1 << 1, SUBMIT_STABLE = 1 << 2, @@ -231,6 +240,7 @@ export type features = enum u32 { // Flags for [[enter]]. export type enter_flags = enum uint { + NONE = 0, GETEVENTS = 1 << 0, SQ_WAKEUP = 1 << 1, SQ_WAIT = 1 << 2, @@ -263,6 +273,7 @@ export type files_update = struct { // Flags for a probe operation. export type op_flags = enum u16 { + NONE = 0, SUPPORTED = 1 << 0, }; @@ -297,6 +308,7 @@ export type restriction = struct { // Opcode for a [[restriction]]. export type resop = enum u16 { + NONE = 0, // Allow an io_uring_register(2) opcode REGISTER_OP = 0, // Allow an sqe opcode diff --git a/rt/types.ha b/rt/types.ha @@ -45,6 +45,7 @@ type types::variadism = enum { }; type types::func_flags = enum uint { + NONE = 0, NORETURN = 1 << 0, };