snix/users/sterni/blipqn/blipqn.bqn
sterni 04261c274f refactor(sterni/blipqn): only attempt •CurrentError when it'll work
I've finally figured out what the problem was with •CurrentError:
Passing a namespace as 𝕩 to •CurrentError is not supported as it may
control some kind of special behavior in the future. The right thing to
do seems to check the •Type of 𝕩 and only attempt to use •CurrentError
if it isn't a namespace.

Change-Id: I012009d0f1b913e77d65776ee43062817199baab
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13106
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2025-02-06 11:30:44 +00:00

42 lines
1.5 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

WithFlipdot
t {
bool "i8"
# needs bound checking in wrapper (no c7 in CBQN) and zero byte appended
charp "*i8:c8"
# assume size_t is at least 32bit
size "u32"
# used for struct flipdot *
hdl "*"
}
ffi_flipdot_open "libflipdot.so" •FFI t.hdl"flipdot_open"t.charp"u16"
ffi_flipdot_close "libflipdot.so" •FFI """flipdot_close"t.hdl
ffi_flipdot_send "libflipdot.so" •FFI t.bool"flipdot_send"t.hdl"*u8"t.size
Compact +´( × 2)˘(8)
MakeFlipdot {
hostportwh:
"Hostname must be ASCII" ! ´(@+127)host
"Total pixel count must be divisible by 8" ! 0=8|w×h
hdl FFI_flipdot_open (host@)port
Close {𝕤 FFI_flipdot_close hdl}
shape hw
empty shape0
Send {FFI_flipdot_send hdl() Compact 𝕩}
}
# Inspired by Go's defer. Will execute 𝔽 after 𝔾 (passing 𝕨 and 𝕩 to each)
# even if an error occurs. If an error occurred, _defer_ will cause an
# assertion failure with the error message after executing 𝔾. This looses
# the original error location, though.
_defer_ {
# can't use •CurrentError if 𝕩 is namespace: https://github.com/dzaima/cbqn/commit/d6609df82
sr (1𝔾)(0((6=•Type)•CurrentError,"_defer_: Unknown Error occurred"˙)) 𝕩 𝔽 𝕩 rr!s;
(𝕨𝔽) _𝕣_ (𝕨𝔾) 𝕩
}
WithFlipdot {{𝕩.Close @} _defer_ 𝕏 MakeFlipdot 𝕨}