summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/jets/c/bex.c
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-05 21:56:51 +0700
committerpolwex <polwex@sortug.com>2025-10-05 21:56:51 +0700
commitfcedfddf00b3f994e4f4e40332ac7fc192c63244 (patch)
tree51d38e62c7bdfcc5f9a5e9435fe820c93cfc9a3d /vere/pkg/noun/jets/c/bex.c
claude is gud
Diffstat (limited to 'vere/pkg/noun/jets/c/bex.c')
-rw-r--r--vere/pkg/noun/jets/c/bex.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/vere/pkg/noun/jets/c/bex.c b/vere/pkg/noun/jets/c/bex.c
new file mode 100644
index 0000000..497ebfd
--- /dev/null
+++ b/vere/pkg/noun/jets/c/bex.c
@@ -0,0 +1,55 @@
+/// @file
+
+#include "jets/k.h"
+#include "jets/q.h"
+#include "jets/w.h"
+
+#include "noun.h"
+
+u3_noun
+u3qc_bex(u3_atom a)
+{
+ c3_d a_d;
+ u3i_slab sab_u;
+
+ if ( a < 31 ) {
+ return 1U << a;
+ }
+
+ if ( c3y == u3a_is_cat(a) ) {
+ a_d = a;
+ }
+ else {
+ if ( c3n == u3r_safe_chub(a, &a_d) ) {
+ return u3m_bail(c3__fail);
+ }
+
+ // We don't currently support atoms 2GB or larger (fails while
+ // mugging). The extra term of 16 is experimentally determined.
+ if ( a_d >= ((c3_d)1 << (c3_d)34) - 16 ) {
+ u3l_log("bex: overflow");
+ return u3m_bail(c3__fail);
+ }
+ }
+
+ u3i_slab_init(&sab_u, 0, a_d + 1);
+
+ sab_u.buf_w[a_d >> 5] = 1U << (a_d & 31);
+
+ return u3i_slab_moot(&sab_u);
+}
+
+u3_noun
+u3kc_bex(u3_atom a)
+{
+ u3_noun b = u3qc_bex(a);
+ u3z(a);
+ return b;
+}
+
+u3_noun
+u3wc_bex(u3_noun cor)
+{
+ u3_noun a = u3x_at(u3x_sam, cor);
+ return u3qc_bex(u3x_atom(a));
+}