~sircmpwn/hare-dev

hare-irc: bump language usage v1 APPLIED

Willow Barraco: 1
 bump language usage

 5 files changed, 27 insertions(+), 33 deletions(-)
If you want to pick that bufio thread back up, get a rebased patch with
a flag to choose the appropriate behavior on the list for discussion and
I'll make sure to find some time to have it reviewed and merged.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/54270/mbox | git am -3
Learn more about email & git

[PATCH hare-irc] bump language usage Export this patch

- void to opaque
- void to done
- unreachable aborts

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
---
 cmd/testbot/main.ha |  4 ++--
 net/irc/client.ha   |  9 ++++-----
 net/irc/isupport.ha | 15 ++++++---------
 net/irc/message.ha  |  8 +++-----
 net/irc/state.ha    | 24 ++++++++++++------------
 5 files changed, 27 insertions(+), 33 deletions(-)

diff --git a/cmd/testbot/main.ha b/cmd/testbot/main.ha
index e09af6b..e073410 100644
--- a/cmd/testbot/main.ha
+++ b/cmd/testbot/main.ha
@@ -43,7 +43,7 @@ export fn main() void = {
	for (!(irc::dispatch(conn)! is io::EOF)) void;
};

fn logmsg(state: nullable *void, party: irc::party, msg: *irc::message) void = {
fn logmsg(state: nullable *opaque, party: irc::party, msg: *irc::message) void = {
	switch (party) {
	case irc::party::SERVER =>
		fmt::print("<= ")!;
@@ -58,7 +58,7 @@ fn logmsg(state: nullable *void, party: irc::party, msg: *irc::message) void = {
};

fn handle_privmsg(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *irc::message,
) (void | irc::error) = {
	fmt::printfln("PRIVMSG from {}: {}", msg.prefix.nick, msg.params[1])!;
diff --git a/net/irc/client.ha b/net/irc/client.ha
index e4cc767..2428941 100644
--- a/net/irc/client.ha
+++ b/net/irc/client.ha
@@ -15,10 +15,10 @@ export type config = struct {
	pass: str,
	realname: str,
	logfn: nullable *logfn,
	logstate: nullable *void,
	logstate: nullable *opaque,
};

export type logfn = fn(state: nullable *void, party: party, msg: *message) void;
export type logfn = fn(state: nullable *opaque, party: party, msg: *message) void;

export type client = struct {
	conn: net::socket,
@@ -27,7 +27,7 @@ export type client = struct {
	dirty: size,
	nick: str,
	logfn: nullable *logfn,
	logstate: nullable *void,
	logstate: nullable *opaque,
	next_id: uint,
	handlers: [64][]handler,
	isupport: isupport,
@@ -171,7 +171,6 @@ export fn recv(client: *client) (message | io::EOF | error) = {
		client.dirty = end + 2;
		return msg;
	};
	abort();
};

// Performs a blocking read on the IRC connection, processes one message, and
@@ -226,7 +225,7 @@ export type party = enum {
export fn setlog(
	client: *client,
	func: nullable *logfn,
	state: nullable *void,
	state: nullable *opaque,
) void = {
	client.logfn = func;
	client.logstate = state;
diff --git a/net/irc/isupport.ha b/net/irc/isupport.ha
index 280d59d..891aba6 100644
--- a/net/irc/isupport.ha
+++ b/net/irc/isupport.ha
@@ -194,7 +194,7 @@ fn isupport_setparam(
		};
	case "CHANTYPES" =>
		free(sup.chantypes);
		sup.chantypes = strings::runes(value);
		sup.chantypes = strings::torunes(value);
	case "NETWORK" =>
		free(sup.network);
		sup.network = strings::dup(value);
@@ -202,7 +202,7 @@ fn isupport_setparam(
		free(sup.prefixes);
		let iter = strings::iter(value);
		match (strings::next(&iter)) {
		case void =>
		case done =>
			return invalid;
		case let r: rune =>
			if (r != '(') {
@@ -211,7 +211,7 @@ fn isupport_setparam(
		};
		for (true) {
			match (strings::next(&iter)) {
			case void =>
			case done =>
				return invalid;
			case let r: rune =>
				if (r == ')') {
@@ -224,21 +224,18 @@ fn isupport_setparam(
			};
		};
		for (let i = 0z; i < len(sup.prefixes); i += 1) {
			match (strings::next(&iter)) {
			case void =>
				return invalid;
			case let r: rune =>
			for (let r => strings::next(&iter)) {
				sup.prefixes[i].prefix = r;
			};
		};
		if (!(strings::next(&iter) is void)) {
		if (!(strings::next(&iter) is done)) {
			return invalid;
		};
	};
};

fn handle_isupport(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error) = {
	let client = state: *client;
diff --git a/net/irc/message.ha b/net/irc/message.ha
index 6d9533a..4505157 100644
--- a/net/irc/message.ha
+++ b/net/irc/message.ha
@@ -62,7 +62,7 @@ export fn parse(in: const str) (message | invalid) = {
// will handle truncation if required.
export fn serialize(sink: io::handle, msg: *message) (size | io::error) = {
	let buf: [MAXLEN + 2]u8 = [0...];
	let sink = bufio::buffered(sink, [], buf[..]);
	let sink = bufio::init(sink, [], buf[..]);
	defer io::close(&sink)!;

	let z = 0z;
@@ -160,11 +160,10 @@ fn next(tok: *strings::tokenizer) (str | invalid) = {
			if (len(s) > 0) {
				return s;
			};
		case void =>
		case done =>
			return invalid;
		};
	};
	abort(); // Unreachable
};

fn peek(tok: *strings::tokenizer) (str | void) = {
@@ -176,9 +175,8 @@ fn peek(tok: *strings::tokenizer) (str | void) = {
			} else {
				strings::next_token(tok);
			};
		case void =>
		case done =>
			return;
		};
	};
	abort(); // Unreachable
};
diff --git a/net/irc/state.ha b/net/irc/state.ha
index 9d3f182..5a955fc 100644
--- a/net/irc/state.ha
+++ b/net/irc/state.ha
@@ -6,7 +6,7 @@ use time;

// A function which handles an incoming IRC message.
export type callback = fn(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error);

@@ -14,7 +14,7 @@ export type handler = struct {
	id: uint,
	cmd: const str,
	func: *callback,
	state: nullable *void,
	state: nullable *opaque,
};

// Registers a callback for an IRC event, returning the internally assigned ID
@@ -26,7 +26,7 @@ export fn on(
	client: *client,
	cmd: const str,
	callback: *callback,
	state: nullable *void,
	state: nullable *opaque,
) uint = {
	const hash = fnv::string(cmd);
	const bucket = &client.handlers[hash % len(client.handlers)];
@@ -97,12 +97,12 @@ fn delchan(client: *client, name: str) void = {
	};
};

fn handle_ping(state: nullable *void, msg: const *message) (void | error) = {
fn handle_ping(state: nullable *opaque, msg: const *message) (void | error) = {
	let client = state: *client;
	send(client, "PONG", msg.params...)?;
};

fn handle_topic(state: nullable *void, msg: const *message) (void | error) = {
fn handle_topic(state: nullable *opaque, msg: const *message) (void | error) = {
	let client = state: *client;
	let chan = getchan(client, msg.params[1]);
	free(chan.topic);
@@ -110,7 +110,7 @@ fn handle_topic(state: nullable *void, msg: const *message) (void | error) = {
};

fn handle_topicwhotime(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error) = {
	let client = state: *client;
@@ -126,7 +126,7 @@ fn handle_topicwhotime(
};

fn handle_namereply(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error) = {
	let client = state: *client;
@@ -150,7 +150,7 @@ fn handle_namereply(
};

fn handle_nick(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error) = {
	let client = state: *client;
@@ -173,7 +173,7 @@ fn handle_nick(
};

fn handle_join(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error) = {
	let client = state: *client;
@@ -201,7 +201,7 @@ fn handle_join(
};

fn handle_part(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error) = {
	let client = state: *client;
@@ -222,7 +222,7 @@ fn handle_part(
};

fn handle_kick(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error) = {
	let client = state: *client;
@@ -247,7 +247,7 @@ fn handle_kick(
};

fn handle_quit(
	state: nullable *void,
	state: nullable *opaque,
	msg: const *message,
) (void | error) = {
	let client = state: *client;
-- 
2.46.0
Thanks! This should probably be rewritten to use hare-ev at some point.

To git@git.sr.ht:~sircmpwn/hare-irc
   c1d902a..78ba2f5  master -> master