~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH hare v2] encoding::utf8: implement streamnext()

Details
Message ID
<20230516031133.2846-1-autumnull@posteo.net>
DKIM signature
pass
Download raw message
Patch: +34 -15
Signed-off-by: Autumn! <autumnull@posteo.net>
---
rebase to upstream
 encoding/utf8/stream.ha | 19 +++++++++++++++++++
 io/+freebsd/file.ha     |  1 -
 io/+linux/file.ha       |  1 -
 io/+test/stream.ha      |  1 -
 scripts/gen-stdlib      |  9 +++++----
 stdlib.mk               | 18 ++++++++++--------
 6 files changed, 34 insertions(+), 15 deletions(-)
 create mode 100644 encoding/utf8/stream.ha

diff --git a/encoding/utf8/stream.ha b/encoding/utf8/stream.ha
new file mode 100644
index 00000000..d78ee74e
--- /dev/null
+++ b/encoding/utf8/stream.ha
@@ -0,0 +1,19 @@
use io;

export fn streamnext(in: io::handle) (rune | invalid | io::EOF | io::error) = {
	let next = 0, state = 0;
	let r = 0u32;
	let buf: [1]u8 = [0...];
	for (true) match(io::readall(in, buf)?) {
	case io::EOF => return if (next == 0) io::EOF else invalid;
	case size =>
		const b = buf[0];
		next = table[state][b];
		r = r << 6 | b & masks[(state - 1): uint >> 31][next & 7];
		if (next <= 0) {
			return if (next == 0) r: rune else invalid;
		};
		state = next;
	};
	abort(); // unreachable
};
diff --git a/io/+freebsd/file.ha b/io/+freebsd/file.ha
index ead2c97a..5d7653e8 100644
--- a/io/+freebsd/file.ha
+++ b/io/+freebsd/file.ha
@@ -3,7 +3,6 @@
// (c) 2021 Ember Sawady <ecs@d2evs.net>
use errors;
use rt;
use strings;

// This is an opaque type which encloses an OS-level file handle resource. It
// can be used as a [[handle]] in most situations, but there are some APIs which
diff --git a/io/+linux/file.ha b/io/+linux/file.ha
index b30b0b9a..a498ba66 100644
--- a/io/+linux/file.ha
+++ b/io/+linux/file.ha
@@ -4,7 +4,6 @@
// (c) 2021 Ember Sawady <ecs@d2evs.net>
use errors;
use rt;
use strings;

// This is an opaque type which encloses an OS-level file handle resource. It
// can be used as a [[handle]] in most situations, but there are some APIs which
diff --git a/io/+test/stream.ha b/io/+test/stream.ha
index 56563aaf..86acb4ae 100644
--- a/io/+test/stream.ha
+++ b/io/+test/stream.ha
@@ -1,7 +1,6 @@
// License: MPL-2.0
// (c) 2021 Bor Grošelj Simić <bor.groseljsimic@telemach.net>
// (c) 2021 Drew DeVault <sir@cmpwn.com>
use strings;

