aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2019-06-10 14:00:51 -0400
committerCalvin Rose <calsrose@gmail.com>2019-06-10 14:00:51 -0400
commit647139cdf960bd89639586c430c3eb1ebca5a0f1 (patch)
treedf70e5e7a34c1bfbaec788db3780531fb022e11b
parentFix defn docstring typo. (diff)
Fix string/check-set.
Also change external unification identifier in match macro to @. This means we can more easily match symbol literals.
-rw-r--r--src/boot/boot.janet6
-rw-r--r--src/core/string.c13
2 files changed, 7 insertions, 12 deletions
diff --git a/src/boot/boot.janet b/src/boot/boot.janet
index ddef6f00..8678c24a 100644
--- a/src/boot/boot.janet
+++ b/src/boot/boot.janet
@@ -1130,8 +1130,8 @@
(put seen pattern true)
~(if (= nil (def ,pattern ,expr)) ,sentinel ,(onmatch))))
- (tuple? pattern)
- (if (and (= (pattern 0) 'quote) (symbol? (pattern 1)))
+ (and (tuple? pattern) (= :parens (tuple/type pattern)))
+ (if (and (= (pattern 0) '@) (symbol? (pattern 1)))
# Unification with external values
~(if (= ,(pattern 1) ,expr) ,(onmatch) ,sentinel)
(match-1
@@ -1139,7 +1139,7 @@
(fn []
~(if (and ,;(tuple/slice pattern 1)) ,(onmatch) ,sentinel)) seen))
- (array? pattern)
+ (indexed? pattern)
(do
(def len (length pattern))
(var i -1)
diff --git a/src/core/string.c b/src/core/string.c
index 2283cfce..c02b2bc7 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -393,25 +393,20 @@ static Janet cfun_string_split(int32_t argc, Janet *argv) {
static Janet cfun_string_checkset(int32_t argc, Janet *argv) {
uint32_t bitset[8] = {0, 0, 0, 0, 0, 0, 0, 0};
- janet_arity(argc, 2, 3);
+ janet_fixarity(argc, 2);
JanetByteView set = janet_getbytes(argv, 0);
JanetByteView str = janet_getbytes(argv, 1);
/* Populate set */
for (int32_t i = 0; i < set.len; i++) {
int index = set.bytes[i] >> 5;
- uint32_t mask = 1 << (set.bytes[i] & 7);
+ uint32_t mask = 1 << (set.bytes[i] & 0x1F);
bitset[index] |= mask;
}
- if (argc == 3) {
- if (janet_getboolean(argv, 2)) {
- for (int i = 0; i < 8; i++)
- bitset[i] = ~bitset[i];
- }
- }
/* Check set */
+ if (str.len == 0) return janet_wrap_false();
for (int32_t i = 0; i < str.len; i++) {
int index = str.bytes[i] >> 5;
- uint32_t mask = 1 << (str.bytes[i] & 7);
+ uint32_t mask = 1 << (str.bytes[i] & 0x1F);
if (!(bitset[index] & mask)) {
return janet_wrap_false();
}