const teststream_vtable: vtable = vtable {
	reader = &teststream_read,
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
index a272faa3..6af609da 100755
--- a/scripts/gen-stdlib
+++ b/scripts/gen-stdlib
@@ -616,8 +616,9 @@ encoding_utf8() {
		decode.ha \
		decodetable.ha \
		encode.ha \
		rune.ha
	gen_ssa encoding::utf8 types
		rune.ha \
		stream.ha
	gen_ssa encoding::utf8 io types
}

endian() {
@@ -951,8 +952,8 @@ io() {
			+test/limit.ha \
			+test/stream.ha
	fi
	gen_ssa -plinux io strings errors bytes rt
	gen_ssa -pfreebsd io strings errors bytes rt
	gen_ssa -plinux io errors bytes rt
	gen_ssa -pfreebsd io errors bytes rt
}

linux() {
diff --git a/stdlib.mk b/stdlib.mk
index 9ee5cb08..91a57d1e 100644
--- a/stdlib.mk
+++ b/stdlib.mk
@@ -1299,9 +1299,10 @@ stdlib_encoding_utf8_any_srcs = \
	$(STDLIB)/encoding/utf8/decode.ha \
	$(STDLIB)/encoding/utf8/decodetable.ha \
	$(STDLIB)/encoding/utf8/encode.ha \
	$(STDLIB)/encoding/utf8/rune.ha
	$(STDLIB)/encoding/utf8/rune.ha \
	$(STDLIB)/encoding/utf8/stream.ha

$(HARECACHE)/encoding/utf8/encoding_utf8-any.ssa: $(stdlib_encoding_utf8_any_srcs) $(stdlib_rt) $(stdlib_types_$(PLATFORM))
$(HARECACHE)/encoding/utf8/encoding_utf8-any.ssa: $(stdlib_encoding_utf8_any_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_types_$(PLATFORM))
	@printf 'HAREC \t$@\n'
	@mkdir -p $(HARECACHE)/encoding/utf8
	@$(stdlib_env) $(HAREC) $(HAREFLAGS) -o $@ -Nencoding::utf8 \
@@ -1639,13 +1640,13 @@ stdlib_io_freebsd_srcs = \
	$(STDLIB)/io/util.ha \
	$(STDLIB)/io/zero.ha

$(HARECACHE)/io/io-linux.ssa: $(stdlib_io_linux_srcs) $(stdlib_rt) $(stdlib_strings_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_rt_$(PLATFORM))
$(HARECACHE)/io/io-linux.ssa: $(stdlib_io_linux_srcs) $(stdlib_rt) $(stdlib_errors_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_rt_$(PLATFORM))
	@printf 'HAREC \t$@\n'
	@mkdir -p $(HARECACHE)/io
	@$(stdlib_env) $(HAREC) $(HAREFLAGS) -o $@ -Nio \
		-t$(HARECACHE)/io/io.td $(stdlib_io_linux_srcs)

$(HARECACHE)/io/io-freebsd.ssa: $(stdlib_io_freebsd_srcs) $(stdlib_rt) $(stdlib_strings_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_rt_$(PLATFORM))
$(HARECACHE)/io/io-freebsd.ssa: $(stdlib_io_freebsd_srcs) $(stdlib_rt) $(stdlib_errors_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_rt_$(PLATFORM))
	@printf 'HAREC \t$@\n'
	@mkdir -p $(HARECACHE)/io
	@$(stdlib_env) $(HAREC) $(HAREFLAGS) -o $@ -Nio \
@@ -3723,9 +3724,10 @@ testlib_encoding_utf8_any_srcs = \
	$(STDLIB)/encoding/utf8/decode.ha \
	$(STDLIB)/encoding/utf8/decodetable.ha \
	$(STDLIB)/encoding/utf8/encode.ha \
	$(STDLIB)/encoding/utf8/rune.ha
	$(STDLIB)/encoding/utf8/rune.ha \
	$(STDLIB)/encoding/utf8/stream.ha

$(TESTCACHE)/encoding/utf8/encoding_utf8-any.ssa: $(testlib_encoding_utf8_any_srcs) $(testlib_rt) $(testlib_types_$(PLATFORM))
$(TESTCACHE)/encoding/utf8/encoding_utf8-any.ssa: $(testlib_encoding_utf8_any_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_types_$(PLATFORM))
	@printf 'HAREC \t$@\n'
	@mkdir -p $(TESTCACHE)/encoding/utf8
	@$(testlib_env) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nencoding::utf8 \
@@ -4080,13 +4082,13 @@ testlib_io_freebsd_srcs = \
	$(STDLIB)/io/+test/limit.ha \
	$(STDLIB)/io/+test/stream.ha

$(TESTCACHE)/io/io-linux.ssa: $(testlib_io_linux_srcs) $(testlib_rt) $(testlib_strings_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_rt_$(PLATFORM))
$(TESTCACHE)/io/io-linux.ssa: $(testlib_io_linux_srcs) $(testlib_rt) $(testlib_errors_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_rt_$(PLATFORM))
	@printf 'HAREC \t$@\n'
	@mkdir -p $(TESTCACHE)/io
	@$(testlib_env) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nio \
		-t$(TESTCACHE)/io/io.td $(testlib_io_linux_srcs)

$(TESTCACHE)/io/io-freebsd.ssa: $(testlib_io_freebsd_srcs) $(testlib_rt) $(testlib_strings_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_rt_$(PLATFORM))
$(TESTCACHE)/io/io-freebsd.ssa: $(testlib_io_freebsd_srcs) $(testlib_rt) $(testlib_errors_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_rt_$(PLATFORM))
	@printf 'HAREC \t$@\n'
	@mkdir -p $(TESTCACHE)/io
	@$(testlib_env) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nio \
-- 
2.40.1

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CSNDHG05Z7HR.1FAHTD9O7BIIP@cirno2>
In-Reply-To
<20230516031133.2846-1-autumnull@posteo.net> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m41s

[encoding::utf8: implement streamnext()][0] v2 from [Autumn!][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/41180
[1]: autumnull@posteo.net

✓ #990576 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/990576
✓ #990577 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/990577
Details
Message ID
<CSNHA96F84K2.1EU6ONYKR6VJS@taiga>
In-Reply-To
<20230516031133.2846-1-autumnull@posteo.net> (view parent)
DKIM signature
pass
Download raw message
Better "ionext" since it takes an arbitrary I/O handle (which may or may
not be a stream).
Reply to thread Export thread (mbox